22using System . Text ;
33using System . Threading . Tasks ;
44using Arcus . WebApi . Hosting . AzureFunctions . Formatting ;
5- using Arcus . WebApi . Logging . AzureFunctions ;
65using Arcus . WebApi . Tests . Unit . Logging . Fixture . AzureFunctions ;
6+ using Bogus ;
77using Microsoft . Azure . Functions . Worker ;
88using Microsoft . Azure . Functions . Worker . Http ;
99using Xunit ;
@@ -12,6 +12,8 @@ namespace Arcus.WebApi.Tests.Unit.Hosting.Formatting
1212{
1313 public class AzureFunctionsJsonFormattingMiddlewareTests
1414 {
15+ private static readonly Faker BogusGenerator = new Faker ( ) ;
16+
1517 [ Fact ]
1618 public async Task Request_WithoutJsonFormattingHeaders_ReturnsFailure ( )
1719 {
@@ -131,6 +133,43 @@ public async Task Request_WithAllAllowAndJsonContentTypeHeaders_ReturnsOk()
131133 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
132134 }
133135
136+ [ Fact ]
137+ public async Task Request_WithJsonAllowHeaderWithExtension_ReturnsOk ( )
138+ {
139+ // Arrange
140+ var middleware = new AzureFunctionsJsonFormattingMiddleware ( ) ;
141+ var weight = BogusGenerator . Random . Double ( ) ;
142+ var context = TestFunctionContext . Create ( req =>
143+ {
144+ req . Headers . TryAddWithoutValidation ( "allow" , $ "application/json, q={ weight } ") ;
145+ } ) ;
146+
147+ // Act
148+ await middleware . Invoke ( context , CreateOkResponse ) ;
149+
150+ // Assert
151+ HttpResponseData response = context . GetHttpResponseData ( ) ;
152+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
153+ }
154+
155+ [ Fact ]
156+ public async Task Request_WithAllAllowHeaderWithExtension_ReturnsOk ( )
157+ {
158+ // Arrange
159+ var middleware = new AzureFunctionsJsonFormattingMiddleware ( ) ;
160+ var context = TestFunctionContext . Create ( req =>
161+ {
162+ req . Headers . TryAddWithoutValidation ( "allow" , "q=0.8, */*" ) ;
163+ } ) ;
164+
165+ // Act
166+ await middleware . Invoke ( context , CreateOkResponse ) ;
167+
168+ // Assert
169+ HttpResponseData response = context . GetHttpResponseData ( ) ;
170+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
171+ }
172+
134173 private static async Task CreateOkResponse ( FunctionContext context )
135174 {
136175 HttpRequestData request = await context . GetHttpRequestDataAsync ( ) ;
0 commit comments