public async Task SHOULD_post_content_to_correct_endpoint() { //Arrange MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await Sut.PostAsync("http://baseaddress.com/testroute", new TestDto { TestDtoProperty = "hello world" }, CancellationToken.None); //Assert MockMessageHandler.VerifyUri("http://baseaddress.com/testroute"); MockMessageHandler.VerifyContent(x => x.Contains("hello world")); }
public async Task SHOULD_post_using_Default_RequestHeaders() { //Arrange MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); Sut.SetDefaultRequestHeader("frogs", "2"); Sut.SetDefaultRequestHeader("pudding", "yes please"); //Act await Sut.PostAsync("http://baseaddress.com/testroute", new TestDto { TestDtoProperty = "hello world" }, CancellationToken.None); //Assert MockMessageHandler.VerifyHeader("frogs", "2"); MockMessageHandler.VerifyHeader("pudding", "yes please"); }
public async Task SHOULD_send_to_correct_endpoint() { //Arrange var wrapper = GetWrapper(); MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await ExecuteAsync(wrapper, CancellationToken.None); //Assert MockMessageHandler.VerifyUri("http://baseaddress.com/testroute"); MockMessageHandler.VerifyMethod(GetHttpMethod()); }
public async Task SHOULD_append_query_string_parameters() { //Arrange var wrapper = GetWrapper() .WithQueryStringParameter("userId", "123") .WithQueryStringParameter("name", "Bob"); MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await ExecuteAsync(wrapper, CancellationToken.None); //Assert MockMessageHandler.VerifyUri("http://baseaddress.com/testroute?userId=123&name=Bob"); }
public async Task SHOULD_append_analytics_headers_if_present() { //Arrange MockAnalyticsService.With(x => x.AnalyticsOperationHeaders, new Dictionary <string, string> { { "analyticsHeaderKey", "analyticsHeaderValue" } }); var wrapper = GetWrapper(); MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await ExecuteAsync(wrapper, CancellationToken.None); //Assert MockMessageHandler.VerifyHeader("analyticsHeaderKey", "analyticsHeaderValue"); }
public async Task SHOULD_append_headers_if_provided() { //Arrange var wrapper = GetWrapper() .WithRequestHeader("userId", "123") .WithRequestHeader("name", "Bob") .WithAuthorizationHeader("Bearer", "bearerToken"); MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await ExecuteAsync(wrapper, CancellationToken.None); //Assert MockMessageHandler.VerifyHeader("userId", "123"); MockMessageHandler.VerifyHeader("name", "Bob"); MockMessageHandler.VerifyAuthHeader("Bearer", "bearerToken"); }
public async Task SHOULD_append_default_headers_if_set() { //Arrange var wrapper = GetWrapper(); Sut.SetDefaultRequestHeader("userId", "123"); Sut.SetDefaultRequestHeader("name", "Bob"); MockAccessToken .With(x => x.Scheme, "Bearer") .With(x => x.Token, "bearerToken"); MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await ExecuteAsync(wrapper, CancellationToken.None); //Assert MockMessageHandler.VerifyHeader("userId", "123"); MockMessageHandler.VerifyHeader("name", "Bob"); MockMessageHandler.VerifyAuthHeader("Bearer", "bearerToken"); }
public async Task SHOULD_append_acces_token_headers_if_set() { //Arrange var wrapper = GetWrapper(); MockAccessToken .With(x => x.Scheme, "Bearer") .With(x => x.Token, "bearerToken") .With(x => x.AdditionalHeaders, new Dictionary <string, string> { { "h1", "header1" }, { "h2", "header2" }, }); MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler.Build().Object)); //Act await ExecuteAsync(wrapper, CancellationToken.None); //Assert MockMessageHandler.VerifyHeader("h1", "header1"); MockMessageHandler.VerifyHeader("h2", "header2"); MockMessageHandler.VerifyAuthHeader("Bearer", "bearerToken"); }