Пример #1
0
        public void GetAllSplitsSuccessfully()
        {
            //Arrange
            var splitName  = "test_split";
            var splitName2 = "test_split2";
            var split      = BuildSplit(splitName);
            var split2     = BuildSplit(splitName2);
            var splitJson  = JsonConvert.SerializeObject(split);
            var splitJson2 = JsonConvert.SerializeObject(split2);

            _redisAdapterMock
            .Setup(x => x.Keys(splitKeyPrefix + "*"))
            .Returns(new RedisKey[] { "test_split", "test_split2" });

            _redisAdapterMock
            .Setup(x => x.MGet(It.IsAny <RedisKey[]>()))
            .Returns(new RedisValue[] { splitJson, splitJson2 });

            _splitParserMock
            .Setup(mock => mock.Parse(It.IsAny <Split>()))
            .Returns(new ParsedSplit());

            //Act
            var result = _redisSplitCache.GetAllSplits();

            //Assert
            Assert.AreEqual(2, result.Count);
        }
Пример #2
0
        public void GetAllSplitsShouldReturnEmptyListIfGetReturnsEmpty()
        {
            //Arrange

            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { });
            redisAdapterMock.Setup(x => x.Get(It.IsAny <RedisKey[]>())).Returns(new RedisValue[] { });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var result = splitCache.GetAllSplits();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
Пример #3
0
        public void GetAllSplitsSuccessfully()
        {
            //Arrange
            var splitName  = "test_split";
            var splitName2 = "test_split2";
            var split      = new Split()
            {
                name = "test_split", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var split2 = new Split()
            {
                name = "test_split2", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var splitJson        = JsonConvert.SerializeObject(split);
            var splitJson2       = JsonConvert.SerializeObject(split);
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Set(It.IsAny <string>(), splitJson)).Returns(true);
            redisAdapterMock.Setup(x => x.Set(It.IsAny <string>(), splitJson2)).Returns(true);
            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { "test_split", "test_split2" });
            redisAdapterMock.Setup(x => x.Get(It.IsAny <RedisKey[]>())).Returns(new RedisValue[] { splitJson, splitJson2 });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            splitCache.AddSplit(splitName, new ParsedSplit()
            {
                name = splitName
            });
            splitCache.AddSplit(splitName2, new ParsedSplit()
            {
                name = splitName2
            });

            var result = splitCache.GetAllSplits();

            //Assert
            Assert.AreEqual(2, result.Count);
        }
Пример #4
0
        public void AddDuplicateSplitTest()
        {
            //Arrange
            var splitName = "test_split";
            var split     = new Split()
            {
                name = "test_split", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var splitJson        = JsonConvert.SerializeObject(split);
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { "test_split" });
            redisAdapterMock.Setup(x => x.Get(It.IsAny <RedisKey[]>())).Returns(new RedisValue[] { splitJson });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var split1 = new Split()
            {
                name = splitName
            };

            splitCache.AddSplit(splitName, split1);
            var split2 = new Split()
            {
                name = "test_split_2"
            };

            splitCache.AddSplit(splitName, split2);
            var result = splitCache.GetAllSplits();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(((Split)result[0]).name, split1.name);
            Assert.AreNotEqual(((Split)result[0]).name, split2.name);
        }