private async Task DoLoad(bool reloading) { try { IConfigQueryResult configQueryResult = await _consulConfigClient.GetConfig(); if (!configQueryResult.Exists && !_source.Optional) { if (!reloading) { throw new Exception($"The configuration for key {_source.Key} was not found and is not optional."); } else { // Don't overwrite mandatory config with empty data if not found when reloading return; } } LoadIntoMemory(configQueryResult); } catch (Exception exception) { HandleLoadException(exception); } }
public async Task ShouldReturnResultWhenGetConfigReceivesValidResponse(HttpStatusCode statusCode) { var result = new QueryResult <KVPair> { StatusCode = statusCode }; IConfigQueryResult configQueryResult = await SimulateGet(result); Assert.That(configQueryResult, Is.Not.Null); }
private void LoadIntoMemory(IConfigQueryResult configQueryResult) { if (!configQueryResult.Exists) { Data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); return; } using (var configStream = new MemoryStream(configQueryResult.Value)) { var parsedData = _source.Parser.Parse(configStream); Data = new Dictionary <string, string>(parsedData, StringComparer.OrdinalIgnoreCase); } }