예제 #1
0
        public void Setup()
        {
            Logger       = new DefaultLogger();
            ErrorHandler = new DefaultErrorHandler();

            Config = ProjectConfig.Create(TestData.Datafile, Logger, ErrorHandler);
        }
예제 #2
0
        public void TestGetAttributeIdWithReservedPrefix()
        {
            // Verify that attribute key is returned for reserved attribute key.
            Assert.AreEqual(Config.GetAttributeId(ControlAttributes.USER_AGENT_ATTRIBUTE), ControlAttributes.USER_AGENT_ATTRIBUTE);

            // Verify that attribute Id is returned for attribute key with reserved prefix that does not exist in datafile.
            Assert.AreEqual(Config.GetAttributeId("$opt_reserved_prefix_attribute"), "$opt_reserved_prefix_attribute");

            // Create config file copy with additional resered prefix attribute.
            string  reservedPrefixAttrKey = "$opt_user_defined_attribute";
            JObject projConfig            = JObject.Parse(TestData.Datafile);
            var     attributes            = (JArray)projConfig["attributes"];

            var reservedAttr = new Entity.Attribute {
                Id = "7723348204", Key = reservedPrefixAttrKey
            };

            attributes.Add((JObject)JToken.FromObject(reservedAttr));

            // Verify that attribute Id is returned and warning is logged for attribute key with reserved prefix that exists in datafile.
            var reservedAttrConfig = ProjectConfig.Create(JsonConvert.SerializeObject(projConfig), LoggerMock.Object, ErrorHandlerMock.Object);

            Assert.AreEqual(reservedAttrConfig.GetAttributeId(reservedPrefixAttrKey), reservedAttrConfig.GetAttribute(reservedPrefixAttrKey).Id);
            LoggerMock.Verify(l => l.Log(LogLevel.WARN, $@"Attribute {reservedPrefixAttrKey} unexpectedly has reserved prefix {ProjectConfig.RESERVED_ATTRIBUTE_PREFIX}; using attribute ID instead of reserved attribute name."));
        }
예제 #3
0
        public void TestIsFeatureExperimentReturnsFalseForExperimentThatDoesNotBelongToAnyFeature()
        {
            var typedConfig = ProjectConfig.Create(TestData.TypedAudienceDatafile, null, null);
            var experiment  = typedConfig.GetExperimentFromKey("typed_audience_experiment");

            Assert.False(typedConfig.IsFeatureExperiment(experiment.Id));
        }
예제 #4
0
        public void TestIsFeatureExperimentReturnsTrueForExperimentThatBelongsToAFeature()
        {
            var typedConfig = ProjectConfig.Create(TestData.TypedAudienceDatafile, null, null);
            var experiment  = typedConfig.GetExperimentFromKey("feat2_with_var_test");

            Assert.True(typedConfig.IsFeatureExperiment(experiment.Id));
        }
예제 #5
0
 private void InitializeProjectConf()
 {
     this._projectConf = ProjectConfig.
                         Create(
         Convert.ToInt32(AppSetting["ProjectID"]),
         this.DataContext.ConfigurationEntities);
 }
예제 #6
0
 public void Setup()
 {
     Config     = ProjectConfig.Create(TestData.TypedAudienceDatafile, null, null);
     LoggerMock = new Mock <ILogger>();
     LoggerMock.Setup(l => l.Log(It.IsAny <LogLevel>(), It.IsAny <string>()));
     Logger = LoggerMock.Object;
 }
예제 #7
0
        public void TempProjectConfigTest()
        {
            ProjectConfig config = ProjectConfig.Create(TestData.Datafile, new Mock <ILogger>().Object, new DefaultErrorHandler());

            Assert.IsNotNull(config);
            Assert.AreEqual("1592310167", config.AccountId);
        }
예제 #8
0
        public void Setup()
        {
            TestUserId = "testUserId";
            var logger = new NoOpLogger();

            Config       = ProjectConfig.Create(TestData.Datafile, logger, new ErrorHandler.NoOpErrorHandler());
            EventBuilder = new EventBuilder(new Bucketer(logger));
        }
