private void UpdateTestStep(IDSFDataObject dataObject, IServiceTestStep serviceTestStep)
        {
            if (!dataObject.IsDebugMode())
            {
                var serviceTestSteps = serviceTestStep.Children;
                foreach (var serviceTestTestStep in serviceTestSteps)
                {
                    UpdateForRegularActivity(dataObject, serviceTestTestStep);
                }
            }
            var testRunResult = new TestRunResult();

            GetFinalTestRunResult(serviceTestStep, testRunResult);
            serviceTestStep.Result = testRunResult;
            if (dataObject.IsDebugMode())
            {
                var states = TestDebugMessageRepo.Instance.GetDebugItems(dataObject.ResourceID, dataObject.TestName);
                if (states != null)
                {
                    states = states.Where(state => state.ID == Guid.Parse(UniqueID)).ToList();
                    var debugState = states.FirstOrDefault();
                    if (debugState != null)
                    {
                        AddDebugItem(testRunResult, debugState);
                    }
                }
            }
        }
        private void RunTestStep(IServiceTestModel selectedServiceTest, IServiceTestStep resTestStep)
        {
            var serviceTestSteps = selectedServiceTest.TestSteps.Where(testStep => testStep.UniqueId == resTestStep.UniqueId).ToList();

            foreach (var serviceTestStep in serviceTestSteps)
            {
                var resServiceTestStep = serviceTestStep as ServiceTestStep;
                if (resServiceTestStep == null)
                {
                    continue;
                }

                UpdateTestStepResult(resServiceTestStep, resTestStep);

                var serviceTestOutputs = resTestStep.StepOutputs;
                if (serviceTestOutputs.Count > 0)
                {
                    resServiceTestStep.StepOutputs = CreateServiceTestOutputFromResult(resTestStep.StepOutputs, resServiceTestStep);
                }
                var children = resTestStep.Children;
                if (children.Count > 0)
                {
                    SetChildrenTestResult(children, resServiceTestStep.Children);
                }
            }
        }
Beispiel #3
0
 private static void UpdateStepOutputsForTest(IServiceTestStep serviceTestStep)
 {
     if (serviceTestStep.Children != null)
     {
         var childs = serviceTestStep.Children.Flatten(step => step.Children);
         foreach (var child in childs)
         {
             child.Result = new TestRunResult {
                 RunTestResult = RunResult.TestInvalid
             };
             foreach (var serviceTestOutput in child.StepOutputs)
             {
                 serviceTestOutput.Result = new TestRunResult {
                     RunTestResult = RunResult.TestInvalid
                 };
             }
         }
     }
     serviceTestStep.Result = new TestRunResult {
         RunTestResult = RunResult.TestInvalid
     };
     foreach (var serviceTestOutput in serviceTestStep.StepOutputs)
     {
         serviceTestOutput.Result = new TestRunResult {
             RunTestResult = RunResult.TestInvalid
         };
     }
 }
Beispiel #4
0
        static IDev2Activity ReplaceActivityWithMock(IDev2Activity resource, IServiceTestStep foundTestStep)
        {
            IDev2Activity overriddenActivity = null;

            if (foundTestStep.ActivityType == typeof(DsfDecision).Name)
            {
                var serviceTestOutput = foundTestStep.StepOutputs.FirstOrDefault(output => output.Variable == GlobalConstants.ArmResultText);
                if (serviceTestOutput != null)
                {
                    overriddenActivity = new TestMockDecisionStep(resource.As <DsfDecision>())
                    {
                        NameOfArmToReturn = serviceTestOutput.Value
                    };
                }
            }
            else if (foundTestStep.ActivityType == typeof(DsfSwitch).Name)
            {
                var serviceTestOutput = foundTestStep.StepOutputs.FirstOrDefault(output => output.Variable == GlobalConstants.ArmResultText);
                if (serviceTestOutput != null)
                {
                    overriddenActivity = new TestMockSwitchStep(resource.As <DsfSwitch>())
                    {
                        ConditionToUse = serviceTestOutput.Value
                    };
                }
            }
            else
            {
                overriddenActivity = new TestMockStep(resource, foundTestStep.StepOutputs.ToList());
            }

            return(overriddenActivity);
        }
Beispiel #5
0
 static void GetStepOutputResults(IDSFDataObject dataObject, IServiceTestStep stepToBeAsserted)
 {
     if (stepToBeAsserted?.StepOutputs != null && stepToBeAsserted.StepOutputs.Count > 0)
     {
         if (stepToBeAsserted.Result != null)
         {
             stepToBeAsserted.Result.RunTestResult = RunResult.TestInvalid;
         }
         else
         {
             stepToBeAsserted.Result = new TestRunResult {
                 RunTestResult = RunResult.TestInvalid
             };
         }
         var states = TestDebugMessageRepo.Instance.GetDebugItems(dataObject.ResourceID, dataObject.TestName);
         if (states != null)
         {
             states = states.Where(state =>
             {
                 var idToUse = state.ID;
                 if (state?.ActualType == "DsfActivity")
                 {
                     idToUse = state.WorkSurfaceMappingId;
                 }
                 return(idToUse == stepToBeAsserted.ActivityID);
             }
                                   ).ToList();
             var debugState = states.LastOrDefault();
             UpdateDebugStateWithAssertion(dataObject, stepToBeAsserted, debugState);
         }
     }
 }
 private void MockMethodExecution(IDSFDataObject dataObject, IServiceTestStep serviceTestStep, IDev2MethodInfo dev2MethodInfo, int index)
 {
     if (serviceTestStep.StepOutputs != null)
     {
         foreach (var serviceTestOutput in serviceTestStep.StepOutputs)
         {
             var start = DateTime.Now;
             if (dev2MethodInfo.IsObject)
             {
                 var jContainer = JToken.Parse(serviceTestOutput.Value) as JContainer
                                  ?? serviceTestOutput.Value.DeserializeToObject();
                 if (!string.IsNullOrEmpty(serviceTestOutput.Variable))
                 {
                     dataObject.Environment.AddToJsonObjects(serviceTestOutput.Variable, jContainer);
                 }
             }
             else
             {
                 dataObject.Environment.Assign(serviceTestOutput.Variable, serviceTestOutput.Value, 0);
             }
             dev2MethodInfo.MethodResult      = serviceTestOutput.Value;
             MethodsToRun[index].MethodResult = serviceTestOutput.Value;
             DispatchDebugStateForMethod(MethodsToRun[index], dataObject, 0, true, start);
         }
     }
 }
 void MockMethodExecution(IDSFDataObject dataObject, IServiceTestStep serviceTestStep, IDev2MethodInfo dev2MethodInfo, int index)
 {
     if (serviceTestStep.StepOutputs != null)
     {
         foreach (var serviceTestOutput in serviceTestStep.StepOutputs)
         {
             DispatchDebugState(dataObject, dev2MethodInfo, index, serviceTestOutput);
         }
     }
 }
 public static IWorkflowNode ToWorkflowNode(this IServiceTestStep step)
 {
     return(new WorkflowNode
     {
         ActivityID = step.ActivityID != Guid.Empty ? step.ActivityID : step.UniqueID,
         UniqueID = step.UniqueID,
         StepDescription = step.StepDescription,
         MockSelected = step.MockSelected,
         ChildNodes = step.Children?.Select(o => ToWorkflowNode(o)).ToList() ?? new List <IWorkflowNode>()
     });
 }
        static void UpdateTestStepResult(ServiceTestStep resServiceTestStep, IServiceTestStep resTestStep)
        {
            resServiceTestStep.Result = resTestStep.Result;

            if (resServiceTestStep.MockSelected)
            {
                resServiceTestStep.TestPending = false;
                resServiceTestStep.TestPassed  = false;
                resServiceTestStep.TestFailing = false;
                resServiceTestStep.TestInvalid = false;
            }
        }
Beispiel #10
0
        private static void UpdateDebugStateWithAssertion(IDSFDataObject dataObject, IServiceTestStep stepToBeAsserted, IDebugState debugState)
        {
            if (debugState != null)
            {
                var factory                   = Dev2DecisionFactory.Instance();
                var res                       = stepToBeAsserted.StepOutputs.SelectMany(output => GetTestRunResults(dataObject, output, factory, debugState));
                var testRunResults            = res as IList <TestRunResult> ?? res.ToList();
                var testPassed                = testRunResults.All(result => result.RunTestResult == RunResult.TestPassed || result.RunTestResult == RunResult.None);
                var serviceTestFailureMessage = string.Join("", testRunResults.Select(result => result.Message));

                UpdateBasedOnFinalResult(dataObject, stepToBeAsserted, testPassed, testRunResults, serviceTestFailureMessage);
            }
        }
