Exemplo n.º 1
0
        public void DsfNativeActivity_DispatchDebugState_After_TestExecution()
        {
            var             parentInstanceID = Guid.NewGuid();
            const StateType StateType        = StateType.After;

            var dataObj = new DsfDataObject(string.Empty, GlobalConstants.NullDataListID)
            {
                IsDebug = true,
                IsOnDemandSimulation   = false,
                IsServiceTestExecution = true,
                EnvironmentID          = Guid.NewGuid(),
                WorkspaceID            = Guid.NewGuid(),
                ServerID           = Guid.NewGuid(),
                ResourceID         = Guid.NewGuid(),
                OriginalInstanceID = Guid.NewGuid(),
                ParentInstanceID   = parentInstanceID.ToString()
            };
            var mockDebugDispatcher = new Mock <IDebugDispatcher>();
            var activity            = new TestActivity(mockDebugDispatcher.Object)
            {
                IsSimulationEnabled = false,
                SimulationMode      = SimulationMode.Never,
                ScenarioID          = Guid.NewGuid().ToString(),
                IsWorkflow          = true,
            };

            var serviceTestModelTO = new ServiceTestModelTO
            {
                TestSteps = new List <IServiceTestStep>
                {
                    new ServiceTestStepTO
                    {
                        UniqueId    = Guid.Parse(activity.UniqueID),
                        Type        = StepType.Assert,
                        StepOutputs = new ObservableCollection <IServiceTestOutput>
                        {
                            new ServiceTestOutputTO
                            {
                                AssertOp = "=",
                                Value    = "Bob",
                                Variable = "[[var]]"
                            }
                        }
                    }
                }
            };

            dataObj.ServiceTest = serviceTestModelTO;

            var cat = new Mock <IResourceCatalog>();
            var res = new Mock <IResource>();

            res.Setup(a => a.ResourceName).Returns("bob");
            cat.Setup(a => a.GetResource(Guid.Empty, It.IsAny <Guid>())).Returns(res.Object);
            activity.ResourceCatalog = cat.Object;
            activity.TestDispatchDebugState(dataObj, StateType);
            Assert.IsTrue(dataObj.StopExecution);
            Assert.AreEqual(RunResult.TestFailed, serviceTestModelTO.TestSteps[0].Result.RunTestResult);
        }
Exemplo n.º 2
0
        static void VerifyDispatcherWriteCount(DsfDataObject dataObject, int expectedCount)
        {
            var dispatcher = new Mock <IDebugDispatcher>();

            dispatcher.Setup(d => d.Write(It.IsAny <IDebugState>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <IDebugState> >())).Verifiable();

            var activity = new TestActivity(dispatcher.Object);

            Run(activity, dataObject,
                () => dispatcher.Verify(d => d.Write(It.IsAny <IDebugState>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <IDebugState> >()), Times.Exactly(expectedCount)));
        }
Exemplo n.º 3
0
        public void DsfNativeActivity_Constructor_OnError_PropertiesInitialized()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var activity = new TestActivity(new Mock <IDebugDispatcher>().Object);

            //------------Assert Results-------------------------
            Assert.IsTrue(string.IsNullOrEmpty(activity.OnErrorVariable));
            Assert.IsTrue(string.IsNullOrEmpty(activity.OnErrorWorkflow));
            Assert.IsFalse(activity.IsEndedOnError);
        }
