Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit b7f71fe

Browse files
committed
Merge branch 'UshakovMV_ServerConsole'
2 parents e43e4a2 + 4cba4c5 commit b7f71fe

31 files changed

Lines changed: 1211 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using MossbauerLab.TinyTcpServer.Console.Builders;
3+
using MossbauerLab.TinyTcpServer.Core.Server;
4+
using NUnit.Framework;
5+
6+
namespace MossbauerLab.TinyTcpServer.Console.Tests.Builder
7+
{
8+
[TestFixture]
9+
public class TestTcpServerConfigBuilder
10+
{
11+
[Test]
12+
public void TestBuildReadFullConfigs()
13+
{
14+
TcpServerConfig expectedConfig = new TcpServerConfig(1000, 200, 1000, 2000, 120, 4, 8, 256, 65535, 4096);
15+
ReadConfigAndCheck(FullSettingsFile, expectedConfig);
16+
}
17+
18+
[Test]
19+
public void TestBuildReadPartialConfig()
20+
{
21+
TcpServerConfig expectedConfig = new TcpServerConfig();
22+
expectedConfig.ParallelTask = 256;
23+
expectedConfig.ServerCloseTimeout = 7000;
24+
ReadConfigAndCheck(PartialSettingsFile, expectedConfig);
25+
}
26+
27+
private void ReadConfigAndCheck(String configFile, TcpServerConfig expectedConfig)
28+
{
29+
TcpServerConfig actualConfig = TcpServerConfigBuilder.Build(configFile);
30+
Assert.AreEqual(expectedConfig.ChunkSize, actualConfig.ChunkSize, "ChunkSize");
31+
Assert.AreEqual(expectedConfig.ClientBufferSize, actualConfig.ClientBufferSize, "ClientBufferSize");
32+
Assert.AreEqual(expectedConfig.ClientConnectAttempts, actualConfig.ClientConnectAttempts, "ClientConnectAttempts");
33+
Assert.AreEqual(expectedConfig.ClientConnectTimeout, actualConfig.ClientConnectTimeout, "ClientConnectTimeout");
34+
Assert.AreEqual(expectedConfig.ClientInactivityTime, actualConfig.ClientInactivityTime, "ClientInactivityTime");
35+
Assert.AreEqual(expectedConfig.ClientReadAttempts, actualConfig.ClientReadAttempts, "ClientReadAttempts");
36+
Assert.AreEqual(expectedConfig.ParallelTask, actualConfig.ParallelTask, "ParallelTask");
37+
Assert.AreEqual(expectedConfig.ReadTimeout, actualConfig.ReadTimeout, "ReadTimeout");
38+
Assert.AreEqual(expectedConfig.ServerCloseTimeout, actualConfig.ServerCloseTimeout, "ServerCloseTimeout");
39+
Assert.AreEqual(expectedConfig.WriteTimeout, actualConfig.WriteTimeout, "WriteTimeout");
40+
}
41+
42+
private const String FullSettingsFile = @"..\..\TestSettingsFiles\FullSettings.txt";
43+
private const String PartialSettingsFile = @"..\..\TestSettingsFiles\PartialSettings.txt";
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{FDB69C9D-09FA-4F38-B098-5C189F199707}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MossbauerLab.TinyTcpServer.Console.Tests</RootNamespace>
11+
<AssemblyName>MossbauerLab.TinyTcpServer.Console.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
34+
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
35+
<Private>True</Private>
36+
</Reference>
37+
<Reference Include="MossbauerLab.TinyTcpServer.Core, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
38+
<HintPath>..\packages\MossbauerLab.TinyTcpServer.Core.1.2.0\lib\net40\MossbauerLab.TinyTcpServer.Core.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
42+
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
43+
<Private>True</Private>
44+
</Reference>
45+
<Reference Include="System" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Xml.Linq" />
48+
<Reference Include="System.Data.DataSetExtensions" />
49+
<Reference Include="Microsoft.CSharp" />
50+
<Reference Include="System.Data" />
51+
<Reference Include="System.Xml" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<Compile Include="Builder\TestTcpServerConfigBuilder.cs" />
55+
<Compile Include="Parser\TestParser.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
<Compile Include="Validator\TestValidator.cs" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<None Include="packages.config" />
61+
</ItemGroup>
62+
<ItemGroup>
63+
<ProjectReference Include="..\MossbauerLab.TinyTcpServer.Console\MossbauerLab.TinyTcpServer.Console.csproj">
64+
<Project>{4fc067c2-7f0b-46a1-8e49-0daebd809872}</Project>
65+
<Name>MossbauerLab.TinyTcpServer.Console</Name>
66+
</ProjectReference>
67+
</ItemGroup>
68+
<ItemGroup />
69+
<ItemGroup>
70+
<Content Include="TestSettingsFiles\FullSettings.txt" />
71+
</ItemGroup>
72+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
73+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
74+
Other similar extension points exist, see Microsoft.Common.targets.
75+
<Target Name="BeforeBuild">
76+
</Target>
77+
<Target Name="AfterBuild">
78+
</Target>
79+
-->
80+
</Project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using MossbauerLab.TinyTcpServer.Console.Cli.Data;
5+
using MossbauerLab.TinyTcpServer.Console.Cli.Options;
6+
using NUnit.Framework;
7+
8+
namespace MossbauerLab.TinyTcpServer.Console.Tests.Parser
9+
{
10+
[TestFixture]
11+
public class TestParser
12+
{
13+
[TestCase("--start", "--ipaddr=192.168.111.6", "--port=3999", "--script=EchoScript.cs", "--settings=serverSetting.txt")]
14+
[TestCase("--StARt", "--IpaddR=192.168.111.6", " --PORT=3999\t ", " --script=EchoScript.cs ", "\t--SeTtInGs=serverSetting.txt")]
15+
[TestCase("--stop", null, null, null, null)]
16+
[TestCase("--StOp", null, null, null, null)]
17+
[TestCase("--restart", null, null, "--script=FtpScript.cs", "--settings=ftpServerSetting.txt")]
18+
public void TestSuccessfulParse(String runOption, String ipAddress, String tcpPort, String scriptFile, String settingsFile)
19+
{
20+
String[] cmdLineArgs = BuildCmdLine(runOption, ipAddress, tcpPort, scriptFile, settingsFile);
21+
CommandInfo expectedInfo = BuildCommandInfo(runOption, ipAddress, tcpPort, scriptFile, settingsFile);
22+
CommandInfo actualInfo = cli.Parser.Parser.Parse(cmdLineArgs);
23+
CheckCommandInfo(expectedInfo, actualInfo);
24+
}
25+
26+
[TestCase("-start", "--ipaddr=192.168.111.6", "--port=3999", "--script=EchoScript.cs", "--settings=serverSetting.txt")]
27+
[TestCase("start", "--ipaddr=192.168.111.6", "--port=3999", "--script=EchoScript.cs", "--settings=serverSetting.txt")]
28+
[TestCase("--start", "--ipaddr=192.168.111.6", "--port=3999", "--script=EchoScript.cs", "settings=serverSetting.txt")]
29+
[TestCase("start", "ipaddr=192.168.111.6", "port=3999", "script=EchoScript.cs", "settings=serverSetting.txt")]
30+
[TestCase("--start", "--ipaddr=192.168.111.6", "--port=3000", "--script=EchoScript.cs", "--invalidKey=serverSetting.txt")]
31+
[TestCase("--start", "--ipaddr=192.168.111.6", "--port=3000", "--script=EchoScript.cs", "invalidKey=serverSetting.txt")]
32+
public void TestParseFailsIncorrectArgsSyntax(String runOption, String ipAddress, String tcpPort, String scriptFile, String settingsFile)
33+
{
34+
String[] cmdLineArgs = BuildCmdLine(runOption, ipAddress, tcpPort, scriptFile, settingsFile);
35+
Assert.Throws<ApplicationException>(() => cli.Parser.Parser.Parse(cmdLineArgs), "checking that parser throws");
36+
}
37+
38+
private String[] BuildCmdLine(String option1, String option2, String option3, String option4, String option5)
39+
{
40+
IList<String> options = new List<String>();
41+
if (option1 != null)
42+
options.Add(option1);
43+
if (option2 != null)
44+
options.Add(option2);
45+
if (option3 != null)
46+
options.Add(option3);
47+
if (option4 != null)
48+
options.Add(option4);
49+
if (option5 != null)
50+
options.Add(option5);
51+
return options.ToArray();
52+
}
53+
54+
private CommandInfo BuildCommandInfo(String command, String ipAddress, String tcpPort, String scriptFile, String settingsFile)
55+
{
56+
CommandInfo info = new CommandInfo();
57+
info.Command = _commands[command.ToLower()];
58+
info.IpAddress = ipAddress != null
59+
? ipAddress.Substring(ipAddress.IndexOf(KeyValueSeparator, StringComparison.CurrentCulture) + 1)
60+
: null;
61+
if(tcpPort != null)
62+
info.Port = UInt16.Parse(tcpPort.Substring(tcpPort.IndexOf(KeyValueSeparator, StringComparison.CurrentCulture) + 1));
63+
info.ScriptFile = scriptFile != null
64+
? scriptFile.Substring(scriptFile.IndexOf(KeyValueSeparator, StringComparison.CurrentCulture) + 1)
65+
: null;
66+
info.SettingsFile = settingsFile != null
67+
? settingsFile.Substring(settingsFile.IndexOf(KeyValueSeparator, StringComparison.CurrentCulture) + 1)
68+
: null;
69+
return info;
70+
}
71+
72+
private void CheckCommandInfo(CommandInfo expectedInfo, CommandInfo actualInfo)
73+
{
74+
Assert.AreEqual(expectedInfo.Command, actualInfo.Command, "Checking that command type are equals");
75+
Assert.AreEqual(expectedInfo.IpAddress, actualInfo.IpAddress, "Checking that ip address are equals");
76+
Assert.AreEqual(expectedInfo.Port, actualInfo.Port, "Checking that port are equals");
77+
Assert.AreEqual(expectedInfo.ScriptFile, actualInfo.ScriptFile, "Checking that script file are equals");
78+
Assert.AreEqual(expectedInfo.SettingsFile, actualInfo.SettingsFile, "Checking that settings are equals");
79+
}
80+
81+
private readonly IDictionary<String, CommandType> _commands = new Dictionary<String, CommandType>()
82+
{
83+
{"--start", CommandType.Start},
84+
{"--stop", CommandType.Stop},
85+
{"--restart", CommandType.Restart},
86+
{"--quit", CommandType.Restart},
87+
{"--help", CommandType.Restart},
88+
};
89+
90+
private const String KeyValueSeparator = "=";
91+
}
92+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MossbauerLab.TinyTcpServer.Console.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("DDGroup")]
12+
[assembly: AssemblyProduct("MossbauerLab.TinyTcpServer.Console.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © DDGroup 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("a7cb007f-9dee-4a61-bf48-aa9f76c938dc")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This is a example of settings file all settings are represented as pair key=value, lines started from # are commentary (ignores)
2+
# number of clients processing the 'same time'
3+
ParallelTask = 256
4+
# buffer on receive for every client (in bytes)
5+
ClientBufferSize = 65535
6+
# chunk is a auant of size for read and write operations
7+
ChunkSize = 4096
8+
# number of times in a row that calls BeginAccept (in a sepatarate from IO processing thread)
9+
ClientConnectAttempts = 4
10+
# time while client stays inactive, after this time is off (in seconds) client will be disconneced by server
11+
ClientInactivityTime = 120
12+
# timeout for BeginAccept in milliseconds
13+
ClientConnectTimeout = 1000
14+
# number of attempts in a row to get data from client
15+
ClientReadAttempts = 8
16+
# timeout in milliseconds on every read attemp
17+
ReadTimeout = 200
18+
# timeout in milliseconds for server to shutdown, close all opened resources
19+
ServerCloseTimeout = 2000
20+
# timeout in milliseconds to complete write operation
21+
WriteTimeout = 1000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This is a example of settings file all settings are represented as pair key=value, lines started from # are commentary (ignores)
2+
# number of clients processing the 'same time'
3+
ParallelTask = 256
4+
# buffer on receive for every client (in bytes)
5+
#ClientBufferSize = 65535
6+
# chunk is a auant of size for read and write operations
7+
#ChunkSize = 4096
8+
# number of times in a row that calls BeginAccept (in a sepatarate from IO processing thread)
9+
#ClientConnectAttempts = 4
10+
# time while client stays inactive, after this time is off (in seconds) client will be disconneced by server
11+
#ClientInactivityTime = 120
12+
# timeout for BeginAccept in milliseconds
13+
#ClientConnectTimeout = 1000
14+
# number of attempts in a row to get data from client
15+
#ClientReadAttempts = 8
16+
# timeout in milliseconds on every read attemp
17+
#ReadTimeout = 200
18+
# timeout in milliseconds for server to shutdown, close all opened resources
19+
ServerCloseTimeout = 7000
20+
# timeout in milliseconds to complete write operation
21+
#WriteTimeout = 1000
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using MossbauerLab.TinyTcpServer.Console.Cli.Data;
3+
using MossbauerLab.TinyTcpServer.Console.Cli.Options;
4+
using NUnit.Framework;
5+
6+
namespace MossbauerLab.TinyTcpServer.Console.Tests.Validator
7+
{
8+
[TestFixture]
9+
public class TestValidator
10+
{
11+
[TestCase(CommandType.Start, "192.168.66.66", 1134U, "HttpScript.cs", null, false)]
12+
[TestCase(CommandType.Start, null, null, "HttpScript.cs", null, false)]
13+
[TestCase(CommandType.Start, null, null, "HttpScript.cs", "Settings.txt", false)]
14+
[TestCase(CommandType.Start, null, null, null, null, true)]
15+
[TestCase(CommandType.Stop, null, null, null, null, true)]
16+
[TestCase(CommandType.Restart, null, null, null, null, true)]
17+
[TestCase(CommandType.Restart, "192.168.66.66", 1134U, null, null, true)]
18+
[TestCase(CommandType.Quit, null, null, null, null, true)]
19+
[TestCase(CommandType.Help, null, null, null, null, true)]
20+
[TestCase(CommandType.Quit, null, null, null, null, false)]
21+
[TestCase(CommandType.Help, null, null, null, null, false)]
22+
public void TestSuccessfulValidate(CommandType command, String ipAddress, Object port, String script, String settings, Boolean serverInited)
23+
{
24+
TestValidateImpl(command, ipAddress, port, script, settings, serverInited, true);
25+
}
26+
27+
[TestCase(CommandType.Start, null, null, null, null, false)]
28+
[TestCase(CommandType.Stop, "192.168.66.66", 1134U, null, null, false)]
29+
[TestCase(CommandType.Restart, "192.168.66.66", 1134U, "FtpServer.cs", null, false)]
30+
[TestCase(CommandType.Restart, null, null, "FtpServer.cs", null, true)]
31+
[TestCase(CommandType.Restart, null, null, null, null, false)]
32+
[TestCase(CommandType.Quit, "192.168.66.66", null, null, null, true)]
33+
[TestCase(CommandType.Help, "192.168.66.66", null, null, null, true)]
34+
[TestCase(CommandType.Quit, "192.168.66.66", null, null, null, false)]
35+
[TestCase(CommandType.Help, "192.168.66.66", null, null, null, false)]
36+
public void TestValidateFails(CommandType command, String ipAddress, Object port, String script, String settings, Boolean serverInited)
37+
{
38+
TestValidateImpl(command, ipAddress, port, script, settings, serverInited, false);
39+
}
40+
41+
private void TestValidateImpl(CommandType command, String ipAddress, Object port, String script, String settings,
42+
Boolean serverInited, Boolean expectedResult)
43+
{
44+
UInt32? portValue = null;
45+
if (port != null)
46+
portValue = (UInt32?)port;
47+
CommandInfo info = GetCommandInfo(command, ipAddress, (UInt16?)portValue, script, settings);
48+
Boolean result = Cli.Validator.Validator.Validate(info, serverInited);
49+
if (expectedResult)
50+
Assert.IsTrue(result, "Checking that validation was successful");
51+
else Assert.IsFalse(result, "Checking that validation failed");
52+
}
53+
54+
private CommandInfo GetCommandInfo(CommandType command, String ipAddress, UInt16? port, String script, String settings)
55+
{
56+
CommandInfo info = new CommandInfo();
57+
info.Command = command;
58+
info.IpAddress = ipAddress;
59+
info.Port = port;
60+
info.ScriptFile = script;
61+
info.SettingsFile = settings;
62+
return info;
63+
}
64+
}
65+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="log4net" version="2.0.3" targetFramework="net40" />
4+
<package id="MossbauerLab.TinyTcpServer.Core" version="1.2.0" targetFramework="net40" />
5+
<package id="NUnit" version="2.6.3" targetFramework="net40" />
6+
</packages>

0 commit comments

Comments
 (0)