public void SaveDefaultMergeSettingsForCurrentSolution(DefaultMergeSettings defaultMergeSettings) { var saveSelectedBranchSettingsBySolution = _configManager.GetValue <bool>(ConfigKeys.SAVE_BRANCH_PERSOLUTION); if (saveSelectedBranchSettingsBySolution) { var currentSolutionName = GetActiveSolution()?.FullName; defaultMergeSettings.Solution = currentSolutionName; if (!string.IsNullOrWhiteSpace(currentSolutionName)) { var currentSettings = _configManager.GetValue <List <DefaultMergeSettings> >(ConfigKeys.SOLUTIONWIDE_SELECTEDMERGE_SETTINGS) ?? new List <DefaultMergeSettings>(); var currentSolutionSetting = currentSettings.SingleOrDefault(c => c.Solution == currentSolutionName); if (currentSolutionSetting != null) { currentSolutionSetting.SourceBranch = defaultMergeSettings.SourceBranch; currentSolutionSetting.TargetBranch = defaultMergeSettings.TargetBranch; currentSolutionSetting.ProjectName = defaultMergeSettings.ProjectName; } else { currentSettings.Add(defaultMergeSettings); } _configManager.AddValue(ConfigKeys.SOLUTIONWIDE_SELECTEDMERGE_SETTINGS, currentSettings); _configManager.SaveDictionary(); } } }
public async Task TeamMergeViewModel_Initialize_WhenSavePerSolution_AndSolutionHasSavedPreferences_ThenRestoreFromSavedPreferences_Async() { var workspaceModel = new Workspace { Name = "Go test", OwnerName = "14525" }; const string solutionName = "Solution"; const string projectName = "Project"; const string selectedSource = "$/TFS/Dev"; const string selectedTarget = "$/TFS/Main"; var defaultMergeSetting = new DefaultMergeSettings { Solution = solutionName, ProjectName = projectName, SourceBranch = selectedSource, TargetBranch = selectedTarget }; _teamService.Expect(x => x.GetProjectNamesAsync()).Return(Task.FromResult <IEnumerable <string> >(new List <string> { projectName })); _teamService.Expect(x => x.AllWorkspacesAsync()).Return(Task.FromResult <IEnumerable <Workspace> >(new List <Workspace> { workspaceModel })); _teamService.Expect(x => x.CurrentWorkspace()).Return(workspaceModel); _teamService.Expect(x => x.GetBranches(projectName)).Return(new List <Branch>() { new Branch() { Name = selectedSource, Branches = new List <string>() { selectedTarget } } }); _solutionService.Expect(x => x.GetDefaultMergeSettingsForCurrentSolution()).Return(defaultMergeSetting); _configManager.Expect(x => x.GetValue <bool>(ConfigKeys.SAVE_BRANCH_PERSOLUTION)).Return(true); _configManager.Expect(x => x.GetValue <bool>(ConfigKeys.SHOULD_SHOW_BUTTON_SWITCHING_SOURCE_TARGET_BRANCH)).Return(false); await _sut.InitializeAsync(null); Assert.IsTrue(_sut.SelectedProjectName == projectName); Assert.IsTrue(_sut.SelectedSourceBranch == selectedSource); Assert.IsTrue(_sut.SelectedTargetBranch == selectedTarget); Assert.IsFalse(_sut.ShouldShowButtonSwitchingSourceTargetBranch); }
public void TeamMergeViewModel_Initialize_WhenSavePerSolution_AndSolutionHasSavedPreferences_ThenRestoreFromSavedPreferences() { var workspaceModel = new WorkspaceModel { Name = "Go test", OwnerName = "14525" }; const string solutionName = "Solution"; const string projectName = "Project"; const string selectedSource = "$/TFS/Dev"; const string selectedTarget = "$/TFS/Main"; var defaultMergeSetting = new DefaultMergeSettings(solutionName, projectName, selectedSource, selectedTarget); _teamService.Expect(x => x.GetProjectNames()).Return(Task.FromResult <IEnumerable <string> >(new List <string> { projectName })); _teamService.Expect(x => x.AllWorkspaces()).Return(Task.FromResult <IEnumerable <WorkspaceModel> >(new List <WorkspaceModel> { workspaceModel })); _teamService.Expect(x => x.CurrentWorkspace()).Return(workspaceModel); _teamService.Expect(x => x.GetBranches(projectName)).Return(new List <BranchModel>() { new BranchModel() { Name = selectedSource, Branches = new List <string>() { selectedTarget } } }); _solutionService.Expect(x => x.GetDefaultMergeSettingsForCurrentSolution()).Return(defaultMergeSetting); _configHelper.Expect(x => x.GetValue <bool>(ConfigKeys.SAVE_BRANCH_PERSOLUTION)).Return(true); _sut.Initialize(this, new SectionInitializeEventArgs(_serviceProvider, null)); Assert.IsTrue(_sut.SelectedProjectName == projectName); Assert.IsTrue(_sut.SelectedSourceBranch == selectedSource); Assert.IsTrue(_sut.SelectedTargetBranch == selectedTarget); }
public DefaultMergeSettings GetDefaultMergeSettingsForCurrentSolution() { DefaultMergeSettings settings = null; var solution = GetActiveSolution(); if (!string.IsNullOrWhiteSpace(solution?.FullName)) { var defaultMergeSettings = _configManager.GetValue <List <DefaultMergeSettings> >(ConfigKeys.SOLUTIONWIDE_SELECTEDMERGE_SETTINGS) ?? new List <DefaultMergeSettings>(); if (defaultMergeSettings.Any()) { var currentSolutionInCache = defaultMergeSettings.SingleOrDefault(m => m.Solution == solution.FullName); if (currentSolutionInCache != null) { settings = currentSolutionInCache; } } } return(settings); }