Exemplo n.º 1
0
        public void GetTreatmentWithConfig_WithtBUR_WhenTreatmentDoesntExist_ReturnsControl()
        {
            // Arrange.
            using (var httpClientMock = GetHttpClientMock())
            {
                var impressionListener = new IntegrationTestsImpressionListener(50);
                var configurations     = GetConfigurationOptions(httpClientMock?.GetUrl(), impressionListener: impressionListener);

                var apikey = "base-apikey6";

                var splitFactory = new SplitFactory(apikey, configurations);
                var client       = splitFactory.Client();

                client.BlockUntilReady(10000);

                // Act.
                var result = client.GetTreatment("nico_test", "Random_Treatment");

                // Assert.
                Assert.AreEqual("control", result);

                // Validate impressions in listener.
                Thread.Sleep(2000);
                var impressionQueue = impressionListener.GetQueue();
                var keyImpressions  = impressionQueue.FetchAll();

                Assert.AreEqual(0, keyImpressions.Count);

                //Validate impressions sent to the be.
                AssertSentImpressions(0, httpClientMock);

                client.Destroy();
            }
        }
Exemplo n.º 2
0
        public void GetTreatments_WithtBUR_WhenTreatmentsDoesntExist_ReturnsTreatments()
        {
            // Arrange.
            using (var httpClientMock = GetHttpClientMock())
            {
                var impressionListener = new IntegrationTestsImpressionListener(50);
                var configurations     = GetConfigurationOptions(httpClientMock?.GetUrl(), impressionListener: impressionListener);

                var apikey = "base-apikey9";

                var splitFactory = new SplitFactory(apikey, configurations);
                var client       = splitFactory.Client();

                client.BlockUntilReady(10000);

                // Act.
                var result = client.GetTreatments("nico_test", new List <string> {
                    "FACUNDO_TEST", "Random_Treatment", "MAURO_TEST", "Test_Save_1", "Random_Treatment_2",
                });

                // Assert.
                Assert.AreEqual("on", result["FACUNDO_TEST"]);
                Assert.AreEqual("control", result["Random_Treatment"]);
                Assert.AreEqual("off", result["MAURO_TEST"]);
                Assert.AreEqual("off", result["Test_Save_1"]);
                Assert.AreEqual("control", result["Random_Treatment_2"]);

                client.Destroy();

                // Validate impressions.
                Thread.Sleep(2000);
                var impressionQueue = impressionListener.GetQueue();
                var keyImpressions  = impressionQueue.FetchAll();

                var impression1 = keyImpressions
                                  .Where(ki => ki.feature.Equals("FACUNDO_TEST"))
                                  .Where(ki => ki.keyName.Equals("nico_test"))
                                  .FirstOrDefault();

                var impression2 = keyImpressions
                                  .Where(ki => ki.feature.Equals("MAURO_TEST"))
                                  .Where(ki => ki.keyName.Equals("nico_test"))
                                  .FirstOrDefault();

                var impression3 = keyImpressions
                                  .Where(ki => ki.feature.Equals("Test_Save_1"))
                                  .Where(ki => ki.keyName.Equals("nico_test"))
                                  .FirstOrDefault();

                AssertImpression(impression1, 1506703262916, "FACUNDO_TEST", "nico_test", "whitelisted", "on");
                AssertImpression(impression2, 1506703262966, "MAURO_TEST", "nico_test", "not in split", "off");
                AssertImpression(impression3, 1503956389520, "Test_Save_1", "nico_test", "in segment all", "off");

                Assert.AreEqual(3, keyImpressions.Count);

                //Validate impressions sent to the be.
                AssertSentImpressions(3, httpClientMock, impression1, impression2, impression3);
            }
        }