Exemplo n.º 4
0
        public void DsfNativeActivity_UnitTest_InitializeDebugState_SetsPropertiesCorrectly()
        {
            var             parentInstanceID = Guid.NewGuid();
            var             remoteID         = Guid.Empty;
            const bool      HasError         = true;
            const string    ErrorMessage     = "Error occurred..";
            const StateType StateType        = StateType.All;

            var dataObj = new DsfDataObject(string.Empty, GlobalConstants.NullDataListID)
            {
                IsDebug = true,
                IsOnDemandSimulation = false,
                EnvironmentID        = Guid.NewGuid(),
                WorkspaceID          = Guid.NewGuid(),
                ServerID             = Guid.NewGuid(),
                ResourceID           = Guid.NewGuid(),
                OriginalInstanceID   = Guid.NewGuid(),
                ParentInstanceID     = parentInstanceID.ToString()
            };

            var activity = new TestActivity(new Mock <IDebugDispatcher>().Object)
            {
                IsSimulationEnabled = false,
                SimulationMode      = SimulationMode.Never,
                ScenarioID          = Guid.NewGuid().ToString(),
                IsWorkflow          = true,
            };
            var cat = new Mock <IResourceCatalog>();
            var res = new Mock <IResource>();

            res.Setup(a => a.ResourceName).Returns("bob");
            cat.Setup(a => a.GetResource(Guid.Empty, It.IsAny <Guid>())).Returns(res.Object);
            activity.SetResourceCatalog(cat.Object);
            var actual = activity.TestInitializeDebugState(StateType, dataObj, remoteID, HasError, ErrorMessage);

            Assert.AreEqual(activity.UniqueGuid, actual.ID, "DispatchDebugState did not set the DebugState's ID.");
            Assert.AreEqual(parentInstanceID, actual.ParentID, "DispatchDebugState did not set the DebugState's ParentID.");
            Assert.AreEqual(StateType, actual.StateType, "DispatchDebugState did not set the DebugState's StateType.");
            Assert.AreEqual(HasError, actual.HasError, "DispatchDebugState did not set the DebugState's HasError.");
            Assert.AreEqual(ErrorMessage, actual.ErrorMessage, "DispatchDebugState did not set the DebugState's ErrorMessage.");
            Assert.AreEqual("localhost", actual.Server, "DispatchDebugState did not set the DebugState's Server.");

            Assert.AreEqual(dataObj.WorkspaceID, actual.WorkspaceID, "DispatchDebugState did not set the DebugState's WorkspaceID.");
            Assert.AreEqual(dataObj.ServerID, actual.ServerID, "DispatchDebugState did not set the DebugState's ServerID.");
            Assert.AreEqual(dataObj.ResourceID, actual.OriginatingResourceID, "DispatchDebugState did not set the DebugState's OriginatingResourceID.");
            Assert.AreEqual(dataObj.OriginalInstanceID, actual.OriginalInstanceID, "DispatchDebugState did not set the DebugState's OriginalInstanceID.");
            Assert.AreEqual(activity.DisplayName, actual.DisplayName, "DispatchDebugState did not set the DebugState's DisplayName.");
            Assert.IsFalse(actual.IsSimulation, "DispatchDebugState did not set the DebugState's IsSimulation.");
            Assert.AreEqual(ActivityType.Workflow, actual.ActivityType, "DispatchDebugState did not set the DebugState's ActivityType.");

            Assert.AreEqual(dataObj.DebugEnvironmentId, actual.EnvironmentID, "DispatchDebugState did not set the DebugState's EnvironmentID.");
        }
Exemplo n.º 5
0
        static void VerifyDispatcherWriteCount(DsfDataObject dataObject, int expectedCount)
        {
            var dispatcher = new Mock <IDebugDispatcher>();

            dispatcher.Setup(d => d.Write(new WriteArgs {
                debugState = It.IsAny <IDebugState>(), isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
            })).Verifiable();

            var activity = new TestActivity(dispatcher.Object);

            Run(activity, dataObject,
                () => dispatcher.Verify(d => d.Write(new WriteArgs {
                debugState = It.IsAny <IDebugState>(), isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
            }), Times.Exactly(expectedCount)));
        }
        public void DsfAbstractFileActivity_DecryptForShowPassword_ShouldShowTextType()
        {
            //------------Setup for test--------------------------
            const string password = "******";
            var          act      = new TestActivity("TestActivity")
            {
                Password = password
            };
            var privateObject     = new Warewolf.Testing.PrivateObject(act);
            var decryptedPassword = privateObject.GetProperty("DecryptedPassword");

            //------------Execute Test---------------------------
            //------------Assert Results-------------------------
            Assert.AreEqual(password, decryptedPassword);
        }
Exemplo n.º 7
0
        public void DsfNativeActivity_DispatchDebugState_After_SetsEndTimeCorrectly()
        {
            var             parentInstanceID = Guid.NewGuid();
            const StateType StateType        = StateType.After;

            var dataObj = new DsfDataObject(string.Empty, GlobalConstants.NullDataListID)
            {
                IsDebug = true,
                IsOnDemandSimulation = false,
                EnvironmentID        = Guid.NewGuid(),
                WorkspaceID          = Guid.NewGuid(),
                ServerID             = Guid.NewGuid(),
                ResourceID           = Guid.NewGuid(),
                OriginalInstanceID   = Guid.NewGuid(),
                ParentInstanceID     = parentInstanceID.ToString()
            };
            IDebugState passedDebugState    = null;
            var         mockDebugDispatcher = new Mock <IDebugDispatcher>();

            mockDebugDispatcher.Setup(dispatcher => dispatcher.Write(It.IsAny <IDebugState>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <IDebugState> >()))
            .Callback((IDebugState ds, bool isTestExecution, bool isDebugFromWeb, string testName, bool isRemoteInvoke, string remoteID, string parentId, IList <IDebugState> remoteItems) =>
            {
                passedDebugState = ds;
            });
            var activity = new TestActivity(mockDebugDispatcher.Object)
            {
                IsSimulationEnabled = false,
                SimulationMode      = SimulationMode.Never,
                ScenarioID          = Guid.NewGuid().ToString(),
                IsWorkflow          = true,
            };
            var cat = new Mock <IResourceCatalog>();
            var res = new Mock <IResource>();

            res.Setup(a => a.ResourceName).Returns("bob");
            cat.Setup(a => a.GetResource(Guid.Empty, It.IsAny <Guid>())).Returns(res.Object);
            activity.ResourceCatalog = cat.Object;
            activity.TestDispatchDebugState(dataObj, StateType);
            Assert.IsNotNull(passedDebugState);
            Assert.IsNotNull(passedDebugState.EndTime);
            Assert.AreNotEqual(DateTime.MinValue, passedDebugState.StartTime);
            Assert.AreNotEqual(DateTime.MinValue, passedDebugState.EndTime);
        }
