|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Linq; |
4 |
| -using System.Reflection.Metadata.Ecma335; |
5 |
| -using System.Reflection.PortableExecutable; |
6 |
| -using System.Text; |
7 |
| -using System.Threading.Channels; |
8 |
| -using System.Threading.Tasks; |
9 |
| -using Xcaciv.Command; |
10 |
| -using Xcaciv.Command.Interface; |
11 |
| - |
12 |
| -namespace Xcaciv.CommandTests.TestImpementations |
13 |
| -{ |
14 |
| - public class TestTextIo : AbstractTextIo |
15 |
| - { |
16 |
| - /// <summary> |
17 |
| - /// test collection of children to verify commmand behavior |
18 |
| - /// </summary> |
19 |
| - public List<TestTextIo> Children { get; private set; } = new List<TestTextIo>(); |
20 |
| - |
21 |
| - /// <summary> |
22 |
| - /// test collection of output chunks to verify behavior |
23 |
| - /// </summary> |
24 |
| - public List<string> Output { get; private set; } = new List<string>(); |
25 |
| - |
26 |
| - public Dictionary<string, string> PromptAnswers { get; private set; } = new Dictionary<string, string>(); |
27 |
| - |
28 |
| - public TestTextIo(string[]? arguments = null) : base("TestTextIo", null) |
29 |
| - { |
30 |
| - this.Parameters = arguments ?? string.Empty.Split(' '); |
31 |
| - } |
32 |
| - |
33 |
| - public override Task<ITextIoContext> GetChild(string[]? childArguments = null) |
34 |
| - { |
35 |
| - var child = new TestTextIo(childArguments) |
36 |
| - { |
37 |
| - Parent = this.Id |
38 |
| - }; |
39 |
| - this.Children.Add(child); |
40 |
| - return Task.FromResult<ITextIoContext>(child); |
41 |
| - } |
42 |
| - |
43 |
| - public override Task<string> PromptForCommand(string prompt) |
44 |
| - { |
45 |
| - this.Output.Add($"PROMPT> {prompt}"); |
46 |
| - |
47 |
| - var answer = PromptAnswers.ContainsKey(prompt) ? |
48 |
| - PromptAnswers[prompt] : |
49 |
| - prompt; |
50 |
| - |
51 |
| - return Task.FromResult(answer); |
52 |
| - } |
53 |
| - |
54 |
| - public override Task<int> SetProgress(int total, int step) |
55 |
| - { |
56 |
| - return Task.FromResult(step); |
57 |
| - } |
58 |
| - |
59 |
| - public override Task SetStatusMessage(string message) |
60 |
| - { |
61 |
| - this.Output.Add(message); |
62 |
| - return Task.CompletedTask; |
63 |
| - } |
64 |
| - |
65 |
| - public override Task OutputChunk(string message) |
66 |
| - { |
67 |
| - this.Output.Add("> " + message); |
68 |
| - return base.OutputChunk(message); |
69 |
| - } |
70 |
| - |
71 |
| - public override Task HandleOutputChunk(string chunk) |
72 |
| - { |
73 |
| - this.Output.Add(chunk); |
74 |
| - return Task.CompletedTask; |
75 |
| - } |
76 |
| - |
77 |
| - public override string ToString() |
78 |
| - { |
79 |
| - string output = string.Empty; |
80 |
| - if (this.HasPipedInput) |
81 |
| - { |
82 |
| - // combine output into one string seperated by new lines |
83 |
| - // and then add the children output |
84 |
| - output = String.Join(Environment.NewLine, this.Output); |
85 |
| - foreach (var chidl in this.Children) |
86 |
| - { |
87 |
| - output += chidl.ToString() + Environment.NewLine; |
88 |
| - } |
89 |
| - } |
90 |
| - |
91 |
| - |
92 |
| - |
93 |
| - output += String.Join('-', this.Output); |
94 |
| - |
95 |
| - return output; |
96 |
| - } |
97 |
| - |
98 |
| - } |
99 |
| -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Reflection.Metadata.Ecma335; |
| 5 | +using System.Reflection.PortableExecutable; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Channels; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using Xcaciv.Command; |
| 10 | +using Xcaciv.Command.Interface; |
| 11 | + |
| 12 | +namespace Xcaciv.Command.Tests.TestImpementations |
| 13 | +{ |
| 14 | + public class TestTextIo : AbstractTextIo |
| 15 | + { |
| 16 | + /// <summary> |
| 17 | + /// test collection of children to verify commmand behavior |
| 18 | + /// </summary> |
| 19 | + public List<TestTextIo> Children { get; private set; } = new List<TestTextIo>(); |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// test collection of output chunks to verify behavior |
| 23 | + /// </summary> |
| 24 | + public List<string> Output { get; private set; } = new List<string>(); |
| 25 | + |
| 26 | + public Dictionary<string, string> PromptAnswers { get; private set; } = new Dictionary<string, string>(); |
| 27 | + |
| 28 | + public TestTextIo(string[]? arguments = null) : base("TestTextIo", null) |
| 29 | + { |
| 30 | + Parameters = arguments ?? string.Empty.Split(' '); |
| 31 | + } |
| 32 | + |
| 33 | + public override Task<ITextIoContext> GetChild(string[]? childArguments = null) |
| 34 | + { |
| 35 | + var child = new TestTextIo(childArguments) |
| 36 | + { |
| 37 | + Parent = Id |
| 38 | + }; |
| 39 | + Children.Add(child); |
| 40 | + return Task.FromResult<ITextIoContext>(child); |
| 41 | + } |
| 42 | + |
| 43 | + public override Task<string> PromptForCommand(string prompt) |
| 44 | + { |
| 45 | + Output.Add($"PROMPT> {prompt}"); |
| 46 | + |
| 47 | + var answer = PromptAnswers.ContainsKey(prompt) ? |
| 48 | + PromptAnswers[prompt] : |
| 49 | + prompt; |
| 50 | + |
| 51 | + return Task.FromResult(answer); |
| 52 | + } |
| 53 | + |
| 54 | + public override Task<int> SetProgress(int total, int step) |
| 55 | + { |
| 56 | + return Task.FromResult(step); |
| 57 | + } |
| 58 | + |
| 59 | + public override Task SetStatusMessage(string message) |
| 60 | + { |
| 61 | + Output.Add(message); |
| 62 | + return Task.CompletedTask; |
| 63 | + } |
| 64 | + |
| 65 | + public override Task OutputChunk(string message) |
| 66 | + { |
| 67 | + Output.Add("> " + message); |
| 68 | + return base.OutputChunk(message); |
| 69 | + } |
| 70 | + |
| 71 | + public override Task HandleOutputChunk(string chunk) |
| 72 | + { |
| 73 | + Output.Add(chunk); |
| 74 | + return Task.CompletedTask; |
| 75 | + } |
| 76 | + |
| 77 | + public override string ToString() |
| 78 | + { |
| 79 | + string output = string.Empty; |
| 80 | + if (HasPipedInput) |
| 81 | + { |
| 82 | + // combine output into one string seperated by new lines |
| 83 | + // and then add the children output |
| 84 | + output = string.Join(Environment.NewLine, Output); |
| 85 | + foreach (var chidl in Children) |
| 86 | + { |
| 87 | + output += chidl.ToString() + Environment.NewLine; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + output += string.Join('-', Output); |
| 94 | + |
| 95 | + return output; |
| 96 | + } |
| 97 | + |
| 98 | + } |
| 99 | +} |
0 commit comments