// BUG 9143 - 2013.07.03 - TWR - added static void TestModelServiceModelChangedSelfReference(bool isSelfReference) { #region Setup view model constructor parameters var repo = new Mock<IResourceRepository>(); var env = EnviromentRepositoryTest.CreateMockEnvironment(); env.Setup(e => e.ResourceRepository).Returns(repo.Object); var crm = new Mock<IContextualResourceModel>(); crm.Setup(r => r.Environment).Returns(env.Object); crm.Setup(r => r.ResourceName).Returns("Test"); var wh = new Mock<IWorkflowHelper>(); #endregion var properties = new Dictionary<string, Mock<ModelProperty>>(); var propertyCollection = new Mock<ModelPropertyCollection>(); foreach (var propertyName in WorkflowDesignerViewModel.SelfConnectProperties) { var prop = new Mock<ModelProperty>(); prop.Setup(p => p.ClearValue()).Verifiable(); properties.Add(propertyName, prop); propertyCollection.Protected().Setup<ModelProperty>("Find", propertyName, true).Returns(prop.Object); } var source = new Mock<ModelItem>(); source.Setup(s => s.Properties).Returns(propertyCollection.Object); var target = isSelfReference ? source : new Mock<ModelItem>(); var info = new Mock<ModelChangeInfo>(); info.Setup(i => i.ModelChangeType).Returns(ModelChangeType.PropertyChanged); info.Setup(i => i.Subject).Returns(source.Object); info.Setup(i => i.Value).Returns(target.Object); var args = new Mock<ModelChangedEventArgs>(); args.Setup(m => m.ModelChangeInfo).Returns(info.Object); var wfd = new WorkflowDesignerViewModelMock(crm.Object, wh.Object); foreach (var propertyName in WorkflowDesignerViewModel.SelfConnectProperties) { info.Setup(i => i.PropertyName).Returns(propertyName); wfd.TestModelServiceModelChanged(args.Object); var prop = properties[propertyName]; if (isSelfReference) { prop.Verify(p => p.ClearValue(), Times.Once()); } else { prop.Verify(p => p.ClearValue(), Times.Never()); } } wfd.Dispose(); }
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_UnitTest_ViewModelModelChanged_ExpectFirstFocusDoesNotReflectEdit() { var ok = true; var msg = string.Empty; var t = new Thread(() => { try { #region Setup viewModel var workflow = new ActivityBuilder(); var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.SetupAllProperties(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); StringBuilder xamlBuilder = new StringBuilder(StringResources.xmlServiceDefinition); resourceModel.Object.WorkflowXaml = new StringBuilder("<a/>"); resourceModel.Object.ResourceName = "Test"; var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); workflowHelper.Setup(h => h.SanitizeXaml(It.IsAny<StringBuilder>())).Returns(xamlBuilder); workflowHelper.Setup(h => h.SerializeWorkflow(It.IsAny<ModelService>())).Returns(new StringBuilder("<x></x>")); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object) { ServiceDefinition = xamlBuilder }; #endregion #region setup Mock ModelItem var properties = new Dictionary<string, Mock<ModelProperty>>(); var propertyCollection = new Mock<ModelPropertyCollection>(); var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment var testAct = DsfActivityFactory.CreateDsfActivity(resourceModel.Object, new DsfActivity(), true, environmentRepository, true); var prop = new Mock<ModelProperty>(); prop.Setup(p => p.SetValue(It.IsAny<DsfActivity>())).Verifiable(); prop.Setup(p => p.ComputedValue).Returns(testAct); properties.Add("Action", prop); propertyCollection.Protected().Setup<ModelProperty>("Find", "Action", true).Returns(prop.Object); var source = new Mock<ModelItem>(); source.Setup(s => s.Properties).Returns(propertyCollection.Object); source.Setup(s => s.ItemType).Returns(typeof(FlowStep)); #endregion #region setup mock to change properties //mock item adding - this is obsolete functionality but not refactored due to overhead var args = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object }); #pragma warning restore 618 #endregion //Execute var workSurfaceKey = WorkSurfaceKeyFactory.CreateKey(resourceModel.Object); OpeningWorkflowsHelper.AddWorkflowWaitingForFirstFocusLoss(workSurfaceKey); resourceModel.Object.IsWorkflowSaved = true; viewModel.TestWorkflowDesignerModelChanged(); viewModel.Dispose(); OpeningWorkflowsHelper.RemoveWorkflowWaitingForFirstFocusLoss(workSurfaceKey); //Verify Assert.IsTrue(resourceModel.Object.IsWorkflowSaved); Assert.IsTrue(resourceModel.Object.ResourceName.IndexOf("*", StringComparison.Ordinal) < 0); StringAssert.Contains("<x></x>", resourceModel.Object.WorkflowXaml.ToString()); Assert.AreEqual("<x></x>", resourceModel.Object.WorkflowXaml.ToString()); } catch (Exception e) { ok = false; msg = e.Message + " -> " + e.StackTrace; } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); Assert.IsTrue(ok, msg); }
public void WorkflowDesignerViewModel_UnitTest_ViewModelModelChanged_ExpectMarksResourceIsWorkflowSavedFalse() { var ok = true; var msg = string.Empty; var t = new Thread(() => { try { #region Setup viewModel var workflow = new ActivityBuilder(); var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(r => r.ResourceName).Returns("Test"); StringBuilder xamlBuilder = new StringBuilder(StringResources.xmlServiceDefinition); resourceModel.Setup(res => res.WorkflowXaml).Returns(xamlBuilder); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); workflowHelper.Setup(h => h.SanitizeXaml(It.IsAny<StringBuilder>())).Returns(xamlBuilder); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); //viewModel.InitializeDesigner(new Dictionary<Type, Type>()); #endregion #region setup Mock ModelItem var properties = new Dictionary<string, Mock<ModelProperty>>(); var propertyCollection = new Mock<ModelPropertyCollection>(); var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment var testAct = DsfActivityFactory.CreateDsfActivity(resourceModel.Object, new DsfActivity(), true, environmentRepository, true); var prop = new Mock<ModelProperty>(); prop.Setup(p => p.SetValue(It.IsAny<DsfActivity>())).Verifiable(); prop.Setup(p => p.ComputedValue).Returns(testAct); properties.Add("Action", prop); propertyCollection.Protected().Setup<ModelProperty>("Find", "Action", true).Returns(prop.Object); var source = new Mock<ModelItem>(); source.Setup(s => s.Properties).Returns(propertyCollection.Object); source.Setup(s => s.ItemType).Returns(typeof(FlowStep)); #endregion #region setup mock to change properties //mock item adding - this is obsolote functionality but not refactored due to overhead var args = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object }); #pragma warning restore 618 #endregion //Execute viewModel.TestWorkflowDesignerModelChangedWithNullSender(); viewModel.Dispose(); //Verify prop.Verify(p => p.SetValue(It.IsAny<DsfActivity>()), Times.Never()); Assert.IsFalse(resourceModel.Object.IsWorkflowSaved); } catch (Exception e) { ok = false; msg = e.Message + " -> " + e.StackTrace; } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); Assert.IsTrue(ok, msg); }
public void WorkflowDesignerViewModel_PerformAddItems_ModelItemWithUniqueID_NewIDAssigned() { var notExpected = Guid.NewGuid().ToString(); #region Setup view model constructor parameters var repo = new Mock<IResourceRepository>(); var env = EnviromentRepositoryTest.CreateMockEnvironment(); env.Setup(e => e.ResourceRepository).Returns(repo.Object); var crm = new Mock<IContextualResourceModel>(); crm.Setup(r => r.Environment).Returns(env.Object); crm.Setup(r => r.ResourceName).Returns("Test"); crm.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition)); var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(new ActivityBuilder()); #endregion #region setup Mock ModelItem var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment var testAct = DsfActivityFactory.CreateDsfActivity(crm.Object, new DsfActivity(), true, environmentRepository, true); (testAct as IDev2Activity).UniqueID = notExpected; var prop = new Mock<ModelProperty>(); prop.Setup(p => p.ComputedValue).Returns(testAct); var source = new Mock<ModelItem>(); source.Setup(c => c.Content).Returns(prop.Object); #endregion #region setup mock to change properties //mock item adding - this is obsolote functionality but not refactored due to overhead var args = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object }); #pragma warning restore 618 #endregion var wd = new WorkflowDesignerViewModelMock(crm.Object, workflowHelper.Object, new Mock<IEventAggregator>().Object); // Execute unit var actual = wd.TestPerformAddItems(source.Object); wd.Dispose(); //Assert Unique ID has changed Assert.IsNotNull(actual); Assert.IsNotNull(actual.Content); if (actual.Content != null) { IDev2Activity dev2Activity = actual.Content.ComputedValue as IDev2Activity; Assert.IsNotNull(dev2Activity); // ReSharper disable ConditionIsAlwaysTrueOrFalse if (dev2Activity != null) // ReSharper restore ConditionIsAlwaysTrueOrFalse { Assert.AreNotEqual(notExpected, dev2Activity.UniqueID, "Activity ID not changed"); } } }
public void WorkflowDesignerViewModel_PerformAddItems_SwitchActivity_SwitchMessageWithIsNewTruePublished() { #region Setup view model constructor parameters var repo = new Mock<IResourceRepository>(); var env = EnviromentRepositoryTest.CreateMockEnvironment(); env.Setup(e => e.ResourceRepository).Returns(repo.Object); var crm = new Mock<IContextualResourceModel>(); crm.Setup(r => r.Environment).Returns(env.Object); crm.Setup(r => r.ResourceName).Returns("Test"); crm.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition)); var wh = new Mock<IWorkflowHelper>(); #endregion #region setup Mock ModelItem var properties = new Dictionary<string, Mock<ModelProperty>>(); var propertyCollection = new Mock<ModelPropertyCollection>(); var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment var testAct = DsfActivityFactory.CreateDsfActivity(crm.Object, new DsfActivity(), true, environmentRepository, true); var prop = new Mock<ModelProperty>(); prop.Setup(p => p.ComputedValue).Returns(testAct); properties.Add("Action", prop); propertyCollection.Protected().Setup<ModelProperty>("Find", "Action", true).Returns(prop.Object); var source = new Mock<ModelItem>(); source.Setup(s => s.Properties).Returns(propertyCollection.Object); source.Setup(s => s.ItemType).Returns(typeof(FlowSwitch<string>)); #endregion #region setup mock to change properties //mock item adding - this is obsolote functionality but not refactored due to overhead var args = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object }); #pragma warning restore 618 #endregion #region setup mock ModelChangedEventArgs var eventArgs = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 eventArgs.Setup(c => c.ItemsAdded).Returns(new List<ModelItem> { source.Object }); #pragma warning restore 618 #endregion #region setup event aggregator #endregion var eventAggregator = new Mock<IEventAggregator>(); var wd = new WorkflowDesignerViewModelMock(crm.Object, wh.Object, eventAggregator.Object); var expectedMessage = new ConfigureSwitchExpressionMessage { ModelItem = source.Object, EnvironmentModel = crm.Object.Environment, IsNew = true }; eventAggregator.Setup(c => c.Publish(It.IsAny<ConfigureSwitchExpressionMessage>())) .Callback<Object>(actualMessage => Assert.AreEqual(expectedMessage.IsNew, ((ConfigureSwitchExpressionMessage)actualMessage).IsNew, "Wrong message published")) .Verifiable(); // Execute unit wd.TestModelServiceModelChanged(eventArgs.Object); wd.Dispose(); eventAggregator.Verify(c => c.Publish(It.IsAny<ConfigureSwitchExpressionMessage>()), Times.Once(), "Dropping a switch onto an auto connect node did not publish configure switch message"); }
public void WorkflowDesignerViewModel_PerformAddItems_ForEachActivity_DragOnRemoteWorkflow() { #region Setup view model constructor parameters if (Application.Current != null) { try { Application.Current.MainWindow = null; } catch (InvalidOperationException) { } } var repo = new Mock<IResourceRepository>(); var mockResourceModel = new Mock<IContextualResourceModel>(); mockResourceModel.Setup(model => model.ID).Returns(Guid.NewGuid()); var mockRemoteEnvironment = new Mock<IEnvironmentModel>(); var remoteServerID = Guid.NewGuid(); mockRemoteEnvironment.Setup(model => model.ID).Returns(remoteServerID); var mockRemoteConnection = new Mock<IEnvironmentConnection>(); mockRemoteConnection.Setup(connection => connection.WebServerUri).Returns(new Uri("http://remoteserver:3142/")); mockRemoteEnvironment.Setup(model => model.Connection).Returns(mockRemoteConnection.Object); mockResourceModel.Setup(model => model.Environment).Returns(mockRemoteEnvironment.Object); repo.Setup(repository => repository.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), It.IsAny<bool>(), It.IsAny<bool>())).Returns(mockResourceModel.Object); var env = EnviromentRepositoryTest.CreateMockEnvironment(); env.Setup(model => model.ID).Returns(Guid.Empty); env.Setup(e => e.ResourceRepository).Returns(repo.Object); var crm = new Mock<IContextualResourceModel>(); crm.Setup(r => r.Environment).Returns(env.Object); crm.Setup(r => r.ResourceName).Returns("Test"); crm.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition)); var wh = new Mock<IWorkflowHelper>(); #endregion GetEnvironmentRepository(env); // Set the active environment #region setup mock ModelChangedEventArgs var eventArgs = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 eventArgs.Setup(c => c.ItemsAdded).Returns((IEnumerable<ModelItem>)null); var mock = new Mock<ModelProperty>(); DsfActivity setValue = null; mock.Setup(property => property.SetValue(It.IsAny<object>())).Callback<object>(o => { setValue = o as DsfActivity; }); mock.Setup(property => property.Name).Returns("Handler"); eventArgs.Setup(c => c.PropertiesChanged).Returns(new List<ModelProperty> { mock.Object }); #pragma warning restore 618 #endregion var eventAggregator = new Mock<IEventAggregator>(); var wd = new WorkflowDesignerViewModelMock(crm.Object, wh.Object, eventAggregator.Object); wd.SetActiveEnvironment(env.Object); wd.SetDataObject(new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new TestAsyncWorker(), new Mock<IConnectControlSingleton>().Object)); // Execute unit wd.TestModelServiceModelChanged(eventArgs.Object); wd.Dispose(); Assert.IsNotNull(setValue); Assert.AreEqual("http://remoteserver:3142/", setValue.ServiceUri); Assert.AreEqual(remoteServerID, setValue.ServiceServer); }
public void CheckIfRemoteWorkflowAndSetPropertiesExpectedServiceUriToBeNull() { const string ServiceUri = "http://localhost:1234/"; var resourceEnvironmentID = Guid.NewGuid(); var envId = Guid.NewGuid(); var mockResourceModel = Dev2MockFactory.SetupResourceModelMock(); var mockWorkflowHelper = new Mock<IWorkflowHelper>(); var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment var testAct = DsfActivityFactory.CreateDsfActivity(mockResourceModel.Object, new DsfActivity(), true, environmentRepository, true); var mockEnv = Dev2MockFactory.SetupEnvironmentModel(mockResourceModel, null); mockEnv.Setup(c => c.ID).Returns(envId); mockResourceModel.Setup(c => c.Environment).Returns(mockEnv.Object); var testClass = new WorkflowDesignerViewModelMock(mockResourceModel.Object, mockWorkflowHelper.Object); testClass.TestCheckIfRemoteWorkflowAndSetProperties(testAct, mockResourceModel.Object, mockEnv.Object); Assert.IsTrue(testAct.ServiceUri == null); Assert.IsTrue(testAct.ServiceServer == Guid.Empty); var contextEnvironment = new Mock<IEnvironmentModel>(); contextEnvironment.Setup(e => e.ID).Returns(resourceEnvironmentID); var activity = new DsfActivity(); var workflow = new ActivityBuilder { Implementation = activity }; #region Setup resourceModel var resourceRep = new Mock<IResourceRepository>(); resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>()); var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object); resourceModel.Setup(m => m.ResourceType).Returns(ResourceType.WorkflowService); resourceModel.Setup(m => m.Environment.ID).Returns(resourceEnvironmentID); resourceModel.Setup(m => m.Environment.Connection.WebServerUri).Returns(new Uri(ServiceUri)); resourceModel.Setup(m => m.ResourceName).Returns("Some resource name 1"); #endregion #region Setup viewModel var workflowHelper = new Mock<IWorkflowHelper>(); workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); // not necessary to invoke: viewModel.InitializeDesigner(new Dictionary<Type, Type>()); #endregion viewModel.TestCheckIfRemoteWorkflowAndSetProperties(activity, resourceModel.Object, contextEnvironment.Object); viewModel.Dispose(); Assert.IsNull(activity.ServiceUri); Assert.AreEqual(Guid.Empty, activity.ServiceServer); }
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_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); }
public void WorkflowDesignerViewModelTestStartNodeNotDoubleConnect() { #region Setup view model constructor parameters var repo = new Mock<IResourceRepository>(); var env = EnviromentRepositoryTest.CreateMockEnvironment(); env.Setup(e => e.ResourceRepository).Returns(repo.Object); var crm = new Mock<IContextualResourceModel>(); crm.Setup(r => r.Environment).Returns(env.Object); crm.Setup(r => r.ResourceName).Returns("Test"); crm.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition)); //, new Mock<IWizardEngine>().Object var explorerItem = new ExplorerItemModel(); IContextualResourceModel contextualResourceModel = crm.Object; explorerItem.DisplayName = contextualResourceModel.ResourceName; explorerItem.EnvironmentId = contextualResourceModel.Environment.ID; var wh = new Mock<IWorkflowHelper>(); #endregion #region setup Mock ModelItem var properties = new Dictionary<string, Mock<ModelProperty>>(); var propertyCollection = new Mock<ModelPropertyCollection>(); var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment var testAct = DsfActivityFactory.CreateDsfActivity(contextualResourceModel, new DsfActivity(), true, environmentRepository, true); var prop = new Mock<ModelProperty>(); prop.Setup(p => p.SetValue(It.IsAny<DsfActivity>())).Verifiable(); prop.Setup(p => p.ComputedValue).Returns(testAct); properties.Add("Action", prop); propertyCollection.Protected().Setup<ModelProperty>("Find", "Action", true).Returns(prop.Object); var source = new Mock<ModelItem>(); source.Setup(s => s.Properties).Returns(propertyCollection.Object); source.Setup(s => s.ItemType).Returns(typeof(FlowStep)); #endregion #region setup mock to change properties //mock item adding - this is obsolote functionality but not refactored due to overhead var args = new Mock<ModelChangedEventArgs>(); #pragma warning disable 618 args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object }); #pragma warning restore 618 #endregion //Execute var wfd = new WorkflowDesignerViewModelMock(contextualResourceModel, wh.Object); wfd.SetDataObject(explorerItem); wfd.TestModelServiceModelChanged(args.Object); wfd.Dispose(); //Verify prop.Verify(p => p.SetValue(It.IsAny<DsfActivity>()), Times.Never()); }