Ejemplo n.º 1
0
        [DoNotParallelize]//CustomContainer.Register is not threadsafe
        public void WfExecutionContainer_LogStopExecutionState()
        {
            var serviceAction  = new ServiceAction();
            var mockDataObject = new Mock <IDSFDataObject>();

            var dev2WorkflowSettings = new Mock <Common.Interfaces.IDev2WorkflowSettings>();

            dev2WorkflowSettings.Setup(o => o.EnableDetailedLogging).Returns(true);
            dev2WorkflowSettings.Setup(o => o.ExecutionLogLevel).Returns(LogLevel.DEBUG.ToString);
            mockDataObject.Setup(o => o.Settings).Returns(dev2WorkflowSettings.Object);

            var mockExecutionEnvironment = new Mock <IExecutionEnvironment>();

            mockExecutionEnvironment.Setup(o => o.Eval(It.IsAny <string>(), It.IsAny <int>()))
            .Returns(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomListresult(new WarewolfAtomList <DataStorage.WarewolfAtom>(DataStorage.WarewolfAtom.NewDataString("Value"))))
            .Verifiable();
            mockExecutionEnvironment.Setup(o => o.FetchErrors()).Returns("Error").Verifiable();

            mockDataObject.Setup(o => o.Environment)
            .Returns(mockExecutionEnvironment.Object);
            mockDataObject.SetupGet(o => o.Environment.AllErrors)
            .Returns(new HashSet <string> {
                "2nd false error from WfExecutionContainerTests"
            });
            mockDataObject.SetupGet(o => o.Environment.Errors)
            .Returns(new HashSet <string> {
                "1st false error from WfExecutionContainerTests"
            });

            var mockStateNotifier = new Mock <IStateNotifier>();

            mockDataObject.Setup(o => o.StopExecution).Returns(true);
            mockDataObject.Setup(o => o.StateNotifier).Returns(mockStateNotifier.Object);

            var mockWorkspace        = new Mock <IWorkspace>();
            var mockEsbChannel       = new Mock <IEsbChannel>();
            var mockExecutionManager = new Mock <IExecutionManager>();

            mockStateNotifier.Setup(o => o.LogStopExecutionState(It.IsAny <IDev2Activity>()))
            .Verifiable();

            var logManagerMock = new Mock <IStateNotifierFactory>();

            logManagerMock.Setup(o => o.New(It.IsAny <IDSFDataObject>())).Returns(mockStateNotifier.Object);

            CustomContainer.Register <IExecutionManager>(mockExecutionManager.Object);
            CustomContainer.Register <IStateNotifierFactory>(logManagerMock.Object);
            var wfExecutionContainer = new WfExecutionContainer(serviceAction, mockDataObject.Object, mockWorkspace.Object, mockEsbChannel.Object);

            wfExecutionContainer.Eval(FlowchartProcess, mockDataObject.Object, 0);

            mockStateNotifier.Verify(o => o.LogStopExecutionState(It.IsAny <IDev2Activity>()), Times.Exactly(1));
            mockStateNotifier.Verify(o => o.LogExecuteCompleteState(It.IsAny <IDev2Activity>()), Times.Never);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The ForEach Activity requires the data returned from an activity
        /// We will mock the DSF channel to return something that we expect is shaped.
        /// </summary>
        /// <returns></returns>
        public Mock <IEsbChannel> ExecuteForEachProcess(out IDSFDataObject dataObject, bool isDebug = false, int nestingLevel = 0)
        {
            var svc = new ServiceAction {
                Name = "ForEachTestAction", ServiceName = "UnitTestService"
            };
            var mockChannel = new Mock <IEsbChannel>();

            svc.SetActivity(FlowchartProcess);

            if (CurrentDl == null)
            {
                CurrentDl = TestData;
            }

            Compiler = DataListFactory.CreateDataListCompiler();
            ErrorResultTO errors;
            Guid          exId = Compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), new StringBuilder(TestData), new StringBuilder(CurrentDl), out errors);


            if (errors.HasErrors())
            {
                string errorString = errors.FetchErrors().Aggregate(string.Empty, (current, item) => current + item);

                throw new Exception(errorString);
            }

            dataObject = new DsfDataObject(CurrentDl, exId)
            {
                // NOTE: WorkflowApplicationFactory.InvokeWorkflowImpl() will use HostSecurityProvider.Instance.ServerID
                //       if this is NOT provided which will cause the tests to fail!
                ServerID            = Guid.NewGuid(),
                IsDebug             = isDebug,
                ForEachNestingLevel = nestingLevel,
                ParentThreadID      = 1
            };


            // we need to set this now ;)

            mockChannel.Setup(c => c.ExecuteSubRequest(It.IsAny <IDSFDataObject>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), out errors)).Verifiable();
            CustomContainer.Register <IActivityParser>(new ActivityParser());
            WfExecutionContainer wfec = new WfExecutionContainer(svc, dataObject, WorkspaceRepository.Instance.ServerWorkspace, mockChannel.Object);

            errors.ClearErrors();
            wfec.Eval(FlowchartProcess, Guid.NewGuid(), dataObject);

            return(mockChannel);
        }
