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.
Add tests for NetClientConfiguration
- Loading branch information
Filipe GOMES PEIXOTO
committed
Feb 21, 2018
1 parent
7546d1c
commit 4fd1ade
Showing
5 changed files
with
132 additions
and
9 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
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; | ||
} | ||
} | ||
} |
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
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(); | ||
} | ||
} | ||
} | ||
} | ||
} |