예제 #9
0
        public void Setup()
        {
            LoggerMock       = new Mock <ILogger>();
            ErrorHandlerMock = new Mock <IErrorHandler>();
            ErrorHandlerMock.Setup(e => e.HandleError(It.IsAny <Exception>()));

            Config = ProjectConfig.Create(TestData.Datafile, LoggerMock.Object, ErrorHandlerMock.Object);
        }
예제 #10
0
        public void TestExperimentAudiencesRetrivedFromTypedAudiencesFirstThenFromAudiences()
        {
            var typedConfig = ProjectConfig.Create(TestData.TypedAudienceDatafile, null, null);
            var experiment  = typedConfig.GetExperimentFromKey("feat_with_var_test");

            var expectedAudienceIds = new string[] { "3468206642", "3988293898", "3988293899", "3468206646", "3468206647", "3468206644", "3468206643" };

            Assert.That(expectedAudienceIds, Is.EquivalentTo(experiment.AudienceIds));
        }
예제 #11
0
    public static void Clone(string[] options, string[] args)
    {
        if (!Verification.ProfileIsValid())
        {
            return;
        }

        if (args.Length == 0)
        {
            Msg.InfoCount();
            return;
        }

        if (args.Length > 1)
        {
            ErrorMsg.TooManyArgs();
            return;
        }

        if (options.Length > 0)
        {
            ErrorMsg.TooManyOptions();
            return;
        }

        string url           = args[0];
        string name          = Path.GetFileNameWithoutExtension(url);
        string workspacePath = Program.settings.Read("workspace");

        if (url.EndsWith(".git", StringComparison.OrdinalIgnoreCase))
        {
            url = url.Replace(".git", @"/archive/master.zip");
        }

        string    outPath   = workspacePath + "/~webpac.zip";
        WebClient webClient = new WebClient();

        try
        {
            webClient.DownloadFile(url, outPath);

            ZipFile.ExtractToDirectory(outPath, workspacePath, true);
            Directory.Move(workspacePath + "/" + name + "-master", workspacePath + "/" + name);
            ProjectConfig.Create(workspacePath + "/" + name + "/.ftm");
        }
        catch
        {
            Print.ErrorMessage("Could not clone project.");
            return;
        }

        try
        {
            File.Delete(outPath);
        }
        catch { }
    }
