diff --git a/src/BitzArt.Blazor.Cookies.Server/Services/HttpContextCookieService.cs b/src/BitzArt.Blazor.Cookies.Server/Services/HttpContextCookieService.cs index 832e1a7..1b95766 100644 --- a/src/BitzArt.Blazor.Cookies.Server/Services/HttpContextCookieService.cs +++ b/src/BitzArt.Blazor.Cookies.Server/Services/HttpContextCookieService.cs @@ -13,7 +13,7 @@ internal class HttpContextCookieService : ICookieService private IHeaderDictionary _responseHeaders { get; set; } - public HttpContextCookieService(IHttpContextAccessor httpContextAccessor, IFeatureCollection features, ILogger logger) + public HttpContextCookieService(IHttpContextAccessor httpContextAccessor, ILogger logger) { _httpContext = httpContextAccessor.HttpContext!; _logger = logger; @@ -21,7 +21,7 @@ public HttpContextCookieService(IHttpContextAccessor httpContextAccessor, IFeatu _requestCookies = _httpContext.Request.Cookies .Select(x => new Cookie(x.Key, x.Value)).ToDictionary(cookie => cookie.Key); - _responseHeaders = features.GetRequiredFeature().Headers; + _responseHeaders = _httpContext.Features.GetRequiredFeature().Headers; } public Task> GetAllAsync() diff --git a/tests/BitzArt.Blazor.Cookies.Server.Tests/HttpContextCookieServiceTests.cs b/tests/BitzArt.Blazor.Cookies.Server.Tests/HttpContextCookieServiceTests.cs index 16fc6ef..4537b66 100644 --- a/tests/BitzArt.Blazor.Cookies.Server.Tests/HttpContextCookieServiceTests.cs +++ b/tests/BitzArt.Blazor.Cookies.Server.Tests/HttpContextCookieServiceTests.cs @@ -57,24 +57,16 @@ public async Task SetCookie_WhenDuplicate_ShouldOnlySetCookieOnce() private static TestServices CreateTestServices() { var httpContext = new DefaultHttpContext(); - var accessor = new TestHttpContextAccessor(httpContext); + var accessor = new HttpContextAccessor + { + HttpContext = httpContext + }; var logger = new LoggerFactory().CreateLogger(); - var cookieService = new HttpContextCookieService(accessor, httpContext.Features, logger); + var cookieService = new HttpContextCookieService(accessor, logger); return new TestServices(httpContext, accessor, cookieService); } private record TestServices(HttpContext HttpContext, IHttpContextAccessor HttpContextAccessor, ICookieService CookieService); - - private class TestHttpContextAccessor(HttpContext httpContext) : IHttpContextAccessor - { - private HttpContext? _httpContext = httpContext; - - public HttpContext? HttpContext - { - get => _httpContext; - set => _httpContext = value; - } - } } \ No newline at end of file