예제 #1
0
        public static void VoidMethodThrowsExceptionWhileRecording(
            InMemoryRecordedCallRepository inMemoryRecordedCallRepository,
            IService realServiceWhileRecording,
            Exception originalException,
            Exception exceptionWhileRecording,
            Exception exceptionWhileEndingRecordingSession)
        {
            "Given a call storage object"
            .x(() => inMemoryRecordedCallRepository = new InMemoryRecordedCallRepository());

            "And a real service to wrap while recording"
            .x(() => realServiceWhileRecording = A.Fake <IService>());

            "And the real service throws an exception when executing a void method"
            .x(() =>
            {
                A.CallTo(() => realServiceWhileRecording.Action())
                .Throws(originalException = new InvalidOperationException());
            });

            "When I use a self-initializing fake in recording mode to execute the method"
            .x(() =>
            {
                var fakeService = SelfInitializingFake <IService> .For(() => realServiceWhileRecording, inMemoryRecordedCallRepository);
                var fake        = fakeService.Object;

                exceptionWhileRecording = Record.Exception(() => fake.Action());

                exceptionWhileEndingRecordingSession = Record.Exception(() => fakeService.Dispose());
            });

            "Then the recording fake throws the original exception"
            .x(() => exceptionWhileRecording.Should().BeSameAs(originalException));

            "But ending the recording session throws a recording exception"
            .x(() => exceptionWhileEndingRecordingSession.Should().BeOfType <RecordingException>()
               .Which.Message.Should().Be("error encountered while recording actual service calls"));

            "And the session-ending exception has the original exception as its inner exception"
            .x(() => exceptionWhileEndingRecordingSession.InnerException.Should().BeSameAs(originalException));
        }