예제 #1
0
        public async Task UserExposedTest()
        {
            const string functionName    = "UserExposed";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);

            var key = "key1";
            await defaultStrategy.UserExposed(key, "defaultValue", null).ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.GET_FLAG_ERROR, key), functionName), Times.Once());

            var flagDto = CampaignsData.GetFlag()[0];
            await defaultStrategy.UserExposed(flagDto.Key, 1, flagDto).ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.USER_EXPOSED_CAST_ERROR, flagDto.Key), functionName), Times.Once());

            await defaultStrategy.UserExposed(flagDto.Key, "defaultValueString", flagDto).ConfigureAwait(false);

            trackingManagerMock.Verify(x => x.SendActive(visitorDelegate, flagDto), Times.Once());

            var flagDtoValueNull = CampaignsData.GetFlag()[1];

            await defaultStrategy.UserExposed(flagDtoValueNull.Key, "defaultValueString", flagDtoValueNull).ConfigureAwait(false);

            trackingManagerMock.Verify(x => x.SendActive(visitorDelegate, flagDtoValueNull), Times.Once());

            var error = new Exception("userExposed error");

            trackingManagerMock.Setup(x => x.SendActive(visitorDelegate, flagDto)).Throws(error);
            await defaultStrategy.UserExposed(flagDto.Key, "defaultValueString", flagDto).ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(error.Message, functionName), Times.Once());
        }
예제 #2
0
        public void PredefinedContextTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            var newContext = new Dictionary <string, object>()
            {
                ["key1"] = "value1",
                [PredefinedContext.LOCATION_CITY]    = "London",
                [PredefinedContext.OS_VERSION_CODE]  = 1,
                [PredefinedContext.APP_VERSION_CODE] = "1",
                [PredefinedContext.DEVICE_LOCALE]    = Array.Empty <string>(),
                [PredefinedContext.DEVICE_MODEL]     = null,
                [PredefinedContext.FLAGSHIP_CLIENT]  = "custom client"
            };

            defaultStrategy.UpdateContext(newContext);

            Assert.AreEqual(visitorDelegate.Context.Count, 6);
            Assert.AreEqual(visitorDelegate.Context[PredefinedContext.LOCATION_CITY], "London");

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.PREDEFINED_CONTEXT_TYPE_ERROR,
                                                               PredefinedContext.APP_VERSION_CODE, "number"), "UpdateContext"), Times.Once());

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.PREDEFINED_CONTEXT_TYPE_ERROR,
                                                               PredefinedContext.DEVICE_LOCALE, "string"), "UpdateContext"), Times.Once());

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.PREDEFINED_CONTEXT_TYPE_ERROR,
                                                               PredefinedContext.DEVICE_MODEL, "string"), "UpdateContext"), Times.Once());
        }
예제 #3
0
        public async Task SendHitWithHitNullTest()
        {
            const string functionName    = "SendHit";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);
            await defaultStrategy.SendHit(hit : null).ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(Constants.HIT_NOT_NULL, functionName), Times.Once());
        }
예제 #4
0
        public async Task SendHitTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);
            var hit             = new Flagship.Hit.Screen("HomeView");
            await defaultStrategy.SendHit(hit).ConfigureAwait(false);

            trackingManagerMock.Verify(x => x.SendHit(hit), Times.Once());
        }
예제 #5
0
        public async Task SendHitNotReadyTest()
        {
            const string functionName    = "SendHit";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);
            var          hit             = new Flagship.Hit.Screen(null);
            await defaultStrategy.SendHit(hit).ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(hit.GetErrorMessage(), functionName), Times.Once());
        }
예제 #6
0
        public void UpdateContexTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            var newContext = new Dictionary <string, object>()
            {
                ["key1"] = "value1",
                ["key2"] = "value2"
            };

            defaultStrategy.UpdateContext(newContext);

            Assert.AreEqual(visitorDelegate.Context.Count, 5);

            var newContext2 = new Dictionary <string, object>()
            {
                ["key3"] = 5,
                ["key4"] = 1
            };

            defaultStrategy.UpdateContext(newContext2);

            Assert.AreEqual(visitorDelegate.Context.Count, 7);

            var newContext3 = new Dictionary <string, object>()
            {
                ["key5"] = true,
                ["key6"] = false
            };

            defaultStrategy.UpdateContext(newContext3);

            Assert.AreEqual(visitorDelegate.Context.Count, 9);

            defaultStrategy.UpdateContext("key1", "value3");
            Assert.AreEqual(visitorDelegate.Context["key1"], "value3");

            defaultStrategy.UpdateContext("key3", 10);
            Assert.AreEqual(10d, visitorDelegate.Context["key3"]);

            defaultStrategy.UpdateContext("key5", false);
            Assert.AreEqual(visitorDelegate.Context["key5"], false);

            var newContext4 = new Dictionary <string, object>()
            {
                ["key6"] = new object(),
            };

            defaultStrategy.UpdateContext(newContext4);
            Assert.AreEqual(visitorDelegate.Context.Count, 9);
            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.CONTEXT_PARAM_ERROR, "key6"), "UpdateContex"), Times.Once());

            //Test clearContext

            defaultStrategy.ClearContext();
            Assert.AreEqual(visitorDelegate.Context.Count, 0);
        }
