public void Load_When_Configuration_Exists_With_Values_DoesNotThrow() { // Arrange var filePath = $"test-file-{Random.Int()}"; var testPropertyName = "testProperty"; var testPropertyValue = Random.Int().ToString(); var expected = new { iis = new { env = new string[] { $"{testPropertyName}={testPropertyValue}" } } }; File.WriteAllText(filePath, JsonConvert.SerializeObject(expected, Formatting.Indented)); var sut = new AmazonEBConfigurationProvider(configurationFilePath: filePath); // Act var result = Record.Exception(() => sut.Load()); // Assert result.ShouldBeNull(); }
public void Read_When_ConfigurationFilePath_With_Env_Variable_Containing_Double_Underscores_Returns_Dictionary_With_Value_Containing_Colon() { // Arrange var filePath = $"test-file-{Random.Int()}"; var testPropertyName = "test__Property"; var testPropertyNameTwo = "test__Property__Two"; var testPropertyValue = Random.Int().ToString(); var testPropertyValueTwo = Random.Int().ToString(); var expected = new { iis = new { env = new string[] { $"{testPropertyName}={testPropertyValue}", $"{testPropertyNameTwo}={testPropertyValueTwo}" } } }; File.WriteAllText(filePath, JsonConvert.SerializeObject(expected, Formatting.Indented)); var sut = new AmazonEBConfigurationProvider(configurationFilePath: filePath); // Act var result = sut.Read(); // Assert File.Delete(filePath); result.ShouldNotBeNull(); result.ShouldNotBeEmpty(); result[testPropertyName.Replace("__", ":")].ShouldBe(testPropertyValue); result[testPropertyNameTwo.Replace("__", ":")].ShouldBe(testPropertyValueTwo); }
public void Has_When_Key_DoesNotExist_Returns_False() { // Arrange var sut = new AmazonEBConfigurationProvider(); // Act var result = sut.Has("notfound"); // Assert result.ShouldBeFalse(); }
public void Get_When_Key_DoesNotExist_Returns_Null() { // Arrange var sut = new AmazonEBConfigurationProvider(); // Act var result = sut.Get("notfound"); // Assert result.ShouldBeNull(); }
public void Load_When_Configuration_DoesNotExist_DoesNotThrow() { // Arrange var sut = new AmazonEBConfigurationProvider(configurationFilePath: "file-that-does-not-exist"); // Act var result = Record.Exception(() => sut.Load()); // Assert result.ShouldBeNull(); }
public void Read_When_ConfigurationFilePath_DoesNotExist_Returns_Empty_Dictionary() { // Arrange var sut = new AmazonEBConfigurationProvider(configurationFilePath: "/file-that-does-not-exist"); // Act var result = sut.Read(); // Assert result.ShouldNotBeNull(); result.ShouldBeEmpty(); }
public void Read_When_CachedConfiguration_Set_Returns_CachedConfiguration() { // Arrange var expected = new Dictionary <string, string>(); var sut = new AmazonEBConfigurationProvider(); AmazonEBConfigurationProvider.CachedConfiguration = expected; // Act var result = sut.Read(); // Assert result.ShouldBe(expected); }
public void Load_When_Configuration_Exists_Without_Values_DoesNotThrow() { // Arrange var filePath = $"test-file-{Random.Int()}"; File.WriteAllText(filePath, "{}"); var sut = new AmazonEBConfigurationProvider(configurationFilePath: filePath); // Act var result = Record.Exception(() => sut.Load()); // Assert result.ShouldBeNull(); }
/// <summary> /// Configures resources from Amazon Elastic Beanstalk (EB) before AspNetCore /// is started up. Namely, reading of ASPNET environment /// </summary> /// <param name="builder"></param> /// <param name="stdoutEnabled">Should errors be output to standard output for debugging being this could be run before logging starts</param> /// <param name="configurationProvider"> TODO https://github.com/AndcultureCode/AndcultureCode.CSharp.Core/issues/37 /// </param> /// <returns></returns> public static IAndcultureCodeWebHostBuilder PreloadAmazonElasticBeanstalk( this IAndcultureCodeWebHostBuilder builder, bool stdoutEnabled = false, AmazonEBConfigurationProvider configurationProvider = null) { var ebProvider = configurationProvider ?? new AmazonEBConfigurationProvider(stdoutEnabled); if (ebProvider.Has(ASPNETCORE_ENVIRONMENT)) { var ebEnvironment = ebProvider.Get(ASPNETCORE_ENVIRONMENT); Environment.SetEnvironmentVariable(ASPNETCORE_ENVIRONMENT, ebEnvironment); } return(builder); }
public void Read_When_ConfigurationFilePath_Without_Env_Variable_Returns_Empty_Dictionary() { // Arrange var filePath = $"test-file-{Random.Int()}"; File.WriteAllText(filePath, "{}"); var sut = new AmazonEBConfigurationProvider(configurationFilePath: filePath); // Act var result = sut.Read(); // Assert File.Delete(filePath); result.ShouldNotBeNull(); result.ShouldBeEmpty(); }