private async Task WriteMaintenanceResponse(HttpContext context) { MaintenanceResponse response = GetLatestOptions() .GetSingleOrDefault <IResponseHolder>() .GetResponse(_dirMapperSvc); context .Response .StatusCode = (int)HttpStatusCode.ServiceUnavailable; context .Response .Headers .Add("Retry-After", response.Code503RetryInterval.ToString()); context .Response .ContentType = response.GetContentTypeString(); string responseStr = response .ContentEncoding .GetString(response.ContentBytes); await context .Response .WriteAsync(responseStr, response.ContentEncoding); }
public void GetContentTypeString_WithInalidEnumValue_ShouldThrow() { ResponseContentType invalidEnumValue = (ResponseContentType)(-1); MaintenanceResponse response = new MaintenanceResponse { ContentType = invalidEnumValue }; Func <string> testFunc = () => response.GetContentTypeString(); testFunc.ShouldThrow(typeof(InvalidOperationException)); }
public void GetContentTypeString_WithValidEnumValue_ShouldReturnValidContentType(ResponseContentType contentType, string contentTypeString) { MaintenanceResponse response = new MaintenanceResponse { ContentType = contentType }; string returned = response.GetContentTypeString(); returned .ShouldBe(contentTypeString); }