Exemplo n.º 1
0
        public void ShouldContain_WithPredicate_UsingObjectsShouldDisplayMeaningfulMessage()
        {
            var vampires = new[]
            {
                new Vampire {
                    BitesTaken = 1
                },
                new Vampire {
                    BitesTaken = 2
                },
                new Vampire {
                    BitesTaken = 3
                },
                new Vampire {
                    BitesTaken = 4
                },
                new Vampire {
                    BitesTaken = 5
                },
                new Vampire {
                    BitesTaken = 6
                },
            };

            Should.Error(() =>
                         vampires.ShouldContain(x => x.BitesTaken > 7),
                         "vampires should contain an element satisfying the condition (x.BitesTaken > 7) but does not");
        }
Exemplo n.º 2
0
 public void ShouldNotThrow_IfCallThrows_ShouldShowException()
 {
     Should.Error(
         () => Shouldly.Should.NotThrow(() => { throw new IndexOutOfRangeException(); }),
         "() => Shouldly.Should not throw System.IndexOutOfRangeException but does"
         );
 }
Exemplo n.º 3
0
        public void ShouldBeSameAs()
        {
            var aReferenceType       = new object();
            var anotherReferenceType = new object();

            Should.Error(
                () => aReferenceType.ShouldBeSameAs(anotherReferenceType),
                "() => aReferenceType should be same as System.Object but was System.Object"
                );

            var list = new List <int> {
                1, 2, 3
            };
            var equalListWithDifferentRef = new List <int> {
                1, 2, 3
            };

            Should.Error(
                () => list.ShouldBeSameAs(equalListWithDifferentRef),
                "() => list should be same as [1, 2, 3] but was [1, 2, 3] difference [1, 2, 3]"
                );

            const int boxedInt = 1;

            Should.Error(
                () => boxedInt.ShouldBeSameAs(boxedInt),
                "() => boxedInt should be same as 1 but was 1"
                );
        }
Exemplo n.º 4
0
 public void CanGenerate()
 {
     Should.Error(
         () => 2.ShouldBe(1),
         "() => 2 should be 1 but was 2"
         );
 }
Exemplo n.º 5
0
 public void ShouldlyMessage_PassedObjectsWhichCannotCompared_ShouldNotShowDifferences()
 {
     Should.Error(
         () => new UncomparableClass("ted").ShouldBe(new UncomparableClass("bob")),
         "() => new UncomparableClass(\"ted\") should be bob but was ted"
         );
 }
Exemplo n.º 6
0
        public void ShouldBe_Action()
        {
            Action a = () => 1.ShouldBe(2);

            Should.Error(a,
                         "Action a = () => 1 should be 2 but was 1");
        }
Exemplo n.º 7
0
        public void ShouldBe_Expression()
        {
            Expression <Action> lambda = () => 1.ShouldBe(2);

            Should.Error(lambda.Compile(),
                         "The provided expression should be 2 but was 1");
        }
Exemplo n.º 8
0
 public void CanGenerateErrorMessage()
 {
     Should.Error(
         () => "expected".ShouldBe("actual"),
         "() => \"expected\" should be \"actual\" but was \"expected\""
         );
 }
Exemplo n.º 9
0
 public void ShouldlyMessage_PassedCollectionsWhichCanBeCompared_ShouldShowDifferences()
 {
     Should.Error(
         () => (new[] { 1, 2, 3 }).ShouldBe(new[] { 2, 2, 3 }),
         "() => (new[] { 1, 2, 3 }) should be [2, 2, 3] but was [1, 2, 3] difference [*1*, 2, 3]"
         );
 }
Exemplo n.º 10
0
        public void ShouldNotBeEmpty_WhenEmpty_ShouldError()
        {
            var objects = new object[0];

            Should.Error(() =>
                         objects.ShouldNotBeEmpty(),
                         "objects should not be empty but was");
        }
Exemplo n.º 11
0
        public void ShouldBe_ShouldNotThrowWhenCalledOnANullEnumerableReference()
        {
            IEnumerable <int> something = null;

            Should.Error(
                () => something.ShouldBe(new[] { 1, 2, 3 }),
                "() => something should be [1, 2, 3] but was null");
        }
Exemplo n.º 12
0
        public void ShouldNotBeEmpty_WhenNull_ShouldError()
        {
            IEnumerable <object> objects = null;

            Should.Error(() =>
                         objects.ShouldNotBeEmpty(),
                         "objects should not be empty but was null");
        }
Exemplo n.º 13
0
        public void ShouldBeEmpty_WhenNotEmpty_ShouldError()
        {
            var objects = (new[] { new object(), new object() });

            Should.Error(() =>
                         objects.ShouldBeEmpty(),
                         "objects should be empty but was [System.Object, System.Object]");
        }
