Inheritance: ViewModelBase, IControlViewModel
        public void ConfigIsSavedOnSave()
        {
            //arrange
            var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);

            //act
            //simulate Update button click
            vm.UpdateSettingsCommand.Execute(null);

            //assert
            _configService.Verify(s => s.SaveConfiguration(_config));
        }
        public void ViewIsPopulatedOnRefresh()
        {
            //arrange
            var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);

            //act
            vm.RefreshView();

            //assert
            Assert.AreEqual(Name, vm.UserName, "Name");
            Assert.AreEqual(Email, vm.EmailAddress, "Email");
            Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location");
        }
        public void ConfigIsPopulatedFromViewOnSave()
        {
            //arrange
            var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);

            //simulate user input
            vm.UserName = OtherName;
            vm.EmailAddress = OtherEmail;
            vm.DefaultRepositoryLocation = OtherRepoLocation;

            //simulate Update button click
            vm.UpdateSettingsCommand.Execute(null);

            //assert
            Assert.AreEqual(OtherName, _config.UserName, "Name");
            Assert.AreEqual(OtherEmail, _config.EmailAddress, "Email");
            Assert.AreEqual(OtherRepoLocation, _config.DefaultRepositoryLocation, "Default Repo Location");
        }
        public void InitializeMocks()
        {
            _window = Mocks.MockFactory.CreateWindowMock();
            _windows = new MockWindowsCollection(new List<Window> { _window.Object });
            _vbe = Mocks.MockFactory.CreateVbeMock(_windows);

            _configService = new Mock<IConfigurationService<SourceControlConfiguration>>();
            _configService.Setup(c => c.LoadConfiguration()).Returns(GetDummyConfig());

            _folderBrowser = new Mock<IFolderBrowser>();
            _folderBrowserFactory = new Mock<IFolderBrowserFactory>();
            _folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny<string>())).Returns(_folderBrowser.Object);
            _folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny<string>(), false)).Returns(_folderBrowser.Object);


            var masterRemote = new Mock<LibGit2Sharp.Branch>();
            masterRemote.SetupGet(git => git.Tip).Returns(new Mock<LibGit2Sharp.Commit>().Object);
            masterRemote.SetupGet(git => git.FriendlyName).Returns("master");

            var initialBranch = new Branch("master", "refs/Heads/master", false, true, masterRemote.Object);

            _provider = new Mock<ISourceControlProvider>();
            _provider.SetupGet(git => git.CurrentBranch).Returns(initialBranch);
            _provider.SetupGet(git => git.UnsyncedLocalCommits).Returns(new List<ICommit>());
            _provider.SetupGet(git => git.UnsyncedRemoteCommits).Returns(new List<ICommit>());
            _provider.Setup(git => git.InitVBAProject(It.IsAny<string>())).Returns(GetDummyRepo());
            _provider.Setup(git => git.Clone(It.IsAny<string>(), It.IsAny<string>())).Returns(GetDummyRepo());

            _providerFactory = new Mock<ISourceControlProviderFactory>();
            _providerFactory.Setup(f => f.CreateProvider(It.IsAny<VBProject>()))
                .Returns(_provider.Object);
            _providerFactory.Setup(f => f.CreateProvider(It.IsAny<VBProject>(), It.IsAny<IRepository>(), It.IsAny<ICodePaneWrapperFactory>()))
                .Returns(_provider.Object);
            _providerFactory.Setup(f => f.CreateProvider(It.IsAny<VBProject>(), It.IsAny<IRepository>(), It.IsAny<SecureCredentials>(), It.IsAny<ICodePaneWrapperFactory>()))
                .Returns(_provider.Object);

            _changesVM = new ChangesViewViewModel();
            _branchesVM = new BranchesViewViewModel();
            _unsyncedVM = new UnsyncedCommitsViewViewModel();
            _settingsVM = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);
        }
        public void ChangesToViewAreRevertedOnCancel()
        {
            //arrange
            var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);

            //simulate user input
            vm.UserName = OtherName;
            vm.EmailAddress = OtherEmail;
            vm.DefaultRepositoryLocation = OtherRepoLocation;

            //act
            //simulate Cancel button click
            vm.CancelSettingsChangesCommand.Execute(null);

            //assert
            Assert.AreEqual(Name, vm.UserName, "Name");
            Assert.AreEqual(Email, vm.EmailAddress, "Email");
            Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location");
        }
        public void OnBrowserDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged()
        {
            //arrange
            var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object)
            {
                DefaultRepositoryLocation = RepoLocation
            };
            _folderBrowser.Object.SelectedPath = OtherRepoLocation;
            _folderBrowser.Setup(f => f.ShowDialog()).Returns(DialogResult.Cancel);

            //act
            vm.ShowFilePickerCommand.Execute(null);

            //assert
            Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation);
        }