public void ShouldFailWhenFieldDoesNotMatch() { var subject = new FakeObject { Id = 5, TitleField = "Mr", Name = "Bob", }; var expected = new FakeObject { Id = 5, TitleField = "Sir", Name = "Bob", }; Verify.ShouldFail(() => subject.ShouldBeEquivalentTo(expected, "Some additional context"), errorWithSource: @"Comparing object equivalence, at path: subject [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] TitleField [System.String] Expected value to be ""Sir"" but was ""Mr"" Additional Info: Some additional context", errorWithoutSource: @"Comparing object equivalence, at path: <root> [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] TitleField [System.String] Expected value to be ""Sir"" but was ""Mr"" Additional Info: Some additional context"); }
public void ShouldFailWhenIdDoesNotMatch() { var subject = new FakeObject { Id = 5, Name = "Bob" }; var expected = new FakeObject { Id = 6, Name = "Bob" }; Verify.ShouldFail(() => subject.ShouldBeEquivalentTo(expected, "Some additional context"), errorWithSource: @"Comparing object equivalence, at path: subject [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Id [System.Int32] Expected value to be 6 but was 5 Additional Info: Some additional context", errorWithoutSource: @"Comparing object equivalence, at path: <root> [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Id [System.Int32] Expected value to be 6 but was 5 Additional Info: Some additional context"); }
public void ShouldPassWhenObjectContainsInfiniteLoop() { var subject = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" } }; subject.Child = subject; var expected = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" } }; expected.Child = expected; subject.ShouldBeEquivalentTo(expected); }
public void ShouldPassWhenObjectIsComplex() { var subject = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" }, TitleField = "Mr", Child = new FakeObject { Id = 6, Name = "Sally", Adjectives = new[] { "beautiful", "intelligent" }, Colors = new[] { "purple", "orange" } } }; var expected = new FakeObject { Id = 5, TitleField = "Mr", Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" }, Child = new FakeObject { Id = 6, Name = "Sally", Adjectives = new[] { "beautiful", "intelligent" }, Colors = new[] { "purple", "orange" } } }; subject.ShouldBeEquivalentTo(expected); }
public void ShouldFailWhenObjectIsComplex() { var subject = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" }, Child = new FakeObject { Id = 6, Name = "Sally", Adjectives = new[] { "ugly", "intelligent" }, Colors = new[] { "purple", "orange" } } }; var expected = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" }, Child = new FakeObject { Id = 6, Name = "Sally", Adjectives = new[] { "beautiful", "intelligent" }, Colors = new[] { "purple", "orange" } } }; Verify.ShouldFail(() => subject.ShouldBeEquivalentTo(expected, "Some additional context"), errorWithSource: @"Comparing object equivalence, at path: subject [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Child [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Adjectives [System.String[]] Element beautiful not found Expected value to be [""beautiful"", ""intelligent""] but was [""ugly"", ""intelligent""] Additional Info: Some additional context", errorWithoutSource: @"Comparing object equivalence, at path: <root> [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Child [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Adjectives [System.String[]] Element beautiful not found Expected value to be [""beautiful"", ""intelligent""] but was [""ugly"", ""intelligent""] Additional Info: Some additional context"); }
public void ShouldFailWhenObjectContainsInfiniteLoop() { var subject = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" }, Child = new FakeObject { Id = 6, Name = "Sally", Adjectives = new[] { "beautiful", "intelligent" }, Colors = new[] { "purple", "orange" } } }; subject.Child.Child = subject; var expected = new FakeObject { Id = 5, Name = "Bob", Adjectives = new[] { "funny", "wise" }, Colors = new[] { "red", "blue" }, Child = new FakeObject { Id = 6, Name = "Sally", Adjectives = new[] { "beautiful", "dumb" }, Colors = new[] { "purple", "orange" } } }; expected.Child.Child = expected; Verify.ShouldFail(() => subject.ShouldBeEquivalentTo(expected, "Some additional context"), errorWithSource: @"Comparing object equivalence, at path: subject [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Child [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Adjectives [System.String[]] Element [1] [System.String] Expected value to be ""dumb"" but was ""intelligent"" Additional Info: Some additional context", errorWithoutSource: @"Comparing object equivalence, at path: <root> [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Child [Shouldly.Tests.ShouldBeEquivalentTo.FakeObject] Adjectives [System.String[]] Element [1] [System.String] Expected value to be ""dumb"" but was ""intelligent"" Additional Info: Some additional context"); }