Esempio n. 1
0
            public void File_location_interprets_tilde_as_home_directory_on_windows()
            {
                var platform = Platform.Analyze();

                if (platform.IsRunningOnMono)
                {
                    return;
                }

                var homeDir = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

                this.file = Substitute.For <IFile>();
                this.file.ReadAllText($"{homeDir}\\test.properties")
                .Returns(this.fileContents);

                var env = Substitute.For <IEnvironment>();

                env.ExpandEnvironmentVariables(Arg.Any <string>())
                .Returns(call => Environment.ExpandEnvironmentVariables(call.Arg <string>()));

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For <IConfigurationManager>(),
                    env,
                    this.file,
                    Substitute.For <ILogger>());

                var clientApiKey = this.builder
                                   .SetFileLocation("~\\test.properties")
                                   .Build();

                clientApiKey.GetId().ShouldBe("foobar");
                clientApiKey.GetSecret().ShouldBe("bazsecret!");
            }
Esempio n. 2
0
            public void Observes_property_name_settings()
            {
                var newKeyIdName     = "myApiKeyId";
                var newKeySecretName = "myApiKeySecret";

                this.config = Substitute.For <IConfigurationManager>();
                this.config.AppSettings.Returns(new System.Collections.Specialized.NameValueCollection()
                {
                    { newKeyIdName, this.fakeApiKeyId },
                    { newKeySecretName, this.fakeApiSecretId }
                });
                this.builder = new DefaultClientApiKeyBuilder(
                    this.config,
                    Substitute.For <IEnvironment>(),
                    Substitute.For <IFile>(),
                    Substitute.For <ILogger>());

                var clientApiKey = this.builder
                                   .SetIdPropertyName(newKeyIdName)
                                   .SetSecretPropertyName(newKeySecretName)
                                   .Build();

                clientApiKey.GetId().ShouldBe(this.fakeApiKeyId);
                clientApiKey.GetSecret().ShouldBe(this.fakeApiSecretId);
            }
Esempio n. 3
0
 public Building_with_explicit_values()
 {
     this.builder = new DefaultClientApiKeyBuilder(
         Substitute.For <IConfigurationManager>(),
         Substitute.For <IEnvironment>(),
         Substitute.For <IFile>(),
         Substitute.For <ILogger>());
 }
 public With_missing_values()
 {
     this.builder = new DefaultClientApiKeyBuilder(
         Substitute.For<IConfigurationManager>(),
         Substitute.For<IEnvironment>(),
         Substitute.For<IFile>(),
         Substitute.For<ILogger>());
 }
Esempio n. 5
0
            public Building_with_properties_file()
            {
                this.file = Substitute.For <IFile>();
                this.file.ReadAllText(this.testLocation)
                .Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For <IConfigurationManager>(),
                    Substitute.For <IEnvironment>(),
                    this.file,
                    Substitute.For <ILogger>());
            }
Esempio n. 6
0
            public Building_with_environment_variable_values()
            {
                this.env = Substitute.For <IEnvironment>();
                this.env.GetEnvironmentVariable(this.apiKeyIdVariableName).Returns(this.fakeApiKeyId);
                this.env.GetEnvironmentVariable(this.apiKeySecretVariableName).Returns(this.fakeApiSecretId);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For <IConfigurationManager>(),
                    this.env,
                    Substitute.For <IFile>(),
                    Substitute.For <ILogger>());
            }
Esempio n. 7
0
            public With_environment_variable_file()
            {
                this.env = Substitute.For <IEnvironment>();
                this.env.GetEnvironmentVariable(this.envVariableName).Returns(this.testLocation);

                this.file = Substitute.For <IFile>();
                this.file.ReadAllText(this.testLocation).Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For <IConfigurationManager>(),
                    this.env,
                    this.file,
                    Substitute.For <ILogger>());
            }
Esempio n. 8
0
            public Building_with_values_from_AppConfig()
            {
                this.config = Substitute.For <IConfigurationManager>();
                this.config.AppSettings.Returns(new System.Collections.Specialized.NameValueCollection()
                {
                    { this.apiKeyIdVariableName, this.fakeApiKeyId },
                    { this.secretVariableName, this.fakeApiSecretId }
                });

                this.builder = new DefaultClientApiKeyBuilder(
                    this.config,
                    Substitute.For <IEnvironment>(),
                    Substitute.For <IFile>(),
                    Substitute.For <ILogger>());
            }
