public TestProject Apply(IEnumerable <TestProject> testProjects) { var format = this.settings.TestProjectNameFormat; if (string.IsNullOrWhiteSpace(format)) { return(null); } IList <string> selectedProjectNames = SolutionUtilities .GetSelectedFiles(this.dte) .Select(item => item.ProjectName) .ToList(); if (selectedProjectNames.Count != 1) { return(null); // we cannot reliably predict, which test project is correct, when multiple source projects are selected } var expectedTestProject = format.Replace("$ProjectName$", selectedProjectNames.First()); return(testProjects ?.FirstOrDefault(testProject => string.Equals( testProject.Name, expectedTestProject, StringComparison.CurrentCultureIgnoreCase))); }
public void _Path_Linked_List_Follows_Node_Neighbor_Pointers_Along_Best_Path_From_End_Node() { int[,] grid = { { 4, 60, 60, 60 }, { 60, 3, 60, 60 }, { 60, 60, 2, 60 }, { 60, 60, 60, 1 } }; var nodeTableGenerator = new NodeTableGenerator(); Node[,] nodeTable = nodeTableGenerator.GenerateNodeTable(grid, grid.GetLength(0), grid.GetLength(1), out int pathEndColumnIndex); var solutionUtilities = new SolutionUtilities(); int pathEndRowIndex = solutionUtilities.GetPathEndRowIndex(pathEndColumnIndex, nodeTable); LinkedList <int> path = solutionUtilities.GetPath(pathEndRowIndex, pathEndColumnIndex, nodeTable); LinkedListNode <int> currentListNode = path.Last.Previous; //nodeTable[i,i].neighbor starts at 2 and moves diagonally up. for (int i = 3; i > 0; i--) { Assert.AreEqual(nodeTable[i, i].NeighborRowIndex, currentListNode.Value - 1);//-1 because this list is 1 based. currentListNode = currentListNode.Previous; } }
internal void StartupProject_Changed(IVsHierarchy newStartupProjectHierarchy) { if (newStartupProjectHierarchy == null) { return; } var projectName = SolutionUtilities.GetProject(newStartupProjectHierarchy).Name; var currentProblem = (string)cbProblems.SelectedItem; if (currentProblem == null || currentProblem.Equals(projectName, StringComparison.CurrentCultureIgnoreCase)) { return; } if (!IsCaideProblem(projectName)) { // The project doesn't correspond to a problem return; } if (null == CaideExe.Run("checkout", projectName)) { return; } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { Attempt.Action( () => { ThreadHelper.ThrowIfNotOnUIThread(); var options = _package.Options; var source = SolutionUtilities.GetSelectedFiles(_dte, false, options.GenerationOptions).FirstOrDefault(ProjectItemModel.IsSupported); if (source == null) { throw new InvalidOperationException("Cannot go to tests for this item because no supported files were found"); } var status = TargetFinder.FindExistingTargetItem(source, options.GenerationOptions, out var targetItem); switch (status) { case FindTargetStatus.FileNotFound: case FindTargetStatus.FolderNotFound: throw new InvalidOperationException("No unit tests were found for the selected file."); case FindTargetStatus.ProjectNotFound: throw new InvalidOperationException("Cannot go to tests for this item because there is no project '" + source.TargetProjectName + "'"); } VsProjectHelper.ActivateItem(targetItem); }, _package); }
public void TryGetDepedenciesFolderGuid_ValidInput(string solutionFile, string expected) { string actual = string.Empty; SolutionUtilities.TryGetDepedenciesFolderGuid(solutionFile, out actual); Assert.That(actual, Is.EqualTo(expected)); }
public void TryGetDepedenciesFolderGuid_ValidArguments(SolutionFile solution, string expected) { string actual; SolutionUtilities.TryGetDepedenciesFolderGuid(solution, out actual); Assert.That(actual, Is.EqualTo(expected)); }
protected void TestActions( TestWorkspace workspace, string expectedText, int index, IList <CodeAction> actions, IList <TextSpan> expectedConflictSpans = null, IList <TextSpan> expectedRenameSpans = null, IList <TextSpan> expectedWarningSpans = null, string expectedPreviewContents = null, bool compareTokens = true, bool compareExpectedTextAfterApply = false) { var operations = VerifyInputsAndGetOperations(index, actions); VerifyPreviewContents(workspace, expectedPreviewContents, operations); // Test annotations from the operation's new solution var applyChangesOperation = operations.OfType <ApplyChangesOperation>().First(); var oldSolution = workspace.CurrentSolution; var newSolutionFromOperation = applyChangesOperation.ChangedSolution; var documentFromOperation = SolutionUtilities.GetSingleChangedDocument(oldSolution, newSolutionFromOperation); var fixedRootFromOperation = documentFromOperation.GetSyntaxRootAsync().Result; TestAnnotations(expectedText, expectedConflictSpans, fixedRootFromOperation, ConflictAnnotation.Kind, compareTokens); TestAnnotations(expectedText, expectedRenameSpans, fixedRootFromOperation, RenameAnnotation.Kind, compareTokens); TestAnnotations(expectedText, expectedWarningSpans, fixedRootFromOperation, WarningAnnotation.Kind, compareTokens); // Test final text string actualText; if (compareExpectedTextAfterApply) { applyChangesOperation.Apply(workspace, CancellationToken.None); var newSolutionAfterApply = workspace.CurrentSolution; var documentFromAfterApply = SolutionUtilities.GetSingleChangedDocument(oldSolution, newSolutionAfterApply); var fixedRootFromAfterApply = documentFromAfterApply.GetSyntaxRootAsync().Result; actualText = compareTokens ? fixedRootFromAfterApply.ToString() : fixedRootFromAfterApply.ToFullString(); } else { actualText = compareTokens ? fixedRootFromOperation.ToString() : fixedRootFromOperation.ToFullString(); } if (compareTokens) { TokenUtilities.AssertTokensEqual(expectedText, actualText, GetLanguage()); } else { Assert.Equal(expectedText, actualText); } }
protected async Task TestMoveTypeToNewFileAsync( string originalCode, string expectedSourceTextAfterRefactoring, string expectedDocumentName, string destinationDocumentText, IList <string> destinationDocumentContainers = null, bool expectedCodeAction = true, int index = 0, bool ignoreTrivia = true, Action <Workspace> onAfterWorkspaceCreated = null) { var testOptions = new TestParameters(); if (expectedCodeAction) { using (var workspace = await CreateWorkspaceFromFileAsync(originalCode, testOptions)) { onAfterWorkspaceCreated?.Invoke(workspace); // replace with default values on null. if (destinationDocumentContainers == null) { destinationDocumentContainers = Array.Empty <string>(); } var sourceDocumentId = workspace.Documents[0].Id; // Verify the newly added document and its text var oldSolutionAndNewSolution = await TestAddDocumentAsync( testOptions, workspace, destinationDocumentText, index, expectedDocumentName, destinationDocumentContainers, ignoreTrivia); // Verify source document's text after moving type. var oldSolution = oldSolutionAndNewSolution.Item1; var newSolution = oldSolutionAndNewSolution.Item2; var changedDocumentIds = SolutionUtilities.GetChangedDocuments(oldSolution, newSolution); Assert.True(changedDocumentIds.Contains(sourceDocumentId), "source document was not changed."); var modifiedSourceDocument = newSolution.GetDocument(sourceDocumentId); if (ignoreTrivia) { TokenUtilities.AssertTokensEqual( expectedSourceTextAfterRefactoring, (await modifiedSourceDocument.GetTextAsync()).ToString(), GetLanguage()); } else { Assert.Equal(expectedSourceTextAfterRefactoring, (await modifiedSourceDocument.GetTextAsync()).ToString()); } } } else { await TestMissingAsync(originalCode); } }
private static void OnBeforeQueryStatus(object sender, EventArgs e) { if (!(sender is OleMenuCommand command)) { return; } command.Visible = SolutionUtilities.GetSelectedProject()?.IsVcProject() ?? false; }
private void btnEditTests_Click(object sender, RoutedEventArgs e) { string currentProblem = (string)cbProblems.SelectedItem; var problemDirectory = Path.Combine(SolutionUtilities.GetSolutionDir(), currentProblem); var testCases = TestCase.FromDirectory(problemDirectory); testCases = EditTestsWindow.Edit(testCases); TestCase.WriteToDirectory(testCases, problemDirectory); }
protected async Task TestMoveTypeToNewFileAsync( string originalCode, string expectedSourceTextAfterRefactoring, string expectedDocumentName, string destinationDocumentText, ImmutableArray <string> destinationDocumentContainers = default, bool expectedCodeAction = true, int index = 0, Action <Workspace> onAfterWorkspaceCreated = null ) { var testOptions = new TestParameters(index: index); if (expectedCodeAction) { using var workspace = CreateWorkspaceFromOptions(originalCode, testOptions); onAfterWorkspaceCreated?.Invoke(workspace); // replace with default values on null. destinationDocumentContainers = destinationDocumentContainers.NullToEmpty(); var sourceDocumentId = workspace.Documents[0].Id; // Verify the newly added document and its text var oldSolutionAndNewSolution = await TestAddDocumentAsync( testOptions, workspace, destinationDocumentText, expectedDocumentName, destinationDocumentContainers ); // Verify source document's text after moving type. var oldSolution = oldSolutionAndNewSolution.Item1; var newSolution = oldSolutionAndNewSolution.Item2; var changedDocumentIds = SolutionUtilities.GetChangedDocuments( oldSolution, newSolution ); Assert.True( changedDocumentIds.Contains(sourceDocumentId), "source document was not changed." ); var modifiedSourceDocument = newSolution.GetDocument(sourceDocumentId); var actualSourceTextAfterRefactoring = ( await modifiedSourceDocument.GetTextAsync() ).ToString(); Assert.Equal(expectedSourceTextAfterRefactoring, actualSourceTextAfterRefactoring); } else { await TestMissingAsync(originalCode); } }
public SelfTestViewModel() { this.dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE)); IList <Project> allProjects = SolutionUtilities.GetProjects(this.dte); this.targetProjects = allProjects.Where(p => p.Name.EndsWith("TestCases", StringComparison.Ordinal)).ToList(); this.classesProject = allProjects.Single(p => p.Name == "Classes"); this.InitializeAsync(); }
public async Task GettingCompletionListShoudNotRunSourceGenerator(bool forkBeforeFreeze) { var sourceMarkup = @" using System; namespace N { public class C1 { $$ } }"; MarkupTestFile.GetPosition(sourceMarkup.NormalizeLineEndings(), out var source, out int?position); var generatorRanCount = 0; var generator = new CallbackGenerator(onInit: _ => { }, onExecute: _ => Interlocked.Increment(ref generatorRanCount)); using var workspace = WorkspaceTestUtilities.CreateWorkspaceWithPartialSemantics(); var analyzerReference = new TestGeneratorReference(generator); var project = SolutionUtilities.AddEmptyProject(workspace.CurrentSolution) .AddAnalyzerReference(analyzerReference) .AddDocument("Document1.cs", sourceMarkup, filePath: "Document1.cs").Project; Assert.True(workspace.SetCurrentSolution(_ => project.Solution, WorkspaceChangeKind.SolutionChanged)); var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); var compeltionService = document.GetLanguageService <CompletionService>(); Assert.Equal(0, generatorRanCount); if (forkBeforeFreeze) { // Forking before freezing means we'll have to do extra work to produce the final compilation, // but we should still not be running generators. document = document.WithText(SourceText.From(sourceMarkup.Replace("C1", "C2"))); } // We want to make sure import completion providers are also participating. var options = CompletionOptions.From(document.Project.Solution.Options, document.Project.Language); var newOptions = options with { ShowItemsFromUnimportedNamespaces = true }; var(completionList, _) = await compeltionService.GetCompletionsInternalAsync(document, position.Value, options : newOptions); // We expect completion to run on frozen partial semantic, which won't run source generator. Assert.Equal(0, generatorRanCount); var expectedItem = forkBeforeFreeze ? "C2" : "C1"; Assert.True(completionList.Items.Select(item => item.DisplayText).Contains(expectedItem)); } }
private void UpdateSelectedFrameworks() { if (this.selectedProject == null) { this.SelectedTestFramework = TestFrameworks.Default; this.SelectedMockFramework = MockFrameworks.Default; } else { this.SelectedTestFramework = SolutionUtilities.FindTestFramework(this.selectedProject.Project); this.SelectedMockFramework = SolutionUtilities.FindMockFramework(this.selectedProject.Project); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { //var message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", GetType().FullName); //var title = "SettingsCommand"; // Show a message box to prove we were here //VsShellUtilities.ShowMessageBox(ServiceProvider, message, title, // OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); using (var form = new SettingsForm(SolutionUtilities.GetSelectedProject())) { form.ShowDialog(); } }
public void Solution_Opened() { lock (ToDoAfterAllProjectsLoaded) { IsProjectsLoadingInProgress = true; ToDoAfterAllProjectsLoaded.Clear(); } bool isCaideDirectory = SolutionUtilities.IsCaideSolution(); EnableAll(isCaideDirectory); if (isCaideDirectory) { var windowFrame = (IVsWindowFrame)mainToolWindow.Frame; windowFrame.Show(); ReloadProblemList(); if (CHelperServer != null) { CHelperServer.Stop(); CHelperServer = null; } string enableChelperServerStr = CaideExe.Run(new[] { "getopt", "vscaide", "enable_http_server" }, loud: Loudness.QUIET) ?? "1"; if (new[] { "yes", "1", "true" }.Contains(enableChelperServerStr.ToLowerInvariant().Trim())) { CHelperServer = new CHelperServer(); } else { Logger.LogMessage("Disabling CHelper HTTP server due to a setting in caide.ini"); } EnableFsWatcher(false); string path = Path.Combine(SolutionUtilities.GetSolutionDir(), ".caide"); fsWatcher = new FileSystemWatcher(path, "config") { EnableRaisingEvents = false, IncludeSubdirectories = false, NotifyFilter = NotifyFilters.LastWrite, }; fsWatcher.Changed += fsWatcher_Changed; fsWatcher.EnableRaisingEvents = true; AfterProjectsLoaded(() => projectManager.CreateCppLibProject()); } }
public void CreateCppLibProject() { var solutionDir = SolutionUtilities.GetSolutionDir(); const string cpplib = "cpplib"; var cppLibraryDir = Path.Combine(solutionDir, cpplib); if (!Directory.Exists(cppLibraryDir)) { return; } var dte = Services.DTE; var solution = dte.Solution as Solution2; var allProjects = solution.Projects.OfType <Project>(); var project = allProjects.SingleOrDefault(p => p.Name == cpplib); VCProject vcProject; if (project == null) { // Create the project solution.AddFromTemplate(Paths.CppProjectTemplate, Path.Combine(solutionDir, cpplib), cpplib, Exclusive: false); allProjects = solution.Projects.OfType <Project>(); project = allProjects.SingleOrDefault(p => p.Name == cpplib); if (project == null) { Logger.LogError("Couldn't create {0} project", cpplib); return; } // Set to static library vcProject = (VCProject)project.Object; var configs = (IVCCollection)vcProject.Configurations; foreach (var conf in configs.OfType <VCConfiguration>()) { conf.ConfigurationType = ConfigurationTypes.typeStaticLibrary; conf.OutputDirectory = @"$(ProjectDir)\$(Configuration)\"; } } vcProject = (VCProject)project.Object; // Ensure that all files from the directory are added AddDirectoryRecursively(vcProject, cppLibraryDir); SolutionUtilities.SaveSolution(); }
/// <summary> /// Initializes a new instance of the <see cref="GoToUnitTestsCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file). /// </summary> /// <param name="package">Owner package, not null.</param> /// <param name="commandService">Command service to add command to, not null.</param> private GoToUnitTestsCommand(IUnitTestGeneratorPackage package, OleMenuCommandService commandService) { _package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); var menuCommandId = new CommandID(CommandSet, CommandId); var menuItem = new OleMenuCommand(Execute, menuCommandId); menuItem.BeforeQueryStatus += (s, e) => { ThreadHelper.ThrowIfNotOnUIThread(); menuItem.Visible = SolutionUtilities.GetSelectedFiles(_dte, false, _package.Options.GenerationOptions).Any(ProjectItemModel.IsSupported); }; commandService.AddCommand(menuItem); }
public void GetDependenciesProjects_ValidArguments() { string targetSolution = Path.Combine(TEST_ROOT_DIRECTORY, @"SolutionReferenceTester\SolutionReferenceTester.sln"); string[] expected = new string[] { Path.Combine(TEST_ROOT_DIRECTORY, @"SolutionReferenceTester\A\A.csproj"), Path.Combine(TEST_ROOT_DIRECTORY, @"SolutionReferenceTester\B\B.csproj"), Path.Combine(TEST_ROOT_DIRECTORY, @"SolutionReferenceTester\C\C.csproj"), }; string[] actual = SolutionUtilities.GetDependenciesProjects(targetSolution).ToArray(); Assert.That(actual, Is.EquivalentTo(expected)); }
public void GetNestedProjectsForGuid_ValidArguments() { string targetSolution = Path.Combine(TEST_ROOT_DIRECTORY, @"SolutionReferenceTester\SolutionReferenceTester.sln"); string targetDependenciesGuid = @"{8175C2B3-EDF4-41E5-9A52-564CE9E84324}"; string[] expectedResult = new string[] { "{4ACCAD4A-949C-4DFC-A449-B288BB5239C6}", "{7B0E316A-3C60-4166-B59B-338CBB2DFD0C}", "{FA426B0F-A3B1-4FCA-91B0-74100460E464}", }; string[] actual = SolutionUtilities.GetNestedProjectsForGuid(targetSolution, targetDependenciesGuid).ToArray(); Assert.That(actual, Is.EquivalentTo(expectedResult)); }
//// Key is project name, value is the expected detection result //private static readonly Dictionary<string, SelfTestDetectionResult> ExpectedDetectionResults = new Dictionary<string, SelfTestDetectionResult> //{ // { "AutoMoqTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.AutoMoqName) }, // { "NetCoreAutoMoqTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.AutoMoqName) }, // { "NetCoreMoqTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.MoqName) }, // { "NetCoreNSubstituteTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.NSubstituteName) }, // { "NetCoreNUnitTestCases", new SelfTestDetectionResult(TestFrameworks.NUnitName, MockFrameworks.MoqName) }, // { "NetCoreSimpleStubsTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.SimpleStubsName) }, // { "NetCoreVSRhinoMocksTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.RhinoMocksName) }, // { "NoFrameworkTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.MoqName) }, // { "NSubstituteTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.NSubstituteName) }, // { "NUnitTestCases", new SelfTestDetectionResult(TestFrameworks.NUnitName, MockFrameworks.MoqName) }, // { "NUnitUwpTestCases", new SelfTestDetectionResult(TestFrameworks.NUnitName, MockFrameworks.SimpleStubsName) }, // { "SimpleStubsTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.SimpleStubsName) }, // { "VSRhinoMocksTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.RhinoMocksName) }, // { "VSTestCases", new SelfTestDetectionResult(TestFrameworks.VisualStudioName, MockFrameworks.MoqName) }, // { "XUnitMoqTestCases", new SelfTestDetectionResult(TestFrameworks.XUnitName, MockFrameworks.MoqName) }, // { "MultipleFrameworkTestCases", new SelfTestDetectionResult(TestFrameworks.NUnitName, MockFrameworks.NSubstituteName) }, //}; public void Clean(IList <Project> projects = null, bool save = false) { var dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE)); if (projects == null) { projects = SolutionUtilities.GetProjects(dte); } // First clean out cases in projects foreach (var project in projects) { if (project.Name.Contains("TestCases")) { // Delete Cases folder from project if it exists. foreach (ProjectItem item in project.ProjectItems) { if (item.Name == "Cases") { item.Delete(); project.Save(); break; } } // Delete folder if it existed but was not added to project. string projectFolder = Path.GetDirectoryName(project.FileName); string casesFolder = Path.Combine(projectFolder, "Cases"); if (Directory.Exists(casesFolder)) { Directory.Delete(casesFolder, recursive: true); } } } // Next, clean out any files left in SelfTestFiles\Actual string selfTestFilesDirectory = SolutionUtilities.GetSelfTestDirectoryFromSandbox(dte); string actualFolder = Path.Combine(selfTestFilesDirectory, "Actual"); if (Directory.Exists(actualFolder)) { Directory.Delete(actualFolder, recursive: true); } }
public void _Get_Path_End_Row_Index_Returns_Row_Index_Of_Min_Cost_Node_In_End_Column() { int[,] grid = new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, -1 }, { 8, 8, 8, 20 } }; var nodeTableGenerator = new NodeTableGenerator(); Node[,] nodeTable = nodeTableGenerator.GenerateNodeTable(grid, grid.GetLength(0), grid.GetLength(1), out int pathEndColumnIndex); var solutionUtilities = new SolutionUtilities(); int rowIndex = solutionUtilities.GetPathEndRowIndex(pathEndColumnIndex, nodeTable); //-1 is at row index 2 Assert.AreEqual(2, rowIndex); }
public void CreateSubmissionCsProject() { Project project = RecreateProjectOfCorrectType("submission", CSharpProjectType); // Create submission.cs file if it's missing. var submissionCs = Path.Combine(SolutionUtilities.GetSolutionDir(), "submission.cs"); if (!File.Exists(submissionCs)) { File.WriteAllText(submissionCs, ""); } if (!project.ProjectItems.OfType <ProjectItem>().Any(item => "submission.cs".Equals(item.Name, StringComparison.CurrentCultureIgnoreCase))) { project.ProjectItems.AddFromFile(submissionCs); } }
private void ReloadProblemList() { Logger.Trace("ReloadProblemList"); try { EnableFsWatcher(false); string stdout = CaideExe.Run("getstate", "core", "problem"); string currentProblem = stdout == null ? null : stdout.Trim(); var problemNames = new List <string>(); if (string.Empty == currentProblem) { problemNames.Add(""); } foreach (var subdir in Directory.EnumerateDirectories(SolutionUtilities.GetSolutionDir())) { if (Directory.Exists(Path.Combine(subdir, ".caideproblem")) && File.Exists(Path.Combine(subdir, "problem.ini"))) { problemNames.Add(Path.GetFileName(subdir.TrimEnd(Path.DirectorySeparatorChar))); } } problemNames.Sort(StringComparer.CurrentCultureIgnoreCase); cbProblems.Items.Clear(); foreach (var problem in problemNames) { cbProblems.Items.Add(problem); } if (currentProblem == null) { return; } cbProblems.SelectedItem = currentProblem; } finally { EnableFsWatcher(true); } }
public CHelperServer() { var args = new [] { "httpServer" }; var psi = new ProcessStartInfo { FileName = Paths.CaideExe, Arguments = CommandLine.CreateCommandLine(args), WorkingDirectory = SolutionUtilities.GetSolutionDir(), RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, }; Caide = Process.Start(psi); new ReadStreamToOutputWindow(Caide.StandardOutput, CancelTokenSource.Token).RunAsync(); new ReadStreamToOutputWindow(Caide.StandardError, CancelTokenSource.Token).RunAsync(); }
private void btnCreateSolution_Click(object sender, RoutedEventArgs e) { if (SolutionUtilities.IsCaideSolution()) { ReloadProblemList(); } else { string solutionDir = SolutionUtilities.GetSolutionDir(); bool newSolution = solutionDir == null; if (newSolution) { var folderBrowserDialog = new FolderBrowserDialog { Description = "Select solution folder", ShowNewFolderButton = true, RootFolder = Environment.SpecialFolder.Desktop, SelectedPath = recentFolder, }; var result = folderBrowserDialog.ShowDialog(); if (result != DialogResult.OK) { return; } solutionDir = recentFolder = folderBrowserDialog.SelectedPath; } if (null == CaideExe.Run(new[] { "init" }, loud: Loudness.LOUD, solutionDir: solutionDir)) { return; } if (newSolution) { ErrorHandler.ThrowOnFailure( Services.Solution.CreateSolution(solutionDir, "VsCaide", 0) ); File.Copy(Path.Combine(solutionDir, "templates", "vs_common.props"), Path.Combine(solutionDir, "vs_common.props"), overwrite: true); SolutionUtilities.SaveSolution(); } } }
public void _Last_Index_In_List_Is_Row_Index_Of_Last_Node_In_Path() { int[,] grid = { { 1, 1, 1, 60 }, { 60, 60, 60, 1 }, { 60, 60, 60, 60 }, { 60, 60, 60, 60 } }; var nodeTableGenerator = new NodeTableGenerator(); Node[,] nodeTable = nodeTableGenerator.GenerateNodeTable(grid, grid.GetLength(0), grid.GetLength(1), out int pathEndColumnIndex); var solutionUtilities = new SolutionUtilities(); int pathEndRowIndex = solutionUtilities.GetPathEndRowIndex(pathEndColumnIndex, nodeTable); LinkedList <int> path = solutionUtilities.GetPath(pathEndRowIndex, pathEndColumnIndex, nodeTable); //path ends at row index 2 (it is now 1 based to match the desired final output) Assert.AreEqual(2, path.Last.Value); }
private static Document GetDocumentToVerify(DocumentId expectedChangedDocumentId, Solution oldSolution, Solution newSolution) { Document document; // If the expectedChangedDocumentId is not mentioned then we expect only single document to be changed if (expectedChangedDocumentId == null) { var projectDifferences = SolutionUtilities.GetSingleChangedProjectChanges(oldSolution, newSolution); var documentId = projectDifferences.GetChangedDocuments().FirstOrDefault() ?? projectDifferences.GetAddedDocuments().FirstOrDefault(); Assert.NotNull(documentId); document = newSolution.GetDocument(documentId); } else { // This method obtains only the document changed and does not check the project state. document = newSolution.GetDocument(expectedChangedDocumentId); } return(document); }
private async Task InitializeAsync() { DTE2 dte = (DTE2)await this.package.GetServiceAsync(typeof(DTE)); OleMenuCommandService commandService = await this.package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (commandService != null) { var menuCommandId = new CommandID(CommandSet, CommandId); var menuItem = new OleMenuCommand(this.MenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += (sender, args) => { menuItem.Visible = SolutionUtilities.GetSelectedFiles(dte).Any(file => file != null && file.FilePath != null && file.FilePath.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)); }; commandService.AddCommand(menuItem); } }
public void CreateAndActivateCSharpProject(string selectedProblem) { Project project = RecreateProjectOfCorrectType(selectedProblem, CSharpProjectType); if (project == null) { return; } var vsProject = (VSProject)project.Object; // Ensure that the project contains necessary files var solutionFile = string.Format(@"{0}.cs", selectedProblem); var testFile = string.Format(@"{0}_test.cs", selectedProblem); var solutionDir = SolutionUtilities.GetSolutionDir(); var projectDir = Path.Combine(solutionDir, selectedProblem); foreach (var fileName in new[] { solutionFile, testFile }) { if (!project.ProjectItems.OfType <ProjectItem>().Any(item => item.Name.Equals(fileName, StringComparison.CurrentCultureIgnoreCase))) { project.ProjectItems.AddFromFile(Path.Combine(projectDir, fileName)); } } var dte = Services.DTE; dte.Solution.SolutionBuild.StartupProjects = project.UniqueName; var allItems = project.ProjectItems.OfType <ProjectItem>(); var solutionCs = allItems.Single(i => i.Name == solutionFile); var solutionCsWindow = solutionCs.Open(EnvDTE.Constants.vsViewKindCode); solutionCsWindow.Visible = true; solutionCsWindow.Activate(); CreateSubmissionCsProject(); SolutionUtilities.SaveSolution(); }