public TestModelServiceModelChanged ( System.Activities.Presentation.Services.ModelChangedEventArgs e ) : void | ||
e | System.Activities.Presentation.Services.ModelChangedEventArgs | |
return | void |
// 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(); }
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 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 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()); }