Esempio n. 9
0
            public Building_with_file_location_from_AppConfig()
            {
                this.config = Substitute.For <IConfigurationManager>();
                this.config.AppSettings.Returns(new System.Collections.Specialized.NameValueCollection()
                {
                    { this.configVariableName, this.testLocation }
                });

                this.file = Substitute.For <IFile>();
                this.file.ReadAllText(this.testLocation).Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    this.config,
                    Substitute.For <IEnvironment>(),
                    this.file,
                    Substitute.For <ILogger>());
            }
Esempio n. 10
0
            public With_default_properties_file()
            {
                this.env = Substitute.For <IEnvironment>();
                this.env.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%").Returns("~fake");
                this.env.GetEnvironmentVariable("HOME").Returns("~fake");

                var platform = Platform.Analyze();

                this.defaultLocation = platform.IsPlatformUnix
                    ? @"~fake/.stormpath/apiKey.properties"
                    : @"~fake\.stormpath\apiKey.properties";

                this.file = Substitute.For <IFile>();
                this.file.ReadAllText(this.defaultLocation).Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For <IConfigurationManager>(),
                    this.env,
                    this.file,
                    Substitute.For <ILogger>());
            }
Esempio n. 11
0
            public void Observes_property_name_settings()
            {
                var newKeyName    = "different_env_apikeyid";
                var newSecretName = "different_env_secret";

                this.env = Substitute.For <IEnvironment>();
                this.env.GetEnvironmentVariable(newKeyName).Returns(this.fakeApiKeyId);
                this.env.GetEnvironmentVariable(newSecretName).Returns(this.fakeApiSecretId);
                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For <IConfigurationManager>(),
                    this.env,
                    Substitute.For <IFile>(),
                    Substitute.For <ILogger>());

                var clientApiKey = this.builder
                                   .SetIdPropertyName(newKeyName)
                                   .SetSecretPropertyName(newSecretName)
                                   .Build();

                clientApiKey.GetId().ShouldBe(this.fakeApiKeyId);
                clientApiKey.GetSecret().ShouldBe(this.fakeApiSecretId);
            }
            public void Observes_property_name_settings()
            {
                var newKeyIdName = "myApiKeyId";
                var newKeySecretName = "myApiKeySecret";

                this.config = Substitute.For<IConfigurationManager>();
                this.config.AppSettings.Returns(new System.Collections.Specialized.NameValueCollection()
                {
                    { newKeyIdName, this.fakeApiKeyId },
                    { newKeySecretName, this.fakeApiSecretId }
                });
                this.builder = new DefaultClientApiKeyBuilder(
                    this.config,
                    Substitute.For<IEnvironment>(),
                    Substitute.For<IFile>(),
                    Substitute.For<ILogger>());

                var clientApiKey = this.builder
                    .SetIdPropertyName(newKeyIdName)
                    .SetSecretPropertyName(newKeySecretName)
                    .Build();

                clientApiKey.GetId().ShouldBe(this.fakeApiKeyId);
                clientApiKey.GetSecret().ShouldBe(this.fakeApiSecretId);
            }
            public Building_with_values_from_AppConfig()
            {
                this.config = Substitute.For<IConfigurationManager>();
                this.config.AppSettings.Returns(new System.Collections.Specialized.NameValueCollection()
                {
                    { this.apiKeyIdVariableName, this.fakeApiKeyId },
                    { this.secretVariableName, this.fakeApiSecretId }
                });

                this.builder = new DefaultClientApiKeyBuilder(
                    this.config,
                    Substitute.For<IEnvironment>(),
                    Substitute.For<IFile>(),
                    Substitute.For<ILogger>());
            }
            public Building_with_file_location_from_AppConfig()
            {
                this.config = Substitute.For<IConfigurationManager>();
                this.config.AppSettings.Returns(new System.Collections.Specialized.NameValueCollection()
                {
                    { this.configVariableName, this.testLocation }
                });

                this.file = Substitute.For<IFile>();
                this.file.ReadAllText(this.testLocation).Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    this.config,
                    Substitute.For<IEnvironment>(),
                    this.file,
                    Substitute.For<ILogger>());
            }
            public void Observes_property_name_settings()
            {
                var newKeyName = "different_env_apikeyid";
                var newSecretName = "different_env_secret";

                this.env = Substitute.For<IEnvironment>();
                this.env.GetEnvironmentVariable(newKeyName).Returns(this.fakeApiKeyId);
                this.env.GetEnvironmentVariable(newSecretName).Returns(this.fakeApiSecretId);
                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For<IConfigurationManager>(),
                    this.env,
                    Substitute.For<IFile>(),
                    Substitute.For<ILogger>());

                var clientApiKey = this.builder
                    .SetIdPropertyName(newKeyName)
                    .SetSecretPropertyName(newSecretName)
                    .Build();
                clientApiKey.GetId().ShouldBe(this.fakeApiKeyId);
                clientApiKey.GetSecret().ShouldBe(this.fakeApiSecretId);
            }
            public Building_with_environment_variable_values()
            {
                this.env = Substitute.For<IEnvironment>();
                this.env.GetEnvironmentVariable(this.apiKeyIdVariableName).Returns(this.fakeApiKeyId);
                this.env.GetEnvironmentVariable(this.apiKeySecretVariableName).Returns(this.fakeApiSecretId);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For<IConfigurationManager>(),
                    this.env,
                    Substitute.For<IFile>(),
                    Substitute.For<ILogger>());
            }
            public With_environment_variable_file()
            {
                this.env = Substitute.For<IEnvironment>();
                this.env.GetEnvironmentVariable(this.envVariableName).Returns(this.testLocation);

                this.file = Substitute.For<IFile>();
                this.file.ReadAllText(this.testLocation).Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For<IConfigurationManager>(),
                    this.env,
                    this.file,
                    Substitute.For<ILogger>());
            }
 public Building_with_stream()
 {
     this.builder = new DefaultClientApiKeyBuilder(
         Substitute.For<IConfigurationManager>(),
         Substitute.For<IEnvironment>(),
         Substitute.For<IFile>(),
         Substitute.For<ILogger>());
 }
            public void File_location_interprets_tilde_as_home_directory_on_windows()
            {
                var platform = Platform.Analyze();
                if (platform.IsRunningOnMono)
                {
                    return;
                }

                var homeDir = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

                this.file = Substitute.For<IFile>();
                this.file.ReadAllText($"{homeDir}\\test.properties")
                    .Returns(this.fileContents);

                var env = Substitute.For<IEnvironment>();
                env.ExpandEnvironmentVariables(Arg.Any<string>())
                    .Returns(call => Environment.ExpandEnvironmentVariables(call.Arg<string>()));

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For<IConfigurationManager>(),
                    env,
                    this.file,
                    Substitute.For<ILogger>());

                var clientApiKey = this.builder
                    .SetFileLocation("~\\test.properties")
                    .Build();

                clientApiKey.GetId().ShouldBe("foobar");
                clientApiKey.GetSecret().ShouldBe("bazsecret!");
            }
            public Building_with_properties_file()
            {
                this.file = Substitute.For<IFile>();
                this.file.ReadAllText(this.testLocation)
                    .Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For<IConfigurationManager>(),
                    Substitute.For<IEnvironment>(),
                    this.file,
                    Substitute.For<ILogger>());
            }
Esempio n. 21
0
 public DefaultClientBuilder(IUserAgentBuilder userAgentBuilder)
 {
     this.userAgentBuilder    = userAgentBuilder;
     this.clientApiKeyBuilder = ClientApiKeys.Builder();
 }
            public With_default_properties_file()
            {
                this.env = Substitute.For<IEnvironment>();
                this.env.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%").Returns("~fake");
                this.env.GetEnvironmentVariable("HOME").Returns("~fake");

                var platform = Platform.Analyze();

                this.defaultLocation = platform.IsPlatformUnix
                    ? @"~fake/.stormpath/apiKey.properties"
                    : @"~fake\.stormpath\apiKey.properties";

                this.file = Substitute.For<IFile>();
                this.file.ReadAllText(this.defaultLocation).Returns(this.fileContents);

                this.builder = new DefaultClientApiKeyBuilder(
                    Substitute.For<IConfigurationManager>(),
                    this.env,
                    this.file,
                    Substitute.For<ILogger>());
            }
Esempio n. 23
0
 internal DefaultClientBuilder(IClientApiKeyBuilder clientApiKeyBuilder, IUserAgentBuilder userAgentBuilder)
     : this(userAgentBuilder)
 {
     this.clientApiKeyBuilder = clientApiKeyBuilder;
 }