public void WorkflowDesignerViewModel_UnitTest_ViewModelModelChanged_ExpectLoadFromServerDoesNotReflectEdit() { 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); workflowHelper.Setup(h => h.SerializeWorkflow(It.IsAny<ModelService>())).Returns(new StringBuilder("<x/>")); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object) { ServiceDefinition = new StringBuilder("<x/>") }; #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.AddWorkflow(workSurfaceKey); viewModel.TestWorkflowDesignerModelChanged(); viewModel.Dispose(); OpeningWorkflowsHelper.RemoveWorkflowWaitingForDesignerLoad(workSurfaceKey); //Verify StringAssert.Contains(StringResources.xmlServiceDefinition, resourceModel.Object.WorkflowXaml.ToString()); Assert.AreEqual(StringResources.xmlServiceDefinition, 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); }