public void AssertUX(string code, [CallerMemberName] string path = "") { int caret = 0; var assertCodeSnippets = GetAsserts(ref code, ref caret); var filePath = AbsoluteDirectoryPath.Parse(Directory.GetCurrentDirectory()) / new FileName(path); var log = new DummyLogger(); var context = Context.CreateContext(filePath, code, caret, new DummySourcePackage()); var mainPackage = PackageCache.GetPackage(new Log(log.TextWriter), _project); mainPackage.SetCacheDirectory((AbsoluteDirectoryPath.Parse(mainPackage.CacheDirectory) / new DirectoryName("UxCompletion")).NativePath); var build = new CodeNinjaBuild(log, _project, _editors, mainPackage, mainPackage.References.ToList(), code, filePath); build.Execute(); var suggestions = SuggestionParser.GetSuggestions(build.Compiler, context, caret, new DummyReader()); if (assertCodeSnippets != null) { foreach (var codeSnippet in assertCodeSnippets) { OnAssert(code, codeSnippet, suggestions, log); } } }
protected void TestPerformance(string code, [CallerMemberName] string testName = "") { ConfigureProjectReferences(); //get calling method info StackTrace stackTrace = new StackTrace(); var callingMethod = stackTrace.GetFrame(1).GetMethod(); var testAttribute = (PerformanceTestAttribute)callingMethod.GetCustomAttributes(typeof(PerformanceTestAttribute), true)[0]; var caret = GetCaret(ref code); var filePath = AbsoluteDirectoryPath.Parse(Directory.GetCurrentDirectory()) / new FileName(testName); var log = new DummyLogger(); var context = Context.CreateContext(filePath, code, caret, new DummySourcePackage()); var mainPackage = PackageCache.GetPackage(new Log(log.TextWriter), _project); mainPackage.SetCacheDirectory((AbsoluteDirectoryPath.Parse(mainPackage.CacheDirectory) / new DirectoryName("UxCompletion")).NativePath); var build = new CodeNinjaBuild(log, _project, _editors, mainPackage, mainPackage.References.ToList(), code, filePath); build.Execute(); Stopwatch sw = new Stopwatch(); sw.Start(); SuggestionParser.GetSuggestions(build.Compiler, context, caret, new DummyReader()); sw.Stop(); if (_context == null) { throw new ArgumentNullException("_context"); } _context.Logger.LogTimeEvent(testName, testAttribute.Description, sw.ElapsedMilliseconds / 1000f); }
void Build() { var build = new CodeNinjaBuild(new Logger(), _currentProject, _editorManager, MainPackage, MainPackage.References.ToList()); var result = build.Execute(); if (result == ExecuteStatus.NotDirty || result == ExecuteStatus.Fatal) { return; } _lastBuild = build; }
protected void AssertCode(string code, [CallerMemberName] string path = "") { int caret = 0; var assertCodeSnippets = GetAsserts(ref code, ref caret); var ubProject = _project; var filePath = AbsoluteDirectoryPath.Parse(Directory.GetCurrentDirectory()) / new FileName(path); _log = new DummyLogger(); var editors = new DummyEditorManager(); var mainPackage = new PackageCache(new Log(_log.TextWriter), ubProject.Config).GetPackage(ubProject); mainPackage.SetCacheDirectory((AbsoluteDirectoryPath.Parse(mainPackage.CacheDirectory) / new DirectoryName("CodeCompletion")).NativePath); var build = new CodeNinjaBuild(_log, ubProject, editors, mainPackage, mainPackage.References.ToList(), code, filePath); build.Execute(); var engine = new DummyEngine(build.Compiler); var codeCompleter = new CodeCompleter(engine.Compiler, new Source(build.ProjectPackage, filePath.NativePath), new CodeReader(code, caret), caret, Parser.Parse(code)); if (codeCompleter.Context.NodePath.Count < 1) { throw new TestException("Invalid node path was generated for the test case"); } ConfidenceLevel confidenceLevel; var suggestions = codeCompleter.SuggestCompletion("", out confidenceLevel); if (assertCodeSnippets != null) { foreach (var codeSnippet in assertCodeSnippets) { OnAssert(code, codeSnippet, suggestions); } } }