예제 #7
0
        public async Task SendHitsTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);
            var screen          = new Flagship.Hit.Screen("HomeView");
            var page            = new Flagship.Hit.Page("HomePage");
            await defaultStrategy.SendHit(new List <Hit.HitAbstract>() { screen, page }).ConfigureAwait(false);

            trackingManagerMock.Verify(x => x.SendHit(screen), Times.Once());
            trackingManagerMock.Verify(x => x.SendHit(page), Times.Once());
        }
예제 #8
0
        public void GetFlagValue()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);
            var flagDto         = CampaignsData.GetFlag()[0];

            var value = defaultStrategy.GetFlagValue(flagDto.Key, "Default", flagDto);

            Assert.AreEqual(flagDto.Value, value);
            trackingManagerMock.Verify(x => x.SendActive(visitorDelegate, flagDto), Times.Once());
        }
예제 #9
0
        public void GetFlagMetadataTest()
        {
            const string functionName    = "flag.metadata";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);

            var metadata         = new FsFlag.FlagMetadata("CampaignId", "variationGroupId", "variationId", false, "");
            var resultatMetadata = defaultStrategy.GetFlagMetadata(metadata, "key", true);

            Assert.AreEqual(JsonConvert.SerializeObject(metadata), JsonConvert.SerializeObject(resultatMetadata));
            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.GET_METADATA_CAST_ERROR, "key"), functionName), Times.Never());
        }
예제 #10
0
        public void GetFlagValueWithFlagNullTest()
        {
            const string functionName       = "getFlag.value";
            var          defaultStrategy    = new DefaultStrategy(visitorDelegate);
            var          defaultValueString = "defaultValueString";
            var          key   = "key 1";
            var          value = defaultStrategy.GetFlagValue(key, defaultValueString, null);

            Assert.AreEqual(defaultValueString, value);
            fsLogManagerMock.Verify(x => x.Info(string.Format(Constants.GET_FLAG_MISSING_ERROR, key), functionName), Times.Once());
        }
예제 #11
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);
        }
예제 #12
0
        public void GetFlagValueTypeDifferent()
        {
            const string functionName    = "getFlag.value";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);
            var          flagDto         = CampaignsData.GetFlag()[0];

            var value3 = defaultStrategy.GetFlagValue(flagDto.Key, 1, flagDto);

            Assert.AreEqual(1, value3);

            fsLogManagerMock.Verify(x => x.Info(string.Format(Constants.GET_FLAG_CAST_ERROR, flagDto.Key), functionName), Times.Once());
            trackingManagerMock.Verify(x => x.SendActive(visitorDelegate, flagDto), Times.Never());
        }
예제 #13
0
        public void TestASMNotNull()
        {
            //arrange
            double i = 3;
            double j = 3;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.ASM(i, j);

            //assert
            Assert.IsNotNull(actual);
        }
예제 #14
0
        public void TestCONNotNUll()
        {
            //arrange
            double i = 1;
            double j = 7;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.CON(i, j);

            //assert
            Assert.IsNotNull(actual);
        }
예제 #15
0
        public async Task SendConsentHitAsyncTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            await defaultStrategy.SendConsentHitAsync(true).ConfigureAwait(false);

            trackingManagerMock.Verify(x => x.SendHit(It.Is <Hit.Event>(
                                                          item => item.Label == $"{Constants.SDK_LANGUAGE}:{true}" &&
                                                          item.VisitorId == visitorDelegate.VisitorId &&
                                                          item.DS == Constants.SDK_APP &&
                                                          item.AnonymousId == visitorDelegate.AnonymousId
                                                          )), Times.Once());
        }
예제 #16
0
        public async Task SendConsentHitAsyncFailedTest()
        {
            const string functionName    = "SendConsentHit";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);

            const string errorMessage = "error sendHit";

            trackingManagerMock.Setup(x => x.SendHit(It.IsAny <Hit.Event>())).Throws(new Exception(errorMessage));

            await defaultStrategy.SendConsentHitAsync(true).ConfigureAwait(false);

            fsLogManagerMock.Verify(x => x.Error(errorMessage, functionName), Times.Once());
        }
