コード例 #1
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        public void MainViewModelDeactivateItemWithPreviousItemOpenExpectedActiveItemToBePreviousItem()
        {
            lock (syncroot)
            {
                var wsiRepo = new Mock<IWorkspaceItemRepository>();
                wsiRepo.Setup(r => r.WorkspaceItems).Returns(() => new List<IWorkspaceItem>());
                wsiRepo.Setup(r => r.Write()).Verifiable();

                #region Setup ImportService - GRRR!

                var importServiceContext = new ImportServiceContext();
                ImportService.CurrentContext = importServiceContext;
                ImportService.Initialize(new List<ComposablePartCatalog>
                {
                    new FullTestAggregateCatalog()
                });
                ImportService.AddExportedValueToContainer(wsiRepo.Object);
                ImportService.AddExportedValueToContainer(new Mock<IEventAggregator>().Object);

                #endregion

                var envRepo = new Mock<IEnvironmentRepository>();
                var mockMainViewModel = new MainViewModelPersistenceMock(envRepo.Object, false);
                mockMainViewModel.EventAggregator = ImportService.GetExportValue<IEventAggregator>();
                var resourceID = Guid.NewGuid();
                var serverID = Guid.NewGuid();

                #region Setup WorkSurfaceContextViewModel1

                var resourceRepo = new Mock<IResourceRepository>();
                resourceRepo.Setup(r => r.Save(It.IsAny<IResourceModel>())).Verifiable();

                var envConn = new Mock<IEnvironmentConnection>();
                var env = new Mock<IEnvironmentModel>();
                env.Setup(e => e.ResourceRepository).Returns(resourceRepo.Object);
                env.Setup(e => e.Connection).Returns(envConn.Object);

                var resourceModel = new Mock<IContextualResourceModel>();
                resourceModel.Setup(m => m.Environment).Returns(env.Object);
                resourceModel.Setup(m => m.ID).Returns(resourceID);

                var workflowHelper = new Mock<IWorkflowHelper>();
                var designerViewModel = new WorkflowDesignerViewModel(resourceModel.Object, workflowHelper.Object, false);
                var contextViewModel1 = new WorkSurfaceContextViewModel(
                    new WorkSurfaceKey { ResourceID = resourceID, ServerID = serverID, WorkSurfaceContext = designerViewModel.WorkSurfaceContext },
                    designerViewModel);

                #endregion

                mockMainViewModel.Items.Add(contextViewModel1);

                serverID = Guid.NewGuid();
                resourceID = Guid.NewGuid();

                mockMainViewModel.PopupProvider = Dev2MockFactory.CreateIPopup(MessageBoxResult.No).Object;

                mockMainViewModel.ActivateItem(mockMainViewModel.Items[0]);
                mockMainViewModel.ActivateItem(mockMainViewModel.Items[1]);
                mockMainViewModel.CallDeactivate(mockMainViewModel.Items[1]);
                Assert.AreEqual(mockMainViewModel.Items[0], mockMainViewModel.ActiveItem);
            }
        }
コード例 #2
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        public void MainViewModelOnDeactivateWithTrueExpectedSavesWorkspaceItems()
        {
            lock (syncroot)
            {
                var wsiRepo = new Mock<IWorkspaceItemRepository>();
                wsiRepo.Setup(r => r.WorkspaceItems).Returns(() => new List<IWorkspaceItem>());
                wsiRepo.Setup(r => r.Write()).Verifiable();

                #region Setup ImportService - GRRR!

                var importServiceContext = new ImportServiceContext();
                ImportService.CurrentContext = importServiceContext;
                ImportService.Initialize(new List<ComposablePartCatalog>
                {
                    new FullTestAggregateCatalog()
                });
                ImportService.AddExportedValueToContainer(wsiRepo.Object);
                ImportService.AddExportedValueToContainer(new Mock<IEventAggregator>().Object);

                #endregion

                var envRepo = new Mock<IEnvironmentRepository>();
                var viewModel = new MainViewModelPersistenceMock(envRepo.Object, false);

                viewModel.TestClose();
                wsiRepo.Verify(r => r.Write());
            }
        }
