예제 #1
0
        public static void RepeatedAssertion(
            IMyInterface fake,
            Exception exception)
        {
            "establish"
            .x(() =>
            {
                fake = A.Fake <IMyInterface>(o => o.Strict());
                ////fake = A.Fake<IMyInterface>();

                A.CallTo(() => fake.DoIt(Guid.Empty)).Invokes(() => { });

                fake.DoIt(Guid.Empty);
                fake.DoIt(Guid.Empty);
            });

            "when asserting must have happened when did not happen"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.DoIt(Guid.Empty)).MustHaveHappened(Repeated.Exactly.Once)));

            "it should throw an expectation exception"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "it should have an exception message containing the name of the method"
            .x(() => exception.Message.Should().Contain("DoIt"));
        }
예제 #2
0
        public static void RepeatedAssertion(
            IMyInterface fake,
            Exception exception)
        {
            "Given a strict fake"
            .x(() => fake = A.Fake <IMyInterface>(o => o.Strict()));

            "And I configure the fake to do nothing when a method is called with certain arguments"
            .x(() => A.CallTo(() => fake.DoIt(Guid.Empty)).DoesNothing());

            "And I call the method with matching arguments"
            .x(() => fake.DoIt(Guid.Empty));

            "And I call the method with matching arguments again"
            .x(() => fake.DoIt(Guid.Empty));

            "When I assert that the method must have been called exactly once"
            .x(() => exception = Record.Exception(() => A.CallTo(() => fake.DoIt(Guid.Empty)).MustHaveHappened(Repeated.Exactly.Once)));

            "Then the assertion throws an expectation exception"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "And the exception message names the method"
            .x(() => exception.Message.Should().Contain("DoIt"));
        }
예제 #3
0
        public static void RepeatedAssertion(
            IMyInterface fake,
            Exception exception)
        {
            "establish"
                .x(() =>
                    {
                        fake = A.Fake<IMyInterface>(o => o.Strict());
                        ////fake = A.Fake<IMyInterface>();

                        A.CallTo(() => fake.DoIt(Guid.Empty)).Invokes(() => { });

                        fake.DoIt(Guid.Empty);
                        fake.DoIt(Guid.Empty);
                    });

            "when asserting must have happened when did not happen"
                .x(() => exception = Record.Exception(() => A.CallTo(() => fake.DoIt(Guid.Empty)).MustHaveHappened(Repeated.Exactly.Once)));

            "it should throw an expectation exception"
                .x(() => exception.Should().BeAnExceptionOfType<ExpectationException>());

            "it should have an exception message containing the name of the method"
                .x(() => exception.Message.Should().Contain("DoIt"));
        }
예제 #4
0
        public static void ArgumentMismatchVoid(
            IMyInterface fake,
            Exception exception)
        {
            "Given a strict fake"
            .x(() => fake = A.Fake <IMyInterface>(o => o.Strict()));

            "And I configure the fake to do nothing when a void method is called with certain arguments"
            .x(() => A.CallTo(() => fake.DoIt(Guid.Empty)).DoesNothing());

            "When I call the method with non-matching arguments"
            .x(() => exception = Record.Exception(() => fake.DoIt(new Guid("a762f030-d39e-4316-92b1-a51eff3dc51f"))));

            "Then the fake throws an expectation exception"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "And the exception message describes the call"
            .x(() => exception.Message.Should().Be(
                   "Call to unconfigured method of strict fake: FakeItEasy.Specs.StrictFakeSpecs+IMyInterface.DoIt(id: a762f030-d39e-4316-92b1-a51eff3dc51f)."));
        }