public void TestAssertAllWhenPropertyMismatchesCustomConstraint() { var testee = CreateTestee(); var source = new SampleSource { Name = "Job2", Progress = 2, Data = null, Items = null }; var destination = new SampleDestination { FullName = source.Name, Remaining = source.Progress, Info = null, Datas = null }; Assert.That( () => testee.AssertAll(source, destination), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring(PercentageValuesMismatchMessage)); }
public void TestAssertAllWhenInnerComplexPropertyMismatches() { var testee = CreateTestee(); var source = new SampleSource { Name = "Job4", Progress = 4, Data = new SampleInnerSource { Text = "Text" }, Items = null }; var destination = new SampleDestination { FullName = source.Name, Remaining = 100 - source.Progress, Info = new SampleInnerDestination { Message = "Message" }, Datas = null }; Assert.That( () => testee.AssertAll(source, destination), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleInnerSource.Text)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleInnerDestination.Message)}")); }
public void TestAssertAllWhenObjectsMatch() { var testee = CreateTestee(); var source = new SampleSource { Name = "Job1", Progress = 1, Data = new SampleInnerSource { Text = "Hello World!" }, Items = new[] { new SampleSourceItem { Text = "Item text" } } }; var destination = new SampleDestination { FullName = source.Name, Remaining = 100 - source.Progress, Info = new SampleInnerDestination { Message = source.Data.Text }, Datas = new[] { new SampleDestinationItem { TextData = source.Items[0].Text } } }; Assert.That(() => testee.AssertAll(source, destination), Throws.Nothing); }
public void TestAssertAllWhenPropertyValueIsNotEqual() { var testee = CreateTestee(); var source = new SampleSource { Name = "Job3", Progress = 3, Data = null, Items = null }; var destination = new SampleDestination { FullName = "System" + source.Name, Remaining = 100 - source.Progress, Info = null, Datas = null }; Assert.That( () => testee.AssertAll(source, destination), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleSource.Name)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleDestination.FullName)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring("The values are expected to be equal:")); }
public void TestAssertAllWhenRegisteredWithConstantMessageAndPropertyMismatchesCustomConstraint() { const string RemainingPropertyMismatchMessage = @"The remaining value must be the negative progress."; var testee = MappingAccordances .From <SampleSource> .To <SampleDestination>() .Register( source => source.Progress, destination => destination.Remaining, expectedValue => Is.EqualTo(-expectedValue), RemainingPropertyMismatchMessage); var sampleSource = new SampleSource { Progress = 17 }; var sampleDestination = new SampleDestination { Remaining = sampleSource.Progress }; Assert.That( () => testee.AssertAll(sampleSource, sampleDestination), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring(RemainingPropertyMismatchMessage)); }
public void TestAssertAllWhenInnerListPropertyMismatchesByCount() { var testee = CreateTestee(); var source = new SampleSource { Name = "Job6", Progress = 6, Data = null, Items = new[] { new SampleSourceItem { Text = "ItemText5" }, new SampleSourceItem { Text = "ItemText5-A" } } }; var destination = new SampleDestination { FullName = source.Name, Remaining = 100 - source.Progress, Info = null, Datas = new[] { new SampleDestinationItem { TextData = source.Items[0].Text } } }; Assert.That( () => testee.AssertAll(source, destination), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleSource.Items)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleDestination.Datas)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring("The source and destination must have the same item count")); }
public void TestAssertAllWithRegisterAllMatchingProperties() { var testeeImplicitCaseSensitive = MappingAccordances.From <SampleSource> .To <SampleDestination>().RegisterAllMatchingProperties(); var testeeExplicitCaseSensitive = MappingAccordances.From <SampleSource> .To <SampleDestination>().RegisterAllMatchingProperties(false); var testeeCaseInsensitive = MappingAccordances.From <SampleSource> .To <SampleDestination>().RegisterAllMatchingProperties(true); Assert.That(testeeImplicitCaseSensitive.Count, Is.EqualTo(1)); Assert.That(testeeExplicitCaseSensitive.Count, Is.EqualTo(1)); Assert.That(testeeCaseInsensitive.Count, Is.EqualTo(2)); var sampleSource = new SampleSource { Name = "John", MatchingName = "matching", MatchingTextCaseInsensitive = "Text" }; var sampleDestination1 = new SampleDestination { FullName = "FullName", MatchingName = sampleSource.MatchingName, matchingtextcaseinsensitive = sampleSource.MatchingTextCaseInsensitive }; Assert.That(() => testeeImplicitCaseSensitive.AssertAll(sampleSource, sampleDestination1), Throws.Nothing); Assert.That(() => testeeExplicitCaseSensitive.AssertAll(sampleSource, sampleDestination1), Throws.Nothing); Assert.That(() => testeeCaseInsensitive.AssertAll(sampleSource, sampleDestination1), Throws.Nothing); var sampleDestination2 = new SampleDestination { FullName = sampleSource.Name, MatchingName = "no match", matchingtextcaseinsensitive = sampleSource.MatchingTextCaseInsensitive }; const string SourcePrefix = "source."; const string DestinationPrefix = "destination."; Assert.That( () => testeeImplicitCaseSensitive.AssertAll(sampleSource, sampleDestination2), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingName)) .And .Property(nameof(AssertionException.Message)) .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.MatchingName))); Assert.That( () => testeeExplicitCaseSensitive.AssertAll(sampleSource, sampleDestination2), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingName)) .And .Property(nameof(AssertionException.Message)) .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.MatchingName))); Assert.That( () => testeeCaseInsensitive.AssertAll(sampleSource, sampleDestination2), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingName)) .And .Property(nameof(AssertionException.Message)) .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.MatchingName))); var sampleDestination3 = new SampleDestination { FullName = sampleSource.Name, MatchingName = sampleSource.MatchingName, matchingtextcaseinsensitive = "nothing" }; Assert.That(() => testeeImplicitCaseSensitive.AssertAll(sampleSource, sampleDestination3), Throws.Nothing); Assert.That(() => testeeExplicitCaseSensitive.AssertAll(sampleSource, sampleDestination3), Throws.Nothing); Assert.That( () => testeeCaseInsensitive.AssertAll(sampleSource, sampleDestination3), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingTextCaseInsensitive)) .And .Property(nameof(AssertionException.Message)) .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.matchingtextcaseinsensitive))); }
public void TestAssertAllWhenInnerListPropertyMismatchesByNullReferenceCheck() { const string ExpectedMessagePart = "Both the source and destination values must be either null or non-null"; var testee = CreateTestee(); var source1 = new SampleSource { Name = "Job6A", Progress = 6, Data = null, Items = new[] { new SampleSourceItem { Text = "Text6" } } }; var destination1 = new SampleDestination { FullName = source1.Name, Remaining = 100 - source1.Progress, Info = null, Datas = null }; Assert.That( () => testee.AssertAll(source1, destination1), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleSource.Items)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleDestination.Datas)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring(ExpectedMessagePart)); var source2 = new SampleSource { Name = "Job6B", Progress = 6, Data = null, Items = null }; var destination2 = new SampleDestination { FullName = source2.Name, Remaining = 100 - source2.Progress, Info = null, Datas = new[] { new SampleDestinationItem { TextData = "Text6" } } }; Assert.That( () => testee.AssertAll(source2, destination2), Throws.TypeOf <AssertionException>() .With .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleSource.Items)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring($".{nameof(SampleDestination.Datas)}") .And .Property(nameof(AssertionException.Message)) .ContainsSubstring(ExpectedMessagePart)); }