wip on tests
This commit is contained in:
parent
440087c43b
commit
75e0406251
4 changed files with 234 additions and 165 deletions
|
|
@ -11,131 +11,132 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|||
|
||||
namespace Tests.ConfigurationTests
|
||||
{
|
||||
[TestClass]
|
||||
public class JsonConfigurationProviderTests : TestFixture
|
||||
{
|
||||
[TestMethod]
|
||||
public void GetSection_ShouldReturnCorrectFeatureSection()
|
||||
{
|
||||
// Arrange
|
||||
var expectedJObject = JObject.Parse(@"{
|
||||
[TestClass]
|
||||
public class JsonConfigurationProviderTests : TestFixture
|
||||
{
|
||||
public JsonConfigurationProviderTests() : base("ConfigurationTests") { }
|
||||
[TestMethod]
|
||||
public void GetSection_ShouldReturnCorrectFeatureSection()
|
||||
{
|
||||
// Arrange
|
||||
var expectedJObject = JObject.Parse(@"{
|
||||
'Enabled': true,
|
||||
'RolloutPercentage': 25,
|
||||
'AllowedUserGroups': ['beta']
|
||||
}") as JToken;
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var section = builder.GetSection("Feature");
|
||||
// Act
|
||||
var section = builder.GetSection("Feature");
|
||||
|
||||
// Assert
|
||||
section.Should().NotBeNull();
|
||||
section.Value.Should().BeEquivalentTo(expectedJObject);
|
||||
}
|
||||
// Assert
|
||||
section.Should().NotBeNull();
|
||||
section.Value.Should().BeEquivalentTo(expectedJObject);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectFeatureObject()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = new Feature
|
||||
{
|
||||
Enabled = true,
|
||||
RolloutPercentage = 25,
|
||||
AllowedUserGroups = new() { "beta" }
|
||||
};
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectFeatureObject()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = new Feature
|
||||
{
|
||||
Enabled = true,
|
||||
RolloutPercentage = 25,
|
||||
AllowedUserGroups = new() { "beta" }
|
||||
};
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var actualFeature = builder.GetSection("Feature").ToObject<Feature>();
|
||||
// Act
|
||||
var actualFeature = builder.GetSection("Feature").ToObject<Feature>();
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
var actualFeatureObsoleted = builder.GetSection("Feature").Get<Feature>();
|
||||
var actualFeatureObsoleted = builder.GetSection("Feature").Get<Feature>();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
// Assert
|
||||
actualFeature.Should().BeEquivalentTo(expectedFeature);
|
||||
actualFeatureObsoleted.Should().BeEquivalentTo(expectedFeature);
|
||||
// Assert
|
||||
actualFeature.Should().BeEquivalentTo(expectedFeature);
|
||||
actualFeatureObsoleted.Should().BeEquivalentTo(expectedFeature);
|
||||
|
||||
}
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsString()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = "123";
|
||||
}
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsString()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = "123";
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var actualFeature = builder.GetSection("AnotherSetting").Get<string>("Thresholds:High");
|
||||
// Act
|
||||
var actualFeature = builder.GetSection("AnotherSetting").Get<string>("Thresholds:High");
|
||||
|
||||
// Assert
|
||||
actualFeature.Should().BeEquivalentTo(expectedFeature);
|
||||
}
|
||||
/// <summary>
|
||||
/// Testing a stupid indexer for compability with Microsoft ConfigurationBuilder
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void Indexer_ShouldReturnValueAsString()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "SHA256";
|
||||
// Assert
|
||||
actualFeature.Should().BeEquivalentTo(expectedFeature);
|
||||
}
|
||||
/// <summary>
|
||||
/// Testing a stupid indexer for compability with Microsoft ConfigurationBuilder
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void Indexer_ShouldReturnValueAsString()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "SHA256";
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var actual = builder["Authentication"];
|
||||
// Act
|
||||
var actual = builder["Authentication"];
|
||||
|
||||
// Assert
|
||||
actual.Should().BeEquivalentTo(expected);
|
||||
}
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsInt()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = 22;
|
||||
// Assert
|
||||
actual.Should().BeEquivalentTo(expected);
|
||||
}
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsInt()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = 22;
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var actualFeature = builder.GetSection("AnotherSetting:Temperature").Get<int>("Indoor:Max:Limit");
|
||||
// Act
|
||||
var actualFeature = builder.GetSection("AnotherSetting:Temperature").Get<int>("Indoor:Max:Limit");
|
||||
|
||||
// Assert
|
||||
actualFeature.Should().Be(expectedFeature);
|
||||
}
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsBool()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = true;
|
||||
// Assert
|
||||
actualFeature.Should().Be(expectedFeature);
|
||||
}
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsBool()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = true;
|
||||
|
||||
var configRoot = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.AddSmartConfig()
|
||||
.Build();
|
||||
var configRoot = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.AddSmartConfig()
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var actualFeature = configRoot.Get<bool>("Database:UseSSL");
|
||||
// Act
|
||||
var actualFeature = configRoot.Get<bool>("Database:UseSSL");
|
||||
|
||||
// Assert
|
||||
actualFeature.Should().Be(expectedFeature);
|
||||
}
|
||||
}
|
||||
// Assert
|
||||
actualFeature.Should().Be(expectedFeature);
|
||||
}
|
||||
}
|
||||
|
||||
public class Feature
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
public int RolloutPercentage { get; set; }
|
||||
public List<string> AllowedUserGroups { get; set; }
|
||||
}
|
||||
public class Feature
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
public int RolloutPercentage { get; set; }
|
||||
public List<string> AllowedUserGroups { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue