public TestPerformAddItems ( System.Activities.Presentation.Model.ModelItem modelItems ) : System.Activities.Presentation.Model.ModelItem | ||
modelItems | System.Activities.Presentation.Model.ModelItem | |
Résultat | System.Activities.Presentation.Model.ModelItem |
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"); } } }