Exemplo n.º 1
0
        public async Task ReturnAResponseFromAnyProxyRequest()
        {
            // Setup your mocked stuff
            var mockedProxyRequest = ProxyRequestBuilder <string[]>
                                     .CreateBuilder("https://www.this.is/fake", HttpRequestMethod.Get)
                                     .AppendToRoute("api/example")
                                     .Accept("application/json")
                                     .Build();

            var mockedProxyResponse = new ProxyResponse <string[]>
            {
                IsSuccessfulStatusCode = true,
                StatusCode             = HttpStatusCode.OK,
                ResponseDto            = new[] { "Mocked Value From Any Request 1", "Mocked Value From Any Request 2" }
            };

            // Create and configure TestProxy
            var testProxy = new TestProxy();

            testProxy.WhenIReceiveAnyRequest <Missing, string[]>().ThenIShouldReturnThisResponse(mockedProxyResponse);

            // Use the TetProxy in the class that needs it
            var classThatUsesProxy          = new ClassThatUsesProxy(testProxy);
            var methodThatUsesProxyResponse = await classThatUsesProxy.MethodThatUsesProxyAsync(mockedProxyRequest).ConfigureAwait(false);

            Assert.Equal("Mocked Value From Any Request 1", methodThatUsesProxyResponse[0]);
            Assert.Equal("Mocked Value From Any Request 2", methodThatUsesProxyResponse[1]);
        }