public void DisposeStopsServer()
        {
            // Arrange
            var server = new Mock<IWebServer>();
            var impl = new WelcomePageImpl(Mock.Of<ISolutionFolder>(), Mock.Of<IDefaultDocumentPolicy>(),Mock.Of<IItemOperations>(), server.Object);
            impl.OnAfterOpenSolution();

            // Act
            impl.Dispose();

            // Assert
            server.Verify(x => x.Stop(), Times.Once());
        }
        public void CloseSolution()
        {
            // Arrange
            var itemOperations = new Mock<IItemOperations>();
            var solutionFolder = new Mock<ISolutionFolder>();
            var policy = new Mock<IDefaultDocumentPolicy>();
            const string rootFolder = @"Z:\some\path";
            solutionFolder.Setup(x => x.GetDirectoryName())
                          .Returns(rootFolder);
            policy.Setup(x => x.ContainsDefaultDocument(It.IsAny<string>()))
                  .Returns(false);
            var server = new Mock<IWebServer>();
            var impl = new WelcomePageImpl(solutionFolder.Object, policy.Object, itemOperations.Object, server.Object);
            impl.OnAfterOpenSolution();

            // Act
            impl.OnAfterCloseSolution();

            // Assert
            server.Verify(x => x.Stop(), Times.Once());
        }
        protected override void Initialize()
        {
            base.Initialize();

            AddMenuCommands();

            _solution = GetService(typeof (SVsSolution)) as IVsSolution;
            if (_solution != null)
                _solution.AdviseSolutionEvents(this, out _dwCookie);

            var dte = (DTE)GetService(typeof(DTE));

            var itemOperations = new ItemOperationsWrapper(dte);
            var solutionFolderWrapper = new SolutionFolderWrapper(dte);
            var defaultDocumentPolicy = new DefaultDocumentPolicy();
            var server = new WebServer();
            _impl = new WelcomePageImpl(solutionFolderWrapper, defaultDocumentPolicy, itemOperations, server);
        }
 public void CreateInstance()
 {
     var impl = new WelcomePageImpl(Mock.Of<ISolutionFolder>(), Mock.Of<IDefaultDocumentPolicy>(),
                                    Mock.Of<IItemOperations>(), Mock.Of<IWebServer>());
 }
        public void OpenWelcomePageWithReadMe()
        {
            // Arrange
            var itemOperations = new Mock<IItemOperations>();
            var solutionFolder = new Mock<ISolutionFolder>();
            var policy = new Mock<IDefaultDocumentPolicy>();
            const string rootFolder = @"Z:\some\path";
            solutionFolder.Setup(x => x.GetDirectoryName())
                          .Returns(rootFolder);
            policy.Setup(x => x.ContainsDefaultDocument(It.IsAny<string>()))
                  .Returns(true);
            var server = new Mock<IWebServer>();
            var impl = new WelcomePageImpl(solutionFolder.Object, policy.Object, itemOperations.Object, server.Object);

            // Act
            impl.OnAfterOpenSolution();
            impl.OnViewWelcomePage();

            // Assert
            // Server should be started.
            server.Verify(x => x.Start(It.IsAny<Uri>(), rootFolder), Times.AtLeastOnce());
            // Browser should be opened twice: once for solution, once for menu item.
            itemOperations.Verify(x => x.Navigate(It.IsAny<string>()), Times.Exactly(2));
        }
        public void OpenWelcomePageWithNoSolution()
        {
            // Arrange
            var itemOperations = new Mock<IItemOperations>();
            var solutionFolder = new Mock<ISolutionFolder>();
            var policy = new Mock<IDefaultDocumentPolicy>();
            const string rootFolder = @"Z:\some\path";
            solutionFolder.Setup(x => x.GetDirectoryName())
                          .Returns(rootFolder);
            policy.Setup(x => x.ContainsDefaultDocument(It.IsAny<string>()))
                  .Returns(true);
            var server = new Mock<IWebServer>();
            var impl = new WelcomePageImpl(solutionFolder.Object, policy.Object, itemOperations.Object, server.Object);

            // Act
            impl.OnViewWelcomePage();

            // Assert
            server.Verify(x => x.Start(It.IsAny<Uri>(), rootFolder), Times.AtMostOnce());
            itemOperations.Verify(x => x.Navigate(It.IsAny<string>()), Times.Never());
        }