示例#1
0
        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 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);
        }
示例#3
0
        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);
            }
        }