public void SaveRedisSource_Execute_GivenResourceDefination_GivenExising_ShouldReturnResourceDefinationMsg()
        {
            //---------------Set up test pack-------------------
            var serializer = new Dev2JsonSerializer();
            var source     = new RedisSourceDefinition()
            {
                Id                 = Guid.Empty,
                Name               = "Name",
                HostName           = "HostName",
                Port               = "3679",
                AuthenticationType = AuthenticationType.Anonymous
            };
            var compressedExecuteMessage = new CompressedExecuteMessage();
            var serializeToJsonString    = source.SerializeToJsonString(new DefaultSerializationBinder());

            compressedExecuteMessage.SetMessage(serializeToJsonString);
            var values = new Dictionary <string, StringBuilder>
            {
                { "RedisSource", source.SerializeToJsonStringBuilder() }
            };
            var catalog     = new Mock <IResourceCatalog>();
            var redisSource = new RedisSource();

            catalog.Setup(resourceCatalog => resourceCatalog.GetResource(It.IsAny <Guid>(), source.Name)).Returns(redisSource);
            catalog.Setup(resourceCatalog => resourceCatalog.SaveResource(It.IsAny <Guid>(), redisSource, It.IsAny <string>()));
            var saveRedisSource = new SaveRedisSource(catalog.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var jsonResult = saveRedisSource.Execute(values, null);
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            //---------------Test Result -----------------------
            Assert.IsFalse(result.HasError);
            catalog.Verify(resourceCatalog => resourceCatalog.SaveResource(It.IsAny <Guid>(), redisSource, It.IsAny <string>()));
        }
Esempio n. 2
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            try
            {
                RedisSource = ResourceCatalog.GetResource <RedisSource>(GlobalConstants.ServerWorkspaceID, SourceId);
                if (RedisSource == null || RedisSource.ResourceType != enSourceType.RedisSource.ToString())
                {
                    _messages.Add(ErrorResource.RedisSourceHasBeenRemoved);
                    return(_messages);
                }
                _redisCache = new RedisCacheImpl(RedisSource.HostName, Convert.ToInt32(RedisSource.Port), RedisSource.Password);
                if (CounterType == "Increment")
                {
                    _result = _redisCache.Increment(Key, StepSize);

                    Dev2Logger.Debug($"Cache {Key} Incremented {StepSize}: {_result}", GlobalConstants.WarewolfDebug);
                }
                else
                {
                    _result = _redisCache.Decrement(Key, StepSize);
                    Dev2Logger.Debug($"Cache {Key} Decremented {StepSize}: {_result}", GlobalConstants.WarewolfDebug);
                }
                return(new List <string> {
                    _result.ToString()
                });
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(nameof(RedisCounterActivity), ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.GetAllMessages());
            }
        }
        public void RedisCacheIntegration_CacheVariableResult_GetDebugInputs_With_DataListUtilIsEvaluated_ShouldReturnInnerActivityOutputs()
        {
            try
            {
                //----------------------Arrange----------------------
                var key = "key" + Guid.NewGuid();
                TestAnonymousAuth(out string hostName, out string password, out int port);
                var redisSource = new RedisSource {
                    HostName = hostName, Password = password, Port = port.ToString()
                };

                var isCalValue    = GlobalConstants.CalculateTextConvertPrefix + "rec(*).name" + GlobalConstants.CalculateTextConvertSuffix;
                var innerActivity = new DsfMultiAssignActivity()
                {
                    FieldsCollection = new List <ActivityDTO>
                    {
                        new ActivityDTO("[[objectId1]]", "ObjectName1", 1),
                        new ActivityDTO("[[objectId2]]", "ObjectName2", 2),
                        new ActivityDTO(isCalValue, "ObjectName3", 3)
                    }
                };

                GenerateMocks(key, redisSource, out Mock <IResourceCatalog> mockResourceCatalog, out Mock <IDSFDataObject> mockDataObject);
                CreateRedisActivity(key, hostName, port, password, mockResourceCatalog, out TestRedisActivity sut, innerActivity);
                //----------------------Act--------------------------
                sut.TestExecuteTool(mockDataObject.Object);

                var debugInputs = sut.GetDebugOutputs(mockDataObject.Object.Environment, 0);
                //----------------------Assert-----------------------
                var actualInnerActivity = sut.ActivityFunc.Handler;

                Assert.AreEqual("Assign", actualInnerActivity.DisplayName);

                Assert.IsTrue(debugInputs is List <DebugItem>, "Debug inputs must return List<DebugItem>");
                Assert.AreEqual(4, debugInputs.Count);

                Assert.AreEqual(1, debugInputs[0].ResultsList.Count);

                AssertDebugItems(debugInputs, 0, 0, "Redis key { " + sut.Key + " } not found", null, "", "");

                AssertDebugItems(debugInputs, 1, 0, "1", null, "", "");
                AssertDebugItems(debugInputs, 1, 1, null, "[[objectId1]]", "=", "ObjectName1");

                AssertDebugItems(debugInputs, 2, 0, "1", null, "", "");
                AssertDebugItems(debugInputs, 2, 1, null, "[[objectId2]]", "=", "ObjectName2");

                AssertDebugItems(debugInputs, 3, 0, "1", null, "", "");
            }
            catch (Exception e)
            {
                if (e.Message.Contains("could not connect to redis Instance"))
                {
                    Assert.Inconclusive(e.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 4
0
        public void RedisSources_Test_With_InvalidHost__AuthenticationType_Anonymous_Expected_InvalidValidationResult()
        {
            var source = new RedisSource
            {
                HostName           = "ddd:222",
                AuthenticationType = Dev2.Runtime.ServiceModel.Data.AuthenticationType.Anonymous,
                Port = "6379"
            }.ToString();

            try
            {
                var handler = new RedisSources();
                var result  = handler.Test(source);
                Assert.IsFalse(result.IsValid);
                Assert.AreEqual("could not connect to redis Instance at ddd:222:6379\r\nNo such host is known", result.ErrorMessage);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("could not connect to redis Instance"))
                {
                    Assert.Inconclusive(e.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 5
0
        public void RedisSources_Test_With_ValidHost_AuthenticationType_Anonymous_Expected_ValidValidationResult()
        {
            try
            {
                var dependency = new Depends(Depends.ContainerType.AnonymousRedis);
                var source     = new RedisSource
                {
                    HostName           = dependency.Container.IP,
                    AuthenticationType = Dev2.Runtime.ServiceModel.Data.AuthenticationType.Anonymous,
                    Port = dependency.Container.Port
                }.ToString();

                var handler = new RedisSources();
                var result  = handler.Test(source);
                Assert.IsTrue(result.IsValid, result.ErrorMessage);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("could not connect to redis Instance"))
                {
                    Assert.Inconclusive(e.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 6
0
        public void RedisSources_TestWithValidArgs_Expected_Valid_ValidationResult()
        {
            var handler     = new RedisSources();
            var redisSource = new RedisSource();
            var result      = handler.Test(redisSource);

            Assert.IsFalse(result.IsValid);
        }
        public void RedisCacheIntegration_CacheVariableResult_EvaluateVariableAsKey()
        {
            try
            {
                var key      = "[[RedisKey]]";
                var keyValue = "someval" + Guid.NewGuid();
                TestAnonymousAuth(out string hostName, out string password, out int port);
                var redisSource = new RedisSource {
                    HostName = hostName, Password = password, Port = port.ToString()
                };
                var innerActivity = new DsfMultiAssignActivity()
                {
                    FieldsCollection = new List <ActivityDTO>
                    {
                        new ActivityDTO("[[objectId1]]", "ObjectName1", 1),
                        new ActivityDTO("[[objectId2]]", "ObjectName2", 2)
                    }
                };

                var mockResourceCatalog = new Mock <IResourceCatalog>();
                var mockDataObject      = new Mock <IDSFDataObject>();
                var environment         = new ExecutionEnvironment();
                environment.Assign(key, keyValue, 0);

                var env = new Mock <IExecutionEnvironment>();
                env.Setup(e => e.EvalToExpression(It.IsAny <string>(), It.IsAny <int>())).Returns(key);
                mockResourceCatalog.Setup(o => o.GetResource <RedisSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(redisSource);
                mockDataObject.Setup(o => o.IsDebugMode()).Returns(true);
                mockDataObject.Setup(o => o.Environment).Returns(environment);

                CreateRedisActivity(key, hostName, port, password, mockResourceCatalog, out TestRedisActivity sut, innerActivity);
                //----------------------Act--------------------------
                sut.TestExecuteTool(mockDataObject.Object);
                var debugOutputs = sut.GetDebugOutputs(mockDataObject.Object.Environment, 0);
                //----------------------Assert-----------------------
                Assert.AreEqual(3, debugOutputs.Count);
                Assert.AreEqual(1, debugOutputs[0].ResultsList.Count);
                AssertDebugItems(debugOutputs, 0, 0, "Redis key { " + keyValue + " } not found", null, "", "");

                AssertDebugItems(debugOutputs, 1, 0, "1", null, "", "");
                AssertDebugItems(debugOutputs, 1, 1, null, "[[objectId1]]", "=", "ObjectName1");

                AssertDebugItems(debugOutputs, 2, 0, "1", null, "", "");
                AssertDebugItems(debugOutputs, 2, 1, null, "[[objectId2]]", "=", "ObjectName2");
            }
            catch (Exception e)
            {
                if (e.Message.Contains("could not connect to redis Instance"))
                {
                    Assert.Inconclusive(e.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 8
0
        public IRedisServiceSource FetchSource(Guid id)
        {
            var xaml        = _queryProxy.FetchResourceXaml(id);
            var redisSource = new RedisSource(xaml.ToXElement());

            var def = new RedisSourceDefinition(redisSource);

            return(def);
        }
        public void RedisCacheDesignerViewModel_Constructor_ModelItemIsValid_Constructor()
        {
            //------------Setup for test--------------------------
            var expectedId  = Guid.NewGuid();
            var redisSource = new RedisSource
            {
                ResourceID         = expectedId,
                ResourceName       = "ResourceName",
                HostName           = "HostName",
                Port               = "6379",
                AuthenticationType = Runtime.ServiceModel.Data.AuthenticationType.Anonymous
            };

            var redisSources = new List <RedisSource> {
                redisSource
            };

            var mockResourceRepository = new Mock <IResourceRepository>();

            mockResourceRepository.Setup(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource)).Returns(redisSources);
            var mockServer = new Mock <IServer>();

            mockServer.Setup(server => server.ResourceRepository).Returns(mockResourceRepository.Object);

            var mockShellViewModel = new Mock <IShellViewModel>();

            //------------Execute Test---------------------------
            var RedisCacheDesignerViewModel = new RedisCacheDesignerViewModel(CreateModelItem(), mockServer.Object, mockShellViewModel.Object);

            //------------Assert Results-------------------------
            Assert.IsTrue(RedisCacheDesignerViewModel.HasLargeView);
            Assert.IsTrue(RedisCacheDesignerViewModel.ShowLarge);
            Assert.AreEqual(string.Empty, RedisCacheDesignerViewModel.ActivityFuncDisplayName);
            Assert.IsNull(RedisCacheDesignerViewModel.ActivityFuncIcon);
            Assert.AreEqual(1, RedisCacheDesignerViewModel.RedisSources.Count);
            Assert.AreEqual(expectedId, RedisCacheDesignerViewModel.RedisSources[0].ResourceID);
            Assert.AreEqual("ResourceName", RedisCacheDesignerViewModel.RedisSources[0].ResourceName);
            Assert.AreEqual("HostName", RedisCacheDesignerViewModel.RedisSources[0].HostName);
            Assert.AreEqual("6379", RedisCacheDesignerViewModel.RedisSources[0].Port);
            Assert.AreEqual(Runtime.ServiceModel.Data.AuthenticationType.Anonymous, RedisCacheDesignerViewModel.RedisSources[0].AuthenticationType);
            Assert.AreEqual(null, RedisCacheDesignerViewModel.Key);
            Assert.IsNull(RedisCacheDesignerViewModel.SelectedRedisSource);
            Assert.IsFalse(RedisCacheDesignerViewModel.IsRedisSourceSelected);
            Assert.AreEqual(5, RedisCacheDesignerViewModel.TTL);
            Assert.IsFalse(RedisCacheDesignerViewModel.EditRedisSourceCommand.CanExecute(null));
            Assert.IsFalse(RedisCacheDesignerViewModel.IsKeyFocused);
            Assert.IsFalse(RedisCacheDesignerViewModel.IsRedisSourceFocused);
            RedisCacheDesignerViewModel.SelectedRedisSource = redisSource;

            Assert.IsNotNull(RedisCacheDesignerViewModel.SelectedRedisSource);
            Assert.IsTrue(RedisCacheDesignerViewModel.IsRedisSourceSelected);
            Assert.AreEqual(redisSource.ResourceID, RedisCacheDesignerViewModel.SelectedRedisSource.ResourceID);
            Assert.IsTrue(RedisCacheDesignerViewModel.EditRedisSourceCommand.CanExecute(null));

            mockResourceRepository.Verify(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource), Times.Once);
        }
Esempio n. 10
0
        public void RedisSource_Constructor_Validate_DefaultValues()
        {
            var redisSource = new RedisSource();

            Assert.IsNotNull(redisSource.ResourceID);
            Assert.AreEqual(Guid.Empty, redisSource.ResourceID);
            Assert.AreEqual(nameof(RedisSource), redisSource.ResourceType);
            Assert.AreEqual("6379", redisSource.Port);
            Assert.AreEqual(AuthenticationType.Anonymous, redisSource.AuthenticationType);
        }
Esempio n. 11
0
        public void RedisActivity_GetDebugInputs_ShouldReturnInnerActivityOutputs()
        {
            //----------------------Arrange----------------------
            try
            {
                //----------------------Arrange----------------------
                TestAnonymousAuth(new Depends(Depends.ContainerType.AnonymousRedis), out string key, out string hostName, out string password, out int port);

                var redisSource = new RedisSource {
                    HostName = hostName, Password = password, Port = port.ToString()
                };
                var innerActivity = new DsfMultiAssignActivity()
                {
                    FieldsCollection = new List <ActivityDTO> {
                        new ActivityDTO("[[objectId1]]", "ObjectName1", 1), new ActivityDTO("[[objectId2]]", "ObjectName2", 2)
                    }
                };

                GenerateMocks(key, redisSource, out Mock <IResourceCatalog> mockResourceCatalog, out Mock <IDSFDataObject> mockDataObject);
                GenerateSUTInstance(key, hostName, port, password, mockResourceCatalog, out Dictionary <string, string> evel, out TestRedisActivity sut, innerActivity);
                //----------------------Act--------------------------
                sut.TestExecuteTool(mockDataObject.Object);
                sut.TestPerformExecution(evel);

                var debugInputs = sut.GetDebugInputs(mockDataObject.Object.Environment, 0);
                //----------------------Assert-----------------------
                var actualInnerActivity = sut.ActivityFunc.Handler;

                Assert.AreEqual("Assign", actualInnerActivity.DisplayName);

                Assert.IsTrue(debugInputs is List <DebugItem>, "Debug inputs must return List<DebugItem>");
                Assert.AreEqual(4, debugInputs.Count);

                Assert.AreEqual(1, debugInputs[0].ResultsList.Count);
                AssertDebugItems(debugInputs, 0, 0, "Key", null, "=", sut.Key);
                AssertDebugItems(debugInputs, 1, 0, "Redis key { " + sut.Key + " } not found", null, "", "");

                AssertDebugItems(debugInputs, 2, 0, "1", null, "", "");
                AssertDebugItems(debugInputs, 2, 1, null, "[[objectId1]]", "=", "ObjectName1");

                AssertDebugItems(debugInputs, 3, 0, "2", null, "", "");
                AssertDebugItems(debugInputs, 3, 1, null, "[[objectId2]]", "=", "ObjectName2");
            }
            catch (Exception e)
            {
                if (e.Message.Contains("could not connect to redis Instance"))
                {
                    Assert.Inconclusive(e.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 12
0
        public void RedisSource_Validate_DefaultValues()
        {
            var redisSource = new RedisSource();

            Assert.IsTrue(redisSource.IsSource);
            Assert.IsFalse(redisSource.IsService);
            Assert.IsFalse(redisSource.IsFolder);
            Assert.IsFalse(redisSource.IsReservedService);
            Assert.IsFalse(redisSource.IsServer);
            Assert.IsFalse(redisSource.IsResourceVersion);
        }
Esempio n. 13
0
 public CartServiceController(bool mock = false)
 {
     if (mock)
     {
         cache = new CartOnRedisMock();
     }
     else
     {
         cache = new CartOnRedis(Environment.GetEnvironmentVariable("cache_redis_server"));
     }
 }
Esempio n. 14
0
        public void RedisRemoveActivity_ExecuteTool_RedisSource_NotNull_ExpectException_As_ExecutionEnvironmentError()
        {
            var key              = "key";
            var sourceId         = Guid.NewGuid();
            var exceptionMessage = "test: if the resource is not found";

            var env = new ExecutionEnvironment();

            env.Assign("[[key]]", key, 0);

            var redisSource = new RedisSource
            {
                HostName = "localhost",
                Password = "",
                Port     = "1234",
            };

            var mockDataObject = new Mock <IDSFDataObject>();

            mockDataObject.Setup(o => o.Environment)
            .Returns(env);

            var mockResourceCatalog = new Mock <IResourceCatalog>();

            mockResourceCatalog.Setup(o => o.GetResource <Resource>(GlobalConstants.ServerWorkspaceID, sourceId))
            .Throws(new Exception(exceptionMessage));

            var mockRedisCache = new Mock <IRedisCache>();

            mockRedisCache.Setup(o => o.Remove(key))
            .Returns(true);

            var mockRedisConnection = new Mock <IRedisConnection>();

            mockRedisConnection.Setup(o => o.Cache)
            .Returns(mockRedisCache.Object);

            var redisRemoveActivity = new RedisRemoveActivity(mockResourceCatalog.Object, new RedisCacheStub(() => mockRedisConnection.Object))
            {
                Key      = key,
                SourceId = sourceId
            };

            redisRemoveActivity.Execute(mockDataObject.Object, 0);

            var builder = new StringBuilder();

            builder.Append(GlobalConstants.InnerErrorTag);
            builder.Append(exceptionMessage);
            builder.Append(GlobalConstants.InnerErrorTagEnd);

            Assert.AreEqual(builder.ToString(), env.FetchErrors());
        }
        private static void GenerateMocks(string key, RedisSource redisSource, out Mock <IResourceCatalog> mockResourceCatalog, out Mock <IDSFDataObject> mockDataObject)
        {
            mockResourceCatalog = new Mock <IResourceCatalog>();
            mockDataObject      = new Mock <IDSFDataObject>();
            var environment = new ExecutionEnvironment();

            environment.Assign(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>());
            environment.EvalToExpression(key, 0);
            mockResourceCatalog.Setup(o => o.GetResource <RedisSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(redisSource);
            mockDataObject.Setup(o => o.IsDebugMode()).Returns(true);
            mockDataObject.Setup(o => o.Environment).Returns(environment);
        }
Esempio n. 16
0
        public void RedisSources_Test_With_ValidHost_AuthenticationType_Anonymous_Expected_ValidValidationResult()
        {
            var source = new RedisSource
            {
                HostName           = Depends.EnableDocker?Depends.RigOpsIP:Depends.SVRDEVIP,
                AuthenticationType = Dev2.Runtime.ServiceModel.Data.AuthenticationType.Anonymous,
                Port = "6380"
            }.ToString();

            var handler = new RedisSources();
            var result  = handler.Test(source);

            Assert.IsTrue(result.IsValid, result.ErrorMessage);
        }
Esempio n. 17
0
 public ValidationResult Test(RedisSource source)
 {
     try
     {
         return(CanConnectServer(source));
     }
     catch (Exception ex)
     {
         RaiseError(ex);
         return(new ValidationResult {
             IsValid = false, ErrorMessage = ex.Message
         });
     }
 }
Esempio n. 18
0
        public void RedisActivity_GetDebugOutputs_ShouldReturnInnerActivityOutputs_TTLReached()
        {
            //----------------------Arrange----------------------
            TestAnonymousAuth(out string key, out string hostName, out string password, out int port);

            var redisSource = new RedisSource {
                HostName = hostName, Password = password, Port = port.ToString()
            };
            var innerActivity = new DsfMultiAssignActivity()
            {
                FieldsCollection = new List <ActivityDTO> {
                    new ActivityDTO("[[objectId1]]", "ObjectName1", 1), new ActivityDTO("[[objectId2]]", "ObjectName2", 2)
                }
            };

            GenerateMocks(key, redisSource, out Mock <IResourceCatalog> mockResourceCatalog, out Mock <IDSFDataObject> mockDataObject);
            GenerateSUTInstance(key, hostName, port, password, mockResourceCatalog, out Dictionary <string, string> evel, out TestRedisActivity sut, innerActivity);
            //----------------------Act--------------------------
            sut.TestExecuteTool(mockDataObject.Object);
            sut.TestPerformExecution(evel);

            var timer = new Stopwatch();

            timer.Start();
            do
            {
                Thread.Sleep(1000);
            } while (timer.Elapsed < TimeSpan.FromMilliseconds(sut.TTL));
            timer.Stop();

            var debugOutputs = sut.GetDebugOutputs(mockDataObject.Object.Environment, 0);
            //----------------------Assert-----------------------
            var actualInnerActivity = sut.ActivityFunc.Handler;

            Assert.AreEqual("Assign", actualInnerActivity.DisplayName);

            Assert.IsTrue(debugOutputs is List <DebugItem>, "Debug inputs must return List<DebugItem>");
            Assert.AreEqual(3, debugOutputs.Count);

            Assert.AreEqual(1, debugOutputs[0].ResultsList.Count);
            AssertDebugItems(debugOutputs, 0, 0, "Redis key { " + sut.Key + " } found", null, "", "");

            AssertDebugItems(debugOutputs, 1, 0, "1", null, "", "");
            AssertDebugItems(debugOutputs, 1, 1, null, "[[objectId1]]", "=", "ObjectName1");

            AssertDebugItems(debugOutputs, 2, 0, "2", null, "", "");
            AssertDebugItems(debugOutputs, 2, 1, null, "[[objectId2]]", "=", "ObjectName2");
        }
        private static RedisSource TestRedisSource(out string hostName, out string password, out int port)
        {
            var dependency = new Depends(Depends.ContainerType.AnonymousRedis, true);

            hostName = dependency.Container.IP;
            password = "";
            port     = int.Parse(dependency.Container.Port);
            var redisSource = new RedisSource
            {
                HostName = hostName,
                Password = password,
                Port     = port.ToString()
            };

            return(redisSource);
        }
Esempio n. 20
0
        public void RedisSources_Test_With_InvalidHost_AuthenticationType_Password_Expected_InvalidValidationResult()
        {
            var source = new RedisSource
            {
                HostName           = "ddd",
                Port               = "6380",
                AuthenticationType = Dev2.Runtime.ServiceModel.Data.AuthenticationType.Password,
                Password           = "******"
            }.ToString();

            var handler = new RedisSources();
            var result  = handler.Test(source);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual("could not connect to redis Instance at ddd:6380\r\nNo such host is known", result.ErrorMessage);
        }
Esempio n. 21
0
        public void RedisActivity_GetDebugInputs_With_DataListUtilIsEvaluated_ShouldReturnInnerActivityOutputs()
        {
            //----------------------Arrange----------------------
            TestAnonymousAuth(out string key, out string hostName, out string password, out int port);

            var redisSource = new RedisSource {
                HostName = hostName, Password = password, Port = port.ToString()
            };
            var isCalValue    = GlobalConstants.CalculateTextConvertPrefix + "rec(*).name" + GlobalConstants.CalculateTextConvertSuffix;
            var innerActivity = new DsfMultiAssignActivity()
            {
                FieldsCollection = new List <ActivityDTO> {
                    new ActivityDTO("[[objectId1]]", "ObjectName1", 1), new ActivityDTO("[[objectId2]]", "ObjectName2", 2), new ActivityDTO(isCalValue, "ObjectName3", 3)
                }
            };


            GenerateMocks(key, redisSource, out Mock <IResourceCatalog> mockResourceCatalog, out Mock <IDSFDataObject> mockDataObject);
            GenerateSUTInstance(key, hostName, port, password, mockResourceCatalog, out Dictionary <string, string> evel, out TestRedisActivity sut, innerActivity);
            //----------------------Act--------------------------
            sut.TestExecuteTool(mockDataObject.Object);
            sut.TestPerformExecution(evel);

            var debugInputs = sut.GetDebugInputs(mockDataObject.Object.Environment, 0);
            //----------------------Assert-----------------------
            var actualInnerActivity = sut.ActivityFunc.Handler;

            Assert.AreEqual("Assign", actualInnerActivity.DisplayName);

            Assert.IsTrue(debugInputs is List <DebugItem>, "Debug inputs must return List<DebugItem>");
            Assert.AreEqual(5, debugInputs.Count);

            Assert.AreEqual(1, debugInputs[0].ResultsList.Count);
            AssertDebugItems(debugInputs, 0, 0, "Key", null, "=", sut.Key);
            AssertDebugItems(debugInputs, 1, 0, "Redis key { " + sut.Key + " } not found", null, "", "");

            AssertDebugItems(debugInputs, 2, 0, "1", null, "", "");
            AssertDebugItems(debugInputs, 2, 1, null, "[[objectId1]]", "=", "ObjectName1");

            AssertDebugItems(debugInputs, 3, 0, "2", null, "", "");
            AssertDebugItems(debugInputs, 3, 1, null, "[[objectId2]]", "=", "ObjectName2");

            AssertDebugItems(debugInputs, 4, 0, "3", null, "", "");
            AssertDebugItems(debugInputs, 4, 1, null, isCalValue, "=", isCalValue);
        }
Esempio n. 22
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var msg        = new ExecuteMessage();
            var serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Save Redis Resource Service", GlobalConstants.WarewolfInfo);

                values.TryGetValue(Warewolf.Service.SaveRedisSource.RedisSource, out StringBuilder resourceDefinition);

                IRedisServiceSource redisSourceDef = serializer.Deserialize <RedisSourceDefinition>(resourceDefinition);

                if (redisSourceDef.Path == null)
                {
                    redisSourceDef.Path = string.Empty;
                }

                if (redisSourceDef.Path.EndsWith("\\"))
                {
                    redisSourceDef.Path = redisSourceDef.Path.Substring(0, redisSourceDef.Path.LastIndexOf("\\", StringComparison.Ordinal));
                }

                var redisSource = new RedisSource
                {
                    ResourceID         = redisSourceDef.Id,
                    HostName           = redisSourceDef.HostName,
                    Port               = redisSourceDef.Port,
                    AuthenticationType = redisSourceDef.AuthenticationType,
                    Password           = redisSourceDef.Password,
                    ResourceName       = redisSourceDef.Name
                };

                ResourceCat.SaveResource(GlobalConstants.ServerWorkspaceID, redisSource, redisSourceDef.Path);
                msg.HasError = false;
            }
            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
            }

            return(serializer.SerializeToBuilder(msg));
        }
        public void RedisCacheDesignerViewModel_Constructor_ModelItemIsValid_EditRedisServerSource()
        {
            var expectedId  = Guid.NewGuid();
            var redisSource = new RedisSource
            {
                ResourceID         = expectedId,
                ResourceName       = "ResourceName",
                HostName           = "HostName",
                Port               = "6379",
                AuthenticationType = Runtime.ServiceModel.Data.AuthenticationType.Anonymous
            };

            var redisSources = new List <RedisSource> {
                redisSource
            };

            var environmentId = Guid.NewGuid();

            var mockResourceRepository = new Mock <IResourceRepository>();

            mockResourceRepository.Setup(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource)).Returns(redisSources);
            var mockServer = new Mock <IServer>();

            mockServer.Setup(server => server.EnvironmentID).Returns(environmentId);
            mockServer.Setup(server => server.ResourceRepository).Returns(mockResourceRepository.Object);


            var mockShellViewModel = new Mock <IShellViewModel>();

            mockShellViewModel.Setup(shellViewModel => shellViewModel.ActiveServer).Returns(mockServer.Object);
            mockShellViewModel.Setup(shellViewModel => shellViewModel.OpenResource(redisSource.ResourceID, environmentId, mockServer.Object));
            CustomContainer.Register(mockShellViewModel.Object);

            //------------Execute Test---------------------------
            var RedisCacheDesignerViewModel = new RedisCacheDesignerViewModel(CreateModelItem(), mockServer.Object, mockShellViewModel.Object)
            {
                SelectedRedisSource = redisSource
            };

            RedisCacheDesignerViewModel.EditRedisSourceCommand.Execute(null);

            mockShellViewModel.Verify(shellViewModel => shellViewModel.OpenResource(expectedId, environmentId, mockServer.Object), Times.Once);
            mockResourceRepository.Verify(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource), Times.Exactly(2));
        }
Esempio n. 24
0
        static ValidationResult CanConnectServer(RedisSource redisSource)
        {
            RedisClient clientAnon = null;

            try
            {
                if (redisSource.AuthenticationType == AuthenticationType.Anonymous)
                {
                    clientAnon = new RedisClient(redisSource.HostName, int.Parse(redisSource.Port));
                }
                else
                {
                    clientAnon = new RedisClient(redisSource.HostName, int.Parse(redisSource.Port), redisSource.Password);
                }
                var isValid      = false;
                var errorMessage = "";
                if (clientAnon.ServerVersion != null)
                {
                    isValid = true;
                }
                else
                {
                    errorMessage = "No such host can be found.";
                }

                return(new ValidationResult
                {
                    IsValid = isValid,
                    ErrorMessage = errorMessage
                });
            }
            catch (Exception e)
            {
                return(new ValidationResult
                {
                    IsValid = false,
                    ErrorMessage = e.InnerException != null?string.Join(Environment.NewLine, e.Message, e.InnerException.Message) : e.Message
                });
            }
            finally
            {
                clientAnon?.Dispose();
            }
        }
Esempio n. 25
0
        public RedisSource Get(string resourceId, Guid workspaceId)
        {
            var result = new RedisSource();

            try
            {
                var xmlStr = ResourceCatalog.Instance.GetResourceContents(workspaceId, Guid.Parse(resourceId)).ToString();
                if (!string.IsNullOrEmpty(xmlStr))
                {
                    var xml = XElement.Parse(xmlStr);
                    result = new RedisSource(xml);
                }
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }
            return(result);
        }
Esempio n. 26
0
        public void RedisRemoveActivity_ExecuteTool_RedisSource_NotNull_ExpectSuccess()
        {
            var key         = "key";
            var sourceId    = Guid.NewGuid();
            var redisSource = new RedisSource
            {
                HostName = "localhost",
                Password = "",
                Port     = "1234",
            };

            var mockDataObject = new Mock <IDSFDataObject>();

            mockDataObject.Setup(o => o.Environment)
            .Returns(new ExecutionEnvironment());

            var mockResourceCatalog = new Mock <IResourceCatalog>();

            mockResourceCatalog.Setup(o => o.GetResource <Resource>(GlobalConstants.ServerWorkspaceID, sourceId))
            .Returns(redisSource);

            var mockRedisCache = new Mock <IRedisCache>();

            mockRedisCache.Setup(o => o.Remove(key))
            .Returns(true);

            var mockRedisConnection = new Mock <IRedisConnection>();

            mockRedisConnection.Setup(o => o.Cache)
            .Returns(mockRedisCache.Object);

            var redisRemoveActivity = new RedisRemoveActivity(mockResourceCatalog.Object, new RedisCacheStub(() => mockRedisConnection.Object))
            {
                Key      = key,
                SourceId = sourceId
            };

            redisRemoveActivity.Execute(mockDataObject.Object, 0);

            mockRedisCache.Verify(o => o.Remove(key), Times.Once);

            Assert.AreEqual("Success", redisRemoveActivity.Response);
        }
        public void RedisRemoveDesignerViewModel_Constructor_ModelItemIsValid_UpdateHelpDescriptor()
        {
            var expectedHelpText = "redis help text";

            var mockHelpViewModel = new Mock <IHelpWindowViewModel>();

            mockHelpViewModel.Setup(helpViewModel => helpViewModel.UpdateHelpText(expectedHelpText));
            var mockShellViewModel = new Mock <IShellViewModel>();

            mockShellViewModel.Setup(shellViewModel => shellViewModel.HelpViewModel).Returns(mockHelpViewModel.Object);
            CustomContainer.Register(mockShellViewModel.Object);

            var expectedId  = Guid.NewGuid();
            var redisSource = new RedisSource
            {
                ResourceID         = expectedId,
                ResourceName       = "ResourceName",
                HostName           = "HostName",
                Port               = "6379",
                AuthenticationType = Runtime.ServiceModel.Data.AuthenticationType.Anonymous
            };

            var redisSources = new List <RedisSource> {
                redisSource
            };

            var mockResourceRepository = new Mock <IResourceRepository>();

            mockResourceRepository.Setup(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource)).Returns(redisSources);
            var mockServer = new Mock <IServer>();

            mockServer.Setup(server => server.ResourceRepository).Returns(mockResourceRepository.Object);

            //------------Execute Test---------------------------
            var redisRemoveDesignerViewModel = new RedisRemoveDesignerViewModel(CreateModelItem(), mockServer.Object, mockShellViewModel.Object);

            Assert.AreEqual("Use the Redis Remove tool to remove existing key with data from cache.", redisRemoveDesignerViewModel.HelpText);
            redisRemoveDesignerViewModel.UpdateHelpDescriptor(expectedHelpText);

            mockHelpViewModel.Verify(helpViewModel => helpViewModel.UpdateHelpText(expectedHelpText), Times.Once);
        }
        public void RedisCacheDesignerViewModel_ActivityFuncIcon()
        {
            var expectedId  = Guid.NewGuid();
            var redisSource = new RedisSource
            {
                ResourceID         = expectedId,
                ResourceName       = "ResourceName",
                HostName           = "HostName",
                Port               = "6379",
                AuthenticationType = Runtime.ServiceModel.Data.AuthenticationType.Anonymous
            };

            var key          = "redisKey";
            var ttl          = 30;
            var redisSources = new List <RedisSource> {
                redisSource
            };

            var mockResourceRepository = new Mock <IResourceRepository>();

            mockResourceRepository.Setup(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource)).Returns(redisSources);
            var mockServer = new Mock <IServer>();

            mockServer.Setup(server => server.ResourceRepository).Returns(mockResourceRepository.Object);

            var mockShellViewModel     = new Mock <IShellViewModel>();
            var mockApplicationAdapter = new Mock <IApplicationAdaptor>();

            mockApplicationAdapter.Setup(p => p.TryFindResource(It.IsAny <string>())).Verifiable();
            CustomContainer.Register(mockApplicationAdapter.Object);

            //------------Execute Test---------------------------
            var RedisCacheDesignerViewModel = new RedisCacheDesignerViewModel(CreateModelItem(key, ttl), mockServer.Object, mockShellViewModel.Object);

            //------------Assert Results-------------------------
            Assert.IsTrue(RedisCacheDesignerViewModel.HasLargeView);
            Assert.AreEqual("Assign", RedisCacheDesignerViewModel.ActivityFuncDisplayName);
            Assert.IsNull(RedisCacheDesignerViewModel.ActivityFuncIcon);
        }
        public void RedisRemoveDesignerViewModel_Constructor_ResultNotNull()
        {
            var expectedId  = Guid.NewGuid();
            var redisSource = new RedisSource
            {
                ResourceID         = expectedId,
                ResourceName       = "ResourceName",
                HostName           = "HostName",
                Port               = "6379",
                AuthenticationType = Runtime.ServiceModel.Data.AuthenticationType.Anonymous
            };

            var redisSources = new List <RedisSource> {
                redisSource
            };

            var environmentId = Guid.NewGuid();

            var mockResourceRepository = new Mock <IResourceRepository>();

            mockResourceRepository.Setup(resourceRepository => resourceRepository.FindSourcesByType <RedisSource>(It.IsAny <IServer>(), enSourceType.RedisSource)).Returns(redisSources);
            var mockServer = new Mock <IServer>();

            mockServer.Setup(server => server.EnvironmentID).Returns(environmentId);
            mockServer.Setup(server => server.ResourceRepository).Returns(mockResourceRepository.Object);


            var mockShellViewModel = new Mock <IShellViewModel>();

            mockShellViewModel.Setup(shellViewModel => shellViewModel.ActiveServer).Returns(mockServer.Object);
            mockShellViewModel.Setup(shellViewModel => shellViewModel.NewRedisSource(""));
            CustomContainer.Register(mockShellViewModel.Object);

            //------------Execute Test---------------------------
            var redisRemoveDesignerViewModel = new RedisRemoveDesignerViewModel(CreateModelItemWithResult(), mockServer.Object, mockShellViewModel.Object);

            Assert.AreEqual("someResult", redisRemoveDesignerViewModel.Result);
        }
Esempio n. 30
0
        public void RedisRemoveActivity_ExecuteTool_RedisSource_NotNull_ExpectRedisSourceHasBeenRemoved()
        {
            var key         = "key";
            var env         = new ExecutionEnvironment();
            var redisSource = new RedisSource
            {
                HostName = "localhost",
                Password = "",
                Port     = "1234",
            };

            var mockDataObject = new Mock <IDSFDataObject>();

            mockDataObject.Setup(o => o.Environment)
            .Returns(env);

            var mockRedisCache = new Mock <IRedisCache>();

            mockRedisCache.Setup(o => o.Remove(key))
            .Returns(true);

            var mockRedisConnection = new Mock <IRedisConnection>();

            mockRedisConnection.Setup(o => o.Cache)
            .Returns(mockRedisCache.Object);

            var redisRemoveActivity = new RedisRemoveActivity(new Mock <IResourceCatalog>().Object, new RedisCacheStub(() => mockRedisConnection.Object))
            {
                Key = key,
            };

            var result = redisRemoveActivity.Execute(mockDataObject.Object, 0);

            mockRedisCache.Verify(o => o.Remove(key), Times.Never);

            Assert.IsNull(redisRemoveActivity.Response);
        }