public void Test_ConfigureWithDI_HotReload_Ok() { // Arrange PrepareHotReloadFile(); var expected = new ConfigA("Config1", 4, true); var configurations = this.Builder .Auto <ConfigA>(FileType.Json) .Build(); var provider = new ServiceCollection() .AddOptions() .AutoConfigure <ConfigA>(configurations) .BuildServiceProvider(); // Act var old = provider.GetService <IOptions <ConfigA> >().Value; var file = ModifyHotReloadFile(expected); var actual = provider .GetRequiredService <IOptionsSnapshot <ConfigA> >() .Value; // Assert Console.WriteLine(JsonConvert.SerializeObject( old, Formatting.Indented )); expected.AssertWith(actual); file.Delete(); }
public void Test_BuildFromOptionalSources_ConfigAJson_Ok() { // Arrange var expected = new ConfigA("Config1", 2, true); var source = new ConfigurationSource <ConfigA>( Environment.Default, FileType.Json, false ); // Act var actual = new ConfigA(); this.Builder .Register( source, source.With(Environment.Production).With(true) ) .Build() .GetSection(nameof(ConfigA)) .Bind(actual); // Assert expected.AssertWith(actual); }
public void Test_ConfigA_AutoBound() { // Arrange var expected = new ConfigA("Config1", 3, true); // Act var actual = this.Builder .Auto <ConfigA>(FileType.Json) .Build() .Bind <ConfigA>(); // Assert expected.AssertWith(actual); }
public void Test_AutoBuild_ConfigAJson_Ok() { // Arrange var expected = new ConfigA("Config1", 3, true); // Act var actual = new ConfigA(); this.Builder .Auto <ConfigA>(FileType.Json) .Build() .GetSection(nameof(ConfigA)) .Bind(actual); // Assert expected.AssertWith(actual); }
public void Test_AutoBind_MultiConfig_Ok() { // Arrange var expectedA = new ConfigA("Config1", 3, true); var expectedB = new ConfigA("Config1", 2, true); // Act var builder = this.Builder .Auto <ConfigA>(FileType.Json) .Auto <ConfigB>(FileType.Json) .Build(); var actualA = builder.Bind <ConfigA>(); var actualB = builder.Bind <ConfigB>(); // Assert expectedA.AssertWith(actualA); expectedB.AssertWith(actualB.ConfigA); }
public void Test_ConfigureWithDI_Ok() { // Arrange var expected = new ConfigA("Config1", 3, true); var configurations = this.Builder .Auto <ConfigA>(FileType.Json) .Build(); var provider = new ServiceCollection() .AddOptions() .AutoConfigure <ConfigA>(configurations) .BuildServiceProvider(); // Act var actual = provider .GetRequiredService <IOptions <ConfigA> >() .Value; // Assert expected.AssertWith(actual); }