protected static DeployStatsCalculator SetupDeployViewModel(out DeployViewModel deployViewModel)
        {
            var source      = EnviromentRepositoryTest.CreateMockEnvironment();
            var destination = EnviromentRepositoryTest.CreateMockEnvironment();

            source.Setup(a => a.AuthorizationService).Returns(new Mock <IAuthorizationService>().Object);
            destination.Setup(a => a.AuthorizationService).Returns(new Mock <IAuthorizationService>().Object);
            var serverProvider = new Mock <IEnvironmentModelProvider>();

            serverProvider.Setup(s => s.Load()).Returns(new List <IEnvironmentModel> {
                source.Object, destination.Object
            });

            var repo = new TestEnvironmentRespository(source.Object, destination.Object);

            var deployStatsCalculator = new DeployStatsCalculator();
            IExplorerItemModel resourceVm;
            var studioResourceRepository = CreateModels(false, source.Object, out resourceVm);

            deployViewModel = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, repo, new Mock <IEventAggregator>().Object, studioResourceRepository, new Mock <IConnectControlViewModel>().Object, new Mock <IConnectControlViewModel>().Object, deployStatsCalculator)
            {
                SelectedSourceServer      = source.Object,
                SelectedDestinationServer = destination.Object
            };
            return(deployStatsCalculator);
        }
Exemplo n.º 2
0
        public void NotifyPropertyChangedTest()
        {
            var target = new DeployViewModel();

            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.DeployLibrary);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.DeployToESync);
        }
Exemplo n.º 3
0
        public void DeployViewModelConnectWithServerExpectedDoesNotDisconnectOtherServers()
        {
            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var sourceConn = Mock.Get(source.Object.Connection);
            sourceConn.Setup(c => c.Disconnect()).Verifiable();

            var e1 = EnviromentRepositoryTest.CreateMockEnvironment();
            var c1 = Mock.Get(e1.Object.Connection);
            c1.Setup(c => c.Disconnect()).Verifiable();
            var s1 = e1.Object;

            var e2 = EnviromentRepositoryTest.CreateMockEnvironment();
            var c2 = Mock.Get(e2.Object.Connection);
            c2.Setup(c => c.Disconnect()).Verifiable();
            var s2 = e2.Object;

            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { s1, s2 });

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var studioResourceRepository = new Mock<IStudioResourceRepository>();
            studioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>());

            var deployViewModel = new DeployViewModel(new TestAsyncWorker(), serverProvider.Object, repo, new Mock<IEventAggregator>().Object, studioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, null, null, null, new Mock<IConnectControlSingleton>().Object);



            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);

            deployViewModel.SelectedSourceServer = s1;
            sourceConn.Verify(c => c.Disconnect(), Times.Never());
            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Never());

            deployViewModel.SelectedDestinationServer = s2;
            sourceConn.Verify(c => c.Disconnect(), Times.Never());
            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Never());

            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);
        }
