public IMiddlewareOptionsBuilder UseResponse(byte[] responseBytes, ResponseContentType contentType, Encoding encoding, int code503RetryInterval = DefaultValues.DEFAULT_503_RETRY_INTERVAL) { if (responseBytes == null) { throw new ArgumentNullException(nameof(responseBytes)); } MaintenanceResponse response = new MaintenanceResponse { ContentBytes = responseBytes, ContentEncoding = encoding, ContentType = contentType, Code503RetryInterval = code503RetryInterval }; _options.Add(new ResponseOption { Value = response }); return(this); }
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); }