Ejemplo n.º 1
0
        public async Task GetCampaignsTest()
        {
            var config = new Flagship.Config.DecisionApiConfig()
            {
                EnvId = "envID"
            };
            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(GetCampaigns(), Encoding.UTF8, "application/json")
            };

            var url = $"{Constants.BASE_API_URL}{config.EnvId}/campaigns?exposeAllKeys=true&{Constants.SEND_CONTEXT_EVENT}=false";

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            mockHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse);

            var httpClient          = new HttpClient(mockHandler.Object);
            var trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

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

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitorId", false, context, false, configManager);

            var decisionManager = new Flagship.Decision.ApiManager(config, httpClient);

            decisionManager.StatusChange += DecisionManager_StatusChange1;

            Collection <Flagship.Model.Campaign> campaigns = (Collection <Model.Campaign>) await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            Collection <Flagship.Model.FlagDTO> flags = (Collection <Model.FlagDTO>) await decisionManager.GetFlags(campaigns).ConfigureAwait(false);

            Assert.AreEqual(campaigns.Count, 3);
            Assert.AreEqual(campaigns[0].Id, "c3ev1afkprbg5u3burag");
            Assert.AreEqual(campaigns[2].Id, "c20j8bk3fk9hdphqtd1g");

            Assert.AreEqual(flags.Count, 6);
            Assert.AreEqual(flags[0].Key, "array");
            Assert.AreEqual(flags[5].Key, "my_text");

            httpClient.Dispose();
            httpResponse.Dispose();
        }
Ejemplo n.º 2
0
        public async Task GetCampaignsTestFailTest()
        {
            var fsLogManagerMock = new Mock <IFsLogManager>();


            var config = new Flagship.Config.DecisionApiConfig()
            {
                EnvId      = "envID",
                LogManager = fsLogManagerMock.Object,
            };

            var responseContent = "Error";

            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.BadRequest,
                Content    = new StringContent(responseContent, Encoding.UTF8, "application/json")
            };

            var url = $"{Constants.BASE_API_URL}{config.EnvId}/campaigns?exposeAllKeys=true&{Constants.SEND_CONTEXT_EVENT}=false";

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            mockHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse);

            var httpClient          = new HttpClient(mockHandler.Object);
            var trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

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

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitorId", false, context, false, configManager);

            var decisionManager = new Flagship.Decision.ApiManager(config, httpClient);

            var campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            Assert.AreEqual(campaigns.Count, 0);

            fsLogManagerMock.Verify(x => x.Error("Bad Request", "GetCampaigns"), Times.Once());

            httpClient.Dispose();
            httpResponse.Dispose();
        }
Ejemplo n.º 3
0
        public async Task GetCampaignsPanicModeTest()
        {
            var config = new Flagship.Config.DecisionApiConfig()
            {
                EnvId = "envID"
            };
            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent("{'visitorId':'anonymeId','campaigns':[],'panic':true}", Encoding.UTF8, "application/json")
            };

            var url = $"{Constants.BASE_API_URL}{config.EnvId}/campaigns?exposeAllKeys=true&{Constants.SEND_CONTEXT_EVENT}=false";

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            mockHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse);

            var httpClient          = new HttpClient(mockHandler.Object);
            var trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

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

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitorId", false, context, false, configManager);

            var decisionManager = new Flagship.Decision.ApiManager(config, httpClient);

            decisionManager.StatusChange += DecisionManager_StatusChange;

            var campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            Assert.AreEqual(campaigns.Count, 0);

            Assert.IsTrue(decisionManager.IsPanic);

            httpClient.Dispose();
            httpResponse.Dispose();
        }