Exemplo n.º 4
0
        void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            FrameworkElement frameworkElement = sender as FrameworkElement;

            if (frameworkElement != null)
            {
                ExplorerItemModel rtvm = frameworkElement.DataContext as ExplorerItemModel;
                if (rtvm != null)
                {
                    DeployViewModel viewModel = DataContext as DeployViewModel;
                    if (viewModel != null)
                    {
                        viewModel.SelectDependencies(new List <IExplorerItemModel> {
                            rtvm
                        });
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static DeployViewModel GetDeployViewModel(object input)
        {
            DeployViewModel deployViewModel = null;

            if (input != null)
            {
                TypeSwitch.Do(input,
                              TypeSwitch.Case <ExplorerItemModel>(
                                  x => deployViewModel = new DeployViewModel(x.ResourceId, x.EnvironmentId)),
                              TypeSwitch.Case <ResourceModel>(
                                  x => deployViewModel = new DeployViewModel(x.ID, x.Environment.ID)),
                              TypeSwitch.Default(() => deployViewModel = new DeployViewModel()));
            }
            else
            {
                deployViewModel = new DeployViewModel();
            }

            return(deployViewModel);
        }
        public static DeployViewModel GetDeployViewModel(object input)
        {
            DeployViewModel deployViewModel = null;

            if(input != null)
            {
                TypeSwitch.Do(input,
                              TypeSwitch.Case<ExplorerItemModel>(
                                  x => deployViewModel = new DeployViewModel(x.ResourceId, x.EnvironmentId)),
                              TypeSwitch.Case<ResourceModel>(
                                  x => deployViewModel = new DeployViewModel(x.ID, x.Environment.ID)),
                              TypeSwitch.Default(() => deployViewModel = new DeployViewModel()));
            }
            else
            {
                deployViewModel = new DeployViewModel();
            }

            return deployViewModel;
        }
        protected static DeployViewModel SetupDeployViewModel(out Mock <IEnvironmentModel> destEnv, out Mock <IEnvironmentModel> destServer)
        {
            var destConnection = new Mock <IEnvironmentConnection>();

            destEnv = new Mock <IEnvironmentModel>();
            destEnv.Setup(e => e.Connection).Returns(destConnection.Object);
            IAuthorizationService service = new Mock <IAuthorizationService>().Object;

            destEnv.Setup(a => a.AuthorizationService).Returns(service);
            destServer = destEnv;


            var envRepo = new Mock <IEnvironmentRepository>();

            envRepo.Setup(r => r.Fetch(It.IsAny <IEnvironmentModel>())).Returns(destEnv.Object);

            var servers = new List <IEnvironmentModel> {
                destEnv.Object
            };
            var serverProvider = new Mock <IEnvironmentModelProvider>();

            serverProvider.Setup(s => s.Load()).Returns(servers);

            // ReSharper disable RedundantAssignment
            int deployItemCount;
            var statsCalc = new Mock <IDeployStatsCalculator>();

            statsCalc.Setup(c => c.CalculateStats(It.IsAny <IEnumerable <ExplorerItemModel> >(), It.IsAny <Dictionary <string, Func <IExplorerItemModel, bool> > >(), It.IsAny <ObservableCollection <DeployStatsTO> >(), out deployItemCount));
            var mockStudioResourceRepository = new Mock <IStudioResourceRepository>();

            mockStudioResourceRepository.Setup(repository => repository.Filter(It.IsAny <Func <IExplorerItemModel, bool> >())).Returns(new ObservableCollection <IExplorerItemModel>());
            var deployViewModel = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, envRepo.Object, new Mock <IEventAggregator>().Object, mockStudioResourceRepository.Object, new Mock <IConnectControlViewModel>().Object, new Mock <IConnectControlViewModel>().Object, statsCalc.Object)
            {
                Source = { ExplorerItemModels = new ObservableCollection <IExplorerItemModel>() }, Target = { ExplorerItemModels = new ObservableCollection <IExplorerItemModel>() }
            };

            return(deployViewModel);
        }
        protected static DeployStatsCalculator SetupDeployViewModel(out DeployViewModel deployViewModel)
        {
            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var destination = EnviromentRepositoryTest.CreateMockEnvironment();

            source.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            destination.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { source.Object, destination.Object });

            var repo = new TestEnvironmentRespository(source.Object, destination.Object);

            var deployStatsCalculator = new DeployStatsCalculator();
            IExplorerItemModel resourceVm;
            var studioResourceRepository = CreateModels(false, source.Object, out resourceVm);

            deployViewModel = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, repo, new Mock<IEventAggregator>().Object, studioResourceRepository, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, deployStatsCalculator)
            {
                SelectedSourceServer = source.Object,
                SelectedDestinationServer = destination.Object
            };
            return deployStatsCalculator;
        }
        protected static Guid SetupVmForMessages(out IEnvironmentModel server, out DeployViewModel vm, Mock <IEventAggregator> mockEventAggregator = null)
        {
            var env   = EnviromentRepositoryTest.CreateMockEnvironment();
            var envId = env.Object.ID;

            server = env.Object;

            var serverProvider = new Mock <IEnvironmentModelProvider>();

            serverProvider.Setup(s => s.Load()).Returns(new List <IEnvironmentModel> {
                server
            });
            var repo = CreateEnvironmentRepositoryMock();

            if (mockEventAggregator == null)
            {
                mockEventAggregator = new Mock <IEventAggregator>();
            }
            var studioResourceRepository = new Mock <IStudioResourceRepository>();

            studioResourceRepository.Setup(repository => repository.Filter(It.IsAny <Func <IExplorerItemModel, bool> >())).Returns(new ObservableCollection <IExplorerItemModel>());
            vm = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, repo.Object, mockEventAggregator.Object, studioResourceRepository.Object, new Mock <IConnectControlViewModel>().Object, new Mock <IConnectControlViewModel>().Object);
            return(envId);
        }
        protected static DeployViewModel SetupDeployViewModel(out Mock<IEnvironmentModel> destEnv, out Mock<IEnvironmentModel> destServer)
        {

            var destConnection = new Mock<IEnvironmentConnection>();

            destEnv = new Mock<IEnvironmentModel>();
            destEnv.Setup(e => e.Connection).Returns(destConnection.Object);
            IAuthorizationService service = new Mock<IAuthorizationService>().Object;
            destEnv.Setup(a => a.AuthorizationService).Returns(service);
            destServer = destEnv;


            var envRepo = new Mock<IEnvironmentRepository>();
            envRepo.Setup(r => r.Fetch(It.IsAny<IEnvironmentModel>())).Returns(destEnv.Object);

            var servers = new List<IEnvironmentModel> { destEnv.Object };
            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(servers);

            // ReSharper disable RedundantAssignment
            int deployItemCount;
            var statsCalc = new Mock<IDeployStatsCalculator>();
            statsCalc.Setup(c => c.CalculateStats(It.IsAny<IEnumerable<ExplorerItemModel>>(), It.IsAny<Dictionary<string, Func<IExplorerItemModel, bool>>>(), It.IsAny<ObservableCollection<DeployStatsTO>>(), out deployItemCount));
            var mockStudioResourceRepository = new Mock<IStudioResourceRepository>();
            mockStudioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>());
            var deployViewModel = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, envRepo.Object, new Mock<IEventAggregator>().Object, mockStudioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, statsCalc.Object) { Source = { ExplorerItemModels = new ObservableCollection<IExplorerItemModel>() }, Target = { ExplorerItemModels = new ObservableCollection<IExplorerItemModel>() } };

            return deployViewModel;
        }
