void Ex02()
    {
        Given("an assertion that has 'x == s.Length' where x = 3, s = null", () => { var x = 3; var s = (string?)null; Assertion = () => x == s.Length; });
        Expect(
            $@"the description should be as follows:
Expected: an exception occurred ({NullReferenceExceptionMessage})
But was : 3",
            () => AssertionDescription.Of(Assertion).ToString() == $@"Expected: an exception occurred ({NullReferenceExceptionMessage})
But was : 3"
            );
    }
    void Ex01()
    {
        Given("an assertion that has 's.Length == 3' where s = null", () => { var s = (string?)null; Assertion = () => s.Length == 3; });
        Expect(
            $@"the description should be as follows:
Expected: 3
But was : throwing an exception ({NullReferenceExceptionMessage})'",
            () => AssertionDescription.Of(Assertion).ToString() == $@"Expected: 3
But was : throwing an exception ({NullReferenceExceptionMessage})"
            );
    }
Пример #3
0
    void Ex14()
    {
        Given("an assertion that has 'x.SequenceEqual(y)' where x = [1, 2, 3], y = [3, 4]", () =>
              { var x = new[] { 1, 2, 3 }; var y = new[] { 3, 4 }; Assertion = () => x.SequenceEqual(y); }
              );
        Expect(
            @"the description should be as follows:
Expected: [3, 4]
But was : [1, 2, 3]",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: [3, 4]
But was : [1, 2, 3]"
            );
    }
Пример #4
0
    void Ex12()
    {
        Given("an assertion that has 'x == 3 && y == 5' where x = 5; y = 5", () => { var x = 5; var y = 5; Assertion = () => x == 3 && y == 5; });
        Expect(
            @"the description should be as follows:
  [failed]
    Expected: 3
    But was : 5
  [passed]
",
            () => AssertionDescription.Of(Assertion).ToString() == @"
  [failed]
    Expected: 3
    But was : 5
  [passed]"
            );
    }
Пример #5
0
    private static void ExecuteAssertion(this FixtureStep @this, LambdaExpression expression, Func <bool> assertion, Exception?exception = null)
    {
        bool result;

        try
        {
            result = assertion();
        }
        catch (Exception exc)
        {
            throw new AssertionException(@this, exc);
        }

        if (!result)
        {
            throw new AssertionException(@this, AssertionDescription.Of(expression, exception));
        }
    }
    void Ex08()
    {
        Given("an assertion that has 'items.Length == 2 && items[0] == s.Length && items[1] == 2' where items = new[] { 1, 2 }, s = null", () =>
        {
            var items = new[] { 1, 2 };
            var s     = (string?)null;
            Assertion = () => items.Length == 2 && items[0] == s.Length && items[1] == 2;
        });
        Expect($@"the description should be as follows:
  [passed]
  [failed]
    Expected: an exception occurred ({NullReferenceExceptionMessage})
    But was : 1
  [passed]
",
               () => AssertionDescription.Of(Assertion).ToString() == $@"
  [passed]
  [failed]
    Expected: an exception occurred ({NullReferenceExceptionMessage})
    But was : 1
  [passed]");
    }