public void WorkflowDesigner_Initialize_WhenWorkflowXamlNullAndFetchFails_ExpectNewWorkflow() { 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>()); ExecuteMessage exeMsg = null; // ReSharper disable ExpressionIsAlwaysNull resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(exeMsg); // ReSharper restore ExpressionIsAlwaysNull 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("abc"); var workflowHelper = new Mock<IWorkflowHelper>(); var ok2 = false; workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(() => { ok2 = true; return workflow; }); workflowHelper.Setup(h => h.SanitizeXaml(It.IsAny<StringBuilder>())).Returns(xamlBuilder); var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object); #endregion var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment #region setup Mock ModelItem var properties = new Dictionary<string, Mock<ModelProperty>>(); var propertyCollection = new Mock<ModelPropertyCollection>(); 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.LoadXaml(); // verify CreateWorkflow called Assert.IsTrue(ok2); } catch (Exception e) { ok = false; msg = e.Message + " -> " + e.StackTrace; } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); Assert.IsTrue(ok, msg); }