Ejemplo n.º 3
0
        protected Mock <IEsbChannel> ExecuteForEachProcess(out IDSFDataObject dataObject, bool isDebug = false, int nestingLevel = 0)
        {
            using (ServiceAction svc = new ServiceAction {
                Name = "ForEachTestAction", ServiceName = "UnitTestService"
            })
            {
                var mockChannel = new Mock <IEsbChannel>();
                svc.SetActivity(FlowchartProcess);

                if (CurrentDl == null)
                {
                    CurrentDl = TestData;
                }

                var errors = new ErrorResultTO();


                if (errors.HasErrors())
                {
                    var errorString = errors.FetchErrors().Aggregate(string.Empty, (current, item) => current + item);

                    throw new Exception(errorString);
                }

                dataObject = new DsfDataObject(CurrentDl, new Guid())
                {
                    // NOTE: WorkflowApplicationFactory.InvokeWorkflowImpl() will use HostSecurityProvider.Instance.ServerID
                    //       if this is NOT provided which will cause the tests to fail!
                    ServerID            = Guid.NewGuid(),
                    IsDebug             = isDebug,
                    ForEachNestingLevel = nestingLevel,
                    ParentThreadID      = 1
                };

                mockChannel.Setup(c => c.ExecuteSubRequest(It.IsAny <IDSFDataObject>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), out errors, 0, false)).Verifiable();
                CustomContainer.Register <IActivityParser>(new ActivityParser());
                var wfec = new WfExecutionContainer(svc, dataObject, WorkspaceRepository.Instance.ServerWorkspace, mockChannel.Object);
                dataObject.Settings = new Dev2WorkflowSettingsTO {
                    EnableDetailedLogging = false
                };
                errors.ClearErrors();
                wfec.Eval(FlowchartProcess, dataObject, 0);

                return(mockChannel);
            }
        }