Ejemplo n.º 4
0
        public async Task SendActive()
        {
            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent("", Encoding.UTF8, "application/json")
            };

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            mockHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse);


            var fsLogManagerMock = new Mock <IFsLogManager>();

            var config = new Flagship.Config.DecisionApiConfig
            {
                ApiKey     = "apiKey",
                EnvId      = "envId",
                LogManager = fsLogManagerMock.Object,
            };

            var httpClient      = new HttpClient(mockHandler.Object);
            var trackingManager = new Flagship.Api.TrackingManager(config, httpClient);

            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManager);

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

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitorId", false, context, true, configManager);

            var flag = new Flagship.Model.FlagDTO()
            {
                VariationGroupId = "varGroupID",
                VariationId      = "varID",
            };

            var postData = new Dictionary <string, object>
            {
                [Constants.VISITOR_ID_API_ITEM]         = visitorDelegate.VisitorId,
                [Constants.VARIATION_ID_API_ITEM]       = flag.VariationId,
                [Constants.VARIATION_GROUP_ID_API_ITEM] = flag.VariationGroupId,
                [Constants.CUSTOMER_ENV_ID_API_ITEM]    = config.EnvId,
                [Constants.ANONYMOUS_ID] = null
            };



            Func <HttpRequestMessage, bool> action = (HttpRequestMessage x) => {
                var postDataString = JsonConvert.SerializeObject(postData);
                var headers        = new HttpRequestMessage().Headers;
                headers.Add(Constants.HEADER_X_API_KEY, config.ApiKey);
                headers.Add(Constants.HEADER_X_SDK_CLIENT, Constants.SDK_LANGUAGE);
                headers.Add(Constants.HEADER_X_SDK_VERSION, Constants.SDK_VERSION);
                headers.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants.HEADER_APPLICATION_JSON));

                var result = x.Content.ReadAsStringAsync().Result;
                return(result == postDataString && headers.ToString() == x.Headers.ToString() && x.Method == HttpMethod.Post);
            };

            var errorSendAsyn = new Exception("Error Send");

            mockHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(x => action(x)),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse).Verifiable();

            await trackingManager.SendActive(visitorDelegate, flag).ConfigureAwait(false);

            // XC test

            mockHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(x => action(x)),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse).Verifiable();


            var newVisitorId = "newVisitorId";

            visitorDelegate.Authenticate(newVisitorId);

            postData[Constants.VISITOR_ID_API_ITEM] = visitorDelegate.VisitorId;
            postData[Constants.ANONYMOUS_ID]        = visitorDelegate.AnonymousId;


            await trackingManager.SendActive(visitorDelegate, flag).ConfigureAwait(false);

            mockHandler.Verify();

            httpResponse.Dispose();
            httpClient.Dispose();
        }
Ejemplo n.º 5
0
        public async Task GetCampaignsTest()
        {
            var config = new Config.BucketingConfig()
            {
                EnvId           = "envID",
                ApiKey          = "spi",
                PollingInterval = TimeSpan.FromSeconds(0),
            };

            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(GetBucketingRealloc(), Encoding.UTF8, "application/json"),
            };

            HttpResponseMessage httpResponse2 = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(GetBucketingRemovedVariation2(), Encoding.UTF8, "application/json"),
            };

            httpResponse.Headers.Add(HttpResponseHeader.LastModified.ToString(), "2022-01-20");

            var url = string.Format(Constants.BUCKETING_API_URL, config.EnvId);

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            mockHandler.Protected().SetupSequence <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse).ReturnsAsync(httpResponse).ReturnsAsync(httpResponse2);

            var httpClient = new HttpClient(mockHandler.Object);

            var murmurHash      = Murmur.MurmurHash.Create32();
            var decisionManager = new BucketingManager(config, httpClient, murmurHash);

            var decisionManagerPrivate = new PrivateObject(decisionManager);

            var trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

            var context = new Dictionary <string, object>()
            {
                ["age"] = 20
            };


            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitor_1", false, context, false, configManager);


            await decisionManager.StartPolling().ConfigureAwait(false);

            var campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            var flags = await decisionManager.GetFlags(campaigns).ConfigureAwait(false);

            Assert.AreEqual(6, flags.Count);

            Assert.IsNotNull(flags.FirstOrDefault(x => x.VariationId == "c20j9lgbcahhf2mvhbf0"));

            visitorDelegate.VisitorCache = new VisitorCache
            {
                Version = 1,
                Data    = new VisitorCacheDTOV1
                {
                    Version = 1,
                    Data    = new VisitorCacheData
                    {
                        VisitorId          = "visitor_1",
                        Consent            = true,
                        AssignmentsHistory = new Dictionary <string, string>
                        {
                            ["c20j8bk3fk9hdphqtd2g"] = "c20j8bk3fk9hdphqtd3g"
                        }
                    }
                }
            };


            await decisionManager.StartPolling().ConfigureAwait(false);

            campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            flags = await decisionManager.GetFlags(campaigns).ConfigureAwait(false);

            Assert.AreEqual(6, flags.Count);

            // Test realloc
            Assert.IsNull(flags.FirstOrDefault(x => x.VariationId == "c20j9lgbcahhf2mvhbf0"));

            Assert.IsNotNull(flags.FirstOrDefault(x => x.VariationId == "c20j8bk3fk9hdphqtd3g"));



            await decisionManager.StartPolling().ConfigureAwait(false);

            campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            flags = await decisionManager.GetFlags(campaigns).ConfigureAwait(false);

            Assert.AreEqual(5, flags.Count);

            // Test realloc
            Assert.IsNull(flags.FirstOrDefault(x => x.VariationId == "c20j9lgbcahhf2mvhbf0"));

            Assert.IsNull(flags.FirstOrDefault(x => x.VariationId == "c20j8bk3fk9hdphqtd3g"));

            httpResponse.Dispose();
            httpClient.Dispose();
            httpResponse2.Dispose();
            murmurHash.Dispose();
        }
