12345678910111213141516171819202122232425262728293031323334 |
- using System.Security.Claims;
- using Hotline.Configurations;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- namespace Hotline.Tests.Mock;
- public class OptionsSnapshotMock : IOptionsSnapshot<AppConfiguration>
- {
- private readonly IHttpContextAccessor _contextAccessor;
- private readonly IConfiguration _configuration;
- public OptionsSnapshotMock(IHttpContextAccessor contextAccessor, IConfiguration configuration)
- {
- _contextAccessor = contextAccessor;
- _configuration = configuration;
- }
- public AppConfiguration Value
- {
- get
- {
- var appConfiguration = _configuration.GetRequiredSection(nameof(AppConfiguration)).Get<AppConfiguration>();
- if (_contextAccessor != null && _contextAccessor.HttpContext != null)
- appConfiguration.AppScope = _contextAccessor.HttpContext.User.FindFirstValue("AppScope");
- return appConfiguration;
- }
- }
- public AppConfiguration Get(string? name)
- {
- throw new NotImplementedException();
- }
- }
|