Я создал Gist с моей реализацией NetMQ, так как я чувствую, что немного вставил сюда: https://gist.github.com/gthvidsten/e626d7e6c51012b1ba152d22e034d93d
Если я сделаю следующее в консольном приложении .Net Core, все будет работать нормально иЯ получаю событие MessageReceived
:
static void Main(string[] args)
{
_transportWithHost = new NetMqTransport(
"tcp://localhost:9990",
"tcp://localhost:9991",
true);
_transportWithHost.Start();
Console.WriteLine("Press [Enter] to publish");
Console.ReadLine();
_transportWithHost.MessageReceived += (sender, e) =>
{
; // Breakpoints here are hit
};
_transportWithHost.Publish(new byte[] { 1, 2, 3, 4 });
Console.WriteLine("Press [Enter] to exit");
Console.ReadLine();
}
Однако, если я пытаюсь сделать то же самое в тестовой среде NUnit, событие MessageReceived
никогда не запускается!
class NetMqTransportTests
{
private NetMqTransport _transportWithHost;
[OneTimeSetUp]
public void Setup()
{
_transportWithHost = new NetMqTransport(
"tcp://localhost:9990",
"tcp://localhost:9991",
true);
_transportWithHost.Start();
}
[Test]
public void PublishTest()
{
ManualResetEvent mre = new ManualResetEvent(false);
_transportWithHost.MessageReceived += (sender, e) =>
{
mre.Set();
// Breakpoints here are never hit as MessageReceived is never called
};
_transportWithHost.Publish(new byte[] { 1, 2, 3, 4 });
bool eventFired = mre.WaitOne(new TimeSpan(0, 0, 5));
Assert.True(eventFired);
}
}
Почему практически идентичный код работает в консольном приложении, но не в среде NUnit?