SetActiveEnvironment() public method

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