예제 #1
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());
        }
예제 #2
0
        public void CacheHitTest()
        {
            var hitCache  = new Mock <IHitCacheImplementation>();
            var visitorId = visitorDelegate.VisitorId;

            visitorDelegate.Config.HitCacheImplementation = hitCache.Object;

            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            var hit = new Screen("Home");

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

            var hitDataJson = JObject.FromObject(hitData);

            defaultStrategy.CacheHit(hit);

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

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

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

            defaultStrategy.CacheHit(hit);

            fsLogManagerMock.Verify(x => x.Error(error.Message, "CacheHit"), Times.Once());
        }