public void Match_AssertSeveralFields_SuccessfulMatch() { // arrange TestChild testChild = TestDataBuilder.TestChildJames().Build(); TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton() .AddChild(testChild) .Build(); testPerson.Id = Guid.NewGuid(); testPerson.CreationDate = DateTime.UtcNow; testPerson.Address.StreetNumber = -58; testPerson.Address.Country = null; testPerson.Relatives[0].Address.Plz = null; // act & assert Snapshot.Match <TestPerson>(testPerson, matchOption => matchOption .Assert(fieldOption => Assert.NotEqual(Guid.Empty, fieldOption.Field <Guid>("Id"))) .Assert(fieldOption => Assert.NotEqual(DateTime.UtcNow.AddSeconds(5), fieldOption.Field <DateTime>("CreationDate"))) .Assert(fieldOption => Assert.Equal(-58, fieldOption.Field <int>("Address.StreetNumber"))) .Assert(fieldOption => testChild.Should().BeEquivalentTo(fieldOption.Field <TestChild>("Children[3]"))) .Assert(fieldOption => Assert.Null(fieldOption.Field <TestCountry>("Address.Country"))) .Assert(fieldOption => Assert.Null(fieldOption.Field <TestCountry>("Relatives[0].Address.Plz")))); }
public void Match_LargeOverallTest_SuccessfulMatch() { // arrange string snapshotName = nameof(SnapshotTests) + "." + nameof(Match_LargeOverallTest_SuccessfulMatch); TestChild testChild = TestDataBuilder.TestChildJames().Build(); TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton() .AddChild(testChild) .Build(); testPerson.Id = Guid.NewGuid(); testPerson.CreationDate = DateTime.UtcNow; testPerson.Address.StreetNumber = -58; testPerson.Address.Country = null; testPerson.Relatives[0].Address.Plz = null; // act & assert Snapshot.Match(testPerson, snapshotName, matchOption => matchOption .Assert(option => Assert.NotEqual(Guid.Empty, option.Field <Guid>("Id"))) .IgnoreField <DateTime>("CreationDate") .Assert(option => Assert.Equal(-58, option.Field <int>("Address.StreetNumber"))) .Assert(option => testChild.Should().BeEquivalentTo(option.Field <TestChild>("Children[3]"))) .IgnoreField <TestCountry>("Address.Country") .Assert(option => Assert.Null(option.Field <TestCountry>("Relatives[0].Address.Plz")))); }