Exemplo n.º 3
0
        public void GetTreatmentWithConfig_WithtInputValidation_ReturnsTreatments()
        {
            // Arrange.
            using (var httpClientMock = GetHttpClientMock())
            {
                var impressionListener = new IntegrationTestsImpressionListener(50);
                var configurations     = GetConfigurationOptions(httpClientMock?.GetUrl(), impressionListener: impressionListener);

                var apikey = "base-apikey5";

                var splitFactory = new SplitFactory(apikey, configurations);
                var client       = splitFactory.Client();

                client.BlockUntilReady(10000);

                // Act.
                var result1 = client.GetTreatmentWithConfig("nico_test", "FACUNDO_TEST");
                var result2 = client.GetTreatmentWithConfig(string.Empty, "FACUNDO_TEST");
                var result3 = client.GetTreatmentWithConfig("test", string.Empty);
                var result4 = client.GetTreatmentWithConfig("mauro", "MAURO_TEST");

                client.Destroy();

                // Assert.
                Assert.AreEqual("on", result1.Treatment);
                Assert.AreEqual("control", result2.Treatment);
                Assert.AreEqual("control", result3.Treatment);
                Assert.AreEqual("on", result4.Treatment);

                Assert.AreEqual("{\"color\":\"green\"}", result1.Config);
                Assert.IsNull(result2.Config);
                Assert.IsNull(result3.Config);
                Assert.AreEqual("{\"version\":\"v2\"}", result4.Config);

                // Validate impressions.
                Thread.Sleep(3000);
                var impressionQueue = impressionListener.GetQueue();
                var keyImpressions  = impressionQueue.FetchAll();

                Assert.AreEqual(2, keyImpressions.Count);

                var impression1 = keyImpressions
                                  .Where(ki => ki.feature.Equals("FACUNDO_TEST"))
                                  .Where(ki => ki.keyName.Equals("nico_test"))
                                  .FirstOrDefault();

                var impression2 = keyImpressions
                                  .Where(ki => ki.feature.Equals("MAURO_TEST"))
                                  .Where(ki => ki.keyName.Equals("mauro"))
                                  .FirstOrDefault();

                AssertImpression(impression1, 1506703262916, "FACUNDO_TEST", "nico_test", "whitelisted", "on");
                AssertImpression(impression2, 1506703262966, "MAURO_TEST", "mauro", "whitelisted", "on");

                //Validate impressions sent to the be.
                AssertSentImpressions(2, httpClientMock, impression1, impression2);
            }
        }
Exemplo n.º 4
0
        public void GetTreatment_WithtInputValidation_ReturnsTreatments()
        {
            // Arrange.
            using (var httpClientMock = GetHttpClientMock())
            {
                var impressionListener = new IntegrationTestsImpressionListener(50);
                var configurations     = GetConfigurationOptions(httpClientMock?.GetUrl(), impressionListener: impressionListener);

                var apikey = "base-apikey2";

                var splitFactory = new SplitFactory(apikey, configurations);
                var client       = splitFactory.Client();

                client.BlockUntilReady(10000);

                // Act.
                var result1 = client.GetTreatment("nico_test", "FACUNDO_TEST");
                var result2 = client.GetTreatment(string.Empty, "FACUNDO_TEST");
                var result3 = client.GetTreatment("1", string.Empty);
                var result4 = client.GetTreatment("24", "Test_Save_1");

                // Assert.
                Assert.AreEqual("on", result1);
                Assert.AreEqual("control", result2);
                Assert.AreEqual("control", result3);
                Assert.AreEqual("off", result4);

                client.Destroy();

                // Validate impressions in listener.
                Thread.Sleep(2000);
                var impressionQueue = impressionListener.GetQueue();
                var keyImpressions  = impressionQueue.FetchAll();

                Assert.AreEqual(2, keyImpressions.Count);

                var impression1 = keyImpressions
                                  .Where(ki => ki.feature.Equals("FACUNDO_TEST"))
                                  .Where(ki => ki.keyName.Equals("nico_test"))
                                  .FirstOrDefault();

                var impression2 = keyImpressions
                                  .Where(ki => ki.feature.Equals("Test_Save_1"))
                                  .Where(ki => ki.keyName.Equals("24"))
                                  .FirstOrDefault();

                AssertImpression(impression1, 1506703262916, "FACUNDO_TEST", "nico_test", "whitelisted", "on");
                AssertImpression(impression2, 1503956389520, "Test_Save_1", "24", "in segment all", "off");

                //Validate impressions sent to the be.
                AssertSentImpressions(2, httpClientMock, impression1, impression2);

                client.Destroy();
            }
        }