예제 #12
0
        public void TestSendNotifications()
        {
            var config         = ProjectConfig.Create(TestData.Datafile, LoggerMock.Object, new NoOpErrorHandler());
            var logEventMocker = new Mock <LogEvent>("http://mockedurl", new Dictionary <string, object>(), "POST", new Dictionary <string, string>());
            // Mocking notification callbacks.
            var notificationCallbackMock = new Mock <TestNotificationCallbacks>();

            notificationCallbackMock.Setup(nc => nc.TestActivateCallback(It.IsAny <Experiment>(), It.IsAny <string>(),
                                                                         It.IsAny <UserAttributes>(), It.IsAny <Variation>(), It.IsAny <LogEvent>()));

            notificationCallbackMock.Setup(nc => nc.TestAnotherActivateCallback(It.IsAny <Experiment>(),
                                                                                It.IsAny <string>(), It.IsAny <UserAttributes>(), It.IsAny <Variation>(), It.IsAny <LogEvent>()));


            // Adding decision notifications.
            NotificationCenter.AddNotification(NotificationTypeActivate, notificationCallbackMock.Object.TestActivateCallback);
            NotificationCenter.AddNotification(NotificationTypeActivate, notificationCallbackMock.Object.TestAnotherActivateCallback);


            // Adding track notifications.
            NotificationCenter.AddNotification(NotificationTypeTrack, notificationCallbackMock.Object.TestTrackCallback);

            // Fire decision type notifications.
            NotificationCenter.SendNotifications(NotificationTypeActivate, config.GetExperimentFromKey("test_experiment"),
                                                 "testUser", new UserAttributes(), config.GetVariationFromId("test_experiment", "7722370027"), logEventMocker.Object);

            // Verify that only the registered notifications of decision type are called.
            notificationCallbackMock.Verify(nc => nc.TestActivateCallback(It.IsAny <Experiment>(), It.IsAny <string>(),
                                                                          It.IsAny <UserAttributes>(), It.IsAny <Variation>(), It.IsAny <LogEvent>()), Times.Once);

            notificationCallbackMock.Verify(nc => nc.TestAnotherActivateCallback(It.IsAny <Experiment>(), It.IsAny <string>(),
                                                                                 It.IsAny <UserAttributes>(), It.IsAny <Variation>(), It.IsAny <LogEvent>()), Times.Once);

            notificationCallbackMock.Verify(nc => nc.TestTrackCallback(It.IsAny <string>(), It.IsAny <string>(),
                                                                       It.IsAny <UserAttributes>(), It.IsAny <EventTags>(), It.IsAny <LogEvent>()), Times.Never);



            // Verify that after clearing notifications, SendNotification should not call any notification
            // which were previously registered.
            NotificationCenter.ClearAllNotifications();
            notificationCallbackMock.ResetCalls();

            NotificationCenter.SendNotifications(NotificationTypeActivate, config.GetExperimentFromKey("test_experiment"),
                                                 "testUser", new UserAttributes(), config.GetVariationFromId("test_experiment", "7722370027"), null);


            // Again verify notifications which were registered are not called.
            notificationCallbackMock.Verify(nc => nc.TestActivateCallback(It.IsAny <Experiment>(), It.IsAny <string>(),
                                                                          It.IsAny <UserAttributes>(), It.IsAny <Variation>(), It.IsAny <LogEvent>()), Times.Never);

            notificationCallbackMock.Verify(nc => nc.TestAnotherActivateCallback(It.IsAny <Experiment>(), It.IsAny <string>(),
                                                                                 It.IsAny <UserAttributes>(), It.IsAny <Variation>(), It.IsAny <LogEvent>()), Times.Never);

            notificationCallbackMock.Verify(nc => nc.TestTrackCallback(It.IsAny <string>(), It.IsAny <string>(),
                                                                       It.IsAny <UserAttributes>(), It.IsAny <EventTags>(), It.IsAny <LogEvent>()), Times.Never);
        }
예제 #13
0
        public void SetUp()
        {
            LoggerMock             = new Mock <ILogger>();
            ErrorHandlerMock       = new Mock <IErrorHandler>();
            UserProfileServiceMock = new Mock <UserProfileService>();
            BucketerMock           = new Mock <Bucketer>(LoggerMock.Object);

            ValidProjectConfig      = ProjectConfig.Create(TestData.ValidDataFileV3, LoggerMock.Object, ErrorHandlerMock.Object);
            NoAudienceProjectConfig = ProjectConfig.Create(TestData.NoAudienceProjectConfigV3, LoggerMock.Object, ErrorHandlerMock.Object);
            WhitelistedExperiment   = ValidProjectConfig.ExperimentIdMap["223"];
            WhitelistedVariation    = WhitelistedExperiment.VariationKeyToVariationMap["vtag1"];
            ProjectConfig           = ProjectConfig.Create(TestData.Datafile, LoggerMock.Object, ErrorHandlerMock.Object);
            DecisionService         = new DecisionService(new Bucketer(LoggerMock.Object), ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object);

            DecisionServiceMock = new Mock <DecisionService>(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object)
            {
                CallBase = true
            };

            VariationWithKeyControl   = ProjectConfig.GetVariationFromKey("test_experiment", "control");
            VariationWithKeyVariation = ProjectConfig.GetVariationFromKey("test_experiment", "variation");
        }
예제 #14
0
        public void TestBotFilteringValues()
        {
            // Verify that bot filtering value is true as defined in Config data.
            Assert.True(Config.BotFiltering.GetValueOrDefault());

            // Remove botFilering node and verify returned value in null.
            JObject projConfig = JObject.Parse(TestData.Datafile);

            if (projConfig.TryGetValue("botFiltering", out JToken token))
            {
                projConfig.Property("botFiltering").Remove();
                var configWithoutBotFilter = ProjectConfig.Create(JsonConvert.SerializeObject(projConfig),
                                                                  LoggerMock.Object, ErrorHandlerMock.Object);

                // Verify that bot filtering is null when not defined in datafile.
                Assert.Null(configWithoutBotFilter.BotFiltering);
            }
        }