Ejemplo n.º 6
0
        public async Task SendContextTest()
        {
            var fsLogManagerMock = new Mock <IFsLogManager>();

            var config = new Config.BucketingConfig()
            {
                EnvId           = "envID",
                ApiKey          = "spi",
                PollingInterval = TimeSpan.FromSeconds(0),
                LogManager      = fsLogManagerMock.Object,
            };

            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("", Encoding.UTF8, "application/json"),
            };

            HttpResponseMessage httpResponseError = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.BadRequest,
                Content    = new StringContent("Error", Encoding.UTF8, "application/json"),
            };

            var url = string.Format(Constants.BUCKETING_API_CONTEXT_URL, config.EnvId);

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();


            mockHandler.Protected().SetupSequence <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponse).ReturnsAsync(httpResponseError);

            var httpClient = new HttpClient(mockHandler.Object);

            var decisionManagerMock = new BucketingManager(config, httpClient, null);

            var trackingManagerMock  = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock2 = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager        = new Flagship.Config.ConfigManager(config, decisionManagerMock2.Object, trackingManagerMock.Object);

            var context = new Dictionary <string, object>()
            {
                ["age"] = 20
            };

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitor_1", false, context, false, configManager);

            decisionManagerMock.SendContextAsync(visitorDelegate);

            mockHandler.Protected().Verify("SendAsync", Times.Exactly(1),
                                           ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.ToString() == url),
                                           ItExpr.IsAny <CancellationToken>());

            decisionManagerMock.SendContextAsync(visitorDelegate);


            mockHandler.Protected().Verify("SendAsync", Times.Exactly(2),
                                           ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.ToString() == url),
                                           ItExpr.IsAny <CancellationToken>());

            fsLogManagerMock.Verify(x => x.Error("Bad Request", "SendContext"), Times.Once());

            httpResponse.Dispose();
            httpResponseError.Dispose();
        }
Ejemplo n.º 7
0
        public async Task PollingTest()
        {
            var fsLogManagerMock = new Mock <IFsLogManager>();

            var config = new Config.BucketingConfig()
            {
                EnvId           = "envID",
                ApiKey          = "spi",
                PollingInterval = TimeSpan.FromSeconds(0),
                LogManager      = fsLogManagerMock.Object,
            };

            HttpResponseMessage httpResponsePanicMode = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{ \"panic\": true }", Encoding.UTF8, "application/json"),
            };

            httpResponsePanicMode.Headers.Add(HttpResponseHeader.LastModified.ToString(), "2022-01-20");

            var url = string.Format(Constants.BUCKETING_API_URL, config.EnvId);

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            var exception = new Exception("Test");

            mockHandler.Protected().SetupSequence <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponsePanicMode).Throws(exception);

            var httpClient = new HttpClient(mockHandler.Object);

            var decisionManagerMock = new Mock <BucketingManager>(config, httpClient, null)
            {
                CallBase = true
            };

            decisionManagerMock.Setup(x => x.SendContextAsync(It.IsAny <FsVisitor.VisitorDelegateAbstract>()));

            var decisionManager = decisionManagerMock.Object;

            var countStatus = 0;

            void DecisionManager_StatusChange(FlagshipStatus status)
            {
                if (countStatus == 0)
                {
                    countStatus++;
                    Assert.AreEqual(FlagshipStatus.POLLING, status);
                }
                else
                {
                    Assert.AreEqual(FlagshipStatus.READY, status);
                }
            }

            decisionManager.StatusChange += DecisionManager_StatusChange;

            await Task.WhenAll(new Task[]
            {
                decisionManager.StartPolling(),
                decisionManager.StartPolling()
            }).ConfigureAwait(false);

            var trackingManagerMock  = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock2 = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager        = new Flagship.Config.ConfigManager(config, decisionManagerMock2.Object, trackingManagerMock.Object);

            var context = new Dictionary <string, object>()
            {
                ["age"] = 20
            };

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitor_1", false, context, false, configManager);

            var campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            Assert.IsTrue(decisionManager.IsPanic);

            await decisionManager.StartPolling().ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(exception.Message, "Polling"), Times.Once());

            fsLogManagerMock.Verify(x => x.Error(It.Is <string>(y => y != exception.Message), It.Is <string>(y => y != "Polling")), Times.Never());

            httpResponsePanicMode.Dispose();
            httpClient.Dispose();
        }