Beispiel #11
0
 static void RecursivelyMockRecursiveActivities(IDev2Activity activity, IServiceTestStep foundTestStep)
 {
     if (foundTestStep.ActivityType == typeof(DsfSequenceActivity).Name)
     {
         if (activity is DsfSequenceActivity sequenceActivity)
         {
             RecursivelyMockChildrenOfASequence(foundTestStep, sequenceActivity);
         }
     }
     else if (foundTestStep.ActivityType == typeof(DsfForEachActivity).Name && activity is DsfForEachActivity forEach && foundTestStep.Children != null)
     {
         var replacement = MockActivityIfNecessary(forEach.DataFunc.Handler as IDev2Activity, foundTestStep.Children.ToList()) as Activity;
         forEach.DataFunc.Handler = replacement;
     }
        private void HandleDebug(IDSFDataObject dataObject, IServiceTestStep serviceTestStep)
        {
            if (dataObject.IsDebugMode())
            {
                if (dataObject.IsServiceTestExecution && serviceTestStep != null)
                {
                    var debugItems = TestDebugMessageRepo.Instance.GetDebugItems(dataObject.ResourceID, dataObject.TestName);
                    debugItems = debugItems.Where(state => state.WorkSurfaceMappingId == serviceTestStep.ActivityID).ToList();
                    var debugStates = debugItems.LastOrDefault();

                    var debugItemStaticDataParams = new DebugItemServiceTestStaticDataParams(serviceTestStep.Result.Message, serviceTestStep.Result.RunTestResult == RunResult.TestFailed);
                    var itemToAdd = new DebugItem();
                    itemToAdd.AddRange(debugItemStaticDataParams.GetDebugItemResult());
                    debugStates?.AssertResultList?.Add(itemToAdd);
                }
                DispatchDebugState(dataObject, StateType.Duration, 0);
            }
        }
        private static void GetFinalTestRunResult(IServiceTestStep serviceTestStep, TestRunResult testRunResult)
        {
            var nonPassingSteps = serviceTestStep.Children?.Where(step => step.Type != StepType.Mock && step.Result?.RunTestResult != RunResult.TestPassed).ToList();

            if (nonPassingSteps != null && nonPassingSteps.Count == 0)
            {
                testRunResult.Message       = Messages.Test_PassedResult;
                testRunResult.RunTestResult = RunResult.TestPassed;
            }
            else
            {
                if (nonPassingSteps != null)
                {
                    var failMessage = string.Join(Environment.NewLine, nonPassingSteps.Select(step => step.Result.Message));
                    testRunResult.Message = failMessage;
                }
                testRunResult.RunTestResult = RunResult.TestFailed;
            }
        }
        static void GetFinalTestRunResult(IServiceTestStep serviceTestStep, TestRunResult testRunResult)
        {
            var resultList = new ObservableCollection <TestRunResult>();

            foreach (var testStep in serviceTestStep.Children)
            {
                if (testStep.Result != null)
                {
                    resultList.Add(testStep.Result);
                }
            }

            if (resultList.Count == 0)
            {
                testRunResult.RunTestResult = RunResult.TestPassed;
            }
            else
            {
                testRunResult.RunTestResult = RunResult.TestInvalid;

                var testRunResults = resultList.Where(runResult => runResult.RunTestResult == RunResult.TestInvalid).ToList();
                if (testRunResults.Count > 0)
                {
                    testRunResult.Message       = string.Join(Environment.NewLine, testRunResults.Select(result => result.Message));
                    testRunResult.RunTestResult = RunResult.TestInvalid;
                }
                else
                {
                    var failed = resultList.Any(runResult => runResult.RunTestResult == RunResult.TestFailed);
                    if (failed)
                    {
                        testRunResult.Message       = string.Join(Environment.NewLine, testRunResults.Select(result => result.Message));
                        testRunResult.RunTestResult = RunResult.TestFailed;
                    }
                    else
                    {
                        testRunResult.Message       = Messages.Test_PassedResult;
                        testRunResult.RunTestResult = RunResult.TestPassed;
                    }
                }
            }
        }
 static void MockConstructorExecution(IDSFDataObject dataObject, IServiceTestStep serviceTestStep, ref PluginExecutionDto pluginExecutionDto)
 {
     if (!string.IsNullOrEmpty(serviceTestStep.StepOutputs?[0].Variable))
     {
         try
         {
             var languageExpression = EvaluationFunctions.parseLanguageExpression(serviceTestStep.StepOutputs?[0].Variable, 0);
             if (languageExpression.IsJsonIdentifierExpression)
             {
                 var jToken = JToken.Parse(serviceTestStep.StepOutputs?[0].Value) as JContainer ?? serviceTestStep.StepOutputs?[0].Value.DeserializeToObject();
                 dataObject.Environment.AddToJsonObjects(serviceTestStep.StepOutputs[0].Variable, jToken);
                 pluginExecutionDto.ObjectString = serviceTestStep.StepOutputs[0].Value;
             }
         }
         catch (Exception e)
         {
             dataObject.Environment.Errors.Add(e.Message);
         }
     }
 }
Beispiel #16
0
        void GetFinalTestRunResult(IServiceTestStep serviceTestStep, TestRunResult testRunResult, IDSFDataObject dataObject)
        {
            RegularActivityAssertion(dataObject, serviceTestStep);
            var nonPassingSteps = serviceTestStep.Children?.Where(step => step.Result?.RunTestResult != RunResult.TestPassed).ToList();

            if (nonPassingSteps != null && nonPassingSteps.Count == 0)
            {
                testRunResult.Message       = Messages.Test_PassedResult;
                testRunResult.RunTestResult = RunResult.TestPassed;
            }
            else
            {
                if (nonPassingSteps != null)
                {
                    var failMessage = string.Join(Environment.NewLine, nonPassingSteps.Select(step => step.Result.Message));
                    testRunResult.Message = failMessage;
                }
                testRunResult.RunTestResult = RunResult.TestFailed;
            }
        }
Beispiel #17
0
        public static void UpdateBasedOnFinalResult(IDSFDataObject dataObject, IServiceTestStep stepToBeAsserted, bool testPassed, IList <TestRunResult> testRunResults, string serviceTestFailureMessage)
        {
            var finalResult = new TestRunResult();

            if (testPassed)
            {
                finalResult.RunTestResult = RunResult.TestPassed;
            }
            if (testRunResults.Any(result => result.RunTestResult == RunResult.TestFailed))
            {
                finalResult.RunTestResult = RunResult.TestFailed;
                finalResult.Message       = serviceTestFailureMessage;
            }
            if (testRunResults.Any(result => result.RunTestResult == RunResult.TestInvalid))
            {
                finalResult.RunTestResult = RunResult.TestInvalid;
                finalResult.Message       = serviceTestFailureMessage;
            }
            stepToBeAsserted.Result  = finalResult;
            dataObject.StopExecution = !testPassed;
        }
Beispiel #18
0
 void UpdateToPending(IServiceTestStep serviceTestStep)
 {
     if (serviceTestStep is null)
     {
         return;
     }
     if (serviceTestStep.Result != null)
     {
         serviceTestStep.Result.RunTestResult = RunResult.TestPending;
     }
     else
     {
         serviceTestStep.Result = new TestRunResult {
             RunTestResult = RunResult.TestPending
         };
     }
     UpdateToPending(serviceTestStep.StepOutputs);
     if (serviceTestStep.Children != null && serviceTestStep.Children.Count > 0)
     {
         UpdateToPending(serviceTestStep.Children);
     }
 }
Beispiel #19
0
 private static void GetStepOutputResults(IDSFDataObject dataObject, IServiceTestStep stepToBeAsserted)
 {
     if (stepToBeAsserted?.StepOutputs != null && stepToBeAsserted.StepOutputs.Count > 0)
     {
         if (stepToBeAsserted.Result != null)
         {
             stepToBeAsserted.Result.RunTestResult = RunResult.TestInvalid;
         }
         else
         {
             stepToBeAsserted.Result = new TestRunResult {
                 RunTestResult = RunResult.TestInvalid
             };
         }
         var states = TestDebugMessageRepo.Instance.GetDebugItems(dataObject.ResourceID, dataObject.TestName);
         if (states != null)
         {
             states = states.Where(state => state.ID == stepToBeAsserted.UniqueId).ToList();
             var debugState = states.LastOrDefault();
             UpdateDebugStateWithAssertion(dataObject, stepToBeAsserted, debugState);
         }
     }
 }
        private void RunTestStep(IServiceTestModel selectedServiceTest, IServiceTestStep resTestStep)
        {
            var serviceTestSteps = selectedServiceTest
                                   .TestSteps
                                   .Select(o => o.As <ServiceTestStep>())
                                   .Where(testStep => testStep != null && testStep.ActivityID == resTestStep.ActivityID)
                                   .ToList();

            foreach (var resServiceTestStep in serviceTestSteps)
            {
                UpdateTestStepResult(resServiceTestStep, resTestStep);

                var serviceTestOutputs = resTestStep.StepOutputs;
                if (serviceTestOutputs.Count > 0)
                {
                    resServiceTestStep.StepOutputs = CreateServiceTestOutputFromResult(resTestStep.StepOutputs, resServiceTestStep);
                }
                var children = resTestStep.Children;
                if (children.Count > 0)
                {
                    SetChildrenTestResult(children, resServiceTestStep.Children);
                }
            }
        }
 private void MethodExecution(int update, IDSFDataObject dataObject, PluginExecutionDto pluginExecutionDto, Isolated <PluginRuntimeHandler> appDomain, int index, IDev2MethodInfo dev2MethodInfo, IServiceTestStep serviceTestStep)
 {
     if (serviceTestStep != null)
     {
         if (serviceTestStep.Type == StepType.Mock)
         {
             MockMethodExecution(dataObject, serviceTestStep, dev2MethodInfo, index);
         }
         else
         {
             RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject);
         }
     }
     else
     {
         RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject);
     }
 }