public async void Test_Adds_Required_Header_And_Default_Value_If_Not_Found_In_Request() { //Arrange string testHeaderKey = "X-Test-Required-Header"; HeadersPolicyBuilder builder = new HeadersPolicyBuilder(); builder.AddRequiredHeaderToRequests(testHeaderKey, "test"); OrganizerMiddleware middleware = new OrganizerMiddleware(nextDelegate: (innerHttpContext) => { return(Task.CompletedTask); }, builder.Build()); DefaultHttpContext context = new DefaultHttpContext(); context.Response.Body = new MemoryStream(); //Act await middleware.InvokeAsync(context); //Assert Assert.Equal(200, context.Response.StatusCode); Assert.Equal("test", context.Request.Headers[testHeaderKey]); Assert.True(context.Request.Headers.ContainsKey(testHeaderKey)); }
public async void Test_Remove_Request_Header_or_Headers_In_HttpRequest_Async() { //Arrange string testHeaderKey = "X-Test-Header-To-Remove"; HeadersPolicyBuilder builder = new HeadersPolicyBuilder(); builder.AddRemoveHeaderToRequests(testHeaderKey); OrganizerMiddleware middleware = new OrganizerMiddleware(nextDelegate: (innerHttpContext) => { innerHttpContext.Request.Headers.Add(testHeaderKey, "Test Value"); return(Task.CompletedTask); }, builder.Build()); DefaultHttpContext context = new DefaultHttpContext(); context.Response.Body = new MemoryStream(); //Act await middleware.InvokeAsync(context); //Assert Assert.False(context.Response.Headers.ContainsKey(testHeaderKey)); }