Exemplo n.º 8
0
        public void DsfAbstractFileActivity_FileOutputStringError_ShouldExistInEnvironmentErrors()
        {
            //------------Setup for test--------------------------
            var env  = new ExecutionEnvironment();
            var data = new Mock <IDSFDataObject>();

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

            var newGuid   = Guid.NewGuid();
            var inputPath = string.Concat(TestContext.TestRunDirectory, "\\", newGuid + "[[CompanyName]]2.txt");
            var act       = new TestActivity("TestActivity")
            {
                InputPath = inputPath, Result = "[[CompanyName]]"
            };



            //------------Execute Test---------------------------
            act.Execute(data.Object, 0);
            //------------Assert Results-------------------------

            Assert.AreEqual("someString error", env.FetchErrors());
        }
Exemplo n.º 9
0
        public void DsfNativeActivity_DispatchDebugState_Before_SetsStartTimeCorrectly()
        {
            var             parentInstanceID = Guid.NewGuid();
            const StateType StateType        = StateType.Before;

            var dataObj = new DsfDataObject(string.Empty, GlobalConstants.NullDataListID)
            {
                IsDebug = true,
                IsOnDemandSimulation = false,
                EnvironmentID        = Guid.NewGuid(),
                WorkspaceID          = Guid.NewGuid(),
                ServerID             = Guid.NewGuid(),
                ResourceID           = Guid.NewGuid(),
                OriginalInstanceID   = Guid.NewGuid(),
                ParentInstanceID     = parentInstanceID.ToString()
            };

            var activity = new TestActivity
            {
                IsSimulationEnabled = false,
                SimulationMode      = SimulationMode.Never,
                ScenarioID          = Guid.NewGuid().ToString(),
                IsWorkflow          = true,
            };
            var cat = new Mock <IResourceCatalog>();
            var res = new Mock <IResource>();

            res.Setup(a => a.ResourceName).Returns("bob");
            cat.Setup(a => a.GetResource(Guid.Empty, It.IsAny <Guid>())).Returns(res.Object);
            activity.ResourceCatalog = cat.Object;
            var actual = activity.TestDispatchDebugState(dataObj, StateType);

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.StartTime);
            Assert.AreNotEqual(DateTime.MinValue, actual.StartTime);
            Assert.AreEqual(DateTime.MinValue, actual.EndTime);
        }
        public void ExecuteSimulation_NoValidSimulationKeyInRepository_Expected_NoDataInjectedIntoDataList()
        {
            var dataObject = CreateDataObject(false, true);
            var compiler   = DataListFactory.CreateDataListCompiler();

            ErrorResultTO errors;

            dataObject.DataListID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), string.Empty, _simulationShape.ToStringBuilder(), out errors);

            var simulationDataID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), _simulationData, _simulationShape.ToStringBuilder(), out errors);

            compiler.FetchBinaryDataList(simulationDataID, out errors);

            #region Setup simulation repository

            var random        = new Random();
            var simulationKey = new SimulationKey
            {
                WorkflowID = "TestActivity", // class name of activity used below
                ActivityID = string.Format("AID-{0}", random.Next()),
                ScenarioID = string.Format("SID-{0}", random.Next())
            };
            //var simulationResult = new SimulationResult {
            //    Key = simulationKey,
            //    Value = simulationDataList
            //};
            //SimulationRepository.Instance.Save(simulationResult);

            #endregion

            var activity = new TestActivity(DebugDispatcher.Instance)
            {
                SimulationMode = SimulationMode.Always,
                UniqueID       = simulationKey.ActivityID,
                ScenarioID     = simulationKey.ScenarioID
            };

            Run(activity, dataObject,
                () =>
            {
                //SimulationRepository.Instance.Delete(simulationResult);

                ErrorResultTO resultErrors;
                var resultDataList = compiler.FetchBinaryDataList(dataObject.DataListID, out resultErrors);
                if (errors.HasErrors())
                {
                    Assert.Fail("Errors fetching Binary DataList result");
                }

                // See SimulationData.xml in XML folder
                try
                {
                    ValidateRecordSet(resultDataList, "Golfer", new[]
                    {
                        new KeyValuePair <string, string[]>("FirstName", new[]
                        {
                            "Tiger", "Ernie"
                        }),
                        new KeyValuePair <string, string[]>("LastName", new[]
                        {
                            "Woods", "Els"
                        })
                    });
                }
                catch (AssertFailedException)
                {
                    // we know that we could not find the value in the datalist
                    Assert.IsTrue(true);
                }


                try
                {
                    ValidateScalar(resultDataList, "A", "6");
                }
                catch (AssertFailedException)
                {
                    // we know that we could not find the value in the datalist
                    Assert.IsTrue(true);
                }
            });
        }
Exemplo n.º 11
0
 public bool Equals(TestActivity other)
 {
     return(ReferenceEquals(this, other));
 }