public void ShouldFailWhenInvalidFlagTypesExistOnNonEmptyFlagsCollection() { Mock<ISettingsRepository> settingsRepo = new Mock<ISettingsRepository>(); _mockSettingsStorageModels.AddRange(new List<SettingsStorageModel>{ new SettingsStorageModel { Category = SettingsManager.FlagsCategoryName, Name = "ServiceBaseAddress", Value = "abbv", UpdatedAt = new DateTime(2015, 1, 1) }, new SettingsStorageModel { Category = SettingsManager.FlagsCategoryName, Name = "StartCount", Value = "12", UpdatedAt = new DateTime(2015, 2, 1) }}); settingsRepo.Setup(x => x.ReadSettings(It.IsAny<string>())) .Returns<string>(category => _mockSettingsStorageModels .Where(x => x.Category == category)); var manager = new SettingsManagerPeriodic(settingsRepo.Object); Assert.AreEqual(false, manager.IsFlagSet("ServiceBaseAddress")); Assert.AreEqual(false, manager.IsFlagSet("StartCount")); }
public void PeriodicReaderMustDetectNewFlags() { var cts = new CancellationTokenSource(); var repo = new InMemoryRepository(); var manager = new SettingsManagerPeriodic(repo); Assert.AreEqual(false, manager.IsFlagSet("TestFlag")); manager.StartReadingTask(TimeSpan.FromMilliseconds(10), cts.Token); repo.Content.Add(new SettingsStorageModel() { Category = SettingsManager.FlagsCategoryName, Name = "TestFlag", Value = "True" }); Thread.Sleep(200); Assert.AreEqual(true, manager.IsFlagSet("TestFlag")); cts.Cancel(); }
public void PeriodicReaderShouldReactToFlagChanges() { Mock<ISettingsRepository> settingsRepo = new Mock<ISettingsRepository>(); _mockSettingsStorageModels.AddRange(new List<SettingsStorageModel> { new SettingsStorageModel { Category = SettingsManager.FlagsCategoryName, Name = "X", Value = "true", UpdatedAt = new DateTime(2015, 1, 1) } }); settingsRepo.Setup(x => x.ReadSettings(It.IsAny<string>())) .Returns<string>(category => _mockSettingsStorageModels); settingsRepo.Setup(x => x.ReadSettings(It.IsAny<IList<string>>(), It.IsAny<DateTime?>())) .Returns<IList<string>, DateTime?>((categories, lastChangedDate) => _mockSettingsStorageModels); var cancellationTokenSource = new CancellationTokenSource(); var manager = new SettingsManagerPeriodic(settingsRepo.Object); var initialValue = manager.IsFlagSet("X"); manager.StartReadingTask(TimeSpan.FromMilliseconds(10), cancellationTokenSource.Token); Thread.Sleep(100); var repoItem = _mockSettingsStorageModels.Single(s => s.Name == "X"); repoItem.Value = "0"; Thread.Sleep(100); Assert.AreEqual(!initialValue, manager.IsFlagSet("X")); }
public void FlagShouldNotBeSetOnEmptyFlagsCollection() { Mock<ISettingsRepository> settingsRepo = new Mock<ISettingsRepository>(); settingsRepo.Setup(x => x.ReadSettings(It.IsAny<string>())) .Returns<string>(category => new List<SettingsStorageModel>().Where(x => x.Category == category)); var manager = new SettingsManagerPeriodic(settingsRepo.Object); Assert.AreEqual(false, manager.IsFlagSet("BiddingSystem")); }