コード例 #1
0
        public static void GenericCalls(
            IHaveOneGenericParameter fake,
            Exception exception)
        {
            "establish"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "when failing to match ordered generic calls"
            .x(() =>
            {
                using (var scope = Fake.CreateScope())
                {
                    fake.Bar(1);
                    fake.Bar(new Generic <bool>());
                    using (scope.OrderedAssertions())
                    {
                        A.CallTo(() => fake.Bar(A <Generic <bool> > .Ignored)).MustHaveHappened();
                        exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <int> .Ignored)).MustHaveHappened());
                    }
                }
            });

            "it should tell us that the call was not matched"
            .x(() => exception.Message.Should().Be(
                   @"

  Assertion failed for the following calls:
    'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<FakeItEasy.Specs.OrderedCallMatchingSpecs+Generic<System.Boolean>>(<Ignored>)' repeated at least once
    'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<System.Int32>(<Ignored>)' repeated at least once
  The calls where found but not in the correct order among the calls:
    1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<System.Int32>(baz: 1)
    2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<FakeItEasy.Specs.OrderedCallMatchingSpecs+Generic<System.Boolean>>(baz: FakeItEasy.Specs.OrderedCallMatchingSpecs+Generic`1[System.Boolean])
"));
        }
コード例 #2
0
        public static void GenericCallsSuccess(
            IHaveOneGenericParameter fake,
            ISequentialCallContext sequentialCallContext,
            Exception exception)
        {
            "Given a Fake"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "And a call on the Fake, passing argument of type int"
            .x(() => fake.Bar(1));

            "And a call on the Fake, passing argument of type Generic<bool>"
            .x(() => fake.Bar(new Generic <bool>()));

            "And a call-ordering context"
            .x(c => sequentialCallContext = A.SequentialCallContext());

            "When I expect the call with any argument of type int to have been made"
            .x(() => A.CallTo(() => fake.Bar(A <int> .Ignored)).MustHaveHappened().InOrder(sequentialCallContext));

            "And I expect the call with any argument of type Generic<bool> to have been made next"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <Generic <bool> > .Ignored)).MustHaveHappened().InOrder(sequentialCallContext)));

            "Then the assertion should succeed"
            .x(() => exception.Should().BeNull("because the assertion should have succeeded"));
        }
コード例 #3
0
        public static void NoGenericCalls(
            IHaveOneGenericParameter fake,
            Exception exception)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "And no calls made on this fake"
            .x(() => { });

            "When I assert that a call has happened on this fake"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar <Generic <string> >(A <Generic <string> > .Ignored)).MustHaveHappened()));

            "Then the assertion should fail"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "And the exception message should tell us that the call was not matched"
            .x(() => exception.Message.Should().Be(@"

  Assertion failed for the following call:
    FakeItEasy.Specs.CallMatchingSpecs+IHaveOneGenericParameter.Bar`1[FakeItEasy.Specs.CallMatchingSpecs+Generic`1[System.String]](baz: <Ignored>)
  Expected to find it at least once but no calls were made to the fake object.

"));
        }
コード例 #4
0
        public static void GenericCallsFailure(
            IHaveOneGenericParameter fake,
            ISequentialCallContext sequentialCallContext,
            Exception exception)
        {
            "Given a Fake"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "And a call on the Fake, passing argument of type int"
            .x(() => fake.Bar(1));

            "And a call on the Fake, passing argument of type Generic<bool>"
            .x(() => fake.Bar(new Generic <bool>()));

            "And a call-ordering context"
            .x(c => sequentialCallContext = A.SequentialCallContext());

            "When I expect the call with any argument of type Generic<bool> to have been made"
            .x(() => A.CallTo(() => fake.Bar(A <Generic <bool> > .Ignored)).MustHaveHappened().InOrder(sequentialCallContext));

            "And I expect the call with any argument of type int to have been made next"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <int> .Ignored)).MustHaveHappened().InOrder(sequentialCallContext)));

            "Then the assertion should fail"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "And the error should tell us that the calls were not matched in order"
            .x(() => exception.Message.Should().Be(
                   @"

  Assertion failed for the following calls:
    'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<FakeItEasy.Specs.OrderedCallMatchingSpecs+Generic<System.Boolean>>(<Ignored>)' repeated at least once
    'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<System.Int32>(<Ignored>)' repeated at least once
  The calls where found but not in the correct order among the calls:
    1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<System.Int32>(baz: 1)
    2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveOneGenericParameter.Bar<FakeItEasy.Specs.OrderedCallMatchingSpecs+Generic<System.Boolean>>(baz: FakeItEasy.Specs.OrderedCallMatchingSpecs+Generic`1[System.Boolean])
"));
        }
コード例 #5
0
        public static void PassingNestedThatIsNotNullConstraintToAMethod(
            IHaveOneGenericParameter fake, Exception exception)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "When I try to configure a method of the fake with a That.IsNotNull constraint nested in an argument"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(new Dummy {
                X = A <string> .That.IsNotNull()
            })).DoesNothing()));

            "Then it throws an invalid operation exception"
            .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>());
        }
