Пример #1
0
        public void AddRule_AddsRuleToRulesListAndAddedRulesIDs()
        {
            var dataStore = RCTestUtils.GetDataStore();
            var addedRule = RCTestUtils.rulesWithSettingsMetadata[0];
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.UpdateRule(addedRule);

            Assert.That(dataStore.rulesList.Contains(addedRule));
            Assert.That(dataStore.addedRulesIDs.Contains(addedRule.id));
            Assert.That(dataStore.rulesList.Contains(addedRule));
        }
Пример #2
0
        public void GetRuleByID_ReturnsRuleWithGivenID()
        {
            var dataStore = RCTestUtils.GetDataStore();
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.SetRulesDataStore(new List <Rule>(RCTestUtils.rulesList));

            for (int i = 0; i < dataStore.rulesList.Count; i++)
            {
                Assert.That(Equals(dataManager.GetRuleByID(dataStore.rulesList[i].id), dataStore.rulesList[i]));
            }
        }
Пример #3
0
        public void AddSetting_AddsSettingToListAndDict()
        {
            var dataStore = RCTestUtils.GetDataStore();
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.AddSetting(RCTestUtils.rsListWithMetadata[0]);
            Assert.That(dataStore.rsKeyList.Contains(RCTestUtils.rsListWithMetadata[0]));
            var rs = dataStore.rsKeyList.Find(s => s.metadata.entityId == RCTestUtils.rsListWithMetadata[0].metadata.entityId);

            Assert.That(string.Equals(rs.rs.key, RCTestUtils.rsListWithMetadata[0].rs.key));
            Assert.That(string.Equals(rs.rs.type, RCTestUtils.rsListWithMetadata[0].rs.type));
            Assert.That(string.Equals(rs.rs.value, RCTestUtils.rsListWithMetadata[0].rs.value));
        }
Пример #4
0
        public void DeleteRule_ShouldDeleteNewlyAddedRuleFromRulesListWithoutAddingItToDeletedRuleIDs()
        {
            var dataStore   = RCTestUtils.GetDataStore();
            var deletedRule = RCTestUtils.rulesWithSettingsMetadata[0];
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.UpdateRule(deletedRule);
            dataManager.DeleteRule(deletedRule.id);

            Assert.That(!dataStore.rulesList.Contains(deletedRule));
            Assert.That(!dataStore.deletedRulesIDs.Contains(deletedRule.id));
            Assert.That(!dataStore.rulesList.Contains(deletedRule));
        }
Пример #5
0
        public void ClearRuleIDs_ClearsAllLists()
        {
            var dataStore = RCTestUtils.GetDataStore();

            dataStore.updatedRulesIDs = new List <string>(RCTestUtils.updatedRuleIDs);
            dataStore.addedRulesIDs   = new List <string>(RCTestUtils.addedRuleIDs);
            dataStore.deletedRulesIDs = new List <string>(RCTestUtils.deletedRuleIDs);
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.ClearRuleIDs();
            Assert.That(dataStore.updatedRulesIDs.Count == 0);
            Assert.That(dataStore.addedRulesIDs.Count == 0);
            Assert.That(dataStore.deletedRulesIDs.Count == 0);
        }
Пример #6
0
        public void DeleteRule_DeletesRuleFromRulesListAndAddsRuleToDeletedRuleIDs()
        {
            var dataStore = RCTestUtils.GetDataStore();

            dataStore.rulesList = new List <RuleWithSettingsMetadata>(RCTestUtils.rulesWithSettingsMetadata);
            var deletedRule = RCTestUtils.rulesWithSettingsMetadata[0];
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.DeleteRule(deletedRule.id);

            Assert.That(!dataStore.rulesList.Contains(deletedRule));
            Assert.That(dataStore.deletedRulesIDs.Contains(deletedRule.id));
            Assert.That(!dataStore.rulesList.Contains(deletedRule));
        }
Пример #7
0
        public void UpdateSettingForRule_ShouldUpdateSettingOnRightRule()
        {
            var dataStore = RCTestUtils.GetDataStore();

            dataStore.rulesList = new List <RuleWithSettingsMetadata>(RCTestUtils.rulesWithSettingsMetadata);
            dataStore.rsKeyList = new List <RsKvtData>(RCTestUtils.rsListWithMetadata);
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();
            var newVal = "new value";

            dataManager.UpdateSettingForRule(RCTestUtils.ruleOneId, new RsKvtData(RCTestUtils.stringKeyEntityId, new RemoteSettingsKeyValueType(RCTestUtils.stringKeyName, "string", newVal)));
            var setting = dataStore.rulesList.Find(r => r.id == RCTestUtils.ruleOneId).value.Find((obj) => obj.metadata.entityId == RCTestUtils.stringKeyEntityId);

            Assert.That(string.Equals(setting.rs.value, newVal));
            Assert.That(dataStore.updatedRulesIDs.Contains(RCTestUtils.ruleOneId));
        }
