Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public void WorkForIsInstanceOf()
        {
            var sut      = new SutClass(2, 42);
            var expected = new { TheProperty = 12 };

            Check.That(expected).Considering().Public.Properties.IsInstanceOf <SutClass>();
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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)));
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        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());
        }
Ejemplo n.º 8
0
        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.");
        }
Ejemplo n.º 9
0
        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]");
        }
Ejemplo n.º 10
0
        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)");
        }
Ejemplo n.º 11
0
        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]");
        }
Ejemplo n.º 12
0
        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)");
        }
Ejemplo n.º 13
0
        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]");
        }
Ejemplo n.º 14
0
        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]");
        }
Ejemplo n.º 15
0
        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]");
        }
Ejemplo n.º 16
0
        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]");
        }
Ejemplo n.º 17
0
        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]");
        }
Ejemplo n.º 18
0
        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]");
        }
Ejemplo n.º 19
0
        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>\\]"));
        }
Ejemplo n.º 20
0
        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]");
        }
Ejemplo n.º 21
0
        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]");
        }
Ejemplo n.º 22
0
        public void ShouldWorkForIdenticalPublicFieldsAndDifferentProperties()
        {
            var sut = new SutClass(2, 42);

            Check.That(sut).Considering().Public.Fields.IsEqualTo(new SutClass(2, 43));
        }
Ejemplo n.º 23
0
        public void WorkForIdenticalPublicFields()
        {
            var sut = new SutClass(2, 42);

            Check.That(sut).Considering().Public.Fields.IsEqualTo(new SutClass(2, 42));
        }
Ejemplo n.º 24
0
        WorkForIsOneOf()
        {
            var sut = new SutClass(12, 13);

            Check.That(sut).Considering().Public.Properties.IsOneOf(new { TheProperty = 12 }, new { TheProperty = 13 });
        }
Ejemplo n.º 25
0
        WorkForHasNotSameValue()
        {
            var sut = new SutClass(12, 13);

            Check.That(sut).Considering().Public.Properties.HasDifferentValueThan(new SutClass(11, 12));
        }
Ejemplo n.º 26
0
        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));
        }
Ejemplo n.º 27
0
        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));
        }
Ejemplo n.º 28
0
        public void WorkForIdenticalPublicProperties()
        {
            var sut = new SutClass(2, 42);

            Check.That(sut).Considering().Public.Properties.IsEqualTo(new SutClass(1, 42));
        }
Ejemplo n.º 29
0
        public void WorkForNull()
        {
            var sut = new SutClass(2, 42);

            Check.That((object)null).Considering().Public.Fields.Equals(null);
        }