public void Build_WhenArgumentAreAfterInMemory_ShouldUseArgumentBinder() { var section = nameof(ICommandLineInterface).TrimStart('I'); var collection = new InMemoryCollection(); collection.Add(section, "name", "name"); collection.Add(section, "Age", "15"); var sut = SettingsBuilder.CreateBuilder(x => x.AddInMemoryCollection(collection)); var result = sut.GetSettings <ICommandLineInterface>(); Assert.Equal("name", result.Name); Assert.Equal(15, result.Age); sut = SettingsBuilder.CreateBuilder(x => x.AddInMemoryCollection(collection) .AddArguments(Args.Split(' '), o => o.SetCaseSensitivity(false))); result = sut.GetSettings <ICommandLineInterface>(); Assert.Equal("value", result.Name); Assert.Equal(3, result.Age); }
public AzureTranslationClient(HttpClient client, ILogger <AzureTranslationClient> logger, IOptions <AzureConfig> config, InMemoryCollection inMemoryCollection) { _config = config?.Value ?? throw new ArgumentNullException(nameof(config)); _client = client ?? throw new ArgumentNullException(nameof(client)); _client.BaseAddress = new Uri(_config.TranslationBaseUrl); _inMemoryCollection = inMemoryCollection ?? throw new ArgumentNullException(nameof(inMemoryCollection)); _logger = logger; }
public TreeEdgesCollection_QueryableTests() { _propertyResolver .Setup(x => x.GetEntityId(It.IsAny <EntityNode>())) .Returns((EntityNode t) => t.Id); _inMemoryCollection = new InMemoryCollection <FakeEntityContext, EntityNode>(_propertyResolver.Object, "fake-entity-context"); _treeEdgesCollection = new EntityNodesCollection(_inMemoryCollection); }
public static T AddInMemoryCollection <T>(this T target, InMemoryCollection collection) where T : ISettingsBuilderFactory { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (collection == null) { throw new ArgumentNullException(nameof(collection)); } target.AddSectionBinder(new InMemoryBinder(collection)); return(target); }
public void Build_WhenMemoryBinderSetValues_ShouldSetProperData() { var value = Guid.NewGuid().ToString(); var collection = new InMemoryCollection(); collection.Add("Root", "Value", value); var sut = BuildSutWithBinder(new InMemoryBinder(collection)); var result = sut.ScanAssemblies(GetType().Assembly); var settings = result.GetSettings <IRoot>(); Assert.Equal(value, settings.Value); }
public void TryGetValue_WhenMemoryCollectionIsLast_ShouldSetValueFromMemoryBinder() { var guid = Guid.NewGuid().ToString(); var badGuid = Guid.NewGuid().ToString(); using (new DisposableEnvironmentVariable(EnvironmentVariable, badGuid)) { var collection = new InMemoryCollection(); collection.Add(nameof(IWithEnvironmentVariable).TrimStart('I'), EnvironmentVariable, guid); var sut = SettingsBuilder.CreateBuilder(x => { x.AddEnvironmentVariable() .AddInMemoryCollection(collection); }); var settings = sut.GetSettings <IWithEnvironmentVariable>(); Assert.Equal(guid, settings.EnvironmentVariable); } }
public InMemoryBinder(InMemoryCollection collection) { _collection = collection; }