public static TestETagCache CreateETagCacheMock(out HttpContext context) { long length = 100; ETagOption etagOption = new ETagOption() { BodyMaxLength = length, ETagAlgorithm = ETagAlgorithm.SHA521, ETagValidator = ETagValidator.Strong }; IOptions <ETagOption> options = Options.Create(etagOption); var etag = new TestETagCache(MockHelper.CreateILoggerFactory(), options); var request = Substitute.For <HttpRequest>(); request.Method.Returns(HttpMethods.Get); request.Headers.Returns(Substitute.For <IHeaderDictionary>()); var response = Substitute.For <HttpResponse>(); response.Body.Returns(Substitute.For <Stream>()); response.Body.Length.ReturnsForAnyArgs(length); response.StatusCode.Returns <int>(200); response.Headers.ContainsKey(HeaderNames.ETag).ReturnsForAnyArgs(false); context = Substitute.For <HttpContext>(); context.Response.Returns(response); context.Request.Returns(request); return(etag); }
public void Create_And_Check_Value2_Ok() { // arange var option = new ETagOption(); // act option.BodyMaxLength = ETagMiddlewareExtensions.DefaultBodyMaxLength; // assert Assert.IsNotNull(option); Assert.AreEqual(ETagMiddlewareExtensions.DefaultBodyMaxLength, option.BodyMaxLength); }
public void Create_And_Check_Value_Ok() { // arange var option = new ETagOption(); // act option.BodyMaxLength = 1; // assert Assert.IsNotNull(option); Assert.AreEqual(1, option.BodyMaxLength); }
public void Create_And_Check_Ctor_Exceptions_LoggerFactory_NOk() { // arange long length = 1; ETagOption etagOption = new ETagOption() { BodyMaxLength = length, ETagAlgorithm = ETagAlgorithm.SHA1, ETagValidator = ETagValidator.Strong }; IOptions <ETagOption> options = Options.Create(etagOption); // act var etag = new TestETagCache(null, options); // assert Assert.Fail("No Exception"); }
public void Create_Check_Ctor_Created_Types_Ok() { // arange long length = 100; ETagOption etagOption = new ETagOption() { BodyMaxLength = length, ETagAlgorithm = ETagAlgorithm.SHA1, ETagValidator = ETagValidator.Strong }; IOptions <ETagOption> options = Options.Create(etagOption); // act var etag = new TestETagCache(MockHelper.CreateILoggerFactory(), options); // assert Assert.IsNotNull(etag.BaseLogger); Assert.AreEqual(length, etag.BaseOptions.BodyMaxLength); }
public void Check_Option_BodyMaxLength_If_10_Then_10_Ok() { // arange long length = 10; ETagOption etagOption = new ETagOption() { BodyMaxLength = length, ETagAlgorithm = ETagAlgorithm.SHA1, ETagValidator = ETagValidator.Strong }; IOptions <ETagOption> options = Options.Create(etagOption); // act var etag = new TestETagCache(Substitute.For <ILoggerFactory>(), options); // assert Assert.AreEqual(length, etag.BaseOptions.BodyMaxLength); Assert.AreNotEqual(ETagMiddlewareExtensions.DefaultBodyMaxLength, etag.BaseOptions.BodyMaxLength); }
/// <summary> /// Initializes a new instance of the <see cref="T:BLun.ETagMiddleware.ETagMiddleware"/> class. /// </summary> /// <param name="logger">An <see cref="ILogger"/> instance used to logging.</param> /// <param name="options">The configuration options.</param> /// <exception cref="ArgumentNullException">ILogger</exception> protected ETagCache( [NotNull] ILogger logger, [CanBeNull] ETagOption options) { if (options == null) { Options = new ETagOption(); } else { Options = options; Options.BodyMaxLength = Options.BodyMaxLength == 0 ? ETagMiddlewareExtensions.DefaultBodyMaxLength : Options.BodyMaxLength; } Logger = logger ?? throw new ArgumentNullException(nameof(logger)); Logger.LogDebug($"The Etag algorithm is [{Options.ETagAlgorithm.ToString()}] and [{Options.ETagValidator.ToString()}] ETag Validator - MaxBodyLength=[{Options.BodyMaxLength}]"); }
public ETagCacheActionFilter( [NotNull] ILogger logger, [CanBeNull] ETagOption options) : base(logger, options) { }
public ETagCacheMiddleware( [NotNull] ILogger logger, [CanBeNull] ETagOption options) : base(logger, options) { }