|
|
@ -2,17 +2,18 @@
|
|
|
|
using System.Net;
|
|
|
|
using System.Net;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
|
using Xunit;
|
|
|
|
using Xunit;
|
|
|
|
using ZeroLevel.Network;
|
|
|
|
using ZeroLevel.Services.Applications;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZeroLevel.NetworkUnitTests
|
|
|
|
namespace ZeroLevel.NetworkUnitTests
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ExchangeTests
|
|
|
|
public class ExchangeTests
|
|
|
|
|
|
|
|
: BaseZeroService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void HandleMessageTest()
|
|
|
|
public void HandleMessageTest()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
var info = new ExServiceInfo
|
|
|
|
var info = new ZeroServiceInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ServiceGroup = "MyServiceGroup",
|
|
|
|
ServiceGroup = "MyServiceGroup",
|
|
|
|
ServiceKey = "MyServiceKey",
|
|
|
|
ServiceKey = "MyServiceKey",
|
|
|
@ -20,18 +21,18 @@ namespace ZeroLevel.NetworkUnitTests
|
|
|
|
Version = "1.1.1.1"
|
|
|
|
Version = "1.1.1.1"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var locker = new ManualResetEvent(false);
|
|
|
|
var locker = new ManualResetEvent(false);
|
|
|
|
var server = ExchangeTransportFactory.GetServer(6666);
|
|
|
|
var server = UseHost(6666);
|
|
|
|
ExServiceInfo received = null;
|
|
|
|
ZeroServiceInfo received = null;
|
|
|
|
|
|
|
|
|
|
|
|
server.RegisterInbox<ExServiceInfo>("register", (i, _, __) =>
|
|
|
|
server.RegisterInbox<ZeroServiceInfo>("register", (c, i) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
received = i;
|
|
|
|
received = i;
|
|
|
|
locker.Set();
|
|
|
|
locker.Set();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
var client = ExchangeTransportFactory.GetClient(IPAddress.Loopback.ToString() + ":6666");
|
|
|
|
var client = ConnectToService(IPAddress.Loopback.ToString() + ":6666");
|
|
|
|
var ir = client.Send<ExServiceInfo>("register", info);
|
|
|
|
var ir = client.Send<ZeroServiceInfo>("register", info);
|
|
|
|
|
|
|
|
|
|
|
|
locker.WaitOne(1000);
|
|
|
|
locker.WaitOne(1000);
|
|
|
|
|
|
|
|
|
|
|
@ -42,21 +43,20 @@ namespace ZeroLevel.NetworkUnitTests
|
|
|
|
// Dispose
|
|
|
|
// Dispose
|
|
|
|
locker.Dispose();
|
|
|
|
locker.Dispose();
|
|
|
|
client.Dispose();
|
|
|
|
client.Dispose();
|
|
|
|
server.Dispose();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void RequestMessageTest()
|
|
|
|
public void RequestMessageTest()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
var info1 = new ExServiceInfo
|
|
|
|
var info1 = new ZeroServiceInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ServiceGroup = "MyServiceGroup",
|
|
|
|
ServiceGroup = "MyServiceGroup",
|
|
|
|
ServiceKey = "MyServiceKey",
|
|
|
|
ServiceKey = "MyServiceKey",
|
|
|
|
ServiceType = "MyServiceType",
|
|
|
|
ServiceType = "MyServiceType",
|
|
|
|
Version = "1.1.1.1"
|
|
|
|
Version = "1.1.1.1"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var info2 = new ExServiceInfo
|
|
|
|
var info2 = new ZeroServiceInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ServiceGroup = "MyServiceGroup",
|
|
|
|
ServiceGroup = "MyServiceGroup",
|
|
|
|
ServiceKey = "MyServiceKey2",
|
|
|
|
ServiceKey = "MyServiceKey2",
|
|
|
@ -64,14 +64,14 @@ namespace ZeroLevel.NetworkUnitTests
|
|
|
|
Version = "1.1.0.1"
|
|
|
|
Version = "1.1.0.1"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var locker = new ManualResetEvent(false);
|
|
|
|
var locker = new ManualResetEvent(false);
|
|
|
|
var server = ExchangeTransportFactory.GetServer(6666);
|
|
|
|
var server = UseHost(6667);
|
|
|
|
IEnumerable<ExServiceInfo> received = null;
|
|
|
|
IEnumerable<ZeroServiceInfo> received = null;
|
|
|
|
|
|
|
|
|
|
|
|
server.RegisterInbox<IEnumerable<ExServiceInfo>>("services", (_, __) => new[] { info1, info2 });
|
|
|
|
server.RegisterInbox<IEnumerable<ZeroServiceInfo>>("services", (_) => new[] { info1, info2 });
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
var client = ExchangeTransportFactory.GetClient(IPAddress.Loopback.ToString() + ":6666");
|
|
|
|
var client = ConnectToService(IPAddress.Loopback.ToString() + ":6667");
|
|
|
|
var ir = client.Request<IEnumerable<ExServiceInfo>>("services", response =>
|
|
|
|
var ir = client.Request<IEnumerable<ZeroServiceInfo>>("services", response =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
received = response;
|
|
|
|
received = response;
|
|
|
|
locker.Set();
|
|
|
|
locker.Set();
|
|
|
@ -86,7 +86,14 @@ namespace ZeroLevel.NetworkUnitTests
|
|
|
|
// Dispose
|
|
|
|
// Dispose
|
|
|
|
locker.Dispose();
|
|
|
|
locker.Dispose();
|
|
|
|
client.Dispose();
|
|
|
|
client.Dispose();
|
|
|
|
server.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void StartAction()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void StopAction()
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|