public void ShouldBuildLineBreak() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementParagraph { IndentSize = 30 }; var result = new TextWriterWrapper(); var run1 = new PrintElementRun { Text = "Before Line Break." }; var run2 = new PrintElementRun { Text = "After Line Break." }; element.Inlines.Add(run1); element.Inlines.Add(new PrintElementLineBreak()); element.Inlines.Add(run2); //When context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildLineBreak, result.GetText()); }
public void ShouldBuildParagraphWithSettings() { // Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementParagraph(); var result = new TextWriterWrapper(); var run = new PrintElementRun(); run.Text = "Проверка текста. "; run.Font = new PrintElementFont { Family = "Courier New", Size = 30 }; run.TextDecoration = PrintElementTextDecoration.Underline; run.Foreground = "Blue"; element.Inlines.Add(run); element.Inlines.Add(run); element.Inlines.Add(run); element.Inlines.Add(run); element.Inlines.Add(run); element.Inlines.Add(run); element.Inlines.Add(run); element.Inlines.Add(run); element.IndentSize = 15; // When context.Build(element, result.Writer); // Then Assert.AreEqual(Resources.ResultTestShouldBuildParagraphWithSettings, result.GetText()); }
/// <summary> /// new command evaluation context /// </summary> /// <param name="commandLineProcessor">the clp it is attached to</param> /// <param name="out">output stream</param> /// <param name="in">input stream</param> /// <param name="err">error stream</param> /// <param name="inputData">input data to begin the context with</param> /// <param name="parentContext">parent context (optionnal, default null)</param> public CommandEvaluationContext( CommandLineProcessor commandLineProcessor, ConsoleTextWriterWrapper @out, TextReader @in, TextWriterWrapper err, object inputData, CommandEvaluationContext parentContext = null) { lock (_instanceLock) { ID = _instanceCounter; _instanceCounter++; } CommandLineProcessor = commandLineProcessor; SetStreams(@out, @in, err); InputData = inputData; SetupShellEnvVar(); Variables = new Variables((VariableNamespace.env, ShellEnv)); ShellEnv.Initialize(this); EchoMap = new EchoPrimitiveMap(); ParentContext = parentContext; @out.ColorSettings = ShellEnv.Colors; }
private void TestInit() { this.stream = new MemoryStream(); StreamWriter innerWriter = new StreamWriter(this.stream); innerWriter.AutoFlush = true; this.writer = new NonIndentedTextWriter(innerWriter); }
public MyIndentedTextWriter(TextWriter writer, string tabString) : base(CultureInfo.InvariantCulture) { this.writer = new TextWriterWrapper(writer); this.tabString = tabString; this.indentLevel = 0; this.tabsPending = false; }
public virtual void Dispose() { if (this.writer != null) { this.writer.DisposeInner(); this.writer = null; } }
private void Reset() { this.buffer = new Ref <char[]>(); this.stream = new MemoryStream(); StreamWriter innerWriter = new StreamWriter(this.stream); innerWriter.AutoFlush = true; this.writer = new NonIndentedTextWriter(innerWriter); }
protected ServiceModelCodeGenerator(TextWriter writer, CodeGenerationOptions options) { this.Options = options; this.writer = new TextWriterWrapper(writer); if (writer == Console.Out) { this.writer.NewLine = "\n"; } }
public void SetStreams( ConsoleTextWriterWrapper @out, TextReader @in, TextWriterWrapper err ) { Out = @out; In = @in; Err = err; }
public void ShouldBuildParagraphWithDefaultSettings() { // Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementParagraph(); var result = new TextWriterWrapper(); // When context.Build(element, result.Writer); // Then Assert.AreEqual(Resources.ResultTestShouldBuildParagraphWithDefaultSettings, result.GetText()); }
public void ShouldBuildImage() { // Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementImage(_getStream(Resources.BarcodeQrRotate0)); var result = new TextWriterWrapper(); // When context.Build(element, result.Writer); // Then Assert.AreEqual(Resources.ResultTestShouldBuildImage, result.GetText()); }
private static void RunActionsOnThreads(int maxConcurrentRunners, IEnumerable <TestRunAction> buildSortedAllActions, CancellationToken token, TextWriterWrapper stdOut, ProgressStats runningTests, int startOrderInt, Stopwatch totalRuntime, ConcurrentBag <RunStats> testResults) { var sortedAllActions = buildSortedAllActions as TestRunAction[] ?? buildSortedAllActions.ToArray(); ThreadPool.SetMaxThreads(maxConcurrentRunners, maxConcurrentRunners); for (var i = 0; i < sortedAllActions.Count(); i++) { CreateThread(sortedAllActions[i], token, stdOut, runningTests, startOrderInt, totalRuntime, testResults); } StopProcessing(); }
public CommandEvaluationContext( CommandLineProcessor commandLineProcessor, ConsoleTextWriterWrapper @out, TextReader @in, TextWriterWrapper err, object inputData) { CommandLineProcessor = commandLineProcessor; Out = @out; In = @in; Err = err; InputData = inputData; Variables = new Variables(); }
/// <summary> /// Creates a new instance of Json writer. /// </summary> /// <param name="writer">Writer to which text needs to be written.</param> /// <param name="indent">If the output should be indented or not.</param> /// <param name="jsonFormat">The json-based format to use when writing.</param> /// <param name="isIeee754Compatible">if it is IEEE754Compatible</param> internal JsonWriter(TextWriter writer, bool indent, ODataFormat jsonFormat, bool isIeee754Compatible) { Debug.Assert(jsonFormat == ODataFormat.Json, "Expected a json-based format."); if (indent == true) { this.writer = new IndentedTextWriter(writer); } else { this.writer = new NonIndentedTextWriter(writer); } this.scopes = new Stack<Scope>(); this.isIeee754Compatible = isIeee754Compatible; }
/// <summary> /// Creates a new instance of Json writer. /// </summary> /// <param name="writer">Writer to which text needs to be written.</param> /// <param name="indent">If the output should be indented or not.</param> /// <param name="jsonFormat">The json-based format to use when writing.</param> /// <param name="isIeee754Compatible">if it is IEEE754Compatible</param> internal JsonWriter(TextWriter writer, bool indent, ODataFormat jsonFormat, bool isIeee754Compatible) { Debug.Assert(jsonFormat == ODataFormat.Json, "Expected a json-based format."); if (indent == true) { this.writer = new IndentedTextWriter(writer); } else { this.writer = new NonIndentedTextWriter(writer); } this.scopes = new Stack <Scope>(); this.isIeee754Compatible = isIeee754Compatible; }
public void ShouldBuildList() { // Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementList(); var result = new TextWriterWrapper(); var item1 = new PrintElementRun { Text = "Item1" }; var item2 = new PrintElementRun { Text = "Item2" }; var item3 = new PrintElementRun { Text = "Item3" }; var par1 = new PrintElementParagraph(); var par2 = new PrintElementParagraph(); var par3 = new PrintElementParagraph(); par1.Inlines.Add(item1); par2.Inlines.Add(item2); par3.Inlines.Add(item3); var section1 = new PrintElementSection(); var section2 = new PrintElementSection(); var section3 = new PrintElementSection(); section1.Blocks.Add(par1); section2.Blocks.Add(par2); section3.Blocks.Add(par3); element.Items.Add(section1); element.Items.Add(section2); element.Items.Add(section3); element.MarkerStyle = PrintElementListMarkerStyle.LowerLatin; element.StartIndex = 24; // When context.Build(element, result.Writer); // Then Assert.AreEqual(Resources.ResultTestShouldBuildList, result.GetText()); }
private static void CreateThread(TestRunAction action, CancellationToken token, TextWriterWrapper stdOut, ProgressStats runningTests, int startOrderInt, Stopwatch totalRuntime, ConcurrentBag <RunStats> testResults) { var parameters = new MethodParameters { Action = action, RunningTests = runningTests, StartOrderInt = startOrderInt, StdOut = stdOut, TestResults = testResults, Token = token, TotalRuntime = totalRuntime }; Interlocked.Increment(ref _threadCounter); ThreadPool.QueueUserWorkItem(RunTest, parameters); }
public void ShouldBuildSectioWithProperties() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementSection(); var result = new TextWriterWrapper(); var run = new PrintElementRun(); run.Text = "Section & Margin & Padding & Border & Background"; var par = new PrintElementParagraph(); par.Inlines.Add(run); par.TextAlignment = PrintElementTextAlignment.Center; var section = new PrintElementSection(); section.Blocks.Add(par); section.Border = new PrintElementBorder { Color = "blue", Thickness = new PrintElementThickness(5) }; section.Margin = new PrintElementThickness(20); section.Padding = new PrintElementThickness(20); section.Background = "yellow"; element.Blocks.Add(section); element.Border = new PrintElementBorder { Color = PrintElementColors.Red, Thickness = new PrintElementThickness(5) }; element.Margin = new PrintElementThickness(20); element.Padding = new PrintElementThickness(20); element.Background = PrintElementColors.Green; //When context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildSectioWithProperties, result.GetText()); }
public void ShouldBuildItalic() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementItalic(); var result = new TextWriterWrapper(); var run = new PrintElementRun { Text = "Italic Text." }; //When element.Inlines.Add(run); context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildItalic, result.GetText()); }
public void ShouldBuildHyperlink() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementHyperlink(); var result = new TextWriterWrapper(); element.Reference = new Uri("http://google.com"); var run = new PrintElementRun { Text = "Hyperlink Google" }; element.Inlines.Add(run); //When context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildHyperlink, result.GetText()); }
public void ShouldBuildRun() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementRun { Text = "Здесь много текста", Font = new PrintElementFont { Family = "Tahoma", Size = 30 } }; var result = new TextWriterWrapper(); //When context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildRun, result.GetText()); }
public void ShouldBuildSpan() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementSpan(); var result = new TextWriterWrapper(); var inline1 = new PrintElementRun { Text = "Inline1. " }; var inline2 = new PrintElementRun { Text = "Inline2. " }; //When element.Inlines.Add(inline1); element.Inlines.Add(inline2); context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildSpan, result.GetText()); }
public string GetRunResultsAsXml(int maxConcurrentRunners) { //Keep a reference to standard out var stdOut = new TextWriterWrapper(Console.Out); var totalRuntime = new Stopwatch(); totalRuntime.Start(); var outputPath = _outputPath; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var categories = _featureTypes.GetCategories().ToList(); var categoryMessage = "Categories run will be: " + string.Join(", ", categories); Debug.WriteLine(categoryMessage); Console.WriteLine(categoryMessage); var runners = new List <CategoryRunner>(); using (var countdownEvent = new CountdownEvent(1)) { int totalCount = categories.Count + 1; //NOTE: Ideally we want to start something like the top (concurrentRunners/2) longest running process first //Run all other tests var other = GetExcludeFitler(categories.ToArray()); var anyOthers = new CategoryRunner(_assemblyLocation, other, "all", _outputPath, countdownEvent); runners.Add(anyOthers); anyOthers.RunTesterAsync(); foreach (var cat in categories) { var filter = GetIncludefilter(cat); var runner = new CategoryRunner(_assemblyLocation, filter, cat, _outputPath, countdownEvent); runners.Add(runner); runner.RunTesterAsync(); while (maxConcurrentRunners > 0 && countdownEvent.CurrentCount > maxConcurrentRunners) { stdOut.WriteLine("Reached limit: " + (countdownEvent.CurrentCount - 1) + " Runners created: " + runners.Count + " / " + totalCount); Thread.Sleep(2000); } } //Wait for all runners to complete, outputting status countdownEvent.Signal(); while (countdownEvent.CurrentCount > 0) { stdOut.WriteLine("Running: " + countdownEvent.CurrentCount + " / " + totalCount); countdownEvent.Wait(2000); } } totalRuntime.Stop(); if (_outputRunStats) { OutputRunStats(outputPath, totalRuntime.Elapsed, runners); } stdOut.WriteLine("Finished with tests, merging"); var outputResultsXmlPath = _runnerSettings.ResultsXmlFilepath; var outputResultsReportPath = _runnerSettings.ResultsHtmlReportFilepath; var xmlOutput = _resultsWriter.MergeResultsProcess(outputPath, outputResultsXmlPath, outputResultsReportPath); return(xmlOutput); }
public void ShouldBuildTable() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementTable(); var result = new TextWriterWrapper(); var text1 = new PrintElementRun { Text = "Text11, colspan = 2" }; var cell1 = new PrintElementTableCell { ColumnSpan = 2, Border = new PrintElementBorder { Thickness = new PrintElementThickness(1), Color = "black" } }; var par1 = new PrintElementParagraph(); par1.Inlines.Add(text1); cell1.Block = par1; var row1 = new PrintElementTableRow(); row1.Cells.Add(cell1); var text21 = new PrintElementRun { Text = "Text21" }; var cell21 = new PrintElementTableCell { Border = new PrintElementBorder { Thickness = new PrintElementThickness(1), Color = "black" } }; var par21 = new PrintElementParagraph(); par21.Inlines.Add(text21); cell21.Block = par21; var row2 = new PrintElementTableRow(); row2.Cells.Add(cell21); var text22 = new PrintElementRun { Text = "Text22" }; var cell22 = new PrintElementTableCell { Border = new PrintElementBorder { Thickness = new PrintElementThickness(1), Color = "black" } }; var par22 = new PrintElementParagraph(); par22.Inlines.Add(text22); cell22.Block = par22; row2.Cells.Add(cell22); var column1 = new PrintElementTableColumn { Size = 100 }; var column2 = new PrintElementTableColumn { Size = 200 }; element.Columns.Add(column1); element.Columns.Add(column2); element.Rows.Add(row1); element.Rows.Add(row2); //When context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildTable, result.GetText()); }
public string GetRunResultsAsXml(int maxConcurrentRunners) { if (!_configured) { throw new InvalidOperationException("You must call ConfigureRun first"); } //Keep a reference to standard out var stdOut = new TextWriterWrapper(Console.Out); var totalRuntime = new Stopwatch(); totalRuntime.Start(); var outputPath = _runnerSettings.OutputBasePath; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var shouldRunOther = _categoriesToRun.Count == 0 || _categoriesToRun.Contains("all"); //var categoryMessage = "Categories run will be: " + string.Join(", ", runnableCategories); //Debug.WriteLine(categoryMessage); //Console.WriteLine(categoryMessage); stdOut.WriteLine("Starting tests..."); if (maxConcurrentRunners > 0) { stdOut.WriteLine(" Running upto " + maxConcurrentRunners + " concurrently"); } stdOut.WriteLine("(ctrl-c and a few seconds to cancel, '{0}' means running, '{1}' means finished)", _progressDisplayBuilder.ArrayValueToRunningStatusChar(ProgressState.Running), _progressDisplayBuilder.ArrayValueToRunningStatusChar(ProgressState.Finished)); var testFixturesToRun = new List <string>(); if (shouldRunOther) { testFixturesToRun = new List <string>(_otherTestFixtures); } var runnableCategories = _categoriesToRun.Count > 0 ? _categories.Intersect(_categoriesToRun).ToList() : _categories; int totalToRun = runnableCategories.Count(); if (_runnerSettings.RunUncategorizedTestFixturesParallel) { totalToRun += testFixturesToRun.Count; } else if (shouldRunOther && _otherTestFixtures.Any()) { totalToRun += 1; } stdOut.WriteLine(); stdOut.WriteLine("Found {0} categories/fixtures to run", totalToRun); var testResults = new ConcurrentBag <RunStats>(); bool cancelled = false; try { var runningTests = new ProgressStats(totalToRun); int indicatorPos = 0; var buildingDisplay = new object(); var timer = new Timer(x => { if (Console.IsOutputRedirected) { return; } if (!Monitor.TryEnter(buildingDisplay)) { return; } try { int windowWidth = Console.WindowWidth; stdOut.Write("\r"); stdOut.Write(_progressDisplayBuilder.BuildProgressDisplay(windowWidth, runningTests, ref indicatorPos, _runnerSettings.DisplayFailureSymbolsInProgressDisplay)); } catch (Exception exception) { stdOut.Write("display error..."); throw new ApplicationException("Unable to properly build progress display.", exception); } finally { Monitor.Exit(buildingDisplay); } }, null, 0, 250); if (Console.IsOutputRedirected) { timer.Change(Timeout.Infinite, Timeout.Infinite); } //Setup ability to catch ctrl-c Console.CancelKeyPress += (sender, args) => { timer.Change(Timeout.Infinite, Timeout.Infinite); args.Cancel = true; _cancelTokenSource.Cancel(); //stdOut.WriteLine(); //stdOut.WriteLine("CANCEL KEY PUSHED"); //Stop any running ones... maybe don't do this until pressed twice? Process.GetProcesses() .Where(p => p.ProcessName == "nunit-console" || p.ProcessName == "nunit-agent") .Each(x => x.Kill()); }; var startOrderInt = 0; var token = _cancelTokenSource.Token; var buildSortedAllActions = BuildSortedAllActions(testFixturesToRun, runnableCategories) .ToArray(); RunActionsOnThreads(maxConcurrentRunners, buildSortedAllActions, token, stdOut, runningTests, startOrderInt, totalRuntime, testResults); timer.Change(0, Timeout.Infinite); //Tacky way to fix line printing problem Thread.Sleep(100); stdOut.WriteLine(); } catch (OperationCanceledException) { cancelled = true; stdOut.WriteLine(); stdOut.WriteLine("== Cancelled =="); } totalRuntime.Stop(); stdOut.WriteLine("= Total runtime: " + TimeSpanFormat(totalRuntime.Elapsed)); stdOut.WriteLine("Finished with tests, merging results"); var SkippedTests = _categories.Except(testResults.Select(a => a.Name)).ToList(); _resultsStatsWriter.OutputRunStats(totalRuntime.Elapsed, testResults, SkippedTests); var outputResultsXmlPath = _runnerSettings.ResultsXmlFilepath; var outputResultsReportPath = _runnerSettings.ResultsHtmlReportFilepath; var xmlOutput = _resultsWriter.MergeResultsProcess(outputPath, outputResultsXmlPath, outputResultsReportPath); if (cancelled) { Environment.ExitCode = -9; } if (testResults.Any(x => x.ExitCode != 0)) { stdOut.WriteLine("ERROR: Test process exited with error!"); Environment.ExitCode = -1; } //Do we really need to return this? if so we should have the writing happen elsewhere... return(xmlOutput); }