コード例 #3
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        private Mock<IEnvironmentRepository> SetupForDeleteServer()
        {
            CreateResourceRepo();
            var securityContext = GetMockSecurityContext();
            var workspaceRepo = GetworkspaceItemRespository();
            var models = new List<IEnvironmentModel> { _environmentModel.Object };
            var mock = new Mock<IEnvironmentRepository>();
            mock.Setup(s => s.All()).Returns(models);
            mock.Setup(s => s.Get(It.IsAny<string>())).Returns(_environmentModel.Object);
            mock.Setup(s => s.Remove(It.IsAny<IEnvironmentModel>()))
                .Callback<IEnvironmentModel>(s =>
                                             Assert.AreEqual(_environmentModel.Object, s))
                .Verifiable();
            _popupController = new Mock<IPopupController>();
            _resourceDependencyService = new Mock<IResourceDependencyService>();
            _eventAggregator = new Mock<IEventAggregator>();
            _eventAggregator.Setup(e => e.Publish(It.IsAny<EnvironmentDeletedMessage>()))
                            .Callback<object>(m =>
                            {
                                var removeMsg = (EnvironmentDeletedMessage)m;
                                Assert.AreEqual(_environmentModel.Object, removeMsg.EnvironmentModel);
                            })
                            .Verifiable();

            _importServiceContext =
                CompositionInitializer.InitializeMockedMainViewModel(securityContext: securityContext,
                                                                     environmentRepo: mock.Object,
                                                                     workspaceItemRepository: workspaceRepo,
                                                                     popupController: _popupController,
                                                                     resourceDepService: _resourceDependencyService,
                                                                     aggregator: _eventAggregator);

            ImportService.CurrentContext = _importServiceContext;
            _mainViewModel = new MainViewModel(mock.Object, false);
            SetupForDelete();
            _firstResource.Setup(r => r.ResourceType).Returns(ResourceType.Source);
            _firstResource.Setup(r => r.ServerResourceType).Returns("Server");
            _firstResource.Setup(r => r.ConnectionString)
                          .Returns(TestResourceStringsTest.ResourceToHydrateConnectionString1);
            _environmentConnection = new Mock<IEnvironmentConnection>();
            _environmentConnection.Setup(c => c.AppServerUri)
                                  .Returns(new Uri(TestResourceStringsTest.ResourceToHydrateActualAppUri));
            _environmentModel.Setup(r => r.Connection).Returns(_environmentConnection.Object);
            return mock;
        }
コード例 #4
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        public void MainViewModelConstructorWithNullBrowserPopupControllerExpectedCreatesExternalBrowserPopupController()
        {
            #region Setup ImportService - GRRR!

            var importServiceContext = new ImportServiceContext();
            ImportService.CurrentContext = importServiceContext;
            ImportService.Initialize(new List<ComposablePartCatalog>
            {
                new FullTestAggregateCatalog()
            });
            ImportService.AddExportedValueToContainer(new Mock<IEventAggregator>().Object);

            #endregion

            var envRepo = new Mock<IEnvironmentRepository>();
            envRepo.Setup(e => e.All()).Returns(new List<IEnvironmentModel>());

            var vm = new MainViewModel(envRepo.Object, false);
            Assert.IsInstanceOfType(vm.BrowserPopupController, typeof(ExternalBrowserPopupController));
        }
コード例 #5
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        private void CreateFullExportsAndVmWithEmptyRepo()
        {
            CreateResourceRepo();
            var securityContext = GetMockSecurityContext();
            var mockEnv = new Mock<IEnvironmentRepository>();
            mockEnv.Setup(g => g.All()).Returns(new List<IEnvironmentModel>());
            var environmentRepo = mockEnv.Object;
            var workspaceRepo = GetworkspaceItemRespository();
            _eventAggregator = new Mock<IEventAggregator>();
            _popupController = new Mock<IPopupController>();
            _resourceDependencyService = new Mock<IResourceDependencyService>();
            _importServiceContext =
                CompositionInitializer.InitializeMockedMainViewModel(securityContext: securityContext,
                                                                     environmentRepo: environmentRepo,
                                                                     workspaceItemRepository: workspaceRepo,
                                                                     aggregator: _eventAggregator,
                                                                     popupController: _popupController,
                                                                     resourceDepService: _resourceDependencyService);

            ImportService.CurrentContext = _importServiceContext;
            _mainViewModel = new MainViewModel(environmentRepo, false);
        }