예제 #17
0
        public void TestENTGeneral()
        {
            //arrange
            double i        = 0.11;
            double j        = 0.7;
            int    expected = 0;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.ENT(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #18
0
        public void TestP()
        {
            //arrange
            double i        = 5;
            double j        = 4.46;
            int    expected = 20;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.p(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #19
0
        public void TestENTiLessj()
        {
            //arrange
            double i        = 2;
            double j        = 8;
            int    expected = 32;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.ENT(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #20
0
        public void TestENTjequali()
        {
            //arrange
            double i        = 3;
            double j        = 3;
            int    expected = 18;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.ENT(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #21
0
        public void CacheHitActivateTest()
        {
            var hitCache  = new Mock <IHitCacheImplementation>();
            var visitorId = visitorDelegate.VisitorId;

            visitorDelegate.Config.HitCacheImplementation = hitCache.Object;

            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            var flag = new FlagDTO
            {
                CampaignId       = "campaignId",
                CampaignType     = "ab",
                IsReference      = true,
                Key              = "key",
                Value            = "value",
                VariationGroupId = "varGrID",
                VariationId      = "varID"
            };

            var hitData = new HitCacheDTOV1
            {
                Version = 1,
                Data    = new HitCacheData
                {
                    VisitorId   = visitorDelegate.VisitorId,
                    AnonymousId = visitorDelegate.AnonymousId,
                    Type        = HitCacheType.ACTIVATE,
                    Content     = flag,
                    Time        = DateTime.Now
                }
            };

            var hitDataJson = JObject.FromObject(hitData);

            defaultStrategy.CacheHit(flag);

            hitCache.Verify(x => x.CacheHit(visitorId, It.Is <JObject>(y =>
                                                                       y["Data"]["Type"].Value <int>() == ((int)HitCacheType.ACTIVATE) &&
                                                                       y["Data"]["Content"].Value <JObject>().ToString() == JObject.FromObject(flag).ToString()
                                                                       )), Times.Once());

            var error = new Exception("CacheHit error");

            hitCache.Setup(x => x.CacheHit(visitorId, It.IsAny <JObject>())).Throws(error);

            defaultStrategy.CacheHit(flag);

            fsLogManagerMock.Verify(x => x.Error(error.Message, "CacheHit"), Times.Once());
        }
예제 #22
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);
        }
예제 #23
0
        public void TestCONjLESSi()
        {
            //arrange
            double i        = 11;
            double j        = 7;
            int    expected = 1232;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.CON(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #24
0
        public void TestpEquals()
        {
            //arrange
            double i        = 8.56;
            double j        = 8.56;
            int    expected = 64;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.p(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #25
0
        public void TestASMjlLessi()
        {
            //arrange
            double i        = 4;
            double j        = 3;
            int    expected = 144;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.ASM(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #26
0
        public void TestCORNotNuLL()
        {
            //arrange
            double i = 3;
            double j = 5;


            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.COR(i, j);

            //assert
            Assert.IsNotNull(actual);
        }
예제 #27
0
        public void TestCORPow()
        {
            //arrange
            double i        = 3;
            double j        = 5;
            int    expected = 15;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.COR(i, j);

            //assert
            Assert.AreEqual(Math.Pow(expected, 2), actual);
        }
예제 #28
0
        public void TestCOR0()
        {
            //arrange
            double i        = 1;
            double j        = 0;
            int    expected = 0;

            //act
            DefaultStrategy def    = new DefaultStrategy();
            int             actual = def.COR(i, j);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #29
0
        public async Task SendHitFailedTest()
        {
            const string functionName    = "SendHit";
            var          errorMessage    = "error hit";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);
            var          hit             = new Flagship.Hit.Screen("HomeView");

            trackingManagerMock.Setup(x => x.SendHit(hit)).Throws(new Exception(errorMessage));

            await defaultStrategy.SendHit(hit).ConfigureAwait(false);

            trackingManagerMock.Verify(x => x.SendHit(hit), Times.Once());

            fsLogManagerMock.Verify(x => x.Error(errorMessage, functionName), Times.Once());
        }
예제 #30
0
        public void GetFlagValueWithValueNullTest()
        {
            const string functionName    = "getFlag.value";
            var          defaultStrategy = new DefaultStrategy(visitorDelegate);

            var defaultValueString = "defaultValueString";
            var flagDtoValueNull   = CampaignsData.GetFlag()[1];

            var value2 = defaultStrategy.GetFlagValue(flagDtoValueNull.Key, defaultValueString, flagDtoValueNull);

            Assert.AreEqual(defaultValueString, value2);

            fsLogManagerMock.Verify(x => x.Info(string.Format(Constants.GET_FLAG_CAST_ERROR, flagDtoValueNull.Key), functionName), Times.Once());
            trackingManagerMock.Verify(x => x.SendActive(visitorDelegate, flagDtoValueNull), Times.Once());
        }