コード例 #1
0
        public static IHttpClientFactory CreateWithResponse(HttpResponseMessage response)
        {
            var mock = Substitute.For <IHttpClientFactory>();

            mock.CreateClient(Arg.Any <string>()).Returns(HttpClientStub.Create(response));

            return(mock);
        }
コード例 #2
0
        public static IHttpClientFactory CreateWithException(Exception exception)
        {
            var mock = Substitute.For <IHttpClientFactory>();

            mock.CreateClient(Arg.Any <string>()).Returns(HttpClientStub.Create(exception));

            return(mock);
        }
コード例 #3
0
        public static IHttpClientFactory Create(Exception exception)
        {
            var handler = HttpMessageHandlerStub.Create(req =>
            {
                throw exception;
            });

            var factoryMock = new Mock <IHttpClientFactory>();

            factoryMock.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(HttpClientStub.Create(handler));

            return(factoryMock.Object);
        }
コード例 #4
0
        public static IHttpClientFactory Create(HttpResponseMessage response)
        {
            var handler = HttpMessageHandlerStub.Create(req =>
            {
                return(response);
            });

            var factoryMock = new Mock <IHttpClientFactory>();

            factoryMock.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(HttpClientStub.Create(handler));

            return(factoryMock.Object);
        }