using Core.Configurations.SmartConfig; using Core.Configurations; using FluentAssertions; using Core.Configurations.JsonConfigProvider; using Autofac; using System.Data; using Insight.Database; using Npgsql; namespace Tests.ConfigurationTests { [TestClass] public class SmartConfigProviderTests : TestFixture { [TestMethod] public void TrySmartConfigWithOptionsForPostgres() { var config = new ConfigurationBuilder() .AddJsonFile("appconfiguration.dev.json") .AddSmartConfig(options => options.UsePostgres("DefaultConnection")) .Build(); var actualFeature = config.Get("Database:UseSSL"); } [TestMethod] public void Get_ShouldReturnCorrectValueAsBool() { // Arrange var expectedFeature = true; var config = new ConfigurationBuilder() .AddJsonFile("appconfiguration.dev.json") .AddSmartConfig() .Build(); // Act var actualFeature = config.Get("Database:UseSSL"); // Assert actualFeature.Should().Be(expectedFeature); } [TestMethod] public void Get_ShouldReturnCorrectValueWhenSelectingIntoValueRowInConfigTable() { // Arrange var expectedFeature = 100; var builder = new ConfigurationBuilder() .AddJsonFile("appconfiguration.dev.json") .AddSmartConfig() .Build(); // Act var actualFeature = builder.GetSection("Logging:FileOptions").Get("MaxSizeMB"); var withoutSectionThisAlsoWorks = builder.Get("Logging:FileOptions:MaxSizeMB"); // Assert actualFeature.Should().Be(expectedFeature); actualFeature.Should().Be(withoutSectionThisAlsoWorks); } [TestMethod] public void TryGetActiveConfigurations() { const string sql = @" SELECT id, ""key"", value, label, content_type, valid_from, expires_at, created_at, modified_at, etag FROM app_configuration WHERE CURRENT_TIMESTAMP BETWEEN valid_from AND expires_at OR (valid_from IS NULL AND expires_at IS NULL)"; var conn = Container.Resolve(); var result = conn.QuerySql(sql); } } }