Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 26d2ef8

Browse files
authored
LiveTestServer basic execution flow, vs-csproj for test project, build fixes (#262)
* LiveTestServer basic execution flow, more vs-csproj, build fixes
1 parent 91ff8e1 commit 26d2ef8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1978
-92
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,5 @@ PSSwagger.LiveTestFramework/src/PSSwagger.LTF.Lib/*.Code.ps1
271271

272272
# LiveTestFramework test results
273273
PSSwagger.LiveTestFramework/test/PSSwagger.LTF.Lib.UnitTests/Results/
274+
PSSwagger.LiveTestFramework/test/PSSwagger.LTF.Lib.UnitTests/vs-csproj/Results/
274275
PSSwagger.LiveTestFramework/test/Pester/PesterResults.xml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project ToolsVersion="15.0">
2+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
3+
<PackageReference Include="Microsoft.NETCore.App" Version="2.0.0-preview2-25407-01" />
4+
<PackageReference Include="NETStandard.Library" Version="2.0.0-preview2-25401-01" />
5+
<PackageReference Include="Microsoft.CSharp" Version="4.4.0-preview2-25405-01" />
6+
</ItemGroup>
7+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
8+
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
9+
<DebugType>portable</DebugType>
10+
</PropertyGroup>
11+
</Project>

PSSwagger.LiveTestFramework/src/PSSwagger.LTF.Lib/Class1.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace PSSwagger.LTF.Lib
2+
{
3+
using Interfaces;
4+
using Messages;
5+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
9+
/// <summary>
10+
/// Contains metadata for a generated module being tested.
11+
/// </summary>
12+
public class GeneratedModule
13+
{
14+
private IRunspaceManager runspace;
15+
16+
public string ModulePath { get; set; }
17+
18+
public IList<GeneratedModule> RequiredModules { get; set; }
19+
20+
public GeneratedModule(IRunspaceManager runspace)
21+
{
22+
this.runspace = runspace;
23+
this.RequiredModules = new List<GeneratedModule>();
24+
}
25+
26+
public virtual IEnumerable ProcessRequest(LiveTestRequest request)
27+
{
28+
return null;
29+
}
30+
31+
public virtual void Load(bool force = false)
32+
{
33+
foreach (GeneratedModule requiredModule in this.RequiredModules)
34+
{
35+
requiredModule.Load(force: force);
36+
}
37+
38+
ICommandBuilder command = this.runspace.CreateCommand();
39+
command.Command = "Import-Module";
40+
if (!String.IsNullOrEmpty(ModulePath))
41+
{
42+
command.AddParameter("Name", this.ModulePath, switchParameter: false);
43+
}
44+
45+
if (force)
46+
{
47+
command.AddParameter("Force", true, switchParameter: true);
48+
}
49+
50+
command.Invoke();
51+
}
52+
}
53+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
namespace PSSwagger.LTF.Lib.IO
2+
{
3+
using Interfaces;
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
/// <summary>
8+
/// Read valid JSON blocks.
9+
/// </summary>
10+
public class JsonBlockPipe : IInputPipe
11+
{
12+
private IInputPipe characterReader;
13+
14+
/// <summary>
15+
/// Constructor.
16+
/// </summary>
17+
/// <param name="characterReader">InputPipe to use for reading single characters.</param>
18+
public JsonBlockPipe(IInputPipe characterReader)
19+
{
20+
this.characterReader = characterReader;
21+
}
22+
23+
/// <summary>
24+
/// Not implemented for JsonBlockPipe.
25+
/// </summary>
26+
public char ReadChar()
27+
{
28+
throw new NotImplementedException();
29+
}
30+
31+
/// <summary>
32+
/// Read a single valid JSON block. Ignores any characters until the first { is read. Ends when the matching } character is read.
33+
/// </summary>
34+
/// <typeparam name="T">Type of block to read and deserialize.</typeparam>
35+
/// <returns>Block of type <typeparamref name="T"/>.</returns>
36+
public async Task<T> ReadBlockAsync<T>() where T : class
37+
{
38+
string jsonString = String.Empty;
39+
int openBraces = 0;
40+
while (openBraces > 0 || String.IsNullOrEmpty(jsonString))
41+
{
42+
char c = this.characterReader.ReadChar();
43+
switch (c)
44+
{
45+
case '{':
46+
openBraces++;
47+
jsonString += c;
48+
break;
49+
case '}':
50+
if (openBraces > 0)
51+
{
52+
openBraces--;
53+
jsonString += c;
54+
}
55+
break;
56+
default:
57+
if (openBraces > 0)
58+
{
59+
jsonString += c;
60+
}
61+
break;
62+
}
63+
}
64+
65+
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonString);
66+
}
67+
68+
/// <summary>
69+
/// Not implemented for JsonBlockPipe.
70+
/// </summary>
71+
public string ReadLine()
72+
{
73+
throw new NotImplementedException();
74+
}
75+
}
76+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
namespace PSSwagger.LTF.Lib.IO
2+
{
3+
using Interfaces;
4+
using System;
5+
using System.IO;
6+
using System.IO.Pipes;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
public delegate void NamedPipeClientDataReceived(string message);
11+
12+
/// <summary>
13+
/// I/O operations for named pipe client.
14+
/// </summary>
15+
public class NamedPipeClient : IInputPipe, IOutputPipe, IDisposable
16+
{
17+
private NamedPipeClientStream stream;
18+
private StreamReader reader;
19+
private StreamWriter writer;
20+
21+
/// <summary>
22+
/// Fired when the client reads a new line of data in its asynchronous processing thread.
23+
/// </summary>
24+
public event NamedPipeClientDataReceived OnDataReceived;
25+
26+
/// <summary>
27+
/// Gets if the named pipe client is connected.
28+
/// </summary>
29+
public bool IsConnected
30+
{
31+
get
32+
{
33+
return this.stream.IsConnected;
34+
}
35+
}
36+
37+
/// <summary>
38+
/// Create a named pipe client on the local machine.
39+
/// </summary>
40+
/// <param name="pipeName">Name of pipe.</param>
41+
public NamedPipeClient(string pipeName)
42+
{
43+
this.stream = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut);
44+
this.reader = null;
45+
this.writer = null;
46+
}
47+
48+
/// <summary>
49+
/// Connect to the named pipe.
50+
/// </summary>
51+
public void Connect()
52+
{
53+
this.stream.Connect();
54+
this.reader = new StreamReader(this.stream);
55+
this.writer = new StreamWriter(this.stream);
56+
}
57+
58+
/// <summary>
59+
/// Start the data processing thread.
60+
/// </summary>
61+
public void BeginProcessing()
62+
{
63+
new Thread(() =>
64+
{
65+
while (this.stream.IsConnected)
66+
{
67+
string line = this.ReadLine();
68+
OnDataReceived?.Invoke(line);
69+
}
70+
}){ IsBackground = true }.Start();
71+
}
72+
73+
/// <summary>
74+
/// Dispose the StreamReader, StreamWriter, and NamedClientPipeStream.
75+
/// </summary>
76+
public void Dispose()
77+
{
78+
this.reader?.Dispose();
79+
this.writer?.Dispose();
80+
this.stream?.Dispose();
81+
}
82+
83+
/// <summary>
84+
/// Flush the NamedClientPipeStream.
85+
/// </summary>
86+
public void Flush()
87+
{
88+
this.stream.Flush();
89+
}
90+
91+
/// <summary>
92+
/// Read a single character.
93+
/// </summary>
94+
/// <returns>Character read.</returns>
95+
public char ReadChar()
96+
{
97+
return (char)this.reader.Read();
98+
}
99+
100+
/// <summary>
101+
/// Write a single character.
102+
/// </summary>
103+
/// <param name="b">Character to write.</param>
104+
public void Write(char b)
105+
{
106+
this.writer.Write(b);
107+
}
108+
109+
/// <summary>
110+
/// Write the given string then a new line.
111+
/// </summary>
112+
/// <param name="line">Line to write, not including new line.</param>
113+
public void WriteLine(string line)
114+
{
115+
this.writer.WriteLine(line);
116+
}
117+
118+
/// <summary>
119+
/// Read until the next new line character.
120+
/// </summary>
121+
/// <returns>All text input up to but not including the new line character.</returns>
122+
public string ReadLine()
123+
{
124+
return this.reader.ReadLine();
125+
}
126+
127+
/// <summary>
128+
/// NotImplemented
129+
/// </summary>
130+
public Task<T> ReadBlockAsync<T>() where T : class
131+
{
132+
throw new NotImplementedException();
133+
}
134+
135+
/// <summary>
136+
/// NotImplemented
137+
/// </summary>
138+
public Task WriteBlockAsync<T>(T msg) where T : class
139+
{
140+
throw new NotImplementedException();
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)