Exemplo n.º 11
0
        public void DeployViewModel_Constructor_Default()
        {
            //------------Setup for test--------------------------
            IEnvironmentModel environmentModel = Dev2MockFactory.SetupEnvironmentModel().Object;
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);

            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement
            //------------Execute Test---------------------------
            var deployViewModel = new DeployViewModel();
            //------------Assert Results-------------------------
            Assert.IsNotNull(deployViewModel);
            Assert.IsNotNull(deployViewModel.EnvironmentRepository);
            Assert.IsNotNull(deployViewModel.EventPublisher);
        }
Exemplo n.º 12
0
        public void DeployViewModel_Constructor_GuidsPassed_SetsValues()
        {
            //------------Setup for test--------------------------
            var a = Dev2MockFactory.SetupEnvironmentModel();
            a.Setup(x => x.AuthorizationService).Returns(_authService.Object);
            IEnvironmentModel environmentModel = a.Object;

            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement


            //------------Execute Test---------------------------
            var deployViewModel = new DeployViewModel(Guid.NewGuid(), Guid.Empty);
            //------------Assert Results-------------------------
            Assert.IsNotNull(deployViewModel);
            Assert.IsNotNull(deployViewModel.EnvironmentRepository);
            Assert.IsNotNull(deployViewModel.EventPublisher);
            Assert.IsFalse(deployViewModel.DestinationServerHasDropped);
        }
Exemplo n.º 13
0
        public void DeployViewModel_DestinationContext_NullValue_ExpectNewguid()
        {
            //------------Setup for test--------------------------
            var a = Dev2MockFactory.SetupEnvironmentModel();
            a.Setup(x => x.AuthorizationService).Returns(_authService.Object);
            IEnvironmentModel environmentModel = a.Object;

            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement


            //------------Execute Test---------------------------
            var deployViewModel = new DeployViewModel(Guid.NewGuid(), Guid.Empty);


            //------------Assert Results-------------------------
            Assert.IsNotNull(deployViewModel.DestinationContext);
            Assert.AreNotEqual(deployViewModel.DestinationContext, Guid.Empty);
        }
