void Ex07()
    {
        Given("an assertion that has 'items.Length == 2 && items[0] == 1 && items[1] == 2' where items = new[] { 1 }", () =>
        {
            var items = new[] { 1 };
            Assertion = () => items.Length == 2 && items[0] == 1 && items[1] == 2;
        });
        Expect($@"the description should be as follows:
  [failed]
    Expected: 2
    But was : 1
  [passed]
  [failed]
    Expected: 2
    But was : throwing an exception ({IndexOutOfRangeExceptionMessage})
",
               () => AssertionDescription.Of(Assertion).ToString() == $@"
  [failed]
    Expected: 2
    But was : 1
  [passed]
  [failed]
    Expected: 2
    But was : throwing an exception ({IndexOutOfRangeExceptionMessage})");
    }
Exemple #2
0
    void Ex13()
    {
        Given("an assertion that has 'x == 3 && y == 5 && z == 7 && u == 9' where x = 5; y = 5; z == 7; u == 7", () =>
              { var x = 5; var y = 5; var z = 7; var u = 7; Assertion = () => x == 3 && y == 5 && z == 7 && u == 9; }
              );
        Expect(
            @"the description should be as follows:
  [failed]
    Expected: 3
    But was : 5
  [passed]
  [passed]
  [failed]
    Expected: 9
    But was : 7
",
            () => AssertionDescription.Of(Assertion).ToString() == @"
  [failed]
    Expected: 3
    But was : 5
  [passed]
  [passed]
  [failed]
    Expected: 9
    But was : 7"
            );
    }
Exemple #3
0
        void Ex04()
        {
            Given("an assertion that has 'Equals((x: 3, y: 3), Expected)'", () => Assertion = () => Equals(new TestAssertion(3, 3), Expected));
            Expect(
                @"the description should be as follows:
Expected: {X: 5, Y: 3}
But was : {X: 3, Y: 3}",
                () => AssertionDescription.Of(Assertion).ToString() == @"Expected: {X: 5, Y: 3}
But was : {X: 3, Y: 3}"
                );
        }
Exemple #4
0
        void Ex02()
        {
            Given("an assertion that has '(x: 5, y: 3) != Expected'", () => Assertion = () => new TestAssertion(5, 3) != Expected);
            Expect(
                @"the description should be as follows:
Expected: not {X: 5, Y: 3}
But was : {X: 5, Y: 3}",
                () => AssertionDescription.Of(Assertion).ToString() == @"Expected: not {X: 5, Y: 3}
But was : {X: 5, Y: 3}"
                );
        }
    void Ex06()
    {
        Given("an assertion that has 'Equals(x, s.Length)' where x = 3, s = null", () => { var x = 3; var s = (string?)null; Assertion = () => Equals(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 Ex05()
    {
        Given("an assertion that has 'Equals(x.Length, 3)' where x = null", () => { var x = (string?)null; Assertion = () => Equals(x.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})"
            );
    }
Exemple #7
0
    void Ex10()
    {
        Given("an assertion that has 'Equals(x, 3)' where x = 5", () => { var x = 5; Assertion = () => Equals(x, 3); });
        Expect(
            @"the description should be as follows:
Expected: 3
But was : 5",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: 3
But was : 5"
            );
    }
Exemple #8
0
    void Ex11()
    {
        Given("an assertion that has 'x == \"3\"' where x = null", () => { var x = (string?)null; Assertion = () => x == "3"; });
        Expect(
            @"the description should be as follows:
Expected: 3
But was : null",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: 3
But was : null"
            );
    }
Exemple #9
0
    void Ex07()
    {
        Given("an assertion that has 'x > 7' where x = 5", () => { var x = 5; Assertion = () => x > 7; });
        Expect(
            @"the description should be as follows:
Expected: greater than 7
But was : 5",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: greater than 7
But was : 5"
            );
    }
Exemple #10
0
    void Ex06()
    {
        Given("an assertion that has 'x <= 2' where x = 5", () => { var x = 5; Assertion = () => x <= 2; });
        Expect(
            @"the description should be as follows:
Expected: less than or equal 2
But was : 5",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: less than or equal 2
But was : 5"
            );
    }
Exemple #11
0
    void Ex02()
    {
        Given("an assertion that has '!x' where x = true", () => { var x = true; Assertion = () => !x; });
        Expect(
            @"the description should be as follows:
Expected: False
But was : True",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: False
But was : True"
            );
    }
Exemple #12
0
    void Ex04()
    {
        Given("an assertion that has 'x != 5' where x = 5", () => { var x = 5; Assertion = () => x != 5; });
        Expect(
            @"the description should be as follows:
Expected: not 5
But was : 5",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: not 5
But was : 5"
            );
    }
Exemple #13
0
    void Ex01()
    {
        Given("an assertion", () => { var x = false; Assertion = () => x; });
        Expect(
            @"the description should be as follows:
Expected: True
But was : False",
            () => AssertionDescription.Of(Assertion).ToString() == @"Expected: True
But was : False"
            );
    }
Exemple #14
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]"
            );
    }
Exemple #15
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]"
            );
    }
    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]");
    }
Exemple #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssertionException"/> class
 /// with the specified fixture step and assertion description.
 /// </summary>
 /// <param name="step">The fixture step when the assertion was failed.</param>
 /// <param name="description">The assertion description when the assertion was failed.</param>
 public AssertionException(FixtureStep step, AssertionDescription description) : base($"{step.Description}{Environment.NewLine}{description}")
 {
     StackTrace = CreateStackTrace(step);
 }