Exemplo n.º 1
0
        public void ExecuteGetTreatmentsWithBucketing()
        {
            //Arrange
            var           client   = new JSONFileClient(@"Resources\splits_staging_3.json", "");
            List <string> features = new List <string>();

            features.Add("fail");
            features.Add("asd");
            features.Add("get_environment");

            var attributes = new Dictionary <string, object>();

            attributes.Add("env", "test");

            var keys = new Key("test", "test");

            //Act
            var result = client.GetTreatments(keys, features, attributes);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("control", result["fail"]);
            Assert.AreEqual("off", result["asd"]);
            Assert.AreEqual("test", result["get_environment"]);
        }
Exemplo n.º 2
0
        public void GetTreatments_WhenNameDoesntExist_DontLogImpression()
        {
            // Arrange.
            var treatmentLogMock = new Mock <IListener <KeyImpression> >();
            var client           = new JSONFileClient("splits_staging_3.json", "", _logMock.Object, null, null, treatmentLogMock.Object);
            var splitNames       = new List <string> {
                "not_exist", "not_exist_1"
            };

            client.BlockUntilReady(1000);

            // Act.
            var result = client.GetTreatments("key", splitNames);

            // Assert.
            foreach (var res in result)
            {
                Assert.AreEqual("control", res.Value);
            }

            foreach (var name in splitNames)
            {
                _logMock.Verify(mock => mock.Warn($"GetTreatment: you passed {name} that does not exist in this environment, please double check what Splits exist in the web console."), Times.Once());
            }

            treatmentLogMock.Verify(x => x.Log(It.IsAny <KeyImpression>()), Times.Never());
        }
Exemplo n.º 3
0
        public void ExecuteGetTreatmentsWithBucketing()
        {
            //Arrange
            var           client   = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _logMock.Object);
            List <string> features = new List <string>
            {
                "fail",
                "asd",
                "get_environment"
            };

            var attributes = new Dictionary <string, object>
            {
                { "env", "test" }
            };

            var keys = new Key("test", "test");

            client.BlockUntilReady(1000);

            //Act
            var result = client.GetTreatments(keys, features, attributes);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("control", result["fail"]);
            Assert.AreEqual("off", result["asd"]);
            Assert.AreEqual("test", result["get_environment"]);
        }
Exemplo n.º 4
0
        public void ExecuteGetTreatments()
        {
            //Arrange
            var           client   = new JSONFileClient("splits_staging_3.json", "", _logMock.Object);
            List <string> features = new List <string>();

            features.Add("fail");
            features.Add("asd");
            features.Add("get_environment");

            var attributes = new Dictionary <string, object>();

            attributes.Add("env", "test");

            client.BlockUntilReady(1000);

            //Act
            var result = client.GetTreatments("test", features, attributes);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("control", result["fail"]);
            Assert.AreEqual("off", result["asd"]);
            Assert.AreEqual("test", result["get_environment"]);
        }
Exemplo n.º 5
0
        public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList()
        {
            // Arrange.
            var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _logMock.Object);

            // Act.
            var result = client.GetTreatments("key", new List <string>());

            // Assert.
            Assert.IsTrue(result.Count == 0);
            _logMock.Verify(mock => mock.Error($"GetTreatment: the SDK is not ready, the operation cannot be executed."), Times.Never);
        }
Exemplo n.º 6
0
        public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList()
        {
            // Arrange.
            var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _logMock.Object);

            client.BlockUntilReady(100);

            // Act.
            var result = client.GetTreatments("key", new List <string>());

            // Assert.
            Assert.IsTrue(result.Count == 0);
        }
Exemplo n.º 7
0
        public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList()
        {
            // Arrange.
            var treatmentLogMock = new Mock <IListener <KeyImpression> >();
            var client           = new JSONFileClient("splits_staging_3.json", "", _logMock.Object, null, null, treatmentLogMock.Object);

            client.BlockUntilReady(100);

            // Act.
            var result = client.GetTreatments("key", new List <string>());

            // Assert.
            Assert.IsTrue(result.Count == 0);
        }
Exemplo n.º 8
0
        public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn()
        {
            //Arrange
            var client = new JSONFileClient(@"Resources\splits_staging_6.json", "");

            //Act
            var features = new List <string>();

            features.Add("test_whitelist");
            features.Add("test_dependency");
            var result = client.GetTreatments("fake_user_id_1", features, null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("on", result["test_whitelist"]);
            Assert.AreEqual("on", result["test_dependency"]);
        }
Exemplo n.º 9
0
        public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn()
        {
            //Arrange
            var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _logMock.Object);

            client.BlockUntilReady(1000);

            //Act
            var features = new List <string>
            {
                "test_whitelist",
                "test_dependency"
            };
            var result = client.GetTreatments("fake_user_id_1", features, null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("on", result["test_whitelist"]);
            Assert.AreEqual("on", result["test_dependency"]);
        }
Exemplo n.º 10
0
        public void ExecuteGetTreatmentsWithDependencyMatcherWithAttributesReturnsOn()
        {
            //Arrange
            var client = new JSONFileClient("splits_staging_6.json", "", _logMock.Object);

            //Act
            var features = new List <string>();

            features.Add("test_whitelist");
            features.Add("test_dependency");
            var attributes = new Dictionary <string, object>();

            attributes.Add("st", "allow");
            var result = client.GetTreatments("fake_user_id_1", features, attributes);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("on", result["test_whitelist"]);
            Assert.AreEqual("on", result["test_dependency"]);
        }
Exemplo n.º 11
0
        public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments()
        {
            // Arrange.
            var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _logMock.Object);

            // Act.
            var result = client.GetTreatments("key", new List <string> {
                "anding", "in_ten_keys"
            });

            // Assert.
            var treatment1 = result.FirstOrDefault(r => r.Key.Equals("anding"));

            Assert.AreEqual("off", treatment1.Value);

            var treatment2 = result.FirstOrDefault(r => r.Key.Equals("in_ten_keys"));

            Assert.AreEqual("on", treatment2.Value);

            _logMock.Verify(mock => mock.Error($"GetTreatment: the SDK is not ready, the operation cannot be executed."), Times.Never);
        }