public void UseSplitioAndUserPrefix() { //Arrange var splitName = "test_split"; var split = new Split { name = splitName, changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test" }; var splitParser = new Mock <ISplitParser>(); var redisAdapterMock = new Mock <IRedisAdapter>(); var splitCache = new RedisSplitCache(redisAdapterMock.Object, splitParser.Object, "mycompany"); redisAdapterMock .Setup(x => x.Get("mycompany.SPLITIO.split.test_split")) .Returns(JsonConvert.SerializeObject(split)); splitParser .Setup(mock => mock.Parse(It.IsAny <Split>())) .Returns(new ParsedSplit { name = split.name, changeNumber = split.changeNumber, killed = split.killed, seed = split.seed, defaultTreatment = split.defaultTreatment, trafficTypeName = split.trafficTypeName }); //Act var result = splitCache.GetSplit(splitName); //Assert Assert.IsNotNull(result); Assert.AreEqual(split.name, result.name); Assert.AreEqual(split.changeNumber, result.changeNumber); Assert.AreEqual(split.killed, result.killed); Assert.AreEqual(split.seed, result.seed); Assert.AreEqual(split.defaultTreatment, result.defaultTreatment); Assert.AreEqual(split.trafficTypeName, result.trafficTypeName); }
public void GetInexistentSplitOrRedisExceptionShouldReturnNull() { //Arrange var splitName = "test_split"; var redisAdapterMock = new Mock <IRedisAdapter>(); string value = null; redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(value); var splitCache = new RedisSplitCache(redisAdapterMock.Object); //Act var result = splitCache.GetSplit(splitName); //Assert Assert.IsNull(result); }
public void RemoveSplitTest() { //Arrange var splitName = "test_split"; var redisAdapterMock = new Mock <IRedisAdapter>(); redisAdapterMock.Setup(x => x.Del(splitKeyPrefix + "test_split")).Returns(true); string value = null; redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(value); var splitCache = new RedisSplitCache(redisAdapterMock.Object); //Act var isRemoved = splitCache.RemoveSplit(splitName); var result = splitCache.GetSplit(splitName); //Assert Assert.IsTrue(isRemoved); Assert.IsNull(result); }
public void UseSplitioAndUserPrefix() { //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.Get("mycompany.SPLITIO.split.test_split")).Returns(splitJson); var splitCache = new RedisSplitCache(redisAdapterMock.Object, "mycompany"); //Act var result = splitCache.GetSplit(splitName); //Assert Assert.IsNotNull(result); }
public void AddAndGetSplitTest() { //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.Set(splitKeyPrefix + "test_split", splitJson)).Returns(true); redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(splitJson); var splitCache = new RedisSplitCache(redisAdapterMock.Object); //Act splitCache.AddSplit(splitName, split); var result = (Split)splitCache.GetSplit(splitName); //Assert Assert.IsNotNull(result); Assert.AreEqual(splitName, result.name); }
public void RemoveSplitsTest() { //Arrange var splitName = "test_split"; var redisAdapterMock = new Mock <IRedisAdapter>(); redisAdapterMock.Setup(x => x.Del(It.IsAny <RedisKey[]>())).Returns(1); string value = null; redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(value); var splitCache = new RedisSplitCache(redisAdapterMock.Object); //Act var removedCount = splitCache.RemoveSplits(new List <string>() { splitName }); var result = splitCache.GetSplit(splitName); //Assert Assert.AreEqual(1, removedCount); Assert.IsNull(result); }