public Facts(ITestOutputHelper output) { Options = new Mock <IOptionsSnapshot <FeatureFlagConfiguration> >(); CacheService = new Mock <IFeatureFlagCacheService>(); Logger = new LoggerFactory().AddXunit(output).CreateLogger <FeatureFlagRefresher>(); IsCacheServiceInitialized = false; Config = new FeatureFlagConfiguration { ConnectionString = "some-connection-string", RefreshInternal = TimeSpan.FromSeconds(5), }; FeatureFlags = new NuGet.Services.FeatureFlags.FeatureFlags( new Dictionary <string, FeatureStatus>(), new Dictionary <string, Flight>()); Options.Setup(x => x.Value).Returns(() => Config); LazyCacheService = new Lazy <IFeatureFlagCacheService>(() => { IsCacheServiceInitialized = true; return(CacheService.Object); }); Operations = new ConcurrentQueue <string>(); CacheService .Setup(x => x.GetLatestFlagsOrNull()) .Returns(() => FeatureFlags) .Callback(() => Operations.Enqueue(nameof(IFeatureFlagCacheService.GetLatestFlagsOrNull))); CacheService .Setup(x => x.RefreshAsync()) .Returns(Task.CompletedTask) .Callback(() => Operations.Enqueue(nameof(IFeatureFlagCacheService.RefreshAsync))); CacheService .Setup(x => x.RunAsync(It.IsAny <CancellationToken>())) .Returns <CancellationToken>(async token => { // We use a delay here to simulate a real long running task. We don't want to delay for too // long so that if there is a test or product bug we don't want to hang. This is enough time // for test logic to complete. try { await Task.Delay(TimeSpan.FromSeconds(30), token); } catch (OperationCanceledException) { Cancelled = true; } }) .Callback(() => Operations.Enqueue(nameof(IFeatureFlagCacheService.RunAsync))); Target = new FeatureFlagRefresher( Options.Object, LazyCacheService, Logger); }
public FeatureFlagService(IOptions <FeatureFlagConfiguration> featureFlagConfigurationOptions) { _featureFlagConfigurationOptions = featureFlagConfigurationOptions.Value; }
public GetPersonBySearchTermQueryHandler(BookingsDbContext context, IOptions <FeatureFlagConfiguration> featureFlagConfigurationOptions) { _context = context; _featureFlagConfiguration = featureFlagConfigurationOptions.Value; }