public void WorkflowDesignerViewModel_LinkName_SavedDebugData_ShouldReturnUrlWithDataListUsingSavedData() { //------------Setup for test-------------------------- var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = CreateFlowNode(Guid.NewGuid(), "CanSaveTest", true, typeof(TestActivity)) } }; #region Setup viewModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); resourceRep.Setup(repository => repository.Save(It.IsAny<IResourceModel>())).Verifiable(); var resourceModel = new Mock<IContextualResourceModel>(); var mockEnvironmentModel = new Mock<IEnvironmentModel>(); var mockConnection = new Mock<IEnvironmentConnection>(); mockConnection.Setup(connection => connection.IsConnected).Returns(true); mockConnection.Setup(connection => connection.WebServerUri).Returns(new Uri("http://myMachineName:3142")); mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object); resourceModel.Setup(m => m.Environment).Returns(mockEnvironmentModel.Object); resourceModel.Setup(m => m.Environment.IsConnected).Returns(true); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(m => m.Environment.Connection).Returns(mockConnection.Object); resourceModel.Setup(model => model.IsNewWorkflow).Returns(true); resourceModel.Setup(model => model.Category).Returns("myservice"); resourceModel.Setup(model => model.ResourceName).Returns("myservice"); resourceModel.Setup(model => model.DataList).Returns(StringResourcesTest.DebugInputWindow_DataList); var workflowInputDataViewModel = WorkflowInputDataViewModel.Create(resourceModel.Object); workflowInputDataViewModel.LoadWorkflowInputs(); workflowInputDataViewModel.WorkflowInputs[0].Value = "1"; workflowInputDataViewModel.WorkflowInputs[1].Value = "2"; workflowInputDataViewModel.DoSaveActions(); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); workflowHelper.Setup(helper => helper.SerializeWorkflow(It.IsAny<ModelService>())).Returns(new StringBuilder("my workflow")); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); resourceModel.SetupProperty(model => model.WorkflowXaml); #endregion //------------Assert Preconditions------------------- Assert.IsNull(resourceModel.Object.WorkflowXaml); //------------Execute Test--------------------------- var workflowLink = viewModel.GetWorkflowLink(); var displayWorkflowLink = viewModel.DisplayWorkflowLink; //------------Assert Results------------------------- Assert.AreEqual("http://mymachinename:3142/secure/myservice.json?scalar1=1&scalar2=2&wid=00000000-0000-0000-0000-000000000000", workflowLink); Assert.AreEqual("http://mymachinename:3142/secure/myservice.json?scalar1=1&scalar2=2", displayWorkflowLink); workflowInputDataViewModel.WorkflowInputs[0].Value = ""; workflowInputDataViewModel.WorkflowInputs[1].Value = ""; workflowInputDataViewModel.DoSaveActions(); }
static void Verify_DebugSelectionChanged(ActivitySelectionType selectionType, Type selectedActivityType, bool selectsModelItem = true) { //----------------------- Setup -----------------------// var ID = Guid.NewGuid(); var states = new List<IDebugState> { new DebugState { DisplayName = "SelectionChangedTest1", ID = ID, WorkSurfaceMappingId = ID } }; ID = Guid.NewGuid(); if (selectionType == ActivitySelectionType.Add || selectionType == ActivitySelectionType.Remove) { states.Add(new DebugState { DisplayName = "SelectionChangedTest2", ID = ID, WorkSurfaceMappingId = ID }); } #region Setup workflow FlowNode prevNode = null; var nodes = new List<FlowNode>(); foreach (var node in states.Select(state => CreateFlowNode(state.ID, state.DisplayName, selectsModelItem, selectedActivityType))) { if (prevNode != null) { var flowStep = prevNode as FlowStep; if (flowStep != null) { flowStep.Next = node; } } nodes.Add(node); prevNode = node; } var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = nodes[0] } }; #endregion #region Setup viewModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(m => m.ResourceName).Returns("Some resource name 5"); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); #endregion //----------------------- Execute -----------------------// var i = 0; foreach (var debugState in states) { if (selectionType == ActivitySelectionType.None || selectionType == ActivitySelectionType.Remove) { // Ensure we have something to clear/remove EventPublishers.Studio.Publish(new DebugSelectionChangedEventArgs { DebugState = debugState, SelectionType = ActivitySelectionType.Add }); // Only issue change event after all have been added if (++i == states.Count) { var selectionBefore = viewModel.Designer.Context.Items.GetValue<Selection>(); Assert.AreEqual(states.Count, selectionBefore.SelectionCount); EventPublishers.Studio.Publish(new DebugSelectionChangedEventArgs { DebugState = debugState, SelectionType = selectionType }); } } else { EventPublishers.Studio.Publish(new DebugSelectionChangedEventArgs { DebugState = debugState, SelectionType = selectionType }); } } //----------------------- Assert -----------------------// var selection = viewModel.Designer.Context.Items.GetValue<Selection>(); switch (selectionType) { case ActivitySelectionType.None: Assert.AreEqual(0, selection.SelectionCount); Assert.AreEqual(1, viewModel.BringIntoViewHitCount); // 1 because we had to add something first! Assert.AreEqual(0, viewModel.SelectedDebugModelItems.Count); break; case ActivitySelectionType.Single: Assert.AreEqual(1, selection.SelectionCount); Assert.AreEqual(1, viewModel.BringIntoViewHitCount); Assert.AreEqual(1, viewModel.SelectedDebugModelItems.Count); break; case ActivitySelectionType.Add: Assert.AreEqual(2, selection.SelectionCount); Assert.AreEqual(2, viewModel.BringIntoViewHitCount); Assert.AreEqual(2, viewModel.SelectedDebugModelItems.Count); break; case ActivitySelectionType.Remove: Assert.AreEqual(2, selection.SelectionCount); Assert.AreEqual(2, viewModel.BringIntoViewHitCount); // 2 because we had to add something first! Assert.AreEqual(1, viewModel.SelectedDebugModelItems.Count); break; } foreach (var modelItem in selection.SelectedObjects) { Assert.AreEqual(selectedActivityType, modelItem.ItemType); if (selectsModelItem) { var actualID = selectedActivityType == typeof(FlowDecision) ? Guid.Parse(((TestDecisionActivity)modelItem.GetProperty("Condition")).UniqueID) : ModelItemUtils.GetUniqueID(modelItem); var actualState = states.FirstOrDefault(s => s.ID == actualID); Assert.IsNotNull(actualState); } } viewModel.Dispose(); }
public void WorkflowDesignerViewModel_LinkName_HasDataListNoInputs_ShouldReturnUrlEmptyDataListPortion() { //------------Setup for test-------------------------- var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = CreateFlowNode(Guid.NewGuid(), "CanSaveTest", true, typeof(TestActivity)) } }; #region Setup viewModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); resourceRep.Setup(repository => repository.Save(It.IsAny<IResourceModel>())).Verifiable(); var resourceModel = new Mock<IContextualResourceModel>(); var mockEnvironmentModel = new Mock<IEnvironmentModel>(); var mockConnection = new Mock<IEnvironmentConnection>(); mockConnection.Setup(connection => connection.IsConnected).Returns(true); mockConnection.Setup(connection => connection.WebServerUri).Returns(new Uri("http://myMachineName:3142")); mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object); resourceModel.Setup(m => m.Environment).Returns(mockEnvironmentModel.Object); resourceModel.Setup(m => m.Environment.IsConnected).Returns(true); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(m => m.Environment.Connection).Returns(mockConnection.Object); resourceModel.Setup(model => model.IsNewWorkflow).Returns(true); resourceModel.Setup(model => model.Category).Returns("myservice"); resourceModel.Setup(model => model.ResourceName).Returns("myservice"); resourceModel.Setup(model => model.DataList).Returns(StringResourcesTest.DebugInputWindow_NoInputs_XMLData); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); workflowHelper.Setup(helper => helper.SerializeWorkflow(It.IsAny<ModelService>())).Returns(new StringBuilder("my workflow")); var mockPopController = new Mock<IPopupController>(); mockPopController.Setup(controller => controller.ShowNoInputsSelectedWhenClickLink()).Verifiable(); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object, mockPopController.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); resourceModel.SetupProperty(model => model.WorkflowXaml); #endregion //------------Assert Preconditions------------------- Assert.IsNull(resourceModel.Object.WorkflowXaml); //------------Execute Test--------------------------- var workflowLink = viewModel.GetWorkflowLink(); var displayWorkflowLink = viewModel.DisplayWorkflowLink; viewModel.OpenWorkflowLinkCommand.Execute("Do not perform action"); //------------Assert Results------------------------- Assert.AreEqual("http://mymachinename:3142/secure/myservice.json?<DataList></DataList>&wid=00000000-0000-0000-0000-000000000000", workflowLink); Assert.AreEqual("http://mymachinename:3142/secure/myservice.json?<DataList></DataList>", displayWorkflowLink); mockPopController.Verify(controller => controller.ShowNoInputsSelectedWhenClickLink(), Times.Once()); }
public void WorkflowDesignerViewModel_HandleUpdateResourceMessage_WhenMessageHasErrors_ResourceModelShouldHaveErrors() { //------------Setup for test-------------------------- var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = CreateFlowNode(Guid.NewGuid(), "CanSaveTest", true, typeof(TestActivity)) } }; var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); resourceRep.Setup(repository => repository.Save(It.IsAny<IResourceModel>())).Verifiable(); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(model => model.IsNewWorkflow).Returns(false); resourceModel.Setup(m => m.ResourceName).Returns("Some resource name 11"); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); resourceModel.SetupGet(model => model.Errors); resourceModel.Setup(model => model.Errors).Returns(new ObservableReadOnlyList<IErrorInfo>(new List<IErrorInfo> { new ErrorInfo() })); resourceModel.Setup(model => model.AddError(It.IsAny<IErrorInfo>())).Verifiable(); var updateResourceMessage = new UpdateResourceMessage(resourceModel.Object); //------------Execute Test--------------------------- viewModel.Handle(updateResourceMessage); //------------Assert Results------------------------- resourceModel.Verify(model => model.AddError(It.IsAny<IErrorInfo>()), Times.Once()); }
public void WorkflowDesignerViewModel_ExpandAllCommand_True_RequestExpandAll() { //----------------------- Setup -----------------------// var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = CreateFlowNode(Guid.NewGuid(), "CanSaveTest", true, typeof(TestActivity)) } }; #region Setup viewModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(model => model.ResourceName).Returns("Some workflow 332"); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); viewModel.SetupRequestExapandAll(); #endregion const bool ExpectedCanSave = true; resourceModel.Setup(m => m.IsAuthorized(AuthorizationContext.Contribute)).Returns(ExpectedCanSave).Verifiable(); //----------------------- Execute -----------------------// Assert.IsFalse(viewModel.RequestedExpandAll); viewModel.ExpandAllCommand.Execute(true); viewModel.Dispose(); //----------------------- Assert -----------------------// Assert.IsTrue(viewModel.RequestedExpandAll); }
public void WorkflowDesignerViewModel_DoWorkspaceSave_NotNewResourceModel_ShouldCallSave() { //------------Setup for test-------------------------- var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = CreateFlowNode(Guid.NewGuid(), "CanSaveTest", true, typeof(TestActivity)) } }; #region Setup viewModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); resourceRep.Setup(repository => repository.Save(It.IsAny<IResourceModel>())).Verifiable(); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(model => model.IsNewWorkflow).Returns(false); resourceModel.Setup(m => m.ResourceName).Returns("Some resource name 9"); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); resourceModel.SetupProperty(model => model.WorkflowXaml); #endregion //------------Assert Preconditions------------------- Assert.IsNull(resourceModel.Object.WorkflowXaml); //------------Execute Test--------------------------- viewModel.DoWorkspaceSave(); //------------Assert Results------------------------- resourceRep.Verify(repository => repository.Save(It.IsAny<IResourceModel>()), Times.Never()); Assert.IsNull(resourceModel.Object.WorkflowXaml); }
public void WorkflowDesignerViewModel_DebugSelectionChanged_NullDebugState_DoesNothing() { //----------------------- Setup -----------------------// var workflow = new ActivityBuilder { Implementation = new Flowchart { StartNode = CreateFlowNode(Guid.NewGuid(), "SelectionChangedTest1", true, typeof(TestActivity)) } }; #region Setup viewModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage()); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(m => m.ResourceName).Returns("Some resource name 7"); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); viewModel.InitializeDesigner(new Dictionary<Type, Type>()); #endregion //----------------------- Execute -----------------------// EventPublishers.Studio.Publish(new DebugSelectionChangedEventArgs { DebugState = null, SelectionType = ActivitySelectionType.Single }); var result = viewModel.BringIntoViewHitCount; viewModel.Dispose(); //----------------------- Assert -----------------------// Assert.AreEqual(0, result); }