TestWorkflowDesignerModelChangedWithNullSender() public method

public TestWorkflowDesignerModelChangedWithNullSender ( ) : void
return void
        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);
        }