From abaab4eb85d29efa31b5fb9081a73b78bd97c23d Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Tue, 9 Jul 2024 22:42:36 +0100 Subject: [PATCH] Added tests to UpdateNameRequest --- .../Requests/UpdateNameRequestTests.cs | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs index 04b20ecf..0ad91c61 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs @@ -1,4 +1,5 @@ -using PinguApps.Appwrite.Shared.Requests; +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests; namespace PinguApps.Appwrite.Shared.Tests.Requests; public class UpdateNameRequestTests @@ -28,4 +29,68 @@ public void Properties_CanBeSet(string name) // Assert Assert.Equal(name, request.Name); } + + [Theory] + [InlineData("John")] + [InlineData("John Smith")] + public void IsValid_WithValidData_ReturnsTrue(string name) + { + // Arrange + var request = new UpdateNameRequest + { + Name = name + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData("")] + public void IsValid_WithInvalidData_ReturnsFalse(string name) + { + // Arrange + var request = new UpdateNameRequest + { + Name = name + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateNameRequest + { + Name = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateNameRequest + { + Name = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } }