public async void Middleware_ImposterReceivesRequestWithoutAnyMatchingConditions_ReturnsInternalServerError()
        {
            using (var testServer = new TestServerBuilder()
                                    .UsingImpostersMiddleware(new FakeImposterWithRequestHeaderAndContent().Build())
                                    .Build())
            {
                var response = await testServer
                               .CreateRequest("test")
                               .And(message =>
                {
                    message.Content =
                        new StringContent("This content will not match");
                })
                               .AddHeader("this_key_wont_match", "this_too_wont_match")
                               .PostAsync();

                response.Content.ReadAsStringAsync().Result.Should().Be("None of evaluators could create a response.");
            }
        }
        public async void Middleware_ImposterReceivesRequestWithMatchingContent_ReturnsPreDefinedResponse()
        {
            using (var testServer = new TestServerBuilder()
                                    .UsingImpostersMiddleware(new FakeImposterWithRequestContent(HttpMethod.Get).Build())
                                    .Build())
            {
                var response = await testServer
                               .CreateRequest("test")
                               .And(message =>
                {
                    message.Content =
                        new StringContent("dummy");
                })
                               .GetAsync();

                var content = response.Content.ReadAsStringAsync().Result;

                content.Should().Be("dummy response");
            }
        }
Пример #3
0
        public async void Middleware_WhenMockingIsEnabled_CorrectHtpMethodIsReceivedByTheDataStore()
        {
            var spyDataStore = new SpyDataStore();

            using (var testServer = new TestServerBuilder()

                                    .UsingImposterMiddleWareWithSpyDataStore(new FakeImposterWithMockedRequestContent(HttpMethod.Post)
                                                                             .Build(),
                                                                             spyDataStore)
                                    .Build())
            {
                await testServer
                .CreateRequest("test")
                .And(message =>
                {
                    message.Content = new StringContent("dummy request");
                })
                .PostAsync();

                spyDataStore.Requests.Should().Contain(r => r.HttpMethod == HttpMethod.Post.ToString());
            }
        }