forked from aloisdg/Ether.Network
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from Eastrall/feature/tests
Feature/tests
- Loading branch information
Showing
7 changed files
with
255 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/Ether.Network.Tests/Contexts/NetConfig/ConfigClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Net.Sockets; | ||
using Ether.Network.Client; | ||
|
||
namespace Ether.Network.Tests.Contexts.NetConfig | ||
{ | ||
public class ConfigClient : NetClient | ||
{ | ||
protected override void OnConnected() | ||
{ | ||
} | ||
|
||
protected override void OnDisconnected() | ||
{ | ||
} | ||
|
||
protected override void OnSocketError(SocketError socketError) | ||
{ | ||
} | ||
|
||
public void SetupConfiguration() | ||
{ | ||
this.Configuration.Host = "127.0.0.1"; | ||
this.Configuration.Port = 4445; | ||
this.Configuration.BufferSize = 512; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test/Ether.Network.Tests/Contexts/NetConfig/ConfigServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using Ether.Network.Common; | ||
using Ether.Network.Server; | ||
|
||
namespace Ether.Network.Tests.Contexts.NetConfig | ||
{ | ||
public class ConfigServer : NetServer<Client> | ||
{ | ||
protected override void Initialize() | ||
{ | ||
} | ||
|
||
protected override void OnClientConnected(Client connection) | ||
{ | ||
} | ||
|
||
protected override void OnClientDisconnected(Client connection) | ||
{ | ||
} | ||
|
||
protected override void OnError(Exception exception) | ||
{ | ||
} | ||
|
||
public void SetupConfiguration() | ||
{ | ||
this.Configuration.BufferSize = 512; | ||
this.Configuration.MaximumNumberOfConnections = 10; | ||
this.Configuration.Host = "127.0.0.1"; | ||
this.Configuration.Port = 4445; | ||
this.Configuration.Backlog = 10; | ||
this.Configuration.Blocking = false; | ||
} | ||
} | ||
|
||
public class Client : NetUser | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using Ether.Network.Exceptions; | ||
using Ether.Network.Tests.Contexts.NetConfig; | ||
using Xunit; | ||
|
||
namespace Ether.Network.Tests | ||
{ | ||
public class NetClientConfigurationTest | ||
{ | ||
[Fact] | ||
public void StartClientWihtoutConfiguration() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
server.SetupConfiguration(); | ||
server.Start(); | ||
|
||
using (var client = new ConfigClient()) | ||
{ | ||
Exception ex = Assert.Throws<EtherConfigurationException>(() => client.Connect()); | ||
Assert.IsType<EtherConfigurationException>(ex); | ||
|
||
client.Disconnect(); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void StartClientWithConfiguration() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
server.SetupConfiguration(); | ||
server.Start(); | ||
|
||
using (var client = new ConfigClient()) | ||
{ | ||
client.SetupConfiguration(); | ||
client.Connect(); | ||
client.Disconnect(); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetupClientConfigurationAfterConnected() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
server.SetupConfiguration(); | ||
server.Start(); | ||
|
||
using (var client = new ConfigClient()) | ||
{ | ||
client.SetupConfiguration(); | ||
client.Connect(); | ||
|
||
Exception ex = Assert.Throws<EtherConfigurationException>(() => client.SetupConfiguration()); | ||
Assert.IsType<EtherConfigurationException>(ex); | ||
|
||
client.Disconnect(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Ether.Network.Exceptions; | ||
using Ether.Network.Tests.Contexts.NetConfig; | ||
using System; | ||
using Xunit; | ||
|
||
namespace Ether.Network.Tests | ||
{ | ||
public class NetServerConfigurationTest | ||
{ | ||
[Fact] | ||
public void StartServerWithoutConfiguration() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
Exception ex = Assert.Throws<EtherConfigurationException>(() => server.Start()); | ||
|
||
Assert.IsType<EtherConfigurationException>(ex); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetupServerConfigurationBeforeStart() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
server.SetupConfiguration(); | ||
server.Start(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetupServerConfigurationAfterStart() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
server.SetupConfiguration(); | ||
server.Start(); | ||
|
||
Exception ex = Assert.Throws<EtherConfigurationException>(() => server.SetupConfiguration()); | ||
|
||
Assert.IsType<EtherConfigurationException>(ex); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetupServerConfigurationAfterStartStop() | ||
{ | ||
using (var server = new ConfigServer()) | ||
{ | ||
server.SetupConfiguration(); | ||
server.Start(); | ||
server.Stop(); | ||
|
||
server.SetupConfiguration(); | ||
server.Start(); | ||
server.Stop(); | ||
} | ||
} | ||
} | ||
} |