/// <summary> /// Get single entry from the configuration. /// </summary> /// <returns>Value associated with the key.</returns> public IConfigItem Get(string key) { if (!_memoryCacheService.Contains(key)) { throw new KeyNotFoundException(string.Format("Configuration key not found {0}", key)); } return(_memoryCacheService.Get(key)); }
public void Get_WhenCalledWithKey_ReturnsConfigItem() { // Arrange var configItems = new List <IConfigItem>() { new ConfigItem("key1", "value1"), new ConfigItem("key2", "value2"), new ConfigItem("key3", "value3"), }; var item = new ConfigItem("key1", "value1"); _memoryCacheService.Contains(item.key).Returns(true); _memoryCacheService.Get(item.key).Returns(item); _fileManager.ReadAllEntriesFromFile().Returns(configItems); _configurationService = new ConfigurationService(_fileManager, _memoryCacheService); // Act var result = _configurationService.Get(item.key); // Assert Assert.IsNotNull(result); Assert.AreEqual(item.key, result.key); Assert.AreEqual(item.value, result.value); }