Exemplo n.º 14
0
        public void ShouldContain()
        {
            var longString = new string('a', 110);

            Should.Error(
                () => longString.ShouldContain("zzzz"),
                string.Format("() => longString should contain \"zzzz\" but was \"{0}\"", longString.Substring(0, 100))
                );

            var justTheRightLengthString = new string('a', 80);

            Should.Error(
                () => justTheRightLengthString.ShouldContain("zzzz"),
                string.Format("() => justTheRightLengthString should contain \"zzzz\" but was \"{0}\"", justTheRightLengthString)
                );

            Should.Error(() =>
                         new[] { 1, 2, 3 }.ShouldContain(5),
                         "new[]{ 1, 2, 3 } should contain 5 but was [1, 2, 3]");

            var vampires = new[]
            {
                new Vampire {
                    BitesTaken = 1
                },
                new Vampire {
                    BitesTaken = 2
                },
                new Vampire {
                    BitesTaken = 3
                },
                new Vampire {
                    BitesTaken = 4
                },
                new Vampire {
                    BitesTaken = 5
                },
                new Vampire {
                    BitesTaken = 6
                },
            };

            Should.Error(() =>
                         vampires.ShouldContain(x => x.BitesTaken > 7),
                         "vampires should contain an element satisfying the condition (x.BitesTaken > 7) but does not");

            Should.Error(() =>
                         new[] { 1, 2, 3 }.ShouldContain(x => x % 4 == 0),
                         "new[]{1,2,3} should contain an element satisfying the condition ((x % 4) = 0) but does not");

            Should.Error(() =>
                         new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 }.ShouldContain(3.14, 0.001),
                         "new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 } should contain 3.14 but was [1, 2.1, 3.14159265358979, 4.321, 5.4321]");

            Should.Error(() =>
                         new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f }.ShouldContain(3.14f, 0.001),
                         "new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f } should contain 3.14 but was [1, 2.1, 3.141593, 4.321, 5.4321]");
        }
Exemplo n.º 15
0
        public void ShouldBeCloseTo()
        {
            const string testMessage = "muhst eat braiiinnzzzz";

            Should.Error(() =>
                         testMessage
                         .ShouldBeCloseTo("must eat brains"),
                         @"testMessage should be close to 'must eat brains' but was 'muhst eat braiiinnzzzz'");
        }
Exemplo n.º 16
0
        public void ShouldBe_EnumerableValues_ShouldCompareItemsInEachEnumerable()
        {
            new[] { 1, 2 }.ShouldBe(new[] { 1, 2 });

            Should.Error(() =>
                         new[] { 2, 1 }.ShouldBe(new[] { 1, 2 }),
                         "new[] { 2, 1 } should be [1, 2] but was [2, 1] difference [*2*, *1*]"
                         );
        }
Exemplo n.º 17
0
        public void ShouldThrow_WhenItDoesntThrow()
        {
            Action shouldThrowAction =
                () => Shouldly.Should.Throw <NotImplementedException>(() =>
            {
            });

            Should.Error(shouldThrowAction, "() => Shouldly.Should throw System.NotImplementedException but does not");
        }
Exemplo n.º 18
0
        public void ShouldlyMessage_WhenComparingStringsUnder100Characters_ShouldNotLimitTheMessage()
        {
            var longString = new string('a', 80);

            Should.Error(
                () => longString.ShouldContain("zzzz"),
                string.Format("() => longString should contain \"zzzz\" but was \"{0}\"", longString)
                );
        }
Exemplo n.º 19
0
        public void ShouldlyMessage_WhenComparingStringsOver100Characters_ShouldLimitTheMessageTo100Characters()
        {
            var longString = new string('a', 110);

            Should.Error(
                () => longString.ShouldContain("zzzz"),
                string.Format("() => longString should contain \"zzzz\" but was \"{0}\"", longString.Substring(0, 100))
                );
        }
Exemplo n.º 20
0
 public void ShouldContain_WithNumbersWhenFalse_ShouldErrorWithMessage()
 {
     Should.Error(() =>
                  new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 }.ShouldContain(3.14, 0.001),
                  "new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 } should contain 3.14 but was [1, 2.1, 3.14159265358979, 4.321, 5.4321]");
     Should.Error(() =>
                  new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f }.ShouldContain(3.14f, 0.001),
                  "new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f } should contain 3.14 but was [1, 2.1, 3.141593, 4.321, 5.4321]");
 }
