diff --git a/src/ConfigCat.Client.Tests/ConfigEvaluatorTestsBase.cs b/src/ConfigCat.Client.Tests/ConfigEvaluatorTestsBase.cs deleted file mode 100644 index 0dee4d39..00000000 --- a/src/ConfigCat.Client.Tests/ConfigEvaluatorTestsBase.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using ConfigCat.Client.Evaluation; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace ConfigCat.Client.Tests; - -public abstract class ConfigEvaluatorTestsBase : MatrixTestRunner - where TDescriptor : IMatrixTestDescriptor, new() -{ -#pragma warning disable IDE1006 // Naming Styles - private protected readonly LoggerWrapper Logger; -#pragma warning restore IDE1006 // Naming Styles - - internal readonly IRolloutEvaluator configEvaluator; - - public ConfigEvaluatorTestsBase() - { - this.Logger = new ConsoleLogger(LogLevel.Debug).AsWrapper(); - this.configEvaluator = new RolloutEvaluator(this.Logger); - } - - public static IEnumerable GetMatrixTests() => GetTests(); - - [TestCategory("MatrixTests")] - [DataTestMethod] - [DynamicData(nameof(GetMatrixTests), DynamicDataSourceType.Method)] - public void MatrixTests(string configLocation, string settingKey, string expectedReturnValue, - string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) - { - RunTest(this.configEvaluator, this.Logger, settingKey, expectedReturnValue, userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); - } -} diff --git a/src/ConfigCat.Client.Tests/ConfigV5EvaluationTests.cs b/src/ConfigCat.Client.Tests/ConfigV5EvaluationTests.cs new file mode 100644 index 00000000..cb64a1d6 --- /dev/null +++ b/src/ConfigCat.Client.Tests/ConfigV5EvaluationTests.cs @@ -0,0 +1,96 @@ +using System.Collections.Generic; +using ConfigCat.Client.Tests.Helpers; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ConfigCat.Client.Tests; + +[TestClass] +public class ConfigV5EvaluationTests : EvaluationTestsBase +{ + public class BasicTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d62463-86ec-8fde-f5b5-1c5c426fc830/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A"); + public string MatrixResultFileName => "testmatrix.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class NumericTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d747f0-5986-c2ef-eef3-ec778e32e10a/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/uGyK3q9_ckmdxRyI7vjwCw"); + public string MatrixResultFileName => "testmatrix_number.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class SemanticVersionTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d745f1-f315-7daf-d163-5541d3786e6f/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/BAr3KgLTP0ObzKnBTo5nhA"); + public string MatrixResultFileName => "testmatrix_semantic.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class SemanticVersion2TestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d77fa1-a796-85f9-df0c-57c448eb9934/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/q6jMCFIp-EmuAfnmZhPY7w"); + public string MatrixResultFileName => "testmatrix_semantic_2.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class SensitiveTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d7b724-9285-f4a7-9fcd-00f64f1e83d5/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/qX3TP2dTj06ZpCCT1h_SPA"); + public string MatrixResultFileName => "testmatrix_sensitive.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + private protected override Dictionary BasicConfig => MatrixTestRunner.Default.config; + + [DataTestMethod] + [DynamicData(nameof(BasicTestsDescriptor.GetTests), typeof(BasicTestsDescriptor), DynamicDataSourceType.Method)] + public void BasicTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(NumericTestsDescriptor.GetTests), typeof(NumericTestsDescriptor), DynamicDataSourceType.Method)] + public void NumericTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(SemanticVersionTestsDescriptor.GetTests), typeof(SemanticVersionTestsDescriptor), DynamicDataSourceType.Method)] + public void SemanticVersionTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(SemanticVersion2TestsDescriptor.GetTests), typeof(SemanticVersion2TestsDescriptor), DynamicDataSourceType.Method)] + public void SemanticVersion2Tests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(SensitiveTestsDescriptor.GetTests), typeof(SensitiveTestsDescriptor), DynamicDataSourceType.Method)] + public void SensitiveTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } +} diff --git a/src/ConfigCat.Client.Tests/ConfigV6EvaluationTests.cs b/src/ConfigCat.Client.Tests/ConfigV6EvaluationTests.cs index 7a334197..496541b8 100644 --- a/src/ConfigCat.Client.Tests/ConfigV6EvaluationTests.cs +++ b/src/ConfigCat.Client.Tests/ConfigV6EvaluationTests.cs @@ -12,47 +12,125 @@ namespace ConfigCat.Client.Tests; [TestClass] -public class ConfigV6EvaluationTests +public class ConfigV6EvaluationTests : EvaluationTestsBase { + public class BasicTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08dbc4dc-1927-4d6b-8fb9-b1472564e2d3/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/AG6C1ngVb0CvM07un6JisQ"); + public string MatrixResultFileName => "testmatrix.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class NumericTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08dbc4dc-0fa3-48d0-8de8-9de55b67fb8b/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/FCWN-k1dV0iBf8QZrDgjdw"); + public string MatrixResultFileName => "testmatrix_number.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class SemanticVersionTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08dbc4dc-278c-4f83-8d36-db73ad6e2a3a/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/iV8vH2MBakKxkFZylxHmTg"); + public string MatrixResultFileName => "testmatrix_semantic.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class SemanticVersion2TestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08dbc4dc-2b2b-451e-8359-abdef494c2a2/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/U8nt3zEhDEO5S2ulubCopA"); + public string MatrixResultFileName => "testmatrix_semantic_2.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + + public class SensitiveTestsDescriptor : IMatrixTestDescriptor + { + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08dbc4dc-2d62-4e1b-884b-6aa237b34764/244cf8b0-f604-11e8-b543-f23c917f9d8d + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/-0YmVOUNgEGKkgRF-rU65g"); + public string MatrixResultFileName => "testmatrix_sensitive.csv"; + public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); + } + public class AndOrMatrixTestsDescriptor : IMatrixTestDescriptor { - // https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4c16-c78b-473c-8b68-ca6723c98bfa/08db465d-a64e-4881-8ed0-62b6c9e68e33 - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/FfwncdJg1kq0lBqxhYC_7g", "https://test-cdn-eu.configcat.com"); + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9d5e-4988-891c-fd4a45790bd1/08dbc325-9ebd-4587-8171-88f76a3004cb + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/ByMO9yZNn02kXcm72lnY1A"); public string MatrixResultFileName => "testmatrix_and_or.csv"; public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); } public class ComparatorMatrixTestsDescriptor : IMatrixTestDescriptor { - // https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4be6-4a08-4c5c-8c35-30ef3a571a72/08db465d-a64e-4881-8ed0-62b6c9e68e33 - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/Lv2mD9Tgx0Km27nuHjw_FA", "https://test-cdn-eu.configcat.com"); + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9a6b-4947-84e2-91529248278a/08dbc325-9ebd-4587-8171-88f76a3004cb + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/OfQqcTjfFUGBwMKqtyEOrQ"); public string MatrixResultFileName => "testmatrix_comparators_v6.csv"; public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); } public class FlagDependencyMatrixTestsDescriptor : IMatrixTestDescriptor { - // https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4c12-1ff9-47dc-86ca-1186fe1dd43e/08db465d-a64e-4881-8ed0-62b6c9e68e33 - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/LGO_8DM9OUGpJixrqqqQcA", "https://test-cdn-eu.configcat.com"); + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9b74-45cb-86d0-4d61c25af1aa/08dbc325-9ebd-4587-8171-88f76a3004cb + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/JoGwdqJZQ0K2xDy7LnbyOg"); public string MatrixResultFileName => "testmatrix_prerequisite_flag.csv"; public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); } public class SegmentMatrixTestsDescriptor : IMatrixTestDescriptor { - // https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4c15-8ed0-49d6-8a76-778b50d0bc17/08db465d-a64e-4881-8ed0-62b6c9e68e33 - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/LP0_4hhbQkmVVJcsbO_2Lw", "https://test-cdn-eu.configcat.com"); + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9cfb-486f-8906-72a57c693615/08dbc325-9ebd-4587-8171-88f76a3004cb + public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/h99HYXWWNE2bH8eWyLAVMA"); public string MatrixResultFileName => "testmatrix_segments.csv"; public static IEnumerable GetTests() => MatrixTestRunner.GetTests(); } - private readonly LoggerWrapper logger; - private readonly IRolloutEvaluator configEvaluator; + private protected override Dictionary BasicConfig => MatrixTestRunner.Default.config; + + [DataTestMethod] + [DynamicData(nameof(BasicTestsDescriptor.GetTests), typeof(BasicTestsDescriptor), DynamicDataSourceType.Method)] + public void BasicTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(NumericTestsDescriptor.GetTests), typeof(NumericTestsDescriptor), DynamicDataSourceType.Method)] + public void NumericTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } - public ConfigV6EvaluationTests() + [DataTestMethod] + [DynamicData(nameof(SemanticVersionTestsDescriptor.GetTests), typeof(SemanticVersionTestsDescriptor), DynamicDataSourceType.Method)] + public void SemanticVersionTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) { - this.logger = new ConsoleLogger(LogLevel.Debug).AsWrapper(); - this.configEvaluator = new RolloutEvaluator(this.logger); + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(SemanticVersion2TestsDescriptor.GetTests), typeof(SemanticVersion2TestsDescriptor), DynamicDataSourceType.Method)] + public void SemanticVersion2Tests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); + } + + [DataTestMethod] + [DynamicData(nameof(SensitiveTestsDescriptor.GetTests), typeof(SensitiveTestsDescriptor), DynamicDataSourceType.Method)] + public void SensitiveTests(string configLocation, string settingKey, string expectedReturnValue, + string? userId, string? userEmail, string? userCountry, string? userCustomAttributeName, string? userCustomAttributeValue) + { + MatrixTestRunner.Default.RunTest(this.configEvaluator, this.logger, settingKey, expectedReturnValue, + userId, userEmail, userCountry, userCustomAttributeName, userCustomAttributeValue); } [DataTestMethod] diff --git a/src/ConfigCat.Client.Tests/BasicConfigEvaluatorTests.cs b/src/ConfigCat.Client.Tests/EvaluationTestsBase.cs similarity index 77% rename from src/ConfigCat.Client.Tests/BasicConfigEvaluatorTests.cs rename to src/ConfigCat.Client.Tests/EvaluationTestsBase.cs index e7810bf3..ee67108b 100644 --- a/src/ConfigCat.Client.Tests/BasicConfigEvaluatorTests.cs +++ b/src/ConfigCat.Client.Tests/EvaluationTestsBase.cs @@ -2,26 +2,27 @@ using System.Collections.Generic; using System.Reflection; using ConfigCat.Client.Evaluation; -using ConfigCat.Client.Tests.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ConfigCat.Client.Tests; -[TestClass] -public class BasicConfigEvaluatorTests : ConfigEvaluatorTestsBase +public abstract class EvaluationTestsBase { - public class Descriptor : IMatrixTestDescriptor - { - // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d62463-86ec-8fde-f5b5-1c5c426fc830/244cf8b0-f604-11e8-b543-f23c917f9d8d - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A"); + private protected readonly LoggerWrapper logger; + private protected readonly IRolloutEvaluator configEvaluator; - public string MatrixResultFileName => "testmatrix.csv"; + public EvaluationTestsBase() + { + this.logger = new ConsoleLogger(LogLevel.Debug).AsWrapper(); + this.configEvaluator = new RolloutEvaluator(this.logger); } + private protected abstract Dictionary BasicConfig { get; } + [TestMethod] public void GetValue_WithSimpleKey_ShouldReturnCat() { - var actual = this.configEvaluator.Evaluate(this.config, "stringDefaultCat", string.Empty, user: null, null, this.Logger).Value; + var actual = this.configEvaluator.Evaluate(BasicConfig, "stringDefaultCat", string.Empty, user: null, null, this.logger).Value; Assert.AreNotEqual(string.Empty, actual); Assert.AreEqual("Cat", actual); @@ -30,7 +31,7 @@ public void GetValue_WithSimpleKey_ShouldReturnCat() [TestMethod] public void GetValue_WithNonExistingKey_ShouldReturnDefaultValue() { - var actual = this.configEvaluator.Evaluate(this.config, "NotExistsKey", "NotExistsValue", user: null, null, this.Logger).Value; + var actual = this.configEvaluator.Evaluate(BasicConfig, "NotExistsKey", "NotExistsValue", user: null, null, this.logger).Value; Assert.AreEqual("NotExistsValue", actual); } @@ -38,7 +39,7 @@ public void GetValue_WithNonExistingKey_ShouldReturnDefaultValue() [TestMethod] public void GetValue_WithEmptyProjectConfig_ShouldReturnDefaultValue() { - var actual = this.configEvaluator.Evaluate(new Dictionary(), "stringDefaultCat", "Default", user: null, null, this.Logger).Value; + var actual = this.configEvaluator.Evaluate(new Dictionary(), "stringDefaultCat", "Default", user: null, null, this.logger).Value; Assert.AreEqual("Default", actual); } @@ -46,12 +47,12 @@ public void GetValue_WithEmptyProjectConfig_ShouldReturnDefaultValue() [TestMethod] public void GetValue_WithUser_ShouldReturnEvaluatedValue() { - var actual = this.configEvaluator.Evaluate(this.config, "doubleDefaultPi", double.NaN, new User("c@configcat.com") + var actual = this.configEvaluator.Evaluate(BasicConfig, "doubleDefaultPi", double.NaN, new User("c@configcat.com") { Email = "c@configcat.com", Country = "United Kingdom", Custom = { { "Custom1", "admin" } } - }, null, this.Logger).Value; + }, null, this.logger).Value; Assert.AreEqual(3.1415, actual); } @@ -80,12 +81,12 @@ public void GetValue_WithCompatibleDefaultValue_ShouldSucceed(string key, object var args = new object?[] { this.configEvaluator, - this.config, + BasicConfig, key, defaultValue, null, null, - this.Logger, + this.logger, }; var evaluationDetails = (EvaluationDetails)EvaluateMethodDefinition.MakeGenericMethod(settingClrType).Invoke(null, args)!; @@ -103,12 +104,12 @@ public void GetValue_WithIncompatibleDefaultValueType_ShouldThrowWithImprovedErr var args = new object?[] { this.configEvaluator, - this.config, + BasicConfig, key, defaultValue, null, null, - this.Logger, + this.logger, }; var ex = Assert.ThrowsException(() => @@ -116,6 +117,6 @@ public void GetValue_WithIncompatibleDefaultValueType_ShouldThrowWithImprovedErr try { EvaluateMethodDefinition.MakeGenericMethod(settingClrType).Invoke(null, args); } catch (TargetInvocationException ex) { throw ex.InnerException!; } }); - StringAssert.Contains(ex.Message, $"Setting's type was {this.config[key].SettingType} but the default value's type was {settingClrType}."); + StringAssert.Contains(ex.Message, $"Setting's type was {BasicConfig[key].SettingType} but the default value's type was {settingClrType}."); } } diff --git a/src/ConfigCat.Client.Tests/MatrixTestRunnerBase.cs b/src/ConfigCat.Client.Tests/MatrixTestRunnerBase.cs index 382c6480..65a5feac 100644 --- a/src/ConfigCat.Client.Tests/MatrixTestRunnerBase.cs +++ b/src/ConfigCat.Client.Tests/MatrixTestRunnerBase.cs @@ -27,7 +27,7 @@ public interface IMatrixTestDescriptor { public static readonly TDescriptor DescriptorInstance = new(); - private protected readonly Dictionary config; + internal readonly Dictionary config; public MatrixTestRunnerBase() { diff --git a/src/ConfigCat.Client.Tests/ModelTests.cs b/src/ConfigCat.Client.Tests/ModelTests.cs index 1be3c061..3e7df9f2 100644 --- a/src/ConfigCat.Client.Tests/ModelTests.cs +++ b/src/ConfigCat.Client.Tests/ModelTests.cs @@ -8,13 +8,11 @@ namespace ConfigCat.Client.Tests; [TestClass] public class ModelTests { - private const string TestBaseUrl = "https://test-cdn-eu.configcat.com"; - private const string BasicSampleSdkKey = "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A"; - private const string AndOrV6SampleSdkKey = "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/FfwncdJg1kq0lBqxhYC_7g"; - private const string ComparatorsV6SampleSdkKey = "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/Lv2mD9Tgx0Km27nuHjw_FA"; - private const string FlagDependencyV6SampleSdkKey = "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/LGO_8DM9OUGpJixrqqqQcA"; - private const string SegmentsV6SampleSdkKey = "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/LP0_4hhbQkmVVJcsbO_2Lw"; + private const string AndOrV6SampleSdkKey = "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/ByMO9yZNn02kXcm72lnY1A"; + private const string ComparatorsV6SampleSdkKey = "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/OfQqcTjfFUGBwMKqtyEOrQ"; + private const string FlagDependencyV6SampleSdkKey = "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/JoGwdqJZQ0K2xDy7LnbyOg"; + private const string SegmentsV6SampleSdkKey = "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/h99HYXWWNE2bH8eWyLAVMA"; private static ConfigLocation GetConfigLocation(string? sdkKey, string baseUrlOrFileName) { @@ -41,8 +39,8 @@ public void SettingValue_ToString(object? value, string expectedResult) [DataTestMethod] [DataRow(BasicSampleSdkKey, null, "stringIsNotInDogDefaultCat", 0, 0, new[] { "User.Email IS NOT ONE OF [<2 hashed values>]" })] - [DataRow(SegmentsV6SampleSdkKey, TestBaseUrl, "countrySegment", 0, 0, new[] { "User IS IN SEGMENT 'United'" })] - [DataRow(FlagDependencyV6SampleSdkKey, TestBaseUrl, "boolDependsOnBool", 0, 0, new[] { "Flag 'mainBoolFlag' EQUALS 'True'" })] + [DataRow(SegmentsV6SampleSdkKey, null, "countrySegment", 0, 0, new[] { "User IS IN SEGMENT 'United'" })] + [DataRow(FlagDependencyV6SampleSdkKey, null, "boolDependsOnBool", 0, 0, new[] { "Flag 'mainBoolFlag' EQUALS 'True'" })] public void Condition_ToString(string? sdkKey, string baseUrlOrFileName, string settingKey, int targetingRuleIndex, int conditionIndex, string[] expectedResultLines) { IConfig config = GetConfigLocation(sdkKey, baseUrlOrFileName).FetchConfigCached(); @@ -56,7 +54,7 @@ public void Condition_ToString(string? sdkKey, string baseUrlOrFileName, string [DataTestMethod] [DataRow(BasicSampleSdkKey, null, "string25Cat25Dog25Falcon25Horse", -1, 0, new[] { "25%: 'Cat'" })] - [DataRow(ComparatorsV6SampleSdkKey, TestBaseUrl, "missingPercentageAttribute", 0, 0, new[] { "50%: 'Falcon'" })] + [DataRow(ComparatorsV6SampleSdkKey, null, "missingPercentageAttribute", 0, 0, new[] { "50%: 'Falcon'" })] public void PercentageOption_ToString(string? sdkKey, string baseUrlOrFileName, string settingKey, int targetingRuleIndex, int percentageOptionIndex, string[] expectedResultLines) { IConfig config = GetConfigLocation(sdkKey, baseUrlOrFileName).FetchConfigCached(); @@ -76,14 +74,14 @@ public void PercentageOption_ToString(string? sdkKey, string baseUrlOrFileName, "IF User.Email IS NOT ONE OF [<2 hashed values>]", "THEN 'Dog'", })] - [DataRow(ComparatorsV6SampleSdkKey, TestBaseUrl, "missingPercentageAttribute", 0, new[] + [DataRow(ComparatorsV6SampleSdkKey, null, "missingPercentageAttribute", 0, new[] { "IF User.Email ENDS WITH ANY OF [<1 hashed value>]", "THEN", " 50%: 'Falcon'", " 50%: 'Horse'", })] - [DataRow(AndOrV6SampleSdkKey, TestBaseUrl, "emailAnd", 0, new[] + [DataRow(AndOrV6SampleSdkKey, null, "emailAnd", 0, new[] { "IF User.Email STARTS WITH ANY OF [<1 hashed value>]", " AND User.Email CONTAINS ANY OF ['@']", @@ -116,7 +114,7 @@ public void TargetingRule_ToString(string? sdkKey, string baseUrlOrFileName, str "25% of users: 'Horse'", "To unidentified: 'Chicken'", })] - [DataRow(ComparatorsV6SampleSdkKey, TestBaseUrl, "countryPercentageAttribute", new[] + [DataRow(ComparatorsV6SampleSdkKey, null, "countryPercentageAttribute", new[] { "50% of all Country attributes: 'Falcon'", "50% of all Country attributes: 'Horse'", @@ -137,7 +135,7 @@ public void TargetingRule_ToString(string? sdkKey, string baseUrlOrFileName, str " 25% of users: 'Horse'", "To unidentified: 'Chicken'", })] - [DataRow(ComparatorsV6SampleSdkKey, TestBaseUrl, "missingPercentageAttribute", new[] + [DataRow(ComparatorsV6SampleSdkKey, null, "missingPercentageAttribute", new[] { "IF User.Email ENDS WITH ANY OF [<1 hashed value>]", "THEN", @@ -147,7 +145,7 @@ public void TargetingRule_ToString(string? sdkKey, string baseUrlOrFileName, str "THEN 'NotFound'", "To all others: 'Chicken'", })] - [DataRow(AndOrV6SampleSdkKey, TestBaseUrl, "emailAnd", new[] + [DataRow(AndOrV6SampleSdkKey, null, "emailAnd", new[] { "IF User.Email STARTS WITH ANY OF [<1 hashed value>]", " AND User.Email CONTAINS ANY OF ['@']", @@ -165,7 +163,7 @@ public void Setting_ToString(string? sdkKey, string baseUrlOrFileName, string se } [DataTestMethod] - [DataRow(SegmentsV6SampleSdkKey, TestBaseUrl, 0, new[] { "User.Email IS ONE OF [<2 hashed values>]" })] + [DataRow(SegmentsV6SampleSdkKey, null, 0, new[] { "User.Email IS ONE OF [<2 hashed values>]" })] public void Segment_ToString(string? sdkKey, string baseUrlOrFileName, int segmentIndex, string[] expectedResultLines) { IConfig config = GetConfigLocation(sdkKey, baseUrlOrFileName).FetchConfigCached(); diff --git a/src/ConfigCat.Client.Tests/NumericConfigEvaluatorTests.cs b/src/ConfigCat.Client.Tests/NumericConfigEvaluatorTests.cs deleted file mode 100644 index f2654eff..00000000 --- a/src/ConfigCat.Client.Tests/NumericConfigEvaluatorTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ConfigCat.Client.Tests.Helpers; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace ConfigCat.Client.Tests; - -[TestClass] -public class NumericConfigEvaluatorTests : ConfigEvaluatorTestsBase -{ - public class Descriptor : IMatrixTestDescriptor - { - // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d747f0-5986-c2ef-eef3-ec778e32e10a/244cf8b0-f604-11e8-b543-f23c917f9d8d - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/uGyK3q9_ckmdxRyI7vjwCw"); - - public string MatrixResultFileName => "testmatrix_number.csv"; - } -} diff --git a/src/ConfigCat.Client.Tests/SemanticVersion2ConfigEvaluatorTests.cs b/src/ConfigCat.Client.Tests/SemanticVersion2ConfigEvaluatorTests.cs deleted file mode 100644 index 81abde46..00000000 --- a/src/ConfigCat.Client.Tests/SemanticVersion2ConfigEvaluatorTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ConfigCat.Client.Tests.Helpers; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace ConfigCat.Client.Tests; - -[TestClass] -public class SemanticVersion2ConfigEvaluatorTests : ConfigEvaluatorTestsBase -{ - public class Descriptor : IMatrixTestDescriptor - { - // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d77fa1-a796-85f9-df0c-57c448eb9934/244cf8b0-f604-11e8-b543-f23c917f9d8d - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/q6jMCFIp-EmuAfnmZhPY7w"); - - public string MatrixResultFileName => "testmatrix_semantic_2.csv"; - } -} diff --git a/src/ConfigCat.Client.Tests/SemanticVersionConfigEvaluatorTests.cs b/src/ConfigCat.Client.Tests/SemanticVersionConfigEvaluatorTests.cs deleted file mode 100644 index ef69c358..00000000 --- a/src/ConfigCat.Client.Tests/SemanticVersionConfigEvaluatorTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ConfigCat.Client.Tests.Helpers; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace ConfigCat.Client.Tests; - -[TestClass] -public class SemanticVersionConfigEvaluatorTests : ConfigEvaluatorTestsBase -{ - public class Descriptor : IMatrixTestDescriptor - { - // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d745f1-f315-7daf-d163-5541d3786e6f/244cf8b0-f604-11e8-b543-f23c917f9d8d - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/BAr3KgLTP0ObzKnBTo5nhA"); - - public string MatrixResultFileName => "testmatrix_semantic.csv"; - } -} diff --git a/src/ConfigCat.Client.Tests/SensitiveConfigEvaluatorTests.cs b/src/ConfigCat.Client.Tests/SensitiveConfigEvaluatorTests.cs deleted file mode 100644 index a34a6d53..00000000 --- a/src/ConfigCat.Client.Tests/SensitiveConfigEvaluatorTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ConfigCat.Client.Tests.Helpers; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace ConfigCat.Client.Tests; - -[TestClass] -public class SensitiveEvaluatorTests : ConfigEvaluatorTestsBase -{ - public class Descriptor : IMatrixTestDescriptor - { - // https://app.configcat.com/08d5a03c-feb7-af1e-a1fa-40b3329f8bed/08d7b724-9285-f4a7-9fcd-00f64f1e83d5/244cf8b0-f604-11e8-b543-f23c917f9d8d - public ConfigLocation ConfigLocation => new ConfigLocation.Cdn("PKDVCLf-Hq-h-kCzMp-L7Q/qX3TP2dTj06ZpCCT1h_SPA"); - - public string MatrixResultFileName => "testmatrix_sensitive.csv"; - } -} diff --git a/src/ConfigCat.Client.Tests/data/evaluationlog/and_rules.json b/src/ConfigCat.Client.Tests/data/evaluationlog/and_rules.json index a3a6491a..c6ed879f 100644 --- a/src/ConfigCat.Client.Tests/data/evaluationlog/and_rules.json +++ b/src/ConfigCat.Client.Tests/data/evaluationlog/and_rules.json @@ -1,7 +1,6 @@ { - "configUrl": "https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4c16-c78b-473c-8b68-ca6723c98bfa/08db465d-a64e-4881-8ed0-62b6c9e68e33", - "sdkKey": "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/FfwncdJg1kq0lBqxhYC_7g", - "baseUrl": "https://test-cdn-eu.configcat.com", + "configUrl": "https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9d5e-4988-891c-fd4a45790bd1/08dbc325-9ebd-4587-8171-88f76a3004cb", + "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/ByMO9yZNn02kXcm72lnY1A", "tests": [ { "key": "emailAnd", diff --git a/src/ConfigCat.Client.Tests/data/evaluationlog/comparators.json b/src/ConfigCat.Client.Tests/data/evaluationlog/comparators.json index 12393039..5d5631e5 100644 --- a/src/ConfigCat.Client.Tests/data/evaluationlog/comparators.json +++ b/src/ConfigCat.Client.Tests/data/evaluationlog/comparators.json @@ -1,7 +1,6 @@ { - "configUrl": "https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4be6-4a08-4c5c-8c35-30ef3a571a72/08db465d-a64e-4881-8ed0-62b6c9e68e33", - "sdkKey": "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/Lv2mD9Tgx0Km27nuHjw_FA", - "baseUrl": "https://test-cdn-eu.configcat.com", + "configUrl": "https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9a6b-4947-84e2-91529248278a/08dbc325-9ebd-4587-8171-88f76a3004cb", + "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/OfQqcTjfFUGBwMKqtyEOrQ", "tests": [ { "key": "allinone", diff --git a/src/ConfigCat.Client.Tests/data/evaluationlog/epoch_date_validation.json b/src/ConfigCat.Client.Tests/data/evaluationlog/epoch_date_validation.json index 7a3216c4..e916d218 100644 --- a/src/ConfigCat.Client.Tests/data/evaluationlog/epoch_date_validation.json +++ b/src/ConfigCat.Client.Tests/data/evaluationlog/epoch_date_validation.json @@ -1,7 +1,6 @@ { - "configUrl": "https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4be6-4a08-4c5c-8c35-30ef3a571a72/08db465d-a64e-4881-8ed0-62b6c9e68e33", - "sdkKey": "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/Lv2mD9Tgx0Km27nuHjw_FA", - "baseUrl": "https://test-cdn-eu.configcat.com", + "configUrl": "https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9a6b-4947-84e2-91529248278a/08dbc325-9ebd-4587-8171-88f76a3004cb", + "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/OfQqcTjfFUGBwMKqtyEOrQ", "tests": [ { "key": "boolTrueIn202304", diff --git a/src/ConfigCat.Client.Tests/data/evaluationlog/options_based_on_custom_attr.json b/src/ConfigCat.Client.Tests/data/evaluationlog/options_based_on_custom_attr.json index efa16493..5f8d1c63 100644 --- a/src/ConfigCat.Client.Tests/data/evaluationlog/options_based_on_custom_attr.json +++ b/src/ConfigCat.Client.Tests/data/evaluationlog/options_based_on_custom_attr.json @@ -1,7 +1,6 @@ { - "configUrl": "https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db6eb8-cdfa-4adc-880b-34f75432cc36/08db465d-a64e-4881-8ed0-62b6c9e68e33", - "sdkKey": "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/x0tcrFMkl02A65D8GD20Eg", - "baseUrl": "https://test-cdn-eu.configcat.com", + "configUrl": "https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb", + "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw", "tests": [ { "key": "string75Cat0Dog25Falcon0HorseCustomAttr", diff --git a/src/ConfigCat.Client.Tests/data/evaluationlog/options_within_targeting_rule.json b/src/ConfigCat.Client.Tests/data/evaluationlog/options_within_targeting_rule.json index 5a461cec..4c6c533b 100644 --- a/src/ConfigCat.Client.Tests/data/evaluationlog/options_within_targeting_rule.json +++ b/src/ConfigCat.Client.Tests/data/evaluationlog/options_within_targeting_rule.json @@ -1,7 +1,6 @@ { - "configUrl": "https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db6eb8-cdfa-4adc-880b-34f75432cc36/08db465d-a64e-4881-8ed0-62b6c9e68e33", - "sdkKey": "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/x0tcrFMkl02A65D8GD20Eg", - "baseUrl": "https://test-cdn-eu.configcat.com", + "configUrl": "https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb", + "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw", "tests": [ { "key": "stringContainsString75Cat0Dog25Falcon0HorseDefaultCat", diff --git a/src/ConfigCat.Client.Tests/data/evaluationlog/prerequisite_flag.json b/src/ConfigCat.Client.Tests/data/evaluationlog/prerequisite_flag.json index 46447e00..674e2d33 100644 --- a/src/ConfigCat.Client.Tests/data/evaluationlog/prerequisite_flag.json +++ b/src/ConfigCat.Client.Tests/data/evaluationlog/prerequisite_flag.json @@ -1,7 +1,6 @@ { - "configUrl": "https://test-app.configcat.com/v2/08d89dea-13b2-406b-8ecf-ee94414208a2/08db465d-5756-49ff-8e53-fb90fd760632/08db4c16-c78b-473c-8b68-ca6723c98bfa/08db465d-a64e-4881-8ed0-62b6c9e68e33", - "sdkKey": "configcat-sdk-1/XUbbCFZX_0mOU_uQ_XYGMg/FfwncdJg1kq0lBqxhYC_7g", - "baseUrl": "https://test-cdn-eu.configcat.com", + "configUrl": "https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9d5e-4988-891c-fd4a45790bd1/08dbc325-9ebd-4587-8171-88f76a3004cb", + "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/ByMO9yZNn02kXcm72lnY1A", "tests": [ { "key": "dependentFeatureWithUserCondition",