Ejemplo n.º 4
0
        public void WfExecutionContainer_ExecuteNode_WhenSeverSettings_EnableDetailedLogging_IsTrue_ShouldRunLogActivityExecuteStateAndLogExecuteCompleteState()
        {
            //--------------Arrange------------------------------
            var dataObjectMock           = new Mock <IDSFDataObject>();
            var workSpaceMock            = new Mock <IWorkspace>();
            var esbChannelMock           = new Mock <IEsbChannel>();
            var executionEnvironmentMock = new Mock <IExecutionEnvironment>();
            var serviceAction            = new ServiceAction();
            var mockStateNotifier        = new Mock <IStateNotifier>();
            var mockExecutionManager     = new Mock <IExecutionManager>();

            var dev2WorkflowSettings = new Mock <Dev2.Common.Interfaces.IDev2WorkflowSettings>();

            dev2WorkflowSettings.Setup(o => o.EnableDetailedLogging).Returns(true);
            dev2WorkflowSettings.Setup(o => o.ExecutionLogLevel).Returns(LogLevel.DEBUG.ToString);
            executionEnvironmentMock.Setup(environment => environment.AllErrors).Returns(new HashSet <string>());
            executionEnvironmentMock.Setup(environment => environment.Errors).Returns(new HashSet <string>());
            dataObjectMock.Setup(o => o.Environment.FetchErrors())
            .Returns("");

            dataObjectMock.SetupGet(o => o.Environment).Returns(executionEnvironmentMock.Object);
            dataObjectMock.Setup(o => o.StopExecution).Returns(false);
            dataObjectMock.Setup(o => o.Settings).Returns(dev2WorkflowSettings.Object);
            dataObjectMock.Setup(o => o.StateNotifier).Returns(mockStateNotifier.Object);

            mockStateNotifier.Setup(o => o.LogActivityExecuteState(It.IsAny <IDev2Activity>())).Verifiable();
            mockStateNotifier.Setup(o => o.LogExecuteCompleteState(It.IsAny <IDev2Activity>())).Verifiable();

            var logManagerMock = new Mock <IStateNotifierFactory>();

            logManagerMock.Setup(o => o.New(It.IsAny <IDSFDataObject>())).Returns(mockStateNotifier.Object);

            CustomContainer.Register <IExecutionManager>(mockExecutionManager.Object);
            CustomContainer.Register <IStateNotifierFactory>(logManagerMock.Object);
            var wfExecutionContainer = new WfExecutionContainer(serviceAction, dataObjectMock.Object, workSpaceMock.Object, esbChannelMock.Object);

            //--------------Act----------------------------------
            wfExecutionContainer.Eval(FlowchartProcess, dataObjectMock.Object, 0);

            //--------------Assert-------------------------------
            Assert.IsNull(dataObjectMock.Object.ExecutionException);
            mockStateNotifier.Verify(o => o.LogExecuteCompleteState(It.IsAny <IDev2Activity>()), Times.Once);
            mockStateNotifier.Verify(o => o.Dispose(), Times.Once);
            mockExecutionManager.Verify(o => o.CompleteExecution(), Times.Once);
        }
Ejemplo n.º 5
0
        public void WfExecutionContainer_ExecuteNode_CheckWhenDataObjectStopExecutionIsFalse_ShouldEmptyExecutionExceptionInDataObject()
        {
            //--------------Arrange------------------------------
            var dataObjectMock       = new Mock <IDSFDataObject>();
            var workSpaceMock        = new Mock <IWorkspace>();
            var esbChannelMock       = new Mock <IEsbChannel>();
            var executionEnvironment = new Mock <ExecutionEnvironment>();
            var serviceAction        = new ServiceAction();


            dataObjectMock.SetupAllProperties();
            dataObjectMock.SetupGet(o => o.Environment).Returns(executionEnvironment.Object);
            dataObjectMock.Setup(o => o.StopExecution).Returns(false);

            var wfExecutionContainer = new WfExecutionContainer(serviceAction, dataObjectMock.Object, workSpaceMock.Object, esbChannelMock.Object);

            //--------------Act----------------------------------
            wfExecutionContainer.Eval(FlowchartProcess, dataObjectMock.Object, 0);

            //--------------Assert-------------------------------
            Assert.IsNull(dataObjectMock.Object.ExecutionException);
        }
Ejemplo n.º 6
0
        public void WfExecutionContainer_ExecuteNode_CheckWhenDataObjectStopExecutionIsTrue_ShouldNotEmptyExecutionExceptionInDataObject()
        {
            //--------------Arrange------------------------------
            var dataObjectMock       = new Mock <IDSFDataObject>();
            var workSpaceMock        = new Mock <IWorkspace>();
            var esbChannelMock       = new Mock <IEsbChannel>();
            var executionEnvironment = new Mock <ExecutionEnvironment>();
            var serviceAction        = new ServiceAction();

            dataObjectMock.SetupAllProperties();
            dataObjectMock.SetupGet(o => o.Environment).Returns(executionEnvironment.Object);
            dataObjectMock.Setup(o => o.StopExecution).Returns(true);

            var wfExecutionContainer = new WfExecutionContainer(serviceAction, dataObjectMock.Object, workSpaceMock.Object, esbChannelMock.Object);

            //--------------Act----------------------------------
            wfExecutionContainer.Eval(FlowchartProcess, dataObjectMock.Object, 0);

            //--------------Assert-------------------------------
            Assert.IsNotNull(dataObjectMock.Object.ExecutionException);
            Assert.AreEqual(dataObjectMock.Object.ExecutionException.Message, "An error occurred while formatting a number, an invalid value of '' was returned from the rounding function.");
        }
Ejemplo n.º 7
0
        public void WfExecutionContainer_ExecuteNode_WhenSeverSettings_EnableDetailedLogging_IsTrue_ShouldRunLogExecuteException()
        {
            //--------------Arrange------------------------------
            var dataObjectMock           = new Mock <IDSFDataObject>();
            var workSpaceMock            = new Mock <IWorkspace>();
            var esbChannelMock           = new Mock <IEsbChannel>();
            var executionEnvironmentMock = new Mock <IExecutionEnvironment>();
            var serviceAction            = new ServiceAction();
            var mockStateNotifier        = new Mock <IStateNotifier>();
            var mockExecutionManager     = new Mock <IExecutionManager>();
            var activityParserMock       = new Mock <IActivityParser>();
            var activityMock             = new Mock <IDev2Activity>();

            var dev2WorkflowSettings = new Mock <Dev2.Common.Interfaces.IDev2WorkflowSettings>();

            dev2WorkflowSettings.Setup(o => o.EnableDetailedLogging).Returns(true);
            dev2WorkflowSettings.Setup(o => o.ExecutionLogLevel).Returns(LogLevel.DEBUG.ToString);
            var atomList = new WarewolfAtomList <DataStorage.WarewolfAtom>(DataStorage.WarewolfAtom.Nothing);

            atomList.AddSomething(DataStorage.WarewolfAtom.NewDataString("Bob"));
            atomList.AddSomething(DataStorage.WarewolfAtom.NewDataString("Stub"));
            executionEnvironmentMock.Setup(environment => environment.Eval(It.IsAny <string>(), It.IsAny <int>())).Returns(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomListresult(atomList));
            executionEnvironmentMock.Setup(o => o.AddError(It.IsAny <string>())).Verifiable();

            dataObjectMock.SetupGet(o => o.Environment).Returns(executionEnvironmentMock.Object);
            dataObjectMock.SetupGet(o => o.Environment.AllErrors)
            .Returns(new HashSet <string> {
                "2nd false error from WfExecutionContainerTests"
            });
            dataObjectMock.SetupGet(o => o.Environment.Errors)
            .Returns(new HashSet <string> {
                "1st false error from WfExecutionContainerTests"
            });
            dataObjectMock.Setup(o => o.Environment.FetchErrors())
            .Returns("1st false error from WfExecutionContainerTests, 2nd false error from WfExecutionContainerTests");

            var falseException = new Exception("1st false error from WfExecutionContainerTests, 2nd false error from WfExecutionContainerTests");

            dataObjectMock.Setup(o => o.StopExecution).Returns(false);
            dataObjectMock.Setup(o => o.ExecutionException).Returns(falseException);
            dataObjectMock.Setup(o => o.Settings).Returns(dev2WorkflowSettings.Object);
            dataObjectMock.Setup(o => o.StateNotifier).Returns(mockStateNotifier.Object);

            mockStateNotifier.Setup(o => o.LogActivityExecuteState(It.IsAny <IDev2Activity>())).Verifiable();
            mockStateNotifier.Setup(o => o.LogExecuteException(It.IsAny <Exception>(), It.IsAny <IDev2Activity>())).Verifiable();

            var logManagerMock = new Mock <IStateNotifierFactory>();

            logManagerMock.Setup(o => o.New(It.IsAny <IDSFDataObject>())).Returns(mockStateNotifier.Object);

            activityMock.Setup(o => o.Execute(dataObjectMock.Object, 0)).Throws(falseException);
            activityParserMock.Setup(o => o.Parse(It.IsAny <DynamicActivity>())).Returns(activityMock.Object);

            CustomContainer.Register <IExecutionManager>(mockExecutionManager.Object);
            CustomContainer.Register <IStateNotifierFactory>(logManagerMock.Object);
            CustomContainer.Register <IActivityParser>(activityParserMock.Object);
            var wfExecutionContainer = new WfExecutionContainer(serviceAction, dataObjectMock.Object, workSpaceMock.Object, esbChannelMock.Object);

            //--------------Act----------------------------------
            wfExecutionContainer.Eval(FlowchartProcess, dataObjectMock.Object, 0);

            //--------------Assert-------------------------------
            Assert.IsNotNull(dataObjectMock.Object.ExecutionException);
            mockStateNotifier.Verify(o => o.LogExecuteException(falseException, activityMock.Object), Times.Once);
            mockStateNotifier.Verify(o => o.LogExecuteCompleteState(It.IsAny <IDev2Activity>()), Times.Never);
            mockStateNotifier.Verify(o => o.Dispose(), Times.Once);
            mockExecutionManager.Verify(o => o.CompleteExecution(), Times.Once);
        }