Exemplo n.º 14
0
        public void DeployViewModel_Dispose_ExpectUnsubscribeFromEventPublishers()
        {
            //------------Setup for test--------------------------

            var agg = new Mock<IEventAggregator>();

            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var sourceConn = Mock.Get(source.Object.Connection);
            sourceConn.Setup(c => c.Disconnect()).Verifiable();

            var e1 = EnviromentRepositoryTest.CreateMockEnvironment();
            var c1 = Mock.Get(e1.Object.Connection);
            c1.Setup(c => c.Disconnect()).Verifiable();
            var s1 = e1.Object;

            var e2 = EnviromentRepositoryTest.CreateMockEnvironment();
            var c2 = Mock.Get(e2.Object.Connection);
            c2.Setup(c => c.Disconnect()).Verifiable();
            var s2 = e2.Object;

            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { s1, s2 });

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var studioResourceRepository = new Mock<IStudioResourceRepository>();
            studioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>());

            var deployViewModel = new DeployViewModel(new TestAsyncWorker(), serverProvider.Object, repo, agg.Object, studioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object);



            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);

            deployViewModel.Dispose();
            //------------Assert Results-------------------------
            agg.Verify(ax => ax.Unsubscribe(It.IsAny<object>()));
        }
Exemplo n.º 15
0
        public void DeployViewModelDeployWithServerExpectedDoesNotDisconnectOtherServers()
        {
            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var sourceConn = Mock.Get(source.Object.Connection);
            sourceConn.Setup(c => c.Disconnect()).Verifiable();

            var e1 = EnviromentRepositoryTest.CreateMockEnvironment();
            var s1 = e1.Object;
            var c1 = Mock.Get(e1.Object.Connection);
            c1.Setup(c => c.Disconnect()).Verifiable();

            var resourceRepo1 = new ResourceRepository(e1.Object);
            e1.Setup(e => e.ResourceRepository).Returns(resourceRepo1);
            var r1 = new Mock<IContextualResourceModel>();
            r1.Setup(r => r.Category).Returns("test");
            r1.Setup(r => r.ResourceName).Returns("testResource");
            r1.Setup(r => r.Environment).Returns(e1.Object);
            resourceRepo1.Add(r1.Object);

            var e2 = EnviromentRepositoryTest.CreateMockEnvironment();
            var s2 = e2.Object;
            var c2 = Mock.Get(e2.Object.Connection);
            c2.Setup(c => c.Disconnect()).Verifiable();

            var resourceRepo2 = new ResourceRepository(e2.Object);
            e2.Setup(e => e.ResourceRepository).Returns(resourceRepo2);

            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { s1, s2 });

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);

            var statsCalc = new Mock<IDeployStatsCalculator>();
            IAsyncWorker asyncWorker = new TestAsyncWorker();
            statsCalc.Setup(s => s.SelectForDeployPredicate(It.IsAny<ExplorerItemModel>())).Returns(true);
            Mock<IStudioResourceRepository> mockStudioResourceRepository = new Mock<IStudioResourceRepository>();
            mockStudioResourceRepository.Setup(repository => repository.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ExplorerItemModel(mockStudioResourceRepository.Object, asyncWorker, new Mock<IConnectControlSingleton>().Object));
            IStudioResourceRepository studioResourceRepository = mockStudioResourceRepository.Object;
            var deployViewModel = new DeployViewModel(asyncWorker, serverProvider.Object, repo, new Mock<IEventAggregator>().Object, studioResourceRepository, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, statsCalc.Object, null, null, new Mock<IConnectControlSingleton>().Object)
            {
                SelectedSourceServer = s1,
                SelectedDestinationServer = s2
            };

            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);

            deployViewModel.DeployCommand.Execute(null);

            sourceConn.Verify(c => c.Disconnect(), Times.Never());
            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Never());
        }
