86 lines
No EOL
2.4 KiB
C#
86 lines
No EOL
2.4 KiB
C#
using Core.Configurations;
|
|
using FluentAssertions;
|
|
using Core.Configurations.JsonConfigProvider;
|
|
using Autofac;
|
|
using System.Data;
|
|
using Insight.Database;
|
|
using Npgsql;
|
|
using Core.Configurations.SmartConfigProvider;
|
|
|
|
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<bool>("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<bool>("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<int>("MaxSizeMB");
|
|
var withoutSectionThisAlsoWorks = builder.Get<int>("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<IDbConnection>();
|
|
|
|
var result = conn.QuerySql(sql);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |