コード例 #1
0
ファイル: BehaviorTests.cs プロジェクト: zhaoyingju/microdot
        public async Task ToUpper_MethodCallFailsWithProgrammaticException_CorrectExceptionIsThrown()
        {
            var expected       = new ProgrammaticException("You code is invalid.").ThrowAndCatch();
            var messageHandler = new MockHttpMessageHandler();

            messageHandler.When("*").Respond(HttpResponseFactory.GetResponseWithException(expected));

            var actual = CreateClient(messageHandler).ToUpper("aaaa").ShouldThrow <RemoteServiceException>();

            actual.InnerException.ShouldBeOfType <ProgrammaticException>();
            actual.InnerException.Message.ShouldBe(expected.Message);
        }
コード例 #2
0
        public async Task ToUpper_MethodCallFailsWithProgrammaticException_CorrectExceptionIsThrown()
        {
            var expected = new ProgrammaticException("You code is invalid.").ThrowAndCatch();
            Func <HttpClientConfiguration, HttpMessageHandler> messageHandlerFactory = _ =>
            {
                var messageHandler = new MockHttpMessageHandler();
                messageHandler.When("*").Respond(HttpResponseFactory.GetResponseWithException(ExceptionSerializer, expected));

                return(messageHandler);
            };

            unitTesting.Rebind <Func <HttpClientConfiguration, HttpMessageHandler> >().ToMethod(c => messageHandlerFactory);

            var actual = CreateClient().ToUpper("aaaa").ShouldThrow <RemoteServiceException>();

            actual.InnerException.ShouldBeOfType <ProgrammaticException>();
            actual.InnerException.Message.ShouldBe(expected.Message);
        }