예제 #1
0
        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);
        }
예제 #2
0
        public void SplitsWhenCacheIsNotInstancedShouldReturnNull()
        {
            //Arrange
            var manager = new SplitManager(null);

            //Act
            var result = manager.Splits();

            //Assert
            Assert.IsNull(result);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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");
        }