Exemplo n.º 1
0
        public async Task GetKeyWithBernoulliValueDistribution_SeveralRequestsFromDifferentIdentities_ResultsShouldBeDistributed()
        {
            // Arrange
            const double probablityOfTestFailure             = 0.001;
            const double configurationKeyBernoulliTrialSplit = 0.3;
            var          numberOfAttempts =
                (int)
                Math.Round(
                    Math.Max(
                        Math.Log(probablityOfTestFailure, configurationKeyBernoulliTrialSplit),
                        Math.Log(probablityOfTestFailure, 1 - configurationKeyBernoulliTrialSplit)
                        )
                    );

            // Act
            var keyRequests = Enumerable.Range(0, numberOfAttempts)
                              .Select(async i => await mTweekApi.GetConfigurations("@smoke_tests/value_distribution/bernoulli", new Dictionary <string, string> {
                { "device", Guid.NewGuid().ToString() }
            }));

            var results = await Task.WhenAll(keyRequests);

            var returnedValues = results.Where(x => x.Type == JTokenType.String).Select(x => x.ToString()).ToList();

            // Assert
            Assert.Contains("true", returnedValues);
            Assert.Contains("false", returnedValues);
            mOutput.WriteLine("Attempts: {0}", numberOfAttempts);
            mOutput.WriteLine("Received \"true\" Rate: {0}%", Math.Round(returnedValues.Count(x => x == "true") * 100d / numberOfAttempts));
            mOutput.WriteLine("Chance for a test fail due to statistics: {0}%", probablityOfTestFailure * 100);
        }
Exemplo n.º 2
0
        public async Task AppendContextWithFixedConfiguration()
        {
            var guid = Guid.NewGuid().ToString();
            await mTweekApi.AppendContext("test", "append-context-test-1", new Dictionary <string, FSharpUtils.Newtonsoft.JsonValue>()
            {
                ["@fixed:tests/fixed/some_fixed_configuration"] = NewString(guid.ToString())
            });

            var results = await mTweekApi.GetConfigurations("tests/fixed/some_fixed_configuration", new Dictionary <string, string>()
            {
                ["test"] = "append-context-test-1"
            });

            Assert.Equal(guid, results.ToString());
            var additonalGuid = Guid.NewGuid().ToString();
            await mTweekApi.AppendContext("test", "append-context-test-1", new Dictionary <string, FSharpUtils.Newtonsoft.JsonValue>()
            {
                ["@fixed:tests/fixed/additional_fixed_configuration1"] = NewString(additonalGuid),
                ["@fixed:tests/fixed/additional_fixed_configuration2"] = NewString(additonalGuid)
            });

            results = await mTweekApi.GetConfigurations("tests/fixed/_", new Dictionary <string, string>()
            {
                ["test"] = "append-context-test-1"
            });

            Assert.Equal(additonalGuid, results["additional_fixed_configuration1"].ToString());
            Assert.Equal(additonalGuid, results["additional_fixed_configuration2"].ToString());
            Assert.Equal(guid, results["some_fixed_configuration"].ToString());
        }
Exemplo n.º 3
0
        public async Task GetScanFolder_VisibleFolder_ShouldReturnVisibleKeys()
        {
            // Act
            var response = await mTweekApi.GetConfigurations("smoke_tests/not_hidden/_", new Dictionary <string, string>());

            // Assert
            Assert.Equal(JTokenType.Object, response.Type);
            var expected = JToken.Parse("{\"some_key\":\"some value\"}");

            Assert.Equal(expected, response);
        }
Exemplo n.º 4
0
        public async Task GetStringKey_IgnoreKeyTypesTrue_ReturnsString(string key, string value)
        {
            // Act
            var response = await mTweekApi.GetConfigurations(key, new Dictionary <string, string> {
                { "$ignoreKeyTypes", "true" }
            });

            // Assert
            Assert.Equal(JTokenType.String, response.Type);
            Assert.Equal(JToken.FromObject(value), response);
        }
Exemplo n.º 5
0
        public async Task GetSingleKey_BySimpleRules_ShouldReturnMatchingKeyValue(string osType, string expectedResult)
        {
            // Act
            var response = await mTweekApi.GetConfigurations("smoke_tests/rule_based_keys/simple", new Dictionary <string, string> {
                { "device.DeviceOsType", osType }
            });

            // Assert
            Assert.Equal(JTokenType.String, response.Type);
            Assert.Equal(expectedResult, response.ToString());
        }
Exemplo n.º 6
0
        private async Task RunContextBasedTest(TestContext context)
        {
            // Act
            var response = await mTweekApi.GetConfigurations(context.KeyName, context.Context.ToDictionary(x => x.Key, x => x.Value.AsString()));

            // Assert
            Assert.Equal(JTokenType.String, response.Type);
            Assert.Equal(context.ExpectedValue, response.ToString());
        }
Exemplo n.º 7
0
        public async Task GetSingleKey_KeyExists_ShouldReturnKeyValue()
        {
            // Act
            var response = await mTweekApi.GetConfigurations("smoke_tests/key_path/key1", new Dictionary <string, string>());

            // Assert
            Assert.Equal(JTokenType.String, response.Type);
            Assert.Equal("test", response.ToString());
        }