Improve server connections in Unit Tests

Previously since in the TearDown it opened connections,
it could leave some open connections. It was also trying
to close twice the connections (TearDown and FixtureTearDown)
This commit is contained in:
Benito Palacios Sánchez 2016-09-06 21:21:39 +02:00
parent e9307a08d2
commit 7c144f9d34
No known key found for this signature in database
GPG Key ID: AC62165ED03DAF92
4 changed files with 39 additions and 39 deletions

View File

@ -24,13 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using Moq.Protected;
using NUnit.Framework;
using NitroDebugger;
using NitroDebugger.RSP;
@ -45,9 +39,9 @@ namespace UnitTests
}
[TestFixtureSetUp]
protected override void Setup()
protected override void SetUp()
{
base.Setup();
base.SetUp();
}
[TestFixtureTearDown]
@ -56,10 +50,16 @@ namespace UnitTests
base.Dispose();
}
[SetUp]
protected override void OpenServer()
{
base.OpenServer();
}
[TearDown]
protected override void ResetServer()
protected override void CloseServer()
{
base.ResetServer();
base.CloseServer();
}
[Test]

View File

@ -25,13 +25,6 @@
// SOFTWARE.
using System;
using NUnit.Framework;
using NitroDebugger.RSP;
using System.Net;
using System.Net.Sockets;
using Moq;
using Moq.Protected;
using System.Threading;
using System.Text;
using NitroDebugger;
namespace UnitTests
@ -44,9 +37,9 @@ namespace UnitTests
}
[TestFixtureSetUp]
protected override void Setup()
protected override void SetUp()
{
base.Setup();
base.SetUp();
}
[TestFixtureTearDown]
@ -55,10 +48,16 @@ namespace UnitTests
base.Dispose();
}
[SetUp]
protected override void OpenServer()
{
base.OpenServer();
}
[TearDown]
protected override void ResetServer()
protected override void CloseServer()
{
base.ResetServer();
base.CloseServer();
}
[Test]

View File

@ -43,27 +43,26 @@ namespace UnitTests
Port = PortBase + index;
}
protected virtual void Setup()
protected virtual void SetUp()
{
this.Server = new TcpListener(IPAddress.Loopback, Port);
this.Server.Start();
this.Client = new GdbClient();
this.Client.Connection.Connect(Host, Port);
this.ServerClient = this.Server.AcceptTcpClient();
this.ServerStream = this.ServerClient.GetStream();
}
protected virtual void Dispose()
{
this.Client.Connection.Disconnect();
if (this.ServerClient.Connected)
this.ServerClient.Close();
this.Server.Stop();
}
protected virtual void ResetServer()
protected virtual void OpenServer()
{
this.Client.Connection.Connect(Host, Port);
this.ServerClient = this.Server.AcceptTcpClient();
this.ServerStream = this.ServerClient.GetStream();
}
protected virtual void CloseServer()
{
this.Client.Connection.Disconnect();
if (this.ServerClient.Connected)
@ -71,10 +70,6 @@ namespace UnitTests
while (this.Server.Pending())
this.Server.AcceptTcpClient().Close();
this.Client.Connection.Connect(Host, Port);
this.ServerClient = this.Server.AcceptTcpClient();
this.ServerStream = this.ServerClient.GetStream();
}
protected void SendPacket(string cmd, string args)

View File

@ -41,9 +41,9 @@ namespace UnitTests
}
[TestFixtureSetUp]
protected override void Setup()
protected override void SetUp()
{
base.Setup();
base.SetUp();
manager = Client.Registers;
}
@ -53,10 +53,16 @@ namespace UnitTests
base.Dispose();
}
[SetUp]
protected override void OpenServer()
{
base.OpenServer();
}
[TearDown]
protected override void ResetServer()
protected override void CloseServer()
{
base.ResetServer();
base.CloseServer();
}
[Test]