From 2ee6a84b9453f562d1f7ebd8e2e992f2d8cadd46 Mon Sep 17 00:00:00 2001 From: Ratan Sunder Parai Date: Wed, 13 Apr 2022 02:32:13 +0600 Subject: [PATCH 1/2] add snapshot testing --- .gitignore | 3 +++ ...pplicationShouldSuccessWithValidInput.verified.txt | 6 ++++++ .../Domain/EnrollmentAggregateTests.cs | 11 +++++------ .../Enrolling.UnitTests/Enrolling.UnitTests.csproj | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt diff --git a/.gitignore b/.gitignore index c414e564..75a99b78 100644 --- a/.gitignore +++ b/.gitignore @@ -338,3 +338,6 @@ ASALocalRun/ # Test Results /tests-results + +# Snapshot testing +**/*.received.txt \ No newline at end of file diff --git a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt b/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt new file mode 100644 index 00000000..9698c17f --- /dev/null +++ b/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt @@ -0,0 +1,6 @@ +{ + Id: Guid_3, + Name: John Doe, + EmailAddress: john@example.com, + MobileNumber: 01771999999 +} \ No newline at end of file diff --git a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs b/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs index 011f281f..abd0f40f 100644 --- a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs +++ b/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs @@ -1,25 +1,24 @@ using System; +using System.Threading.Tasks; using Enrolling.UnitTests.Builders; using OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate; +using VerifyXunit; using Xunit; namespace Enrolling.UnitTests.Domain { + [UsesVerify] public class EnrollmentAggregateTests { [Fact] - public void NewApplicationShouldSuccessWithValidInput() + public Task NewApplicationShouldSuccessWithValidInput() { var dto = new EnrollmentDtoBuilder() .WithDefaults() .Build(); var enrollment = Enrollment.CreateNew(dto.Name!, dto.Email!, dto.Mobile!); - - Assert.NotNull(enrollment); - Assert.Equal(dto.Name, enrollment.Name); - Assert.Equal(dto.Email, enrollment.EmailAddress); - Assert.Equal(dto.Mobile, enrollment.MobileNumber); + return Verifier.Verify(enrollment); } [Fact] diff --git a/src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj b/src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj index 714d1291..4b0edad4 100644 --- a/src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj +++ b/src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj @@ -6,6 +6,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive From 4d97a377d8ff26e3304e7f4c8d96f15e06f7e34b Mon Sep 17 00:00:00 2001 From: Ratan Sunder Parai Date: Wed, 13 Apr 2022 02:42:22 +0600 Subject: [PATCH 2/2] store snapshots inside folder --- .../Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs | 2 +- ...Tests.NewApplicationShouldSuccessWithValidInput.verified.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Services/Enrolling/Enrolling.UnitTests/Domain/{ => Snapshots}/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt (86%) diff --git a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs b/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs index abd0f40f..e3595662 100644 --- a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs +++ b/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs @@ -18,7 +18,7 @@ public Task NewApplicationShouldSuccessWithValidInput() .Build(); var enrollment = Enrollment.CreateNew(dto.Name!, dto.Email!, dto.Mobile!); - return Verifier.Verify(enrollment); + return Verifier.Verify(enrollment).UseDirectory("Snapshots"); } [Fact] diff --git a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt b/src/Services/Enrolling/Enrolling.UnitTests/Domain/Snapshots/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt similarity index 86% rename from src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt rename to src/Services/Enrolling/Enrolling.UnitTests/Domain/Snapshots/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt index 9698c17f..0887c883 100644 --- a/src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt +++ b/src/Services/Enrolling/Enrolling.UnitTests/Domain/Snapshots/EnrollmentAggregateTests.NewApplicationShouldSuccessWithValidInput.verified.txt @@ -1,5 +1,5 @@ { - Id: Guid_3, + Id: Guid_1, Name: John Doe, EmailAddress: john@example.com, MobileNumber: 01771999999