コード例 #1
0
        public void FlagNullTest()
        {
            var config = new DecisionApiConfig()
            {
                EnvId = "envID"
            };
            var trackingManagerMock = new Mock <Api.ITrackingManager>();
            var decisionManagerMock = new Mock <Decision.IDecisionManager>();
            var configManager       = new ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

            var context     = new Dictionary <string, object>();
            var visitorMock = new Mock <FsVisitor.VisitorDelegateAbstract>(new object[] { "visitorId", false, context, false, configManager });

            visitorMock.Setup(x => x.GetStrategy()).CallBase();

            var defaultValue = "defaultString";
            var flag         = new Flag <string>("key", visitorMock.Object, defaultValue);

            var metadata = new FlagMetadata("", "", "", false, "");

            var resultMeta = flag.Metadata;

            Assert.IsFalse(flag.Exists);
            Assert.AreEqual(JsonConvert.SerializeObject(metadata), JsonConvert.SerializeObject(resultMeta));

            visitorMock.Verify(x => x.GetFlagMetadata(It.IsAny <IFlagMetadata>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Never());
        }
コード例 #2
0
        public override IFlagMetadata GetFlagMetadata(IFlagMetadata metadata, string key, bool hasSameType)
        {
            const string functionName = "flag.metadata";

            if (!hasSameType && !string.IsNullOrWhiteSpace(metadata.CampaignId))
            {
                Log.LogError(Config, string.Format(Constants.GET_METADATA_CAST_ERROR, key), functionName);
                return(FlagMetadata.EmptyMetadata());
            }
            return(metadata);
        }
コード例 #3
0
        async public Task FlagTest()
        {
            var flagDTO = GetFlag();
            var config  = new DecisionApiConfig()
            {
                EnvId = "envID"
            };

            var metadata = new FlagMetadata(flagDTO.CampaignId, flagDTO.VariationGroupId, flagDTO.VariationId, flagDTO.IsReference, "");

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

            var context     = new Dictionary <string, object>();
            var visitorMock = new Mock <FsVisitor.VisitorDelegateAbstract>(new object[] { "visitorId", false, context, false, configManager });

            visitorMock.Setup(x => x.GetStrategy()).CallBase();

            var flags = new List <Flagship.Model.FlagDTO>
            {
                flagDTO
            };

            visitorMock.SetupGet(x => x.Flags).Returns(flags);

            var defaultValue = "defaultString";
            var flag         = new Flag <string>(flagDTO.Key, visitorMock.Object, defaultValue);

            visitorMock.Setup(x => x.GetFlagValue(flagDTO.Key, defaultValue, flagDTO, true)).Returns((string)flagDTO.Value);
            visitorMock.Setup(x => x.UserExposed(flagDTO.Key, defaultValue, flagDTO)).Returns(Task.CompletedTask);
            visitorMock.Setup(x => x.GetFlagMetadata(It.IsAny <IFlagMetadata>(), flagDTO.Key, true)).Returns(metadata);

            var value = flag.GetValue();

            await flag.UserExposed().ConfigureAwait(false);

            var resultMeta = flag.Metadata;

            Assert.AreEqual(flagDTO.Value, value);
            Assert.IsTrue(flag.Exists);
            Assert.AreEqual(metadata, resultMeta);

            visitorMock.Verify(x => x.UserExposed <object>(flagDTO.Key, defaultValue, flagDTO), Times.Once());
            visitorMock.Verify(x => x.GetFlagValue(flagDTO.Key, defaultValue, flagDTO, true), Times.Once());
            visitorMock.Verify(x => x.GetFlagMetadata(It.Is <IFlagMetadata>(item =>
                                                                            item.CampaignId == metadata.CampaignId &&
                                                                            item.IsReference == metadata.IsReference &&
                                                                            item.VariationGroupId == metadata.VariationGroupId &&
                                                                            item.VariationId == metadata.VariationId &&
                                                                            item.CampaignType == metadata.CampaignType

                                                                            ), flagDTO.Key, true), Times.Once());
        }
コード例 #4
0
        public void ToJson()
        {
            var metadata = new FlagMetadata("CampaignId", "VariationGroupId", "VariationId", true, "");

            var metadataJson = new Dictionary <string, object>()
            {
                ["campaignId"]       = "CampaignId",
                ["variationGroupId"] = "VariationGroupId",
                ["variationId"]      = "VariationId",
                ["isReference"]      = true,
                ["campaignType"]     = ""
            };

            Assert.AreEqual(metadata.ToJson(), JsonConvert.SerializeObject(metadataJson));
        }
コード例 #5
0
 public override IFlagMetadata GetFlagMetadata(IFlagMetadata metadata, string key, bool hasSameType)
 {
     Log("flag.metadata");
     return(FlagMetadata.EmptyMetadata());
 }
コード例 #6
0
 public void EmptyMetadata()
 {
     Assert.AreEqual(JsonConvert.SerializeObject(FlagMetadata.EmptyMetadata()),
                     JsonConvert.SerializeObject(new FlagMetadata("", "", "", false, "")));
 }