WorkForScopeCombinations() { var sut = new SutClass(2, 42, 4, null); Check.That(sut).Considering().NonPublic.Fields.And.Public.Properties.IsEqualTo(new SutClass(3, 42, 4, sut)); Check.That(sut).Considering().Public.Fields.And.NonPublic.Properties.IsEqualTo(new SutClass(2, 0, 0, null)); }
public void WorkForIsInstanceOf() { var sut = new SutClass(2, 42); var expected = new { TheProperty = 12 }; Check.That(expected).Considering().Public.Properties.IsInstanceOf <SutClass>(); }
public void WorkForOtherChecks() { var sut = new SutClass(2, 42); Check.That(sut).Considering().Public.Fields.Equals(new SutClass(2, 42)); Check.That(sut).Considering().All.Fields.Not.Equals(new SutClass(2, 42)); }
public void WorkWithExclusions() { var sut = new SutClass(2, 42, 3, null); Check.That(sut).Considering().All.Fields.Excluding("thePrivateField") .IsEqualTo(new SutClass(2, 42, 4, null)); }
public void WorkWithDeepExclusions() { var sut = new SutClass(2, 42, 4, new SutClass(1, 2)); Check.That(sut).Considering().All.Fields .Excluding("ThePrivateProperty.thePrivateField", "ThePrivateProperty.TheField") .IsEqualTo(new SutClass(2, 42, 4, new SutClass(2, 2))); }
public void NotShouldWorkWhenMissingMember() { var sut = new SutClass(2, 42); var expected = new { TheProperty = 12, Test = 11 }; Check.That(sut).Considering().Public.Properties.IsNoInstanceOfType(expected.GetType()); Check.That(expected).Considering().Public.Properties.IsNoInstanceOfType(sut.GetType()); }
public void ShouldWorkForIsInstanceOfType() { var sut = new SutClass(2, 42); var expected = new { TheProperty = 12 }; Check.That(sut).Considering().Public.Properties.IsInstanceOfType(expected.GetType()); Check.That(expected).Considering().Public.Properties.IsInstanceOfType(sut.GetType()); }
WorkForIsNotNull() { var sut = new SutClass(5, 7); Check.That(sut).Considering().Public.Properties.IsNotNull(); Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.Not.IsNotNull(); }). IsAFaillingCheckWithMessage("", "The checked value has a non null member, whereas it should not.", "The checked value:", "\t[{ TheProperty = 7 }]"); Check.ThatCode(() => { Check.That(sut).Considering().NonPublic.Properties.IsNotNull(); }) .IsAFaillingCheckWithMessage("", "The checked value's property 'ThePrivateProperty' is null, whereas it should not."); }
WorkForHasSameValue() { var sut = new SutClass(12, 13); Check.That(sut).Considering().Public.Properties.HasSameValueAs(new SutClass(11, 13)); Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.HasSameValueAs(new SutClass(11, 12)); }).IsAFaillingCheckWithMessage("", "The checked value is different from the expected one.", "The checked value:", "\t[{ TheProperty = 13 }] of type: [NFluent.Helpers.ReflectionWrapper]", "The expected value: equals to (using operator==)", "\t[NFluent.Tests.ConsideringShould+SutClass] of type: [NFluent.Tests.ConsideringShould+SutClass]"); }
FailIfNegatedOf() { var sut = new SutClass(12, 13); Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.Not.IsOneOf(new { TheProperty = 12 }, new { TheProperty = 13 }); }).IsAFailingCheckWithMessage("", "The checked value is equal to one of the given value(s) whereas it should not.", "The checked value:", "\t[{ TheProperty = 13 }]", "The expected object: none of these", "\t{{ TheProperty = 12 }, { TheProperty = 13 }} (2 items)"); }
public void FailForDifferentPublicFields() { var sut = new SutClass(2, 42); Check.ThatCode(() => Check.That(sut).Considering().Public.Fields.And.All.Properties.IsEqualTo(new SutClass(3, 42))) .IsAFailingCheckWithMessage("", "The checked value's field 'TheField' does not have the expected value.", "The checked value's field 'TheField':", "\t[2]", "The expected value's field 'TheField':", "\t[3]"); }
FailIfNoneOf() { var sut = new SutClass(12, 13); Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.IsOneOf(new { TheProperty = 12 }, new { TheProperty = 14 }); }).IsAFaillingCheckWithMessage("", "The checked value is equal to none of the expected value(s) whereas it should.", "The checked value:", "\t[{ TheProperty = 13 }]", "The expected value(s): one of", "\t[{ TheProperty = 12 }, { TheProperty = 14 }] (2 items)"); }
public void FailForDifferentNonPublicProperties() { var sut = new SutClass(2, 42, 1, 3); Check.ThatCode(() => Check.That(sut).Considering().NonPublic.Properties.IsEqualTo(new SutClass(2, 43, 1, null))) .IsAFailingCheckWithMessage("", "The checked value's property 'ThePrivateProperty' does not have the expected value.", "The checked value's property 'ThePrivateProperty':", "\t[3] of type: [int]", "The expected value's property 'ThePrivateProperty':", "\t[null] of type: [object]"); }
public void FailForDifferentPublicProperties() { var sut = new SutClass(2, 42); Check.ThatCode(() => Check.That(sut).Considering().Public.Properties.IsEqualTo(new SutClass(2, 43))) .IsAFaillingCheckWithMessage("", "The checked value's property 'TheProperty' does not have the expected value.", "The checked value's property 'TheProperty':", "\t[42]", "The expected value's property 'TheProperty':", "\t[43]"); }
public void FailWhenMissingMember() { var sut = new SutClass(2, 42); var expected = new { TheProperty = 12, Test = 11 }; Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.IsInstanceOfType(expected.GetType()); }).IsAFaillingCheckWithMessage("", "The expected one is absent from the checked value's property 'Test'.", "The expected value's property 'Test':", "\t[null]"); Check.ThatCode(() => { Check.That(expected).Considering().Public.Properties.IsInstanceOfType(sut.GetType()); }).IsAFaillingCheckWithMessage("", "The checked value's property 'Test' is absent from the expected one.", "The checked value's property 'Test':", "\t[11]"); }
public void FailWhenDifferentType() { var sut = new SutClass(2, 42); var expected = new { TheProperty = "toto" }; Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.IsInstanceOfType(expected.GetType()); }).IsAFailingCheckWithMessage("", "The checked value's property 'TheProperty' is of a different type than the expected one.", "The checked value's property 'TheProperty':", "\t[42] of type: [int]", "The expected value's property 'TheProperty':", "\tan instance of [string]"); }
public void FailForAllMembers() { var sut = new SutClass(2, 42, 4, null); Check.ThatCode(() => { Check.That(sut).Considering().All.Fields.And.All.Properties .IsEqualTo(new SutClass(2, 42, 4, new object())); }).IsAFailingCheckWithMessage("", "The checked value's property 'ThePrivateProperty' does not have the expected value.", "The checked value's property 'ThePrivateProperty':", "\t[null]", "The expected value's property 'ThePrivateProperty':", "\t[System.Object]"); }
WorkForHasSameValue() { var sut = new SutClass(12, 13); Check.That(sut).Considering().Public.Properties.HasSameValueAs(new SutClass(11, 13)); Check.ThatCode(() => { Check.That(sut).Considering().Public.Properties.HasSameValueAs(new SutClass(11, 12)); }).IsAFailingCheckWithMessage("", "The checked value's property 'TheProperty' does not have the expected value.", "The checked value's property 'TheProperty':", "\t[13]", "The expected value's property 'TheProperty':", "\t[12]"); }
public void NotShouldFailWhenSame() { var sut = new SutClass(2, 42); var expected = new { TheProperty = 12 }; Check.ThatCode(() => { Check.That(sut).Considering().Properties.IsNoInstanceOfType(expected.GetType()); }).IsAFailingCheckWithMessage( "", Criteria.FromRegEx("The checked value is an instance of \\[<>f__AnonymousType\\d<int>\\] whereas it must not\\."), "The checked value:", "\t[{ TheProperty = 42 }] of type: [NFluent.Helpers.ReflectionWrapper]", "The expected value: different from", Criteria.FromRegEx("\tan instance of \\[<>f__AnonymousType\\d<int>\\]")); }
public void FailOnNullForAllMembers() { var sut = new SutClass(2, 42, 4, null); var expected = new SutClass(2, 42, 4, sut); Check.ThatCode(() => Check.That(sut).Considering().All.Fields.And.All.Properties.IsEqualTo(expected)) .IsAFailingCheckWithMessage("", "The checked value's property 'ThePrivateProperty' does not have the expected value.", "The checked value's property 'ThePrivateProperty':", "\t[null] of type: [object]", "The expected value's property 'ThePrivateProperty':", "\t[NFluent.Tests.ConsideringShould+SutClass] of type: [NFluent.Tests.ConsideringShould+SutClass]"); Check.ThatCode(() => Check.That(expected).Considering().All.Fields.And.All.Properties.IsEqualTo(sut)) .IsAFailingCheckWithMessage("", "The checked value's property 'ThePrivateProperty' does not have the expected value.", "The checked value's property 'ThePrivateProperty':", "\t[NFluent.Tests.ConsideringShould+SutClass] of type: [NFluent.Tests.ConsideringShould+SutClass]", "The expected value's property 'ThePrivateProperty':", "\t[null] of type: [object]"); }
public void WorkForPrivateFields() { var sut = new SutClass(2, 42, 4, null); Check.That(sut).Considering().NonPublic.Fields.IsEqualTo(new SutClass(2, 42, 4, null)); Check.ThatCode(() => { Check.That(sut).Considering().NonPublic.Fields.IsEqualTo(new SutClass(2, 42, 4, sut)); }) .IsAFailingCheckWithMessage("", "The checked value's autoproperty 'ThePrivateProperty' (field '<ThePrivateProperty>k__BackingField') does not have the expected value.", "The checked value's autoproperty 'ThePrivateProperty' (field '<ThePrivateProperty>k__BackingField'):", "\t[null] of type: [object]", "The expected value's autoproperty 'ThePrivateProperty' (field '<ThePrivateProperty>k__BackingField'):", "\t[NFluent.Tests.ConsideringShould+SutClass] of type: [NFluent.Tests.ConsideringShould+SutClass]"); Check.ThatCode(() => { Check.That(new SutClass(2, 42, 4, sut)).Considering().NonPublic.Fields.IsEqualTo(sut); }) .IsAFailingCheckWithMessage("", "The checked value's autoproperty 'ThePrivateProperty' (field '<ThePrivateProperty>k__BackingField') does not have the expected value.", "The checked value's autoproperty 'ThePrivateProperty' (field '<ThePrivateProperty>k__BackingField'):", "\t[NFluent.Tests.ConsideringShould+SutClass] of type: [NFluent.Tests.ConsideringShould+SutClass]", "The expected value's autoproperty 'ThePrivateProperty' (field '<ThePrivateProperty>k__BackingField'):", "\t[null] of type: [object]"); }
public void ShouldWorkForIdenticalPublicFieldsAndDifferentProperties() { var sut = new SutClass(2, 42); Check.That(sut).Considering().Public.Fields.IsEqualTo(new SutClass(2, 43)); }
public void WorkForIdenticalPublicFields() { var sut = new SutClass(2, 42); Check.That(sut).Considering().Public.Fields.IsEqualTo(new SutClass(2, 42)); }
WorkForIsOneOf() { var sut = new SutClass(12, 13); Check.That(sut).Considering().Public.Properties.IsOneOf(new { TheProperty = 12 }, new { TheProperty = 13 }); }
WorkForHasNotSameValue() { var sut = new SutClass(12, 13); Check.That(sut).Considering().Public.Properties.HasDifferentValueThan(new SutClass(11, 12)); }
public void SupportDuplicateCriterias() { var sut = new SutClass(2, 42, 4, null); Check.That(sut).Considering().All.Fields.And.All.Fields.IsEqualTo(new SutClass(2, 42, 4, null)); }
public void WorkWhenDoubled() { var sut = new SutClass(2, 42, 4, null); Check.That(sut).Considering().All.Fields.And.All.Properties.Considering().All.Fields.And.All.Properties.IsEqualTo(new SutClass(2, 42, 4, null)); }
public void WorkForIdenticalPublicProperties() { var sut = new SutClass(2, 42); Check.That(sut).Considering().Public.Properties.IsEqualTo(new SutClass(1, 42)); }
public void WorkForNull() { var sut = new SutClass(2, 42); Check.That((object)null).Considering().Public.Fields.Equals(null); }