コード例 #6
0
        public static void PassingAStrictFakeToAMethod <T>(
            Func <T> createFake, string fakeDescription, T fake, IHaveOneGenericParameter anotherFake, Exception exception)
        {
            $"Given a strict fake {fakeDescription}"
            .x(() => fake = createFake());

            "And another fake"
            .x(() => anotherFake = A.Fake <IHaveOneGenericParameter>());

            "When I assert that a call to the second fake must have happened with the first fake as an argument"
            .x(() => exception = Record.Exception(() => A.CallTo(() => anotherFake.Bar(fake)).MustHaveHappened()));

            "Then the call should be described in terms of the first fake"
            .x(() => exception.Message.Should().Contain(
                   $"FakeItEasy.Specs.CallMatchingSpecs+IHaveOneGenericParameter.Bar`1[").And.Subject.Should().Contain($"](baz: {fakeDescription})"));
        }
コード例 #7
0
        public static void PassingAnObjectWithABadToStringToAMethod(
            ToStringThrows obj, IHaveOneGenericParameter fake, Exception exception)
        {
            $"Given an object with a ToString method which throws"
            .x(() => obj = new ToStringThrows());

            "And a fake"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "When I assert that a call to the fake must have happened with the object as an argument"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(obj)).MustHaveHappened()));

            "Then the call should be described in terms of the object"
            .x(() => exception.Message.Should().Contain(
                   $"FakeItEasy.Specs.CallMatchingSpecs+IHaveOneGenericParameter.Bar`1[").And.Subject.Should().Contain($"](baz: {obj.GetType().ToString()})"));
        }
コード例 #8
0
        public static void PassingAFakeWithABadToStringToAMethod <T>(
            T fake, string fakeDescription, IHaveOneGenericParameter anotherFake, Exception exception)
        {
            $"Given a fake {fakeDescription} with a ToString method which throws"
            .x(() => A.CallTo(() => fake.ToString()).Throws <Exception>());

            "And another fake"
            .x(() => anotherFake = A.Fake <IHaveOneGenericParameter>());

            "When I assert that a call to the second fake must have happened with the first fake as an argument"
            .x(() => exception = Record.Exception(() => A.CallTo(() => anotherFake.Bar(fake)).MustHaveHappened()));

            "Then the call should be described in terms of the first fake"
            .x(() => exception.Message.Should().Contain(
                   $"FakeItEasy.Specs.CallMatchingSpecs+IHaveOneGenericParameter.Bar<").And.Subject.Should().Contain($">({fakeDescription})"));
        }
コード例 #9
0
        public static void NoGenericCalls(
            IHaveOneGenericParameter fake,
            Exception exception)
        {
            "establish"
            .x(() => fake = A.Fake <IHaveOneGenericParameter>());

            "when no generic calls"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar <Generic <string> >(A <Generic <string> > .Ignored)).MustHaveHappened()));

            "it should tell us that the call was not matched"
            .x(() => exception.Message.Should().Be(
                   @"

  Assertion failed for the following call:
    FakeItEasy.Specs.CallMatchingSpecs+IHaveOneGenericParameter.Bar<FakeItEasy.Specs.CallMatchingSpecs+Generic<System.String>>(<Ignored>)
  Expected to find it at least once but no calls were made to the fake object.

"));
        }