Exemplo n.º 16
0
        public void DeployViewModel_Deploy_AssertSelectedEnvIsDestination()
        {
            //New Mocks
            var mockedServerRepo = new Mock<IEnvironmentRepository>();
            var server = new Mock<IEnvironmentModel>();

            server.Setup(x => x.AuthorizationService).Returns(_authService.Object);
            _authService.Setup(a => a.IsAuthorized(AuthorizationContext.DeployFrom, It.IsAny<string>())).Returns(true);
            _authService.Setup(a => a.IsAuthorized(AuthorizationContext.DeployTo, It.IsAny<string>())).Returns(true);
            var secondServer = new Mock<IEnvironmentModel>();
            secondServer.Setup(x => x.AuthorizationService).Returns(_authService.Object);
            var provider = new Mock<IEnvironmentModelProvider>();
            var resourceNode = new Mock<IContextualResourceModel>();
            var resRepo = new Mock<IResourceRepository>();
            var resRepo2 = new Mock<IResourceRepository>();
            var id = Guid.NewGuid();

            const string expectedResourceName = "Test Resource";
            resourceNode.Setup(res => res.ResourceName).Returns(expectedResourceName);
            resourceNode.Setup(res => res.Environment.Connection.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            resourceNode.Setup(res => res.ID).Returns(id);

            //Setup Servers
            resRepo.Setup(c => c.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false, false)).Verifiable();
            resRepo.Setup(c => c.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false, false)).Returns(resourceNode.Object);
            resRepo.Setup(c => c.DeployResources(It.IsAny<IEnvironmentModel>(), It.IsAny<IEnvironmentModel>(),
                                       It.IsAny<IDeployDto>(), It.IsAny<IEventAggregator>())).Verifiable();

            resRepo.Setup(c => c.All()).Returns(new List<IResourceModel>());
            resRepo2.Setup(c => c.All()).Returns(new List<IResourceModel>());

            server.Setup(svr => svr.IsConnected).Returns(true);
            server.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object);
            server.Setup(svr => svr.ResourceRepository).Returns(resRepo.Object);

            secondServer.Setup(svr => svr.IsConnected).Returns(true);
            secondServer.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object);
            secondServer.Setup(svr => svr.ResourceRepository).Returns(resRepo2.Object);

            mockedServerRepo.Setup(svr => svr.Fetch(It.IsAny<IEnvironmentModel>())).Returns(server.Object);

            provider.Setup(prov => prov.Load()).Returns(new List<IEnvironmentModel> { server.Object, secondServer.Object });


            var initialResource = new Mock<IContextualResourceModel>();
            initialResource.Setup(res => res.Environment).Returns(server.Object);
            initialResource.Setup(res => res.ResourceName).Returns(expectedResourceName);

            //Setup Navigation Tree



            //Setup Server Resources


            var mockStudioResourceRepository = GetMockStudioResourceRepository();
            var resourceTreeNode = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, mockStudioResourceRepository.Object);
            mockStudioResourceRepository.Setup(repository => repository.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(resourceTreeNode);
            var sourceDeployNavigationViewModel = new DeployNavigationViewModel(new Mock<IEventAggregator>().Object, new TestAsyncWorker(), mockedServerRepo.Object, mockStudioResourceRepository.Object, true, new Mock<IConnectControlSingleton>().Object) { Environment = server.Object, ExplorerItemModels = new ObservableCollection<IExplorerItemModel>() };

            var deployViewModel = new DeployViewModel(new TestAsyncWorker(), provider.Object, mockedServerRepo.Object, new Mock<IEventAggregator>().Object, mockStudioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, null, null, null, new Mock<IConnectControlSingleton>().Object)
            {
                Source = sourceDeployNavigationViewModel,
                Target = sourceDeployNavigationViewModel,
                SelectedSourceServer = server.Object
            };
            int active = 0;
            int getActive = 0;
            resourceTreeNode.IsChecked = true;
            PrivateObject pvt = new PrivateObject(deployViewModel);
            pvt.SetField("_setActive", new Action<IEnvironmentModel>(a => active++));
            pvt.SetField("_getActive", new Func<IEnvironmentModel>(() => { getActive++; return new Mock<IEnvironmentModel>().Object; }));
            //------------Execute Test--------------------------- 
            deployViewModel.DeployCommand.Execute(null);

            Assert.AreEqual(active, 2);
            Assert.AreEqual(getActive, 1);

        }
        protected static Guid SetupVmForMessages(out IEnvironmentModel server, out DeployViewModel vm, Mock<IEventAggregator> mockEventAggregator = null)
        {
            var env = EnviromentRepositoryTest.CreateMockEnvironment();
            var envId = env.Object.ID;
            server = env.Object;

            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { server });
            var repo = CreateEnvironmentRepositoryMock();
            if(mockEventAggregator == null)
            {
                mockEventAggregator = new Mock<IEventAggregator>();
            }
            var studioResourceRepository = new Mock<IStudioResourceRepository>();
            studioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>());
            vm = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, repo.Object, mockEventAggregator.Object, studioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object);
            return envId;
        }
