public void ProviderCommitIsCalledOnCommit()
        {
            //arrange
            _viewMock.SetupProperty(v => v.IncludedChanges);
            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);

            _viewMock.Object.IncludedChanges = new List<IFileStatusEntry>() { new FileStatusEntry(@"C:\path\to\file.txt", FileStatus.Modified) };

            //act
            _viewMock.Raise(v => v.Commit += null, new EventArgs());

            //assert
            _providerMock.Verify(git => git.Commit(It.IsAny<string>()));
        }
        public void ChangesCurrentBranchRefreshesWhenBranchIsCheckedOut()
        {
            //arrange
            _configService.Setup(c => c.LoadConfiguration())
                .Returns(GetDummyConfig());

            SetupValidVbProject();

            var changesView = new Mock<IChangesView>();
            changesView.SetupProperty(v => v.CurrentBranch, "master");
            var changesPresenter = new ChangesPresenter(changesView.Object);

            var branchesView = new Mock<IBranchesView>();
            branchesView.SetupProperty(b => b.Current, "master");

            var branchesPresenter = new BranchesPresenter(branchesView.Object, new Mock<ICreateBranchView>().Object, new Mock<IDeleteBranchView>().Object, new Mock<IMergeView>().Object);

            var provider = new Mock<ISourceControlProvider>();
            provider.Setup(git => git.Checkout(It.IsAny<string>()));
            provider.SetupGet(git => git.CurrentBranch)
                .Returns(new Branch("dev", "/ref/head/dev", false, true));

            branchesPresenter.Provider = provider.Object;
            changesPresenter.Provider = provider.Object;

            //purposely createing a new presenter with specific child presenters
            var presenter = new SourceControlPresenter(_vbe.Object, _addIn.Object, _configService.Object,
                                                        _view.Object, changesPresenter, branchesPresenter,
                                                        _settingsPresenter.Object, _unsyncedPresenter.Object,
                                                        _folderBrowserFactory.Object, _providerFactory.Object,
                                                        _failedActionView.Object, _loginView.Object);

            //act
            branchesView.Object.Current = "dev";
            branchesView.Raise(b => b.SelectedBranchChanged += null, new EventArgs());

            //assert
            Assert.AreEqual("dev", changesView.Object.CurrentBranch);
        }
        public void RefreshDisplaysChangedFiles()
        {
            //arrange
            var fileStatusEntries = new List<FileStatusEntry>()
            {
                new FileStatusEntry(@"C:\path\to\module.bas", FileStatus.Modified),
                new FileStatusEntry(@"C:\path\to\class.cls", FileStatus.Unaltered),
                new FileStatusEntry(@"C:\path\to\added.bas", FileStatus.Added | FileStatus.Modified),
                new FileStatusEntry(@"C:\path\to\untracked.frx", FileStatus.Untracked)
            };

            _viewMock.SetupProperty(v => v.IncludedChanges);
            _viewMock.SetupProperty(v => v.UntrackedFiles);
            _providerMock.Setup(git => git.Status()).Returns(fileStatusEntries);

            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);
            //act
            presenter.RefreshView();

            //Assert
            Assert.AreEqual(2, _viewMock.Object.IncludedChanges.Count, "Incorrect Included Changes");
            Assert.AreEqual(@"C:\path\to\untracked.frx", _viewMock.Object.UntrackedFiles[0].FilePath);
        }
        public void ChangesPresenter_WhenCommitFails_ActionFailedEventIsRaised()
        {
            //arrange
            var wasRaised = false;

            _providerMock.Setup(p => p.Commit(It.IsAny<string>()))
                .Throws(
                    new SourceControlException("A source control exception was thrown.", 
                        new LibGit2Sharp.LibGit2SharpException("With an inner libgit2sharp exception"))
                    );

            _viewMock.SetupProperty(v => v.IncludedChanges);
            _viewMock.Object.IncludedChanges = new List<IFileStatusEntry>() { new FileStatusEntry(@"C:\path\to\module.bas", FileStatus.Modified) };

            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);

            presenter.ActionFailed += (sender, args) => wasRaised = true;

            //act
            presenter.Commit();

            //assert
            Assert.IsTrue(wasRaised, "ActionFailedEvent was not raised.");
        }
        public void ExcludedIsClearedAfterRefresh()
        {
            //arrange
            _viewMock.SetupProperty(v => v.ExcludedChanges);
            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);
            _viewMock.Object.ExcludedChanges = new List<IFileStatusEntry>() { new FileStatusEntry(@"C:\path\to\module.bas", FileStatus.Modified) };

            Assert.IsTrue(_viewMock.Object.ExcludedChanges.Any(), "No changes found prior to refresh. Issue with Test code.");

            //act
            presenter.RefreshView();

            //
            Assert.IsFalse(_viewMock.Object.ExcludedChanges.Any());
        }
        public void RefreshChangesAfterCommit()
        {
            //arrange
            _viewMock.SetupAllProperties();
            _viewMock.Object.CommitMessage = "Test Commit";
            _viewMock.Object.CommitAction = CommitAction.Commit;
            _viewMock.Object.IncludedChanges = new List<IFileStatusEntry>() {new FileStatusEntry(@"C:\path\to\module.bas",FileStatus.Modified) };

            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);

            //act
            _viewMock.Raise(v => v.Commit += null, new EventArgs());
            _providerMock.Setup(git => git.Status()).Returns(new List<FileStatusEntry>());
            
            //assert
            Assert.IsFalse(_viewMock.Object.IncludedChanges.Any());
        }
        public void ClearCommitMessageAfterSuccessfulCommit()
        {

            _viewMock.SetupAllProperties();
            _viewMock.Object.CommitMessage = "Test Commit";
            _viewMock.Object.CommitAction = CommitAction.Commit;
            _viewMock.Object.IncludedChanges = new List<IFileStatusEntry>() { new FileStatusEntry(@"C:\path\to\module.bas", FileStatus.Modified) };

            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);

            //act
            _viewMock.Raise(v => v.Commit += null, new EventArgs());

            //assert
            Assert.AreEqual(string.Empty, _viewMock.Object.CommitMessage);
        }
        public void  CommitEnabledAfterActionSelectedAndMessageEntered()
        {
            //arrange
            _viewMock.SetupAllProperties();
            var presenter = new ChangesPresenter(_viewMock.Object, _providerMock.Object);

            //act
            _viewMock.Object.CommitMessage = "Test Message";
            _viewMock.Raise(v => v.CommitMessageChanged += null, new EventArgs());

            _viewMock.Object.CommitAction = CommitAction.Commit;
            _viewMock.Raise(v => v.SelectedActionChanged += null, new EventArgs());

            //assert
            Assert.IsTrue(_viewMock.Object.CommitEnabled);
        }