Пример #1
0
 public void ShouldThrowWhenInRange()
 {
     Should.Throw <ShouldAssertException>(() => 1.5m.ShouldNotBeInRange(1.4m, 1.6m));
 }
Пример #2
0
 public void ShouldNotThrow_IfCallDoesNotThrow_ShouldDoNothing()
 {
     Should.NotError(
         () => Shouldly.Should.NotThrow(() => {})
         );
 }
Пример #3
0
 public void ShouldNotBeEmpty_WhenNotEmpty_ShouldNotError()
 {
     Should.NotError(() => new[] { new object() }.ShouldNotBeEmpty());
 }
Пример #4
0
 public void ShouldBeEmpty_WhenEmpty_ShouldNotError()
 {
     Should.NotError(() => new object[0].ShouldBeEmpty());
 }
Пример #5
0
        public void ShouldBe()
        {
            Should.Error(
                () => "expected".ShouldBe("actual"),
                "() => \"expected\" should be \"actual\" but was \"expected\""
                );

            Should.Error(
                () => 2.ShouldBe(1),
                "() => 2 should be 1 but was 2"
                );

            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]"
                );

            Should.Error(
                () => new UncomparableClass("ted").ShouldBe(new UncomparableClass("bob")),
                "() => new UncomparableClass(\"ted\") should be bob but was ted"
                );

            Should.Error(() =>
                         "SamplE".ShouldBe("sAMPLe", Case.Sensitive),
                         "'SamplE' should be 'sAMPLe' but was 'SamplE'");

            Should.Error(() =>
                         new[] { 2, 1 }.ShouldBe(new[] { 1, 2 }),
                         "new[] { 2, 1 } should be [1, 2] but was [2, 1] difference [*2*, *1*]"
                         );

            var aWidget = new Widget {
                Name = "Joe", Enabled = true
            };
            var bWidget = new Widget {
                Name = "Joeyjojoshabadoo Jr", Enabled = true
            };

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

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

            IEnumerable <int> something = null;

            Should.Error(
                () => something.ShouldBe(new[] { 1, 2, 3 }),
                "() => something should be [1, 2, 3] but was null");

            Action a = () => 1.ShouldBe(2);

            Should.Error(a,
                         "Action a = () => 1 should be 2 but was 1");

            Expression <Action> lambda = () => 1.ShouldBe(2);

            Should.Error(lambda.Compile(),
                         "The provided expression should be 2 but was 1");
        }
Пример #6
0
 public void ShouldCompleteIn_WhenThrowsNonTimeoutException()
 {
     Should.Throw <NotImplementedException>(() => Should.CompleteIn(() => { throw new NotImplementedException(); }, TimeSpan.FromSeconds(1)));
 }
Пример #7
0
 public void ShouldCompleteIn_WhenFinishBeforeTimeout()
 {
     Should.NotThrow(() => Should.CompleteIn(() => Thread.Sleep(TimeSpan.FromSeconds(0.5)), TimeSpan.FromSeconds(2)));
 }