public void SplitsReturnWithNoRolloutConditionSuccessfully() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { conditionType = ConditionType.WHITELIST, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" } } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); var manager = new SplitManager(splitCache); //Act var result = manager.Splits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(6, result.Count); var firstResult = result.Find(x => x.name == "test1"); Assert.AreEqual(firstResult.name, "test1"); Assert.AreEqual(firstResult.changeNumber, 10000); Assert.AreEqual(firstResult.killed, false); Assert.AreEqual(firstResult.trafficType, "user"); Assert.AreEqual(firstResult.treatments.Count, 0); }
public void SplitsWhenCacheIsNotInstancedShouldReturnNull() { //Arrange var manager = new SplitManager(null); //Act var result = manager.Splits(); //Assert Assert.IsNull(result); }
public void SplitsWhenCacheIsEmptyShouldReturnEmptyList() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var manager = new SplitManager(splitCache); //Act var result = manager.Splits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); }
public void SplitsWhenCacheIsNotInstancedShouldReturnNull() { //Arrange _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(null, _blockUntilReadyService.Object); //Act var result = manager.Splits(); //Assert Assert.IsNull(result); }
public void SplitsWhenCacheIsEmptyShouldReturnEmptyList() { //Arrange _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.Splits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); }
public void Splits_WithConfigs_ReturnSuccessfully() { //Arrange var configurations = new Dictionary <string, string> { { "On", "\"Name = \"Test Config\"" } }; var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" } } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic, configurations = configurations }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic, configurations = configurations }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); manager.BlockUntilReady(1000); //Act var result = manager.Splits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(6, result.Count); var test1Result = result.Find(res => res.name == "test1"); Assert.IsNotNull(test1Result.configs); var test2Result = result.Find(res => res.name == "test2"); Assert.IsNotNull(test2Result.configs); var test3Result = result.Find(res => res.name == "test3"); Assert.IsNull(test3Result.configs); }
public void SplitsReturnSuccessfully() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { conditionType = ConditionType.WHITELIST, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "off" } } }; conditionsWithLogic.Add(conditionWithLogic); var conditionWithLogic2 = new ConditionWithLogic() { conditionType = ConditionType.ROLLOUT, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 90, treatment = "on" }, new PartitionDefinition() { size = 10, treatment = "off" } } }; conditionsWithLogic.Add(conditionWithLogic2); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.Splits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(6, result.Count); var firstResult = result.Find(x => x.name == "test1"); Assert.AreEqual(firstResult.name, "test1"); Assert.AreEqual(firstResult.changeNumber, 10000); Assert.AreEqual(firstResult.killed, false); Assert.AreEqual(firstResult.trafficType, "user"); Assert.AreEqual(firstResult.treatments.Count, 2); var firstTreatment = firstResult.treatments[0]; Assert.AreEqual(firstTreatment, "on"); var secondTreatment = firstResult.treatments[1]; Assert.AreEqual(secondTreatment, "off"); }