Exemplo n.º 18
0
        public void DeployViewModel_SelectItemInDeploy_TwoServers_ItemAndServerSelected_ExpectChecked()
        {

            //New Mocks
            var mockedServerRepo = new Mock<IEnvironmentRepository>();
            var server = new Mock<IEnvironmentModel>();
            var secondServer = new Mock<IEnvironmentModel>();
            var provider = new Mock<IEnvironmentModelProvider>();
            var resourceNode = new Mock<IContextualResourceModel>();

            //Setup Servers
            server.Setup(svr => svr.IsConnected).Returns(true);
            server.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object);
            server.Setup(a => a.AuthorizationService).Returns(_authService.Object);

            secondServer.Setup(svr => svr.IsConnected).Returns(true);
            secondServer.Setup(a => a.AuthorizationService).Returns(_authService.Object);
            secondServer.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object);
            mockedServerRepo.Setup(svr => svr.Fetch(It.IsAny<IEnvironmentModel>())).Returns(server.Object);
            mockedServerRepo.Setup(r => r.FindSingle(It.IsAny<Expression<Func<IEnvironmentModel, bool>>>())).Returns(server.Object);
            provider.Setup(prov => prov.Load()).Returns(new List<IEnvironmentModel> { server.Object, secondServer.Object });

            //Setup Navigation Tree
            var eventAggregator = new Mock<IEventAggregator>().Object;
            var treeParent = new ExplorerItemModel
            {
                DisplayName = "Test Category",
                ResourceType = ResourceType.Folder,
                IsDeploySourceExpanded = false
            };
            const string expectedResourceName = "Test Resource";
            var resourceID = Guid.NewGuid();
            resourceNode.Setup(res => res.ResourceName).Returns(expectedResourceName);
            resourceNode.Setup(model => model.ID).Returns(resourceID);
            resourceNode.Setup(res => res.Environment.Connection.ServerEvents).Returns(new Mock<IEventPublisher>().Object);

            var resourceTreeNode = new ExplorerItemModel
            {
                Parent = treeParent,
                DisplayName = resourceNode.Object.ResourceName,
                ResourceId = resourceID,
                EnvironmentId = server.Object.ID,
                IsChecked = false
            };

            //Setup Server Resources
            var mockStudioResourceRepository = new Mock<IStudioResourceRepository>();
            mockStudioResourceRepository.Setup(repository => repository.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(resourceTreeNode);
            mockStudioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>());

            var sourceDeployNavigationViewModel = new DeployNavigationViewModel(eventAggregator, new TestAsyncWorker(), mockedServerRepo.Object, mockStudioResourceRepository.Object, true, new Mock<IConnectControlSingleton>().Object) { ExplorerItemModels = new ObservableCollection<IExplorerItemModel>() };
            server.Setup(svr => svr.LoadResources()).Callback(() => sourceDeployNavigationViewModel.ExplorerItemModels.Add(treeParent));
            sourceDeployNavigationViewModel.Environment = server.Object;

            var deployViewModel = new DeployViewModel(new TestAsyncWorker(), provider.Object, mockedServerRepo.Object, new Mock<IEventAggregator>().Object, mockStudioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object)
            {
                Source = sourceDeployNavigationViewModel
            };

            var initialResource = new Mock<IContextualResourceModel>();
            initialResource.Setup(res => res.Environment).Returns(server.Object);
            initialResource.Setup(res => res.ID).Returns(resourceID);

            //------------Execute Test--------------------------- 
            deployViewModel.Handle(new SelectItemInDeployMessage(initialResource.Object.ID, initialResource.Object.Environment.ID));

            // Assert item visible and selected
            Assert.IsTrue(resourceTreeNode.IsChecked.GetValueOrDefault(false), "Deployed item not selected in deploy");
            Assert.IsTrue(treeParent.IsDeploySourceExpanded, "Item not visible in deploy view");

            mockStudioResourceRepository.Verify(r => r.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>()));
        }
Exemplo n.º 19
0
        public void PropertiesGetSetTest()
        {
            var target = new DeployViewModel();

            TestsHelper.TestPublicPropertiesGetSet(target);
        }