public async void Middleware_WhenMockingIsEnabled_CorrectResponsePayloadIsReceivedByTheDataStore() { var spyDataStore = new SpyDataStore(); var imposter = new FakeImposterWithMockedRequestContent(HttpMethod.Post) .Build(); using (var testServer = new TestServerBuilder() .UsingImposterMiddleWareWithSpyDataStore(imposter, spyDataStore) .Build()) { await testServer .CreateRequest("test") .And(message => { message.Content = new StringContent("dummy request"); }) .PostAsync(); var expectedResponsePayloadBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes("dummy response")); spyDataStore.Responses.Should() .Contain(r => r.ResponsePayloadBase64.Equals(expectedResponsePayloadBase64)); } }
public async void Middleware_WithVerificationEnabledImposter_SavesTheRequestAndInvocationCountInDataStore() { var requestContent = "dummy request"; var spyDataStore = new SpyDataStore(); var fakeImposter = new FakeImposterWithMockedRequestContent(HttpMethod.Post) .Build(); using (var testServer = new TestServerBuilder() .UsingImposterMiddleWareWithSpyDataStore(fakeImposter, spyDataStore) .Build()) { for (int i = 0; i < 2; i++) { await testServer .CreateRequest($"{fakeImposter.Resource}") .And(message => { message.Content = new StringContent("dummy request"); }) .PostAsync(); } spyDataStore.Requests.Should().HaveCount(2); Encoding.UTF8.GetString(Convert.FromBase64String(spyDataStore.Requests.First().RequestPayloadBase64)) .Should().Be(requestContent); } }
public async void Middleware_WhenMockingIsEnabled_CorrectResourceIsReceivedByTheDataStore() { var resource = "test"; var imposter = new FakeImposterWithMockedRequestContent(HttpMethod.Post) .Build(); var spyDataStore = new SpyDataStore(); using (var testServer = new TestServerBuilder() .UsingImposterMiddleWareWithSpyDataStore(imposter, spyDataStore) .Build()) { await testServer .CreateRequest(resource) .And(message => { message.Content = new StringContent("dummy request"); }) .PostAsync(); spyDataStore.Responses .Should().Contain(r => r.ImposterName.Equals(imposter.Name)); } }