Esempio n. 1
0
        public async Task ManualInjection_RecommendedPassiveMocking()
        {
            // Given
            m_TeePeeBuilder.ForRequest("https://some.api/path/resource", HttpMethod.Get)
            .ContainingQueryParam("filter", "those")
            .Responds()
            .WithStatus(HttpStatusCode.OK)
            .WithBody(new
            {
                Things = new[]
                {
                    new
                    {
                        Value = 10
                    }
                }
            });

            var controller = new HttpClientFactoryNamedUsageController(m_TeePeeBuilder.Build().Manual("https://some.api").CreateHttpClientFactory());

            // When
            var result = await controller.FireAndAct();

            // Then
            Assert.NotNull(result);
            var okResult    = Assert.IsType <OkObjectResult>(result);
            var resultValue = Assert.IsType <int>(okResult.Value);

            Assert.Equal(10, resultValue);
        }
Esempio n. 2
0
        public async Task ManualInjection_MockAndVerify()
        {
            // Given
            var requestTracker = m_TeePeeBuilder.ForRequest("https://some.api/path/resource", HttpMethod.Put)
                                 .ContainingQueryParam("filter", "other")
                                 .WithBody(new { Caller = "ThisCaller" })
                                 .Responds()
                                 .WithStatus(HttpStatusCode.Created)
                                 .TrackRequest();

            var controller = new HttpClientFactoryNamedUsageController(m_TeePeeBuilder.Build().Manual("https://some.api").CreateHttpClientFactory());

            // When
            var result = await controller.FireAndForget();

            // Then
            Assert.NotNull(result);
            Assert.IsType <OkResult>(result);

            requestTracker.WasCalled(1);
        }