Ejemplo n.º 8
0
        public async Task BucketingManagerTest()
        {
            var config = new Config.BucketingConfig()
            {
                EnvId           = "envID",
                ApiKey          = "spi",
                PollingInterval = TimeSpan.FromSeconds(0),
            };


            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(GetBucketing(), Encoding.UTF8, "application/json"),
            };

            HttpResponseMessage httpResponsePanicMode = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{ \"panic\": true }", Encoding.UTF8, "application/json"),
            };

            httpResponse.Headers.Add(HttpResponseHeader.LastModified.ToString(), "2022-01-20");

            var url = string.Format(Constants.BUCKETING_API_URL, config.EnvId);

            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            mockHandler.Protected().SetupSequence <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri.ToString() == url),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(httpResponsePanicMode).ReturnsAsync(httpResponse);

            var httpClient = new HttpClient(mockHandler.Object);

            var decisionManager = new BucketingManager(config, httpClient, Murmur.MurmurHash.Create32());

            var decisionManagerPrivate = new PrivateObject(decisionManager);

            var trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

            var context = new Dictionary <string, object>()
            {
                ["age"] = 20
            };


            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitor_1", false, context, false, configManager);

            // test GetCampaigns empty

            var campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            Assert.AreEqual(0, campaigns.Count);

            // test GetCampaigns Panic mode

            await decisionManager.StartPolling().ConfigureAwait(false);

            campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            Assert.AreEqual(0, campaigns.Count);
            Assert.IsTrue(decisionManager.IsPanic);

            await decisionManager.StartPolling().ConfigureAwait(false);

            campaigns = await decisionManager.GetCampaigns(visitorDelegate).ConfigureAwait(false);

            var flags = await decisionManager.GetFlags(campaigns).ConfigureAwait(false);

            Assert.AreEqual(6, flags.Count);


            httpResponse.Dispose();
            httpClient.Dispose();
            httpResponsePanicMode.Dispose();
        }
