From 3e1089cbb2492c65d4e7969eff774709943e4f87 Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Tue, 9 Jul 2024 22:38:40 +0100 Subject: [PATCH] Added tests for update email request --- .../Requests/UpdateEmailRequestTests.cs | 74 ++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.cs index 18a8ae85..ec08e031 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.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 UpdateEmailRequestTests @@ -32,4 +33,75 @@ public void Properties_CanBeSet(string email, string password) Assert.Equal(email, request.Email); Assert.Equal(password, request.Password); } + + [Theory] + [InlineData("pingu@example.com", "Password")] + [InlineData("something@anotherthing.somethingelse", "£$%^&*()")] + public void IsValid_WithValidData_ReturnsTrue(string email, string password) + { + // Arrange + var request = new UpdateEmailRequest + { + Email = email, + Password = password + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData("not an email", "Password")] + [InlineData("", "Password")] + [InlineData("pingu@example.com", "short")] + [InlineData("pingu@example.com", "")] + public void IsValid_WithInvalidData_ReturnsFalse(string email, string password) + { + // Arrange + var request = new UpdateEmailRequest + { + Email = email, + Password = password + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateEmailRequest + { + Email = "not an email", + Password = "short" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateEmailRequest + { + Email = "not an email", + Password = "short" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } }