public static void GetEnvironmentVariable_GivenMissingVariable_ReturnsNull()
        {
            var env        = new EnvironmentVariableProvider();
            var missingVar = env.GetEnvironmentVariable("THIS_WILL_NOT_BE_FOUND");

            Assert.IsNull(missingVar);
        }
        public static void GetEnvironmentVariableT_GivenMissingVariable_ReturnsDefaultValue()
        {
            var env        = new EnvironmentVariableProvider();
            var missingVar = env.GetEnvironmentVariable <int>("THIS_WILL_NOT_BE_FOUND");

            Assert.AreEqual(missingVar, default(int));
        }
        public static void GetEnvironmentVariableT_GivenExistingVariableAndCorrectType_ReturnsCorrectValue()
        {
            var env = new EnvironmentVariableProvider();

            var numberOfProcessors = env.GetEnvironmentVariable <int>("NUMBER_OF_PROCESSORS");

            Assert.IsTrue(numberOfProcessors > 0);
        }
        public static void HasEnvironmentVariable_GivenMissingVariable_ReturnsFalse()
        {
            var env = new EnvironmentVariableProvider();

            var notFoundVarPresent = env.HasEnvironmentVariable("THIS_WILL_NOT_BE_FOUND");

            Assert.IsFalse(notFoundVarPresent);
        }
        public static void HasEnvironmentVariable_GivenExistingVariable_ReturnsTrue()
        {
            var env = new EnvironmentVariableProvider();

            var pathVarPresent = env.HasEnvironmentVariable("PATH");

            Assert.IsTrue(pathVarPresent);
        }
Exemplo n.º 6
0
        public void ReadAndSeEnvVariables_AllEmpty()
        {
            var environmentVariableProvider = new EnvironmentVariableProvider(_fileSystem, new CurrentApplicationInfo("test"));

            environmentVariableProvider.GetEnvironmentVariable("ZONE").ShouldBe("il1a");
            environmentVariableProvider.GetEnvironmentVariable("REGION").ShouldBe("il1");
            environmentVariableProvider.GetEnvironmentVariable("ENV").ShouldBe("orl11");
            environmentVariableProvider.GetEnvironmentVariable("GIGYA_CONFIG_PATHS_FILE").ShouldBe("c:\\gigya\\config\\loadpaths1.json");
        }
        public static void GetEnvironmentVariable_GivenExistingVariable_ReturnsCorrectValue()
        {
            var env = new EnvironmentVariableProvider();

            var providerPath = env.GetEnvironmentVariable("PATH");
            var sysPath      = Environment.GetEnvironmentVariable("PATH");

            Assert.AreEqual(sysPath, providerPath);
        }
        public static void TryGetEnvironmentVariableT_GivenExistingVariableAndIncorrectType_ReturnsFalseAndDefaultValue()
        {
            var env = new EnvironmentVariableProvider();

            var isFound = env.TryGetEnvironmentVariable <int>("PATH", out var pathInt);

            Assert.IsFalse(isFound);
            Assert.AreEqual(default(int), pathInt);
        }
Exemplo n.º 9
0
        public void OnNotExistingFile_DoNothing()
        {
            _fileSystem.TryReadAllTextFromFile(Arg.Any <string>()).Returns(a => null);

            var environmentVariableProvider = new EnvironmentVariableProvider(_fileSystem, new CurrentApplicationInfo("test"));

            // assert environment variables were not changed
            environmentVariableProvider.GetEnvironmentVariable("ZONE").ShouldBe(DEFAULT_ZONE);
            environmentVariableProvider.GetEnvironmentVariable("REGION").ShouldBe(DEFAULT_REGION);
            environmentVariableProvider.GetEnvironmentVariable("ENV").ShouldBe(DEFAULT_ENV);
        }
        public void ReadAndSeEnvVariables_SomeEmpty()
        {
            Environment.SetEnvironmentVariable("ZONE", "il1b");

            var environmentVariableProvider = new EnvironmentVariableProvider(_fileSystem);

            environmentVariableProvider.GetEnvironmentVariable("ZONE").ShouldBe("il1a");
            environmentVariableProvider.GetEnvironmentVariable("REGION").ShouldBe("il1");
            environmentVariableProvider.GetEnvironmentVariable("ENV").ShouldBe("orl11");
            environmentVariableProvider.GetEnvironmentVariable("GIGYA_CONFIG_PATHS_FILE").ShouldBe("c:\\gigya\\config\\loadpaths1.json");
        }
        public async Task Can_resolve_environment_variables()
        {
            Environment.SetEnvironmentVariable("test-variable-1", @"c:\temp");

            var provider = new PhysicalFileProvider().DecorateWith(EnvironmentVariableProvider.Factory());
            //var provider = new PhysicalFileProvider() + EnvironmentVariableProvider.Factory();
            //var provider = new PhysicalFileProvider() + (left =>  new EnvironmentVariableProvider(left));
            var file = await provider.GetFileAsync(@"%test-variable-1%\test.txt", MimeType.Text);

            Assert.False(file.Exists);
            Assert.Equal("c:/temp/test.txt", file.Uri.Path.Decoded);
        }
        public static void TryGetEnvironmentVariableTWithFormatter_GivenMissingVariable_ReturnsFalseAndDefaultValue()
        {
            var env = new EnvironmentVariableProvider();

            var isFound = env.TryGetEnvironmentVariable <int>("THIS_WILL_NOT_BE_FOUND", null, out var notFoundVar);

            Assert.Multiple(() =>
            {
                Assert.IsFalse(isFound);
                Assert.AreEqual(default(int), notFoundVar);
            });
        }
        public static void TryGetEnvironmentVariable_GivenExistingVariable_ReturnsTrueAndCorrectValue()
        {
            var env = new EnvironmentVariableProvider();

            var isFound = env.TryGetEnvironmentVariable("PATH", out var providerPath);
            var sysPath = Environment.GetEnvironmentVariable("PATH");

            Assert.Multiple(() =>
            {
                Assert.IsTrue(isFound);
                Assert.AreEqual(sysPath, providerPath);
            });
        }
        public static void TryGetEnvironmentVariable_GivenMissingVariable_ReturnsFalseAndNullValue()
        {
            var env = new EnvironmentVariableProvider();

            var isFound = env.TryGetEnvironmentVariable("THIS_WILL_NOT_BE_FOUND", out var notFoundVar);

            _ = Environment.GetEnvironmentVariable("THIS_WILL_NOT_BE_FOUND");

            Assert.Multiple(() =>
            {
                Assert.IsFalse(isFound);
                Assert.IsNull(notFoundVar);
            });
        }
        public static void TryGetEnvironmentVariableT_GivenExistingVariableAndCorrectType_ReturnsTrueAndCorrectValue()
        {
            var env = new EnvironmentVariableProvider();

            // note that this will probably only work on Windows
            var isFound          = env.TryGetEnvironmentVariable <int>("NUMBER_OF_PROCESSORS", out var numberOfProcessors);
            var sysNumberOfProcs = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");

            Assert.Multiple(() =>
            {
                Assert.IsTrue(isFound);
                Assert.IsTrue(numberOfProcessors > 0);
                Assert.AreEqual(sysNumberOfProcs, numberOfProcessors.ToString());
            });
        }
Exemplo n.º 16
0
        public void ReadsEnvFromDefaultFile()
        {
            var environmentVariableProvider = new EnvironmentVariableProvider(_fileSystem, new CurrentApplicationInfo("test"));

            _fileSystem.Received().TryReadAllTextFromFile(environmentVariableProvider.PlatformSpecificPathPrefix + "/gigya/environmentVariables.json");
        }
Exemplo n.º 17
0
        protected override void Load(ContainerBuilder builder)
        {
            //builder
            //    .RegisterType<RuntimeFormatterFactory>()
            //    .As<IRuntimeFormatterFactory>();

            builder
            .RegisterType <PhysicalDirectoryTree>()
            .As <IDirectoryTree>();

            //builder
            //    .RegisterInstance(new PhysicalFileProvider().DecorateWith(EnvironmentVariableProvider.Factory()))
            //    .As<IResourceProvider>();

            //builder
            //    .RegisterInstance(new AppSettingProvider(new UriStringToSettingIdentifierConverter()))
            //    .As<IResourceProvider>();

            //            builder
            //                .RegisterType<CompositeResourceProvider>()
            //                .As<IFirstResourceProvider>();

            builder
            .RegisterInstance(new Configuration(new IResourceProvider[]
            {
                new AppSettingProvider(new UriStringToSettingIdentifierConverter()).DecorateWith(SettingNameProvider.Factory()),
            }))
            //.RegisterType<Configuration>()
            .As <IConfiguration>();

            builder
            .RegisterInstance(new CompositeProvider(new IResourceProvider[]
            {
                new PhysicalFileProvider().DecorateWith(EnvironmentVariableProvider.Factory()),
                new HttpProvider(ConfigurationManager.AppSettings["mailr:BaseUri"])
            }, ResourceMetadata.Empty.AllowRelativeUri(true)))
            .As <IResourceProvider>();

            builder
            .RegisterType <TestFileSerializer>()
            .As <ITestFileSerializer>();

            builder
            .RegisterInstance(RuntimeVariable.Enumerate());

            builder
            .Register(c =>
            {
                var context = c.Resolve <IComponentContext>();
                return(new AutofacContractResolver(context));
            }).SingleInstance()
            .As <IContractResolver>();

            builder
            .RegisterType <VariableNameValidator>()
            .As <IVariableNameValidator>();

            builder
            .RegisterType <TestLoader>()
            .As <ITestLoader>();

            builder
            .RegisterType <TestComposer>()
            .As <ITestComposer>();

            builder
            .RegisterType <TestRunner>()
            .As <ITestRunner>();

            builder
            .RegisterType <RuntimeFormatter>()
            .AsSelf();

            builder
            .RegisterModule(new CommanderModule(commands =>
                                                commands
                                                .Add <Commands.Explicit>()
                                                .Add <Commands.Batch>())
                            );
        }