Ejemplo n.º 8
0
        protected IDSFDataObject ExecuteProcess(IDSFDataObject dataObject = null, bool isDebug = false, IEsbChannel channel = null, bool isRemoteInvoke = false, bool throwException = true, bool isDebugMode = false, Guid currentEnvironmentId = default(Guid), bool overrideRemote = false)
        {
            using (ServiceAction svc = new ServiceAction {
                Name = "TestAction", ServiceName = "UnitTestService"
            })
            {
                svc.SetActivity(FlowchartProcess);
                var mockChannel = new Mock <IEsbChannel>();

                if (CurrentDl == null)
                {
                    CurrentDl = TestData;
                }

                var errors = new ErrorResultTO();
                if (ExecutionId == Guid.Empty)
                {
                    if (dataObject != null)
                    {
                        dataObject.ExecutingUser = User;
                        dataObject.DataList      = new StringBuilder(CurrentDl);
                    }
                }

                if (errors.HasErrors())
                {
                    var errorString = errors.FetchErrors().Aggregate(string.Empty, (current, item) => current + item);

                    if (throwException)
                    {
                        throw new Exception(errorString);
                    }
                }

                if (dataObject == null)
                {
                    dataObject = new DsfDataObject(CurrentDl, ExecutionId)
                    {
                        // NOTE: WorkflowApplicationFactory.InvokeWorkflowImpl() will use HostSecurityProvider.Instance.ServerID
                        //       if this is NOT provided which will cause the tests to fail!
                        ServerID                 = Guid.NewGuid(),
                        ExecutingUser            = User,
                        IsDebug                  = isDebugMode,
                        EnvironmentID            = currentEnvironmentId,
                        IsRemoteInvokeOverridden = overrideRemote,
                        DataList                 = new StringBuilder(CurrentDl)
                    };
                }
                if (!string.IsNullOrEmpty(TestData))
                {
                    ExecutionEnvironmentUtils.UpdateEnvironmentFromXmlPayload(DataObject, new StringBuilder(TestData), CurrentDl, 0);
                }
                dataObject.IsDebug = isDebug;

                // we now need to set a thread ID ;)
                dataObject.ParentThreadID = 1;

                if (isRemoteInvoke)
                {
                    dataObject.RemoteInvoke    = true;
                    dataObject.RemoteInvokerID = Guid.NewGuid().ToString();
                }

                var esbChannel = mockChannel.Object;
                if (channel != null)
                {
                    esbChannel = channel;
                }
                dataObject.ExecutionToken = new ExecutionToken();
                var wfec = new WfExecutionContainer(svc, dataObject, WorkspaceRepository.Instance.ServerWorkspace, esbChannel);

                errors.ClearErrors();
                CustomContainer.Register <IActivityParser>(new ActivityParser());
                if (dataObject.ResourceID == Guid.Empty)
                {
                    dataObject.ResourceID = Guid.NewGuid();
                }
                dataObject.Environment = DataObject.Environment;
                wfec.Eval(FlowchartProcess, dataObject, 0);
                DataObject = dataObject;
                return(dataObject);
            }
        }