diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4778c8e..dfd7e70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,8 @@ jobs: run: dotnet build GrowthBook/GrowthBook.csproj --configuration Release # current tests are written for visual studio only - # - name: Test - # run: dotnet test Test/Growthook.Tests.csproj --configuration Release --no-build + - name: Test + run: dotnet test GrowthBook.Tests/GrowthBook.Tests.csproj --logger:"console;verbosity=normal" - name: pack run: dotnet pack --configuration Release --no-build --output dist GrowthBook/GrowthBook.csproj diff --git a/CHANGELOG.md b/CHANGELOG.md index d635173..6848e49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.2] + +- ci: moved from MSTest to Xunit + ## [0.1.1] - Handle null namespace property. diff --git a/GrowthBook.Tests/GrowthBook.Tests.csproj b/GrowthBook.Tests/GrowthBook.Tests.csproj new file mode 100644 index 0000000..e9b5283 --- /dev/null +++ b/GrowthBook.Tests/GrowthBook.Tests.csproj @@ -0,0 +1,51 @@ + + + + net7.0 + latest + + + + AnyCPU + + + + + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GrowthBook.Tests/GrowthBookTests.cs b/GrowthBook.Tests/GrowthBookTests.cs new file mode 100644 index 0000000..1ba7220 --- /dev/null +++ b/GrowthBook.Tests/GrowthBookTests.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +using GrowthBook.Tests.Json; + +using Newtonsoft.Json.Linq; + +using Xunit; + +namespace GrowthBook.Tests; + +public class GrowthBookTests +{ + + #region helpers + public static JObject getStandardCases() + { + return JObject.Parse(JsonTestHelpers.GetTestJson("standard-cases")); + } + + public static JObject getCustomCases() + { + return JObject.Parse(JsonTestHelpers.GetTestJson("custom-cases")); + } + + public static string GetTestNames(MethodInfo methodInfo, object[] values) + { + return $"{methodInfo.Name} - {values[0]}"; + } + #endregion + + #region data + public static IEnumerable RunTests() + { + foreach (JArray testCase in (JArray)getStandardCases()["run"]) + { + yield return new object[] { + testCase[0].ToString(), + testCase[1].ToObject(), + testCase[2].ToObject(), + testCase[3], + testCase[4].ToObject(), + testCase[5].ToObject(), + }; + } + } + public static IEnumerable EvalFeatureTests() + { + foreach (JArray testCase in (JArray)getStandardCases()["feature"]) + { + yield return new object[] { + testCase[0].ToString(), + testCase[1].ToObject(), + testCase[2].ToString(), + testCase[3].ToObject(), + }; + } + } + #endregion + + [Fact] + public void Run_ShouldCallTrackingCallbackOnce() + { + JArray testCase = (JArray)getCustomCases()["run"]; + int trackingCounter = 0; + + Context context = testCase[0].ToObject(); + context.TrackingCallback = (Experiment experiment, ExperimentResult result) => + { + Assert.True(JToken.DeepEquals(result.Value, testCase[2])); + Assert.Equal(testCase[3].ToObject(), result.InExperiment); + Assert.Equal(testCase[4].ToObject(), result.HashUsed); + trackingCounter++; + }; + + GrowthBook gb = new(context); + gb.Run(testCase[1].ToObject()); + gb.Run(testCase[1].ToObject()); + Assert.Equal(1, trackingCounter); + } + + [Fact] + public void Run_ShouldCallSubscribedCallbacks() + { + JArray testCase = (JArray)getCustomCases()["run"]; + GrowthBook gb = new(testCase[0].ToObject()); + + int subCounterOne = 0; + gb.Subscribe((Experiment experiment, ExperimentResult result) => + { + Assert.True(JToken.DeepEquals(result.Value, testCase[2])); + Assert.Equal(testCase[3].ToObject(), result.InExperiment); + Assert.Equal(testCase[4].ToObject(), result.HashUsed); + subCounterOne++; + }); + + int subCounterTwo = 0; + Action unsubscribe = gb.Subscribe((Experiment experiment, ExperimentResult result) => + { + Assert.True(JToken.DeepEquals(result.Value, testCase[2])); + Assert.Equal(testCase[3].ToObject(), result.InExperiment); + Assert.Equal(testCase[4].ToObject(), result.HashUsed); + subCounterTwo++; + }); + unsubscribe(); + + int subCounterThree = 0; + gb.Subscribe((Experiment experiment, ExperimentResult result) => + { + Assert.True(JToken.DeepEquals(result.Value, testCase[2])); + Assert.Equal(testCase[3].ToObject(), result.InExperiment); + Assert.Equal(testCase[4].ToObject(), result.HashUsed); + subCounterThree++; + }); + + gb.Run(testCase[1].ToObject()); + gb.Run(testCase[1].ToObject()); + gb.Run(testCase[1].ToObject()); + Assert.Equal(1, subCounterOne); + Assert.Equal(0, subCounterTwo); + Assert.Equal(1, subCounterThree); + } + + [Theory] + [MemberData(nameof(RunTests))] + public void Run(string testName, Context context, Experiment experiment, JToken expectedValue, bool inExperiment, bool hashUsed) + { + if (testName is null) + { + throw new ArgumentNullException(nameof(testName)); + } + + GrowthBook gb = new(context); + ExperimentResult actual = gb.Run(experiment); + Assert.Equal(inExperiment, actual.InExperiment); + Assert.Equal(hashUsed, actual.HashUsed); + Assert.True(JToken.DeepEquals(actual.Value, expectedValue)); + } + + [Theory] + [MemberData(nameof(EvalFeatureTests))] + public void EvalFeature(string testname, Context context, string key, FeatureResult expected) + { + if (testname is null) + { + throw new ArgumentNullException(nameof(testname)); + } + + GrowthBook gb = new(context); + FeatureResult actual = gb.EvalFeature(key); + Assert.Equal(expected, actual); + } + +} diff --git a/Test/Json/FeatureDictionary.json b/GrowthBook.Tests/Json/FeatureDictionary.json similarity index 100% rename from Test/Json/FeatureDictionary.json rename to GrowthBook.Tests/Json/FeatureDictionary.json diff --git a/Test/Json/GrowthBookContext.NoFeatures.json b/GrowthBook.Tests/Json/GrowthBookContext.NoFeatures.json similarity index 100% rename from Test/Json/GrowthBookContext.NoFeatures.json rename to GrowthBook.Tests/Json/GrowthBookContext.NoFeatures.json diff --git a/Test/Json/GrowthBookContext.json b/GrowthBook.Tests/Json/GrowthBookContext.json similarity index 100% rename from Test/Json/GrowthBookContext.json rename to GrowthBook.Tests/Json/GrowthBookContext.json diff --git a/Test/Json/JsonTestHelpers.cs b/GrowthBook.Tests/Json/JsonTestHelpers.cs similarity index 96% rename from Test/Json/JsonTestHelpers.cs rename to GrowthBook.Tests/Json/JsonTestHelpers.cs index 769e086..705d647 100644 --- a/Test/Json/JsonTestHelpers.cs +++ b/GrowthBook.Tests/Json/JsonTestHelpers.cs @@ -2,7 +2,7 @@ using System.IO; using System.Reflection; -namespace Growthbook.Tests.Json; +namespace GrowthBook.Tests.Json; public static class JsonTestHelpers { diff --git a/Test/Json/SingleFeatureDictionary.WithNameSpace..json b/GrowthBook.Tests/Json/SingleFeatureDictionary.WithNameSpace.json similarity index 100% rename from Test/Json/SingleFeatureDictionary.WithNameSpace..json rename to GrowthBook.Tests/Json/SingleFeatureDictionary.WithNameSpace.json diff --git a/Test/Json/custom-cases.json b/GrowthBook.Tests/Json/custom-cases.json similarity index 100% rename from Test/Json/custom-cases.json rename to GrowthBook.Tests/Json/custom-cases.json diff --git a/Test/Json/standard-cases.json b/GrowthBook.Tests/Json/standard-cases.json similarity index 100% rename from Test/Json/standard-cases.json rename to GrowthBook.Tests/Json/standard-cases.json diff --git a/GrowthBook.Tests/NamespaceTupleConverterTests.cs b/GrowthBook.Tests/NamespaceTupleConverterTests.cs new file mode 100644 index 0000000..e569aab --- /dev/null +++ b/GrowthBook.Tests/NamespaceTupleConverterTests.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; + +using GrowthBook.Tests.Json; + +using Newtonsoft.Json; + +using Xunit; + +namespace GrowthBook.Tests; + +public class NamespaceTupleConverterTests +{ + [Fact] + public void CreateFromJson_NoFeatures_ShouldSucceed() + { + string json = JsonTestHelpers.GetTestJson("GrowthBookContext.NoFeatures"); + _ = JsonConvert.DeserializeObject(json); + } + + [Fact] + public void CreateFromJson_WithFeatures_ShouldSucceed() + { + string json = JsonTestHelpers.GetTestJson("GrowthBookContext"); + _ = JsonConvert.DeserializeObject(json); + } + + [Fact] + public void CreateFeaturesFromJson_WithFeatures_ShouldSucceed() + { + string json = JsonTestHelpers.GetTestJson("FeatureDictionary"); + _ = JsonConvert.DeserializeObject>(json); + } + + [Fact] + public void CreateFeaturesFromJson_OneFeatureWithNameSpace_ShouldSucceed() + { + string json = JsonTestHelpers.GetTestJson("SingleFeatureDictionary.WithNameSpace"); + _ = JsonConvert.DeserializeObject>(json); + } +} diff --git a/Test/Utilities.cs b/GrowthBook.Tests/UtilitiesTests.cs similarity index 57% rename from Test/Utilities.cs rename to GrowthBook.Tests/UtilitiesTests.cs index 7d8b508..8027ed9 100644 --- a/Test/Utilities.cs +++ b/GrowthBook.Tests/UtilitiesTests.cs @@ -1,45 +1,35 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; -using GrowthBook; -using Growthbook.Tests.Json; -using Microsoft.VisualStudio.TestTools.UnitTesting; + +using GrowthBook.Tests.Json; + using Newtonsoft.Json.Linq; -using Test; -namespace Growthbook.Tests +using Xunit; + +namespace GrowthBook.Tests { - [TestClass] - public class Utilities + public class UtilitiesTests { - public static JObject testCases; + #region helpers - [ClassInitialize] - public static void TestFixtureSetup(TestContext context) + public static JObject getStandardCases() { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - testCases = JObject.Parse(JsonTestHelpers.GetTestJson("standard-cases")); + return JObject.Parse(JsonTestHelpers.GetTestJson("standard-cases")); } public static string GetTestNames(MethodInfo methodInfo, object[] values) { - return $"{methodInfo.Name} - { values[0] }"; + return $"{methodInfo.Name} - {values[0]}"; } - public double RoundStandard(double input) - { - return Math.Round(input, 6); - } + public static double RoundStandard(double input) => Math.Round(input, 6); - public IList RoundArray(IList input) + public static IList RoundArray(IList input) { - List results = new List(); + var results = new List(); for (int i = 0; i < input.Count; i++) { results.Add(RoundStandard(input[i])); @@ -49,49 +39,55 @@ public IList RoundArray(IList input) public IList RoundBucketRanges(IList input) { - List results = new List(); + var results = new List(); foreach (BucketRange range in input) { results.Add(new BucketRange(RoundStandard(range.Start), RoundStandard(range.End))); } return results; } - - [TestMethod] - [DynamicData(nameof(HashTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void Hash(string input, double expected) - { - double actual = GrowthBook.Utilities.Hash(input); - Assert.AreEqual(expected, actual); - } - - public static IEnumerable HashTests() + #endregion + #region data + public static IEnumerable GetBucketRangeTests() { - foreach (JArray testCase in (JArray)testCases["hash"]) + foreach (JArray testCase in ((JArray)getStandardCases()["getBucketRange"]).Cast()) { + var expected = new List(); + foreach (JArray jArray in testCase[2].Cast()) + { + expected.Add(new BucketRange(jArray[0].ToObject(), jArray[1].ToObject())); + } yield return new object[] { testCase[0].ToString(), - testCase[1].ToObject() + testCase[1][0].ToObject(), + testCase[1][1].ToObject(), + testCase[1][2].ToObject(), + expected, }; } } - [TestMethod] - [DynamicData(nameof(InNamespaceTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void InNamespace(string testName, string userId, string id, double start, double end, bool expected) + public static IEnumerable ChooseVariationTests() { - if (testName is null) + foreach (JArray testCase in ((JArray)getStandardCases()["chooseVariation"]).Cast()) { - throw new ArgumentNullException(nameof(testName)); + var ranges = new List(); + foreach (JArray jArray in testCase[2].Cast()) + { + ranges.Add(new BucketRange(jArray[0].ToObject(), jArray[1].ToObject())); + } + yield return new object[] { + testCase[0].ToString(), + testCase[1].ToObject(), + ranges, + testCase[3].ToObject(), + }; } - - bool actual = GrowthBook.Utilities.InNamespace(userId, new GrowthBook.Namespace(id, start, end)); - Assert.AreEqual(expected, actual); } public static IEnumerable InNamespaceTests() { - foreach (JArray testCase in (JArray)testCases["inNamespace"]) + foreach (JArray testCase in ((JArray)getStandardCases()["inNamespace"]).Cast()) { yield return new object[] { testCase[0].ToString(), @@ -104,139 +100,139 @@ public static IEnumerable InNamespaceTests() } } - [TestMethod] - [DynamicData(nameof(GetEqualWeightsTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void GetEqualWeights(int input, IList expected) + public static IEnumerable GetQueryStringOverrideTests() { - IList actual = GrowthBook.Utilities.GetEqualWeights(input); - Assert.IsTrue(RoundArray(expected).SequenceEqual(RoundArray(actual))); + foreach (JArray testCase in ((JArray)getStandardCases()["getQueryStringOverride"]).Cast()) + { + yield return new object[] { + testCase[0].ToString(), + testCase[1].ToString(), + testCase[2].ToString(), + testCase[3].ToObject(), + testCase[4].ToObject(), + }; + } } - public static IEnumerable GetEqualWeightsTests() + public static IEnumerable EvalConditionTests() { - foreach (JArray testCase in (JArray)testCases["getEqualWeights"]) + foreach (JArray testCase in ((JArray)getStandardCases()["evalCondition"]).Cast()) { yield return new object[] { - testCase[0].ToObject(), - testCase[1].ToObject(), + testCase[0].ToString(), + testCase[1], + testCase[2], + testCase[3].ToObject() }; } } - [TestMethod] - [DynamicData(nameof(GetBucketRangeTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void GetBucketRanges(string testName, int numVariations, double coverage, double[] weights, List expected) + public static IEnumerable GetEqualWeightsTests() { - if (testName is null) + foreach (JArray testCase in ((JArray)getStandardCases()["getEqualWeights"]).Cast()) { - throw new ArgumentNullException(nameof(testName)); + yield return new object[] { + testCase[0].ToObject(), + testCase[1].ToObject(), + }; } - - IList actual = GrowthBook.Utilities.GetBucketRanges(numVariations, coverage, weights); - Assert.IsTrue(RoundBucketRanges(expected).SequenceEqual(RoundBucketRanges(actual))); } - public static IEnumerable GetBucketRangeTests() + + public static IEnumerable HashTests() { - foreach (JArray testCase in (JArray)testCases["getBucketRange"]) + foreach (JArray testCase in ((JArray)getStandardCases()["hash"]).Cast()) { - List expected = new List(); - foreach (JArray jArray in testCase[2]) - { - expected.Add(new BucketRange(jArray[0].ToObject(), jArray[1].ToObject())); - } yield return new object[] { testCase[0].ToString(), - testCase[1][0].ToObject(), - testCase[1][1].ToObject(), - testCase[1][2].ToObject(), - expected, + testCase[1].ToObject() }; } } + #endregion - [TestMethod] - [DynamicData(nameof(ChooseVariationTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void ChooseVariation(string testName, double n, List ranges, int expected) + + [Theory] + [MemberData(nameof(EvalConditionTests))] + public void EvalCondition(string testName, JObject condition, JToken attributes, bool expected) { if (testName is null) { throw new ArgumentNullException(nameof(testName)); } - int actual = GrowthBook.Utilities.ChooseVariation(n, ranges); - Assert.AreEqual(expected, actual); + bool actual = Utilities.EvalCondition(attributes, condition); + Assert.Equal(expected, actual); } - public static IEnumerable ChooseVariationTests() + + [Theory] + [MemberData(nameof(HashTests))] + public void Hash(string input, double expected) { - foreach (JArray testCase in (JArray)testCases["chooseVariation"]) - { - List ranges = new List(); - foreach (JArray jArray in testCase[2]) - { - ranges.Add(new BucketRange(jArray[0].ToObject(), jArray[1].ToObject())); - } - yield return new object[] { - testCase[0].ToString(), - testCase[1].ToObject(), - ranges, - testCase[3].ToObject(), - }; - } + double actual = Utilities.Hash(input); + Assert.Equal(expected, actual); } - [TestMethod] - [DynamicData(nameof(GetQueryStringOverrideTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void GetQueryStringOverride(string testName, string id, string url, int numVariations, int? expected) + [Theory] + [MemberData(nameof(InNamespaceTests))] + public void InNamespace(string testName, string userId, string id, double start, double end, bool expected) { if (testName is null) { throw new ArgumentNullException(nameof(testName)); } - int? actual = GrowthBook.Utilities.GetQueryStringOverride(id, url, numVariations); - Assert.AreEqual(expected, actual); + bool actual = Utilities.InNamespace(userId, new Namespace(id, start, end)); + Assert.Equal(expected, actual); } - public static IEnumerable GetQueryStringOverrideTests() + [Theory] + [MemberData(nameof(GetEqualWeightsTests))] + public void GetEqualWeights(int input, IList expected) + { + IList actual = Utilities.GetEqualWeights(input); + Assert.True(RoundArray(expected).SequenceEqual(RoundArray(actual))); + } + + + [Theory] + [MemberData(nameof(GetBucketRangeTests))] + public void GetBucketRanges(string testName, int numVariations, double coverage, double[] weights, List expected) { - foreach (JArray testCase in (JArray)testCases["getQueryStringOverride"]) + if (testName is null) { - yield return new object[] { - testCase[0].ToString(), - testCase[1].ToString(), - testCase[2].ToString(), - testCase[3].ToObject(), - testCase[4].ToObject(), - }; + throw new ArgumentNullException(nameof(testName)); } + + IList actual = Utilities.GetBucketRanges(numVariations, coverage, weights); + Assert.True(RoundBucketRanges(expected).SequenceEqual(RoundBucketRanges(actual))); } - [TestMethod] - [DynamicData(nameof(EvalConditionTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void EvalCondition(string testName, JObject condition, JToken attributes, bool expected) + [Theory] + [MemberData(nameof(ChooseVariationTests))] + public void ChooseVariation(string testName, double n, List ranges, int expected) { if (testName is null) { throw new ArgumentNullException(nameof(testName)); } - bool actual = GrowthBook.Utilities.EvalCondition(attributes, condition); - Assert.AreEqual(expected, actual); + int actual = Utilities.ChooseVariation(n, ranges); + Assert.Equal(expected, actual); } - public static IEnumerable EvalConditionTests() + [Theory] + [MemberData(nameof(GetQueryStringOverrideTests))] + public void GetQueryStringOverride(string testName, string id, string url, int numVariations, int? expected) { - foreach (JArray testCase in (JArray)testCases["evalCondition"]) + if (testName is null) { - yield return new object[] { - testCase[0].ToString(), - testCase[1], - testCase[2], - testCase[3].ToObject() - }; + throw new ArgumentNullException(nameof(testName)); } + + int? actual = Utilities.GetQueryStringOverride(id, url, numVariations); + Assert.Equal(expected, actual); } } } diff --git a/GrowthBook/GrowthBook.csproj b/GrowthBook/GrowthBook.csproj index 33307ad..8cccb65 100644 --- a/GrowthBook/GrowthBook.csproj +++ b/GrowthBook/GrowthBook.csproj @@ -11,7 +11,7 @@ https://github.com/growthbook/growthbook-csharp.git git GrowthBook,A/B test,feature toggle - 0.1.1 + 0.1.2 diff --git a/Test/GrowthBook.Tests.csproj b/Test/GrowthBook.Tests.csproj deleted file mode 100644 index ea910a8..0000000 --- a/Test/GrowthBook.Tests.csproj +++ /dev/null @@ -1,41 +0,0 @@ - - - - net6 - latest - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Test/GrowthBookTests.cs b/Test/GrowthBookTests.cs deleted file mode 100644 index ceac6ff..0000000 --- a/Test/GrowthBookTests.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using GrowthBook; -using Growthbook.Tests.Json; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using Test; - -namespace Growthbook.Tests -{ - [TestClass] - public class GrowthBookTests - { - public static JObject testCases; - public static JObject customCases; - - [ClassInitialize] - public static void TestFixtureSetup(TestContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - testCases = JObject.Parse(JsonTestHelpers.GetTestJson("standard-cases")); - customCases = JObject.Parse(JsonTestHelpers.GetTestJson("custom-cases")); - } - - public static string GetTestNames(MethodInfo methodInfo, object[] values) - { - return $"{methodInfo.Name} - { values[0] }"; - } - - [TestMethod] - [DynamicData(nameof(RunTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void Run(string testname, Context context, Experiment experiment, JToken expectedValue, bool inExperiment, bool hashUsed) - { - if (testname is null) - { - throw new ArgumentNullException(nameof(testname)); - } - - GrowthBook.GrowthBook gb = new GrowthBook.GrowthBook(context); - ExperimentResult actual = gb.Run(experiment); - Assert.AreEqual(inExperiment, actual.InExperiment); - Assert.AreEqual(hashUsed, actual.HashUsed); - Assert.IsTrue(JToken.DeepEquals(actual.Value, expectedValue)); - } - - public static IEnumerable RunTests() - { - foreach (JArray testCase in (JArray)testCases["run"]) - { - yield return new object[] { - testCase[0].ToString(), - testCase[1].ToObject(), - testCase[2].ToObject(), - testCase[3], - testCase[4].ToObject(), - testCase[5].ToObject(), - }; - } - } - - [TestMethod] - public void Run_ShouldCallTrackingCallbackOnce() - { - JArray testCase = (JArray)customCases["run"]; - int trackingCounter = 0; - - Context context = testCase[0].ToObject(); - context.TrackingCallback = (Experiment experiment, ExperimentResult result) => - { - Assert.IsTrue(JToken.DeepEquals(result.Value, testCase[2])); - Assert.AreEqual(testCase[3].ToObject(), result.InExperiment); - Assert.AreEqual(testCase[4].ToObject(), result.HashUsed); - trackingCounter++; - }; - - GrowthBook.GrowthBook gb = new GrowthBook.GrowthBook(context); - gb.Run(testCase[1].ToObject()); - gb.Run(testCase[1].ToObject()); - Assert.AreEqual(1, trackingCounter); - } - - [TestMethod] - public void Run_ShouldCallSubscribedCallbacks() - { - JArray testCase = (JArray)customCases["run"]; - GrowthBook.GrowthBook gb = new GrowthBook.GrowthBook(testCase[0].ToObject()); - - int subCounterOne = 0; - gb.Subscribe((Experiment experiment, ExperimentResult result) => - { - Assert.IsTrue(JToken.DeepEquals(result.Value, testCase[2])); - Assert.AreEqual(testCase[3].ToObject(), result.InExperiment); - Assert.AreEqual(testCase[4].ToObject(), result.HashUsed); - subCounterOne++; - }); - - int subCounterTwo = 0; - Action unsubscribe = gb.Subscribe((Experiment experiment, ExperimentResult result) => - { - Assert.IsTrue(JToken.DeepEquals(result.Value, testCase[2])); - Assert.AreEqual(testCase[3].ToObject(), result.InExperiment); - Assert.AreEqual(testCase[4].ToObject(), result.HashUsed); - subCounterTwo++; - }); - unsubscribe(); - - int subCounterThree = 0; - gb.Subscribe((Experiment experiment, ExperimentResult result) => - { - Assert.IsTrue(JToken.DeepEquals(result.Value, testCase[2])); - Assert.AreEqual(testCase[3].ToObject(), result.InExperiment); - Assert.AreEqual(testCase[4].ToObject(), result.HashUsed); - subCounterThree++; - }); - - gb.Run(testCase[1].ToObject()); - gb.Run(testCase[1].ToObject()); - gb.Run(testCase[1].ToObject()); - Assert.AreEqual(1, subCounterOne); - Assert.AreEqual(0, subCounterTwo); - Assert.AreEqual(1, subCounterThree); - } - - [TestMethod] - [DynamicData(nameof(EvalFeatureTests), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetTestNames))] - public void EvalFeature(string testname, Context context, string key, FeatureResult expected) - { - if (testname is null) - { - throw new ArgumentNullException(nameof(testname)); - } - - GrowthBook.GrowthBook gb = new GrowthBook.GrowthBook(context); - FeatureResult actual = gb.EvalFeature(key); - Assert.AreEqual(expected, actual); - } - - public static IEnumerable EvalFeatureTests() - { - foreach (JArray testCase in (JArray)testCases["feature"]) - { - yield return new object[] { - testCase[0].ToString(), - testCase[1].ToObject(), - testCase[2].ToString(), - testCase[3].ToObject(), - }; - } - } - } -} diff --git a/Test/NamespaceTupleConverterTests.cs b/Test/NamespaceTupleConverterTests.cs deleted file mode 100644 index 51a0713..0000000 --- a/Test/NamespaceTupleConverterTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; -using GrowthBook; -using Growthbook.Tests.Json; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; - -namespace Test -{ - [TestClass] - public class NamespaceTupleConverterTests - { - [TestMethod] - public void CreateFromJson_NoFeatures_ShouldSucceed() - { - string json = JsonTestHelpers.GetTestJson("GrowthBookContext.NoFeatures"); - - var gb = JsonConvert.DeserializeObject(json); - } - - [TestMethod] - public void CreateFromJson_WithFeatures_ShouldSucceed() - { - string json = JsonTestHelpers.GetTestJson("GrowthBookContext"); - - var gb = JsonConvert.DeserializeObject(json); - } - - [TestMethod] - public void CreateFeaturesFromJson_WithFeatures_ShouldSucceed() - { - string json = JsonTestHelpers.GetTestJson("FeatureDictionary"); - - var gb = JsonConvert.DeserializeObject>(json); - } - - [TestMethod] - public void CreateFeaturesFromJson_OneFeatureWithNameSpace_ShouldSucceed() - { - string json = JsonTestHelpers.GetTestJson("SingleFeatureDictionary.WithNameSpace."); - - var gb = JsonConvert.DeserializeObject>(json); - } - - } -} diff --git a/Test/packages.config b/Test/packages.config deleted file mode 100644 index 4928b4b..0000000 --- a/Test/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file