Skip to content

Commit 88de5a4

Browse files
committed
NEW: added unit tests
1 parent c314ede commit 88de5a4

File tree

5 files changed

+191
-32
lines changed

5 files changed

+191
-32
lines changed

ClientUnitTests/BasicBinTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2017 Red Hat Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
20+
namespace ClientUnitTests
21+
{
22+
[TestClass]
23+
public class BasicBinTests
24+
{
25+
private ClientRunner clientRunner = new ClientRunner();
26+
27+
[TestMethod]
28+
public void TestTrySenderHelp()
29+
{
30+
Assert.AreEqual(0, this.clientRunner.RunSender("--help"));
31+
}
32+
33+
[TestMethod]
34+
public void TestTryReceiverHelp()
35+
{
36+
Assert.AreEqual(0, this.clientRunner.RunReceiver("--help"));
37+
}
38+
39+
[TestMethod]
40+
public void TestTryConnectorHelp()
41+
{
42+
Assert.AreEqual(0, this.clientRunner.RunConnector("--help"));
43+
}
44+
45+
[TestMethod]
46+
public void TestSenderWrongArgument()
47+
{
48+
Assert.AreEqual(2, this.clientRunner.RunSender("--foo"));
49+
}
50+
51+
[TestMethod]
52+
public void TestReceiverWrongArgument()
53+
{
54+
Assert.AreEqual(2, this.clientRunner.RunReceiver("--foo"));
55+
}
56+
57+
[TestMethod]
58+
public void TestConnectorWrongArgument()
59+
{
60+
Assert.AreEqual(2, this.clientRunner.RunConnector("--foo"));
61+
}
62+
}
63+
}

ClientUnitTests/ClientRunner.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace ClientUnitTests
5+
{
6+
/// <summary>
7+
/// Enum of client types
8+
/// </summary>
9+
public enum ClientType
10+
{
11+
Sender,
12+
Receiver,
13+
Connector
14+
};
15+
16+
/// <summary>
17+
/// Help class, provide running clients
18+
/// </summary>
19+
class ClientRunner
20+
{
21+
private string projectDir;
22+
23+
/// <summary>
24+
/// Construnctor of class
25+
/// </summary>
26+
public ClientRunner()
27+
{
28+
this.projectDir = System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName;
29+
}
30+
31+
/// <summary>
32+
/// Build path of exucutable client
33+
/// </summary>
34+
/// <param name="client">client string</param>
35+
/// <returns>path to executable</returns>
36+
private String getPath(String client)
37+
{
38+
return System.IO.Path.Combine(new String[] {
39+
this.projectDir,
40+
client + "\\bin\\Debug",
41+
"cli-netlite-" + client + ".exe" });
42+
}
43+
44+
/// <summary>
45+
/// Runner method of client
46+
/// </summary>
47+
/// <param name="type">type of client</param>
48+
/// <param name="args">cmd args for client</param>
49+
/// <returns>ecode</returns>
50+
private int runClient(ClientType type, String args)
51+
{
52+
Process p = new Process();
53+
54+
string client;
55+
if (type == ClientType.Sender)
56+
client = "sender";
57+
else if (type == ClientType.Receiver)
58+
client = "receiver";
59+
else
60+
client = "connector";
61+
62+
p.StartInfo.FileName = this.getPath(client);
63+
Console.WriteLine(p.StartInfo.FileName);
64+
p.StartInfo.Arguments = args;
65+
p.StartInfo.RedirectStandardOutput = true;
66+
p.StartInfo.UseShellExecute = false;
67+
p.StartInfo.CreateNoWindow = true;
68+
p.Start();
69+
p.WaitForExit();
70+
return p.ExitCode;
71+
}
72+
73+
/// <summary>
74+
/// Public method for run sender
75+
/// </summary>
76+
/// <param name="args">cmd args</param>
77+
/// <returns>ecode</returns>
78+
public int RunSender(String args)
79+
{
80+
return this.runClient(ClientType.Sender, args);
81+
}
82+
83+
/// <summary>
84+
/// Public method for run receiver
85+
/// </summary>
86+
/// <param name="args">cmd args</param>
87+
/// <returns>ecode</returns>
88+
public int RunReceiver(String args)
89+
{
90+
return this.runClient(ClientType.Receiver, args);
91+
}
92+
93+
/// <summary>
94+
/// Public method for run connector
95+
/// </summary>
96+
/// <param name="args">cmd args</param>
97+
/// <returns>ecode</returns>
98+
public int RunConnector(String args)
99+
{
100+
return this.runClient(ClientType.Connector, args);
101+
}
102+
}
103+
}

ClientUnitTests/ClientUnitTests.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,17 @@
5050
</Otherwise>
5151
</Choose>
5252
<ItemGroup>
53-
<Compile Include="ParsingArgsTests.cs" />
53+
<Compile Include="BasicBinTests.cs" />
54+
<Compile Include="ClientRunner.cs" />
5455
<Compile Include="Properties\AssemblyInfo.cs" />
5556
<Compile Include="SendReceiveTests.cs" />
5657
</ItemGroup>
58+
<ItemGroup>
59+
<ProjectReference Include="..\ClientLib\ClientLib.csproj">
60+
<Project>{6dc6d0f4-85f4-4380-9c49-ff26bc83d000}</Project>
61+
<Name>ClientLib</Name>
62+
</ProjectReference>
63+
</ItemGroup>
5764
<Choose>
5865
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
5966
<ItemGroup>

ClientUnitTests/ParsingArgsTests.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

ClientUnitTests/SendReceiveTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,25 @@ namespace ClientUnitTests
2222
[TestClass]
2323
public class SendReceiveTests
2424
{
25+
ClientRunner clientRunner = new ClientRunner();
26+
27+
[TestMethod]
28+
public void TestSendMessage()
29+
{
30+
Assert.AreEqual(0, this.clientRunner.RunSender("--address send_example --count 1"));
31+
}
32+
33+
[TestMethod]
34+
public void TestSendReceiveMessage()
35+
{
36+
Assert.AreEqual(0, this.clientRunner.RunSender("--address send_receive_example --count 1"));
37+
Assert.AreEqual(0, this.clientRunner.RunReceiver("--address send_receive_example --count 1"));
38+
}
39+
2540
[TestMethod]
26-
public void TestMethod1()
41+
public void TestConnectorClient()
2742
{
43+
Assert.AreEqual(0, this.clientRunner.RunConnector("--address connector_example --count 5 --timeout 5 --obj-ctrl CESR"));
2844
}
2945
}
3046
}

0 commit comments

Comments
 (0)