コード例 #6
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        private void CreateFullExportsAndVm()
        {
            CreateResourceRepo();
            var securityContext = GetMockSecurityContext();
            var environmentRepo = GetEnvironmentRepository();
            var workspaceRepo = GetworkspaceItemRespository();
            _eventAggregator = new Mock<IEventAggregator>();
            _popupController = new Mock<IPopupController>();
            _feedbackInvoker = new Mock<IFeedbackInvoker>();
            _resourceDependencyService = new Mock<IResourceDependencyService>();
            _webController = new Mock<IWebController>();
            _windowManager = new Mock<IWindowManager>();
            _importServiceContext =
                CompositionInitializer.InitializeMockedMainViewModel(securityContext: securityContext,
                                                                     environmentRepo: environmentRepo,
                                                                     workspaceItemRepository: workspaceRepo,
                                                                     aggregator: _eventAggregator,
                                                                     popupController: _popupController,
                                                                     resourceDepService: _resourceDependencyService,
                                                                     feedbackInvoker: _feedbackInvoker,
                                                                     webController: _webController,
                                                                     windowManager: _windowManager);

            ImportService.CurrentContext = _importServiceContext;
            _mainViewModel = new MainViewModel(environmentRepo, false);
        }
コード例 #7
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        static void SetupImportServiceForPersistenceTests(Mock<IWorkspaceItemRepository> wsiRepo)
        {
            var importServiceContext = new ImportServiceContext();
            ImportService.CurrentContext = importServiceContext;
            ImportService.Initialize(new List<ComposablePartCatalog>
            {
                new FullTestAggregateCatalog()
            });
            ImportService.AddExportedValueToContainer(wsiRepo.Object);
            ImportService.AddExportedValueToContainer(new Mock<IEventAggregator>().Object);
            ImportService.AddExportedValueToContainer(new Mock<IWindowManager>().Object);
            ImportService.AddExportedValueToContainer(new Mock<IPopupController>().Object);
            ImportService.AddExportedValueToContainer(new Mock<IWizardEngine>().Object);

            var securityContext = new Mock<IFrameworkSecurityContext>();
            securityContext.Setup(s => s.UserIdentity).Returns(new GenericIdentity("TestUser"));
            ImportService.AddExportedValueToContainer(securityContext.Object);
        }
コード例 #8
0
ファイル: MainViewModelTest.cs プロジェクト: Robin--/Warewolf
        public void MainViewModelShowCommunityPageExpectedInvokesConstructorsBrowserPopupController()
        {
            var popupController = new Mock<IBrowserPopupController>();
            popupController.Setup(p => p.ShowPopup(It.IsAny<string>())).Verifiable();

            #region Setup ImportService - GRRR!

            var importServiceContext = new ImportServiceContext();
            ImportService.CurrentContext = importServiceContext;
            ImportService.Initialize(new List<ComposablePartCatalog>
            {
                new FullTestAggregateCatalog()
            });
            ImportService.AddExportedValueToContainer(new Mock<IEventAggregator>().Object);

            #endregion

            var envRepo = new Mock<IEnvironmentRepository>();
            envRepo.Setup(e => e.All()).Returns(new List<IEnvironmentModel>());

            var vm = new MainViewModel(envRepo.Object, false, popupController.Object);
            vm.ShowCommunityPage();

            popupController.Verify(p => p.ShowPopup(It.IsAny<string>()));
        }
コード例 #9
0
 public static void MyClassInitialize(TestContext testContext)
 {
     _importServiceContext = CompositionInitializer.InitializeMockedMainViewModel();
 }