public void ConfigIsSavedOnSave() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object); //simulate Update button click vm.UpdateSettingsCommand.Execute(null); _configService.Verify(s => s.Save(_config)); }
public void ViewIsPopulatedOnRefresh() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object); vm.RefreshView(); Assert.AreEqual(Name, vm.UserName, "Name"); Assert.AreEqual(Email, vm.EmailAddress, "Email"); Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location"); Assert.AreEqual(CommandPromptLocation, vm.CommandPromptLocation, "Command Prompt Location"); }
internal static SettingsItemViewModel GetCurrentSettings(DTE2 application) { SettingsPanelViewModel settingsCollection = GetSettingsCollection(application); if (settingsCollection == null) { return(null); } object settings = settingsCollection.ItemsSourceView.CurrentItem; return((SettingsItemViewModel)settings); }
public void OnBrowseCommandPromptLocation_WhenUserCancels_ViewRemainsUnchanged() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object) { CommandPromptLocation = CommandPromptLocation }; _openFileDialog.Setup(o => o.FileName).Returns(OtherCommandPromptLocation); _openFileDialog.Setup(o => o.ShowDialog()).Returns(DialogResult.Cancel); vm.ShowDefaultRepoFolderPickerCommand.Execute(null); Assert.AreEqual(CommandPromptLocation, vm.CommandPromptLocation); }
public void OnBrowseCommandPromptLocation_WhenUserConfirms_ViewMatchesSelectedPath() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object) { CommandPromptLocation = CommandPromptLocation }; _openFileDialog.Setup(o => o.FileName).Returns(OtherCommandPromptLocation); _openFileDialog.Setup(o => o.ShowDialog()).Returns(DialogResult.OK); vm.ShowCommandPromptExePickerCommand.Execute(null); Assert.AreEqual(_openFileDialog.Object.FileName, vm.CommandPromptLocation); }
public void OnBrowseDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object) { DefaultRepositoryLocation = RepoLocation }; _folderBrowser.Object.SelectedPath = OtherRepoLocation; _folderBrowser.Setup(f => f.ShowDialog()).Returns(DialogResult.Cancel); vm.ShowDefaultRepoFolderPickerCommand.Execute(null); Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation); }
public void InitializeMocks() { _vbe = new MockVbeBuilder() .ProjectBuilder("TestProject1", ProjectProtection.Unprotected) .AddComponent("Module1", ComponentType.StandardModule, string.Empty) .MockVbeBuilder() .Build(); _configService = new Mock <IConfigProvider <SourceControlSettings> >(); _configService.Setup(c => c.Create()).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>(), It.IsAny <bool>())).Returns(_folderBrowser.Object); _folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>())).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>(), It.IsAny <SecureCredentials>())).Returns(GetDummyRepo()); _provider.Setup(git => git.CurrentRepository).Returns(GetDummyRepo()); _providerFactory = new Mock <ISourceControlProviderFactory>(); _providerFactory.Setup(f => f.CreateProvider(It.IsAny <IVBProject>())) .Returns(_provider.Object); _providerFactory.Setup(f => f.CreateProvider(It.IsAny <IVBProject>(), It.IsAny <IRepository>())) .Returns(_provider.Object); _providerFactory.Setup(f => f.CreateProvider(It.IsAny <IVBProject>(), It.IsAny <IRepository>(), It.IsAny <SecureCredentials>())) .Returns(_provider.Object); _changesVM = new ChangesPanelViewModel(); _branchesVM = new BranchesPanelViewModel(); _unsyncedVM = new UnsyncedCommitsPanelViewModel(); _settingsVM = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, new Rubberduck.UI.OpenFileDialog()); }
internal static SettingsPanelViewModel GetSettingsCollection(DTE2 application) { string key = typeof(CSqlAddIn).FullName.Replace('.', '_') + "_Settings"; SettingsPanelViewModel settingsViewModel = null; if (application.Globals.get_VariableExists(key)) { settingsViewModel = (SettingsPanelViewModel)application.Globals[key]; } else { // Konfiguration laden und ViewModel vorbereiten ISettingsPersistensProvider persistensProvider = new SettingsFilePersistensProvider(); settingsViewModel = new csql.addin.Gui.Views.SettingsPanelViewModel(persistensProvider); application.Globals[key] = settingsViewModel; } return(settingsViewModel); }
public void ChangesToViewAreRevertedOnCancel() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object); //simulate user input vm.UserName = OtherName; vm.EmailAddress = OtherEmail; vm.DefaultRepositoryLocation = OtherRepoLocation; vm.DefaultRepositoryLocation = OtherCommandPromptLocation; //simulate Cancel button click vm.CancelSettingsChangesCommand.Execute(null); Assert.AreEqual(Name, vm.UserName, "Name"); Assert.AreEqual(Email, vm.EmailAddress, "Email"); Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location"); Assert.AreEqual(CommandPromptLocation, vm.CommandPromptLocation, "Command Prompt Location"); }
public void ConfigIsPopulatedFromViewOnSave() { var vm = new SettingsPanelViewModel(_configService.Object, _folderBrowserFactory.Object, _openFileDialog.Object); //simulate user input vm.UserName = OtherName; vm.EmailAddress = OtherEmail; vm.DefaultRepositoryLocation = OtherRepoLocation; vm.CommandPromptLocation = OtherCommandPromptLocation; //simulate Update button click vm.UpdateSettingsCommand.Execute(null); Assert.AreEqual(OtherName, _config.UserName, "Name"); Assert.AreEqual(OtherEmail, _config.EmailAddress, "Email"); Assert.AreEqual(OtherRepoLocation, _config.DefaultRepositoryLocation, "Default Repo Location"); Assert.AreEqual(OtherCommandPromptLocation, _config.CommandPromptLocation, "Command Prompt Location"); }
public SettingsPanel(SettingsPanelViewModel settingsPanelViewModel) { InitializeComponent(); DataContext = settingsPanelViewModel; }
public void Listen(SettingsPanelViewModel sb) { if (this.listenThread != null) { if (this.listenThread.IsAlive) { this.StopListen = true; while (this.listenThread.IsAlive) { Thread.Sleep(20); } } } this.StopListen = false; IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); var endPoints = new List <IPEndPoint>(); foreach (var entry in hostEntry.AddressList) { if (entry.AddressFamily == AddressFamily.InterNetwork) { endPoints.Add(new IPEndPoint(entry, this.PortNumber)); break; } } if (endPoints.Count == 0) { MessageBox.Show("No valid networks were found to connect to."); return; } var socket = new Socket(endPoints[0].Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp) { ReceiveTimeout = 5000 }; foreach (var e in endPoints) { socket.Bind(e); } this.listenThread = new Thread( new ThreadStart( delegate { while (this.StopListen == false) { var inBuffer = new byte[1000]; EndPoint senderRemote = new IPEndPoint(IPAddress.Any, 0); try { socket.ReceiveFrom(inBuffer, ref senderRemote); } catch (SocketException ex) { int errorCode = ex.ErrorCode; continue; } var packet = ScoreboardPacket.Parse(inBuffer); foreach (var cmd in packet.Commands) { if (cmd.Command == CommandType.Ping) { var pongCmd = new EmptyPacketCommand { Command = CommandType.Pong }; var pongPacket = new ScoreboardPacket() { Commands = new[] { pongCmd } }; socket.SendTo(pongPacket.ToBytes(), senderRemote); } } this.dispatcher.BeginInvoke((Action)(() => sb.HandleRemoteCommands(packet, socket, senderRemote))); } socket.Close(); socket.Dispose(); })); this.listenThread.Start(); this.IsListening = true; }