Exemplo n.º 21
0
        public void ShouldNotContain()
        {
            Should.Error(() =>
                         new[] { 1, 2, 3 }.ShouldNotContain(x => x % 3 == 0),
                         "new[]{1,2,3} should not contain an element satisfying the condition ((x % 3) = 0) but does");

            Should.Error(() =>
                         new[] { 1, 2, 3 }.ShouldNotContain(2),
                         "new[]{1,2,3} should not contain 2 but was [1, 2, 3]");
        }
Exemplo n.º 22
0
        public void ShouldThrow_WhenItThrowsIncorrectException()
        {
            Action shouldThrowAction =
                () => Shouldly.Should.Throw <NotImplementedException>(() =>
            {
                throw new RankException();
            });

            Should.Error(shouldThrowAction, "() => Shouldly.Should throw System.NotImplementedException but was System.RankException");
        }
Exemplo n.º 23
0
        public void ShouldBeSameAs_WhenComparingBoxedValueType_WillThrow()
        {
            var first = 1;

            Should.Error(
                () => first.ShouldBeSameAs(first),
                "() => first should be same as 1 but was 1"
                );

            first.ShouldNotBeSameAs(first);
        }
Exemplo n.º 24
0
        public void ShouldBeSameAs_WhenDifferentReferences_ShouldThrow()
        {
            var first  = new object();
            var second = new object();

            Should.Error(
                () => first.ShouldBeSameAs(second),
                "() => first should be same as System.Object but was System.Object"
                );

            first.ShouldNotBeSameAs(second);
        }
Exemplo n.º 25
0
        public void ShouldBeEmpty()
        {
            IEnumerable <object> objects = null;

            Should.Error(
                () => objects.ShouldBeEmpty(),
                "() => objects should be empty but was null");

            objects = (new[] { new object(), new object() });
            Should.Error(
                () => objects.ShouldBeEmpty(),
                "() => objects should be empty but was [System.Object, System.Object]");
        }
Exemplo n.º 26
0
        public void ShouldNotBeEmpty()
        {
            IEnumerable <object> objects = null;

            Should.Error(
                () => objects.ShouldNotBeEmpty(),
                "() => objects should not be empty but was null");

            objects = new object[0];
            Should.Error(
                () => objects.ShouldNotBeEmpty(),
                "() => objects should not be empty but was");
        }
Exemplo n.º 27
0
        public void ShouldBeSameAs_WhenSameReference_ShouldNotThrow()
        {
            List <int> list = new List <int> {
                1, 2, 3
            };
            IList <int> sameReference = list;

            list.ShouldBeSameAs(sameReference);

            Should.Error(
                () => list.ShouldNotBeSameAs(sameReference),
                "() => list should not be same as [1, 2, 3] but was [1, 2, 3] difference [1, 2, 3]"
                );
        }
Exemplo n.º 28
0
        public void ShouldThrow()
        {
            Action shouldThrowAction =
                () => Shouldly.Should.Throw <NotImplementedException>(() =>
            {
                throw new RankException();
            });

            Should.Error(shouldThrowAction, "() => Shouldly.Should throw System.NotImplementedException but was System.RankException");

            shouldThrowAction =
                () => Shouldly.Should.Throw <NotImplementedException>(() => { });

            Should.Error(shouldThrowAction, "() => Shouldly.Should throw System.NotImplementedException but does not");
        }
Exemplo n.º 29
0
        public void OnShouldHaveBeenCalled_WhenNotCalled_ShouldFailWithOtherCallsShown()
        {
            var steve = Create.Mock <IZombie>();

            steve.EatHuman(Direction.East);
            steve.EatHuman(Direction.South);
            steve.EatHuman(Direction.West);

            Should.Error(() =>
                         steve.ShouldHaveBeenCalled(s => s.EatHuman(Direction.North)),
                         @"*Expecting*
                      EatHuman(Direction.North)
                  *Recorded*
                   0: EatHuman(Direction.East)
                   1: EatHuman(Direction.South)
                   2: EatHuman(Direction.West)");
        }
Exemplo n.º 30
0
        public void ShouldBe_EnumerableTypesOfDifferentRuntimeTypes_ShouldShowDifferences()
        {
            var a = new Widget {
                Name = "Joe", Enabled = true
            };
            var b = new Widget {
                Name = "Joeyjojoshabadoo Jr", Enabled = true
            };

            IEnumerable <Widget> aEnumerable = a.ToEnumerable();
            IEnumerable <Widget> bEnumerable = new[] { b };

            Should.Error(() =>
                         aEnumerable.ShouldBe(bEnumerable),
                         "aEnumerable should be [Name(Joeyjojoshabadoo Jr) Enabled(True)] but was [Name(Joe) Enabled(True)] difference [*Name(Joe) Enabled(True)*]"
                         );
        }