Ejemplo n.º 9
0
        public void BucketingMethod()
        {
            var config = new Config.BucketingConfig()
            {
                EnvId           = "envID",
                ApiKey          = "spi",
                PollingInterval = TimeSpan.FromSeconds(0),
            };

            var httpClient = new HttpClient();

            var decisionManager = new BucketingManager(config, httpClient, Murmur.MurmurHash.Create32());

            var decisionManagerPrivate = new PrivateObject(decisionManager);

            var trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Flagship.Decision.IDecisionManager>();
            var configManager       = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

            var context = new Dictionary <string, object>()
            {
                ["age"] = 20
            };

            var visitorId = "123456";

            var visitorDelegate = new Flagship.FsVisitor.VisitorDelegate(visitorId, false, context, false, configManager);

            //test getVariation
            var variations = new Collection <Model.Bucketing.Variation>
            {
                new Model.Bucketing.Variation
                {
                    Id            = "c20j8bk3fk9hdphqtd30",
                    Modifications = new Modifications {
                        Type  = Model.ModificationType.HTML,
                        Value = new Dictionary <string, object>
                        {
                            ["my_html"] = "<div>\n  <p>Original</p>\n</div>"
                        }
                    },
                    Allocation = 34,
                    Reference  = true
                },
                new Model.Bucketing.Variation
                {
                    Id            = "c20j8bk3fk9hdphqtd3g",
                    Modifications = new Modifications {
                        Type  = Model.ModificationType.HTML,
                        Value = new Dictionary <string, object>
                        {
                            ["my_html"] = "<div>\n  <p>variation 1</p>\n</div>"
                        }
                    },
                    Allocation = 33,
                },
                new Model.Bucketing.Variation
                {
                    Id            = "c20j9lgbcahhf2mvhbf0",
                    Modifications = new Modifications {
                        Type  = Model.ModificationType.HTML,
                        Value = new Dictionary <string, object>
                        {
                            ["my_html"] = "<div>\n  <p>variation 2</p>\n</div>"
                        }
                    },
                    Allocation = 33,
                }
            };

            var VariationGroup = new VariationGroup
            {
                Id         = "9273BKSDJtoto",
                Variations = variations
            };
            var variationResult = (Model.Variation)decisionManagerPrivate.Invoke("GetVariation", new object[] { VariationGroup, visitorDelegate });

            Assert.IsNotNull(variationResult);

            Assert.AreEqual(variations[0].Id, variationResult.Id);

            // Test null variation

            variationResult = (Model.Variation)decisionManagerPrivate.Invoke("GetVariation", new object[] { null, visitorDelegate });

            Assert.IsNull(variationResult);

            VariationGroup = new VariationGroup
            {
                Id         = "9273BKSDJtoto",
                Variations = null
            };
            variationResult = (Model.Variation)decisionManagerPrivate.Invoke("GetVariation", new object[] { VariationGroup, visitorDelegate });

            Assert.IsNull(variationResult);


            // test isMatchTargeting with empty VariationGroupDTO

            var IsMatchedTargeting = (bool)decisionManagerPrivate.Invoke("IsMatchedTargeting", new object[] { new VariationGroup(), visitorDelegate });

            Assert.IsFalse(IsMatchedTargeting);

            VariationGroup = new VariationGroup
            {
                Targeting = new TargetingContainer
                {
                    TargetingGroups = new List <TargetingGroup>
                    {
                        new TargetingGroup
                        {
                            Targetings = new Collection <Targeting>
                            {
                                new Targeting
                                {
                                    Key      = "age",
                                    Operator = TargetingOperator.EQUALS,
                                    Value    = 21
                                }
                            }
                        }
                    }
                }
            };

            IsMatchedTargeting = (bool)decisionManagerPrivate.Invoke("IsMatchedTargeting", new object[] { VariationGroup, visitorDelegate });

            Assert.IsFalse(IsMatchedTargeting);

            var TargetingGroups = VariationGroup.Targeting.TargetingGroups.Append(new TargetingGroup
            {
                Targetings = new Collection <Targeting>
                {
                    new Targeting
                    {
                        Key      = "fs_all_users",
                        Operator = TargetingOperator.EQUALS,
                        Value    = ""
                    }
                }
            }).Append(new TargetingGroup
            {
                Targetings = new Collection <Targeting>
                {
                    new Targeting
                    {
                        Key      = "fs_users",
                        Operator = TargetingOperator.EQUALS,
                        Value    = visitorId
                    }
                }
            });

            VariationGroup.Targeting.TargetingGroups = TargetingGroups;


            IsMatchedTargeting = (bool)decisionManagerPrivate.Invoke("IsMatchedTargeting", new object[] { VariationGroup, visitorDelegate });

            Assert.IsTrue(IsMatchedTargeting);

            //test CheckAndTargeting

            var CheckAndTargeting = (bool)decisionManagerPrivate.Invoke("CheckAndTargeting", new object[] { new Collection <Targeting>(), visitorDelegate });

            Assert.IsFalse(CheckAndTargeting);

            // test checkAndTargeting fs_all_users

            var targetings = new Collection <Targeting>
            {
                new Targeting
                {
                    Key      = "fs_all_users",
                    Operator = TargetingOperator.EQUALS,
                    Value    = ""
                }
            };

            CheckAndTargeting = (bool)decisionManagerPrivate.Invoke("CheckAndTargeting", new object[] { targetings, visitorDelegate });

            Assert.IsTrue(CheckAndTargeting);

            // test checkAndTargeting fs_users

            targetings = new Collection <Targeting>
            {
                new Targeting
                {
                    Key      = "fs_users",
                    Operator = TargetingOperator.STARTS_WITH,
                    Value    = "12"
                },
                new Targeting
                {
                    Key      = "fs_users",
                    Operator = TargetingOperator.ENDS_WITH,
                    Value    = "6"
                }
            };

            CheckAndTargeting = (bool)decisionManagerPrivate.Invoke("CheckAndTargeting", new object[] { targetings, visitorDelegate });

            Assert.IsTrue(CheckAndTargeting);

            // test checkAndTargeting fs_users targeting and

            targetings = new Collection <Targeting>
            {
                new Targeting
                {
                    Key      = "fs_users",
                    Operator = TargetingOperator.STARTS_WITH,
                    Value    = "2"
                },
                new Targeting
                {
                    Key      = "fs_users",
                    Operator = TargetingOperator.ENDS_WITH,
                    Value    = "6"
                }
            };

            CheckAndTargeting = (bool)decisionManagerPrivate.Invoke("CheckAndTargeting", new object[] { targetings, visitorDelegate });

            Assert.IsFalse(CheckAndTargeting);

            // test checkAndTargeting key not match any context

            targetings = new Collection <Targeting>
            {
                new Targeting
                {
                    Key      = "anyKey",
                    Operator = TargetingOperator.EQUALS,
                    Value    = "anyValue"
                }
            };

            CheckAndTargeting = (bool)decisionManagerPrivate.Invoke("CheckAndTargeting", new object[] { targetings, visitorDelegate });

            Assert.IsFalse(CheckAndTargeting);

            // test checkAndTargeting key match context

            targetings = new Collection <Targeting>
            {
                new Targeting
                {
                    Key      = "age",
                    Operator = TargetingOperator.EQUALS,
                    Value    = 20
                }
            };

            CheckAndTargeting = (bool)decisionManagerPrivate.Invoke("CheckAndTargeting", new object[] { targetings, visitorDelegate });

            Assert.IsTrue(CheckAndTargeting);

            // test testOperator EQUALS Test different values

            var testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, 5, 6 });

            Assert.IsFalse(testOperator);

            // test testOperator EQUALS Test different type

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, 5, "5" });

            Assert.IsFalse(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, true, "5" });

            Assert.IsFalse(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, true, false });

            Assert.IsFalse(testOperator);

            // test testOperator EQUALS Test same type and value

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, true, true });

            Assert.IsTrue(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, "abc", "abc" });

            Assert.IsTrue(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, 1, 1 });

            Assert.IsTrue(testOperator);

            // test testOperator EQUALS Test contextValue EQUALS targetingValue list

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, "a", new JArray {
                                                                                                  "a", "b", "c"
                                                                                              } });

            Assert.IsTrue(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.EQUALS, "a", new JArray {
                                                                                                  "b", "c"
                                                                                              } });

            Assert.IsFalse(testOperator);

            // test testOperator NOT_EQUALS Test different values


            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_EQUALS, 5, 6 });

            Assert.IsTrue(testOperator);

            // test testOperator NOT_EQUALS Test different type

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_EQUALS, 5, '5' });

            Assert.IsTrue(testOperator);

            // test testOperator NOT_EQUALS Test same type and value

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_EQUALS, 5, 5 });

            Assert.IsFalse(testOperator);

            // test testOperator NOT_EQUALS Test contextValue NOT_EQUALS targetingValue list


            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_EQUALS, "a", new JArray {
                                                                                                  "b", "c", "d"
                                                                                              } });

            Assert.IsTrue(testOperator);

            // test testOperator NOT_EQUALS Test contextValue NOT_EQUALS targetingValue list

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_EQUALS, "a", new JArray {
                                                                                                  "a", "b", "c"
                                                                                              } });

            Assert.IsFalse(testOperator);


            // test testOperator CONTAINS Test contextValue not contains targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, "a", "b" });

            Assert.IsFalse(testOperator);

            // test testOperator CONTAINS Test contextValue contains targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, "abc", "b" });

            Assert.IsTrue(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, 123, 2 });

            Assert.IsTrue(testOperator);

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, 123, "2" });

            Assert.IsTrue(testOperator);

            // test testOperator CONTAINS Test contextValue contains targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, "nopq_hij", new JArray()
                                                                                              {
                                                                                                  "abc", "dfg", "hij", "klm"
                                                                                              } });

            Assert.IsTrue(testOperator);

            // test testOperator CONTAINS Test contextValue CONTAINS targetingValue list

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, "abcd", new JArray()
                                                                                              {
                                                                                                  "a", "b", "c"
                                                                                              } });

            Assert.IsTrue(testOperator);

            // test testOperator CONTAINS Test contextValue not CONTAINS targetingValue list

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.CONTAINS, "abcd", new JArray {
                                                                                                  "e", "f"
                                                                                              } });

            Assert.IsFalse(testOperator);

            // test testOperator NOT_CONTAINS Test contextValue not contains targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_CONTAINS, "abc", "d" });

            Assert.IsTrue(testOperator);

            // test testOperator NOT_CONTAINS Test contextValue contains targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_CONTAINS, "abc", "b" });

            Assert.IsFalse(testOperator);

            // test testOperator NOT_CONTAINS Test contextValue NOT_CONTAINS targetingValue list

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_CONTAINS, "abcd", new JArray {
                                                                                                  "e", "f"
                                                                                              } });

            Assert.IsTrue(testOperator);

            // test testOperator NOT_CONTAINS Test contextValue not NOT_CONTAINS targetingValue list

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.NOT_CONTAINS, "abcd", new JArray {
                                                                                                  "a", "e"
                                                                                              } });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN Test contextValue not GREATER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN, 5, 6 });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN Test contextValue not GREATER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN, 5, 5 });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN Test contextValue not GREATER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN, "a", "b" });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN Test contextValue not GREATER_THAN targetingValue


            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN, "abz", "bcg" });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN Test contextValue GREATER_THAN targetingValue


            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN, 8, 5 });

            Assert.IsTrue(testOperator);


            // test testOperator GREATER_THAN Test contextValue GREATER_THAN targetingValue


            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN, "9dlk", "8" });

            Assert.IsTrue(testOperator);

            // test testOperator LOWER_THAN Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN, 5, 6 });

            Assert.IsTrue(testOperator);

            // test testOperator LOWER_THAN Test contextValue not GREATER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN, 5, 5 });

            Assert.IsFalse(testOperator);

            // test testOperator LOWER_THAN Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN, "a", "b" });

            Assert.IsTrue(testOperator);

            // test testOperator LOWER_THAN Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN, "abz", "bcg" });

            Assert.IsTrue(testOperator);

            // test testOperator LOWER_THAN Test contextValue not LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN, 8, 2 });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN_OR_EQUALS Test contextValue GREATER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN_OR_EQUALS, 8, 2 });

            Assert.IsTrue(testOperator);

            // test testOperator GREATER_THAN_OR_EQUALS Test contextValue EQUALS targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN_OR_EQUALS, 8, 8 });

            Assert.IsTrue(testOperator);

            // test testOperator GREATER_THAN_OR_EQUALS Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN_OR_EQUALS, 7, 8 });

            Assert.IsFalse(testOperator);

            // test testOperator GREATER_THAN_OR_EQUALS Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.GREATER_THAN_OR_EQUALS, "a", "b" });

            Assert.IsFalse(testOperator);

            // test testOperator LOWER_THAN_OR_EQUALS Test contextValue GREATER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN_OR_EQUALS, 8, 6 });

            Assert.IsFalse(testOperator);

            // test testOperator LOWER_THAN_OR_EQUALS Test contextValue EQUALS targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN_OR_EQUALS, 8, 8 });

            Assert.IsTrue(testOperator);

            // test testOperator LOWER_THAN_OR_EQUALS Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN_OR_EQUALS, 7, 8 });

            Assert.IsTrue(testOperator);

            // test testOperator LOWER_THAN_OR_EQUALS Test contextValue LOWER_THAN targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.LOWER_THAN_OR_EQUALS, "a", "b" });

            Assert.IsTrue(testOperator);

            //test testOperator STARTS_WITH Test contextValue STARTS_WITH targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.STARTS_WITH, "abcd", "ab" });

            Assert.IsTrue(testOperator);

            // test testOperator STARTS_WITH Test contextValue STARTS_WITH targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.STARTS_WITH, "abcd", "AB" });

            Assert.IsFalse(testOperator);

            // test testOperator STARTS_WITH Test contextValue STARTS_WITH targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.STARTS_WITH, "abcd", "ac" });

            Assert.IsFalse(testOperator);

            // test testOperator ENDS_WITH Test contextValue ENDS_WITH targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.ENDS_WITH, "abcd", "cd" });

            Assert.IsTrue(testOperator);

            // test testOperator ENDS_WITH Test contextValue ENDS_WITH targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.ENDS_WITH, "abcd", "CD" });

            Assert.IsFalse(testOperator);

            // test testOperator ENDS_WITH Test contextValue ENDS_WITH targetingValue

            testOperator = (bool)decisionManagerPrivate.Invoke("TestOperator", new object[] { TargetingOperator.ENDS_WITH, "abcd", "bd" });

            Assert.IsFalse(testOperator);

            httpClient.Dispose();
        }