예제 #15
0
파일: Init.cs 프로젝트: TomLievense/FTM
    public static void Init(string[] options, string[] args)
    {
        if (!Verification.ProfileIsValid())
        {
            return;
        }

        if (args.Length == 0)
        {
            Msg.InfoInit();
            return;
        }

        if (args.Length > 1)
        {
            ErrorMsg.TooManyArgs();
            return;
        }

        if (options.Length > 0)
        {
            ErrorMsg.NoOptions();
            return;
        }

        string workspacePath = Program.settings.Read("workspace");
        string dirPath       = workspacePath + "/" + args[0];

        if (!Directory.Exists(dirPath))
        {
            ErrorMsg.ProjectIncorrect();
            return;
        }

        string filePath = dirPath + "/.ftm";

        if (File.Exists(filePath))
        {
            Print.ErrorMessage("Project already initialized");
            return;
        }

        ProjectConfig.Create(filePath);
    }
예제 #16
0
 public void Initialize()
 {
     LoggerMock = new Mock <ILogger>();
     Config     = ProjectConfig.Create(TestData.Datafile, LoggerMock.Object, new ErrorHandler.NoOpErrorHandler());
 }
예제 #17
0
 public void TestCreateDoesNotThrowWithValidDatafile()
 {
     Assert.DoesNotThrow(() => ProjectConfig.Create(TestData.Datafile, null, null));
 }
예제 #18
0
        public void TestCreateThrowsWithUnsupportedDatafileVersion()
        {
            var exception = Assert.Throws <ConfigParseException>(() => ProjectConfig.Create(TestData.UnsupportedVersionDatafile, null, null));

            Assert.AreEqual($"This version of the C# SDK does not support the given datafile version: 5", exception.Message);
        }
예제 #19
0
        public void TestCreateThrowsWithEmptyDatafile()
        {
            var exception = Assert.Throws <ConfigParseException>(() => ProjectConfig.Create("", null, null));

            Assert.AreEqual("Unable to parse empty datafile.", exception.Message);
        }
예제 #20
0
    GetProjectConfig(string projectPath, string remoteProjectPath)
    {
        string keyPath       = projectPath + "/.ftm";
        string remoteKeyPath = remoteProjectPath + "/.ftm/.ftm";

        if (!File.Exists(keyPath))
        {
            ProjectConfig.Create(keyPath);
        }

        string remoteKey = null;

        if (File.Exists(remoteKeyPath))
        {
            string[] remoteConfig = File.ReadAllLines(remoteKeyPath);
            foreach (string line in remoteConfig)
            {
                if (line.StartsWith("Identifier<", StringComparison.Ordinal))
                {
                    remoteKey = line;
                    break;
                }
            }
        }

        string settingsPath = remoteProjectPath + "/.ftm/";

        if (!Directory.Exists(settingsPath))
        {
            Directory.CreateDirectory(settingsPath);
        }

        File.Copy(keyPath, remoteKeyPath, true);

        string[] localConfig = File.ReadAllLines(keyPath);
        bool     isIgnore    = false;

        List <string> ignoreList = new List <string>();

        string key = null;

        foreach (string line in localConfig)
        {
            if (line.StartsWith("Identifier<", StringComparison.Ordinal))
            {
                key = line;
            }

            if (line.StartsWith("Ignore", StringComparison.Ordinal) &&
                line.EndsWith("{", StringComparison.Ordinal))
            {
                isIgnore = true;
                continue;
            }

            if (isIgnore && !line.Contains("}"))
            {
                ignoreList.Add(line.Trim());
            }
        }

        if (remoteKey == null || key == remoteKey)
        {
            return(true, ignoreList.ToArray());
        }

        Print.ErrorMessage("Remote location already contains a different project with the same name.");
        return(false, null);
    }