コード例 #1
0
        async public Task FetchFlagsTest()
        {
            decisionManagerMock.Setup(x => x.GetCampaigns(visitorDelegate))
            .Returns(Task.FromResult(CampaignsData.DecisionResponse().Campaigns));

            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.FetchFlags().ConfigureAwait(false);

            Assert.AreEqual(visitorDelegate.Flags.Count, 6);
        }
コード例 #2
0
        async public Task FetchFlagsFailedTest()
        {
            var errorMessage = "error";

            decisionManagerMock.Setup(x => x.GetCampaigns(visitorDelegate))
            .Throws(new Exception(errorMessage));

            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.FetchFlags().ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(errorMessage, "FetchFlags"), Times.Once());
            Assert.AreEqual(visitorDelegate.Flags.Count, 0);
        }
コード例 #3
0
        async public Task FetchFlagsWithCacheV2Test()
        {
            ICollection <Campaign> campaigns = new Collection <Flagship.Model.Campaign>();

            decisionManagerMock.Setup(x => x.GetCampaigns(visitorDelegate))
            .Returns(Task.FromResult(campaigns));

            visitorDelegate.VisitorCache = new Model.VisitorCache
            {
                Version = 2,
                Data    = new VisitorCacheDTOV1()
                {
                    Version = 2,
                    Data    = new VisitorCacheData
                    {
                    }
                }
            };
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.FetchFlags().ConfigureAwait(false);

            Assert.AreEqual(visitorDelegate.Flags.Count, 0);

            visitorDelegate.VisitorCache = new Model.VisitorCache
            {
                Version = 1,
                Data    = new VisitorCacheDTOV1()
                {
                    Version = 1
                }
            };
            defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.FetchFlags().ConfigureAwait(false);

            Assert.AreEqual(visitorDelegate.Flags.Count, 0);

            visitorDelegate.VisitorCache = null;

            defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.FetchFlags().ConfigureAwait(false);

            Assert.AreEqual(visitorDelegate.Flags.Count, 0);
        }
コード例 #4
0
        async public Task FetchFlagsWithCacheTest()
        {
            ICollection <Campaign> campaigns = new Collection <Flagship.Model.Campaign>();

            decisionManagerMock.Setup(x => x.GetCampaigns(visitorDelegate))
            .Returns(Task.FromResult(campaigns));

            visitorDelegate.VisitorCache = new Model.VisitorCache
            {
                Version = 1,
                Data    = new VisitorCacheDTOV1()
                {
                    Version = 1,
                    Data    = new VisitorCacheData
                    {
                        VisitorId = "visitorID",
                        Consent   = true,
                        Campaigns = new List <VisitorCacheCampaign>
                        {
                            new VisitorCacheCampaign
                            {
                                Activated        = true,
                                CampaignId       = "campaignID",
                                IsReference      = true,
                                Type             = ModificationType.FLAG,
                                VariationGroupId = "variationGbId",
                                VariationId      = "variationID",
                                Flags            = new Dictionary <string, object>
                                {
                                    ["key"] = "value"
                                }
                            }
                        }
                    }
                }
            };
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.FetchFlags().ConfigureAwait(false);

            Assert.AreEqual(1, visitorDelegate.Flags.Count);
        }