Пример #8
0
        public void SetRSDataStore_SetsRSDataStoreWhenAListIsPassedIn()
        {
            var dataStore = RCTestUtils.GetDataStore();
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();
            var config = new RemoteConfigConfigData()
            {
                type  = "settings",
                id    = "someId",
                value = RCTestUtils.rsListWihtoutMetadata
            };

            dataManager.SetRSDataStore(config);

            Assert.That(RSListsAreEqual(dataStore.rsKeyList, RCTestUtils.rsListWihtoutMetadata));
        }
Пример #9
0
        public void SetCurrentEnvironment_SetsCurrentEnvironment()
        {
            var dataStore = RCTestUtils.GetDataStore();
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            Environment currentEnvironment = new Environment();

            currentEnvironment.name = RCTestUtils.currentEnvironment;
            currentEnvironment.id   = RCTestUtils.currentEnvironmentId;

            dataManager.SetCurrentEnvironment(currentEnvironment);

            //Assert.That(Equals(dataStore.currentEnvironment, currentEnvironment.name));
            Assert.That(Equals(dataStore.currentEnvironmentId, currentEnvironment.id));
        }
Пример #10
0
        public void UpdateSetting_UpdatesCorrectSetting()
        {
            var dataStore = RCTestUtils.GetDataStore();

            dataStore.rsKeyList = new List <RsKvtData>(RCTestUtils.rsListWithMetadata);
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();
            var newRs = new RsKvtData(RCTestUtils.rsListWithMetadata[0].metadata.entityId, new RemoteSettingsKeyValueType("updated-key", "updated-type", "updated-value"));

            dataManager.UpdateSetting(RCTestUtils.rsListWithMetadata[0], newRs);
            Assert.That(!dataStore.rsKeyList.Contains(RCTestUtils.rsListWithMetadata[0]));
            Assert.That(dataStore.rsKeyList.Contains(newRs));
            var rs = dataStore.rsKeyList.Find(s => s.metadata.entityId == newRs.metadata.entityId);

            Assert.That(string.Equals(rs.rs.key, newRs.rs.key));
            Assert.That(string.Equals(rs.rs.type, newRs.rs.type));
            Assert.That(string.Equals(rs.rs.value, newRs.rs.value));
        }
Пример #11
0
        public void UpdateRuleAttributes_ShouldUpdateRule()
        {
            var dataStore = RCTestUtils.GetDataStore();

            dataStore.rulesList = new List <RuleWithSettingsMetadata>(RCTestUtils.rulesWithSettingsMetadata);
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.UpdateRuleAttributes(RCTestUtils.ruleOneId, RCTestUtils.updatedRuleOne);
            Assert.That(dataStore.rulesList.Contains(RCTestUtils.updatedRuleOne));
            Assert.That(!dataStore.rulesList.Contains(RCTestUtils.rulesWithSettingsMetadata[0]));
            var ruleFromList = dataStore.rulesList.Find(r => r.id == RCTestUtils.updatedRuleOne.id);

            Assert.That(ruleFromList.enabled == RCTestUtils.updatedRuleOne.enabled);
            Assert.That(string.Equals(ruleFromList.condition, RCTestUtils.updatedRuleOne.condition));
            Assert.That(string.Equals(ruleFromList.name, RCTestUtils.updatedRuleOne.name));
            Assert.That(ruleFromList.rolloutPercentage == RCTestUtils.updatedRuleOne.rolloutPercentage);
        }
Пример #12
0
        public void SetRulesDataStore_SetsEntityIdOnKeys()
        {
            var dataStore = RCTestUtils.GetDataStore();
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            dataManager.SetRulesDataStore(new List <Rule>(RCTestUtils.rulesList));

            var rulesList = dataManager.GetRulesList();

            foreach (var rule in rulesList)
            {
                foreach (var setting in rule.value)
                {
                    Assert.That(RCTestUtils.rsDictWithMetadata.TryGetValue(setting.metadata.entityId, out RsKvtData rsKvt));
                }
            }

            Assert.That(Equals(dataManager.GetRulesList(), dataStore.rulesList));
        }
Пример #13
0
        public void InitDataStore_InitsAll()
        {
            var dataStore = RCTestUtils.GetDataStore();
            RemoteConfigDataManager dataManager = new RemoteConfigDataManager();

            var initDataStoreMethod =
                typeof(RemoteConfigDataManager).GetMethod("InitDataStore", BindingFlags.NonPublic |
                                                          BindingFlags.Instance);

            initDataStoreMethod?.Invoke(dataManager, new object[] { });

            Assert.That(dataStore.rsKeyList != null);
            //Assert.That(Equals(dataStore.currentEnvironment, "Release"));
            Assert.That(string.IsNullOrEmpty(dataStore.currentEnvironmentId));
            Assert.That(dataStore.environments != null);
            Assert.That(dataStore.rulesList != null);
            Assert.That(dataStore.addedRulesIDs != null);
            Assert.That(dataStore.updatedRulesIDs != null);
            Assert.That(dataStore.deletedRulesIDs != null);
        }