public async Task PublishMultiple() { INATS nats = new NATS(_factory, _opts, _log); nats.ShouldNotBe(null); _server.Received().Sent += Arg.Any <EventHandler <dotnet_sockets.EventArgs <int> > >(); await nats.Connect(); nats.Publish("a", "data1"); nats.Publish("a", "data2"); nats.Publish("b", "data"); _server.Received(1).Send(Arg.Is <string>(makePublication("a", "data1"))); _server.Received(1).Send(Arg.Is <string>(makePublication("a", "data2"))); _server.Received(1).Send(Arg.Is <string>(makePublication("b", "data"))); _log.Received(3).Trace("Sent {0} bytes to server @ {1}", 1, _server.URL); }
public async Task PublishConfirm() { Action <string> handler = Substitute.For <Action <string> >(); byte[] pong = Encoding.UTF8.GetBytes(PONG); _msgr.When(x => x.Receive(Arg.Is <byte[]>(pong), Arg.Is <int>(pong.Length))) .Do(x => { handler(""); }); _server .When(x => x.Send(Arg.Is <string>("PING\r\n"))) .Do(x => { _server.ReceivedData += Raise.EventWith(new dotnet_sockets.SocketDataArgs(null, pong, pong.Length)); }); INATS nats = new NATS(_factory, _opts, _log); nats.ShouldNotBe(null); _server.Received().Sent += Arg.Any <EventHandler <dotnet_sockets.EventArgs <int> > >(); _server.Received().ReceivedData += Arg.Any <EventHandler <dotnet_sockets.SocketDataArgs> >(); await nats.Connect(); nats.Publish("a", "data", handler); _server.Received(1).Send(Arg.Is <string>(makePublication("a", "data"))); _server.Received(1).Send(Arg.Is <string>("PING\r\n")); _log.Received(2).Trace("Sent {0} bytes to server @ {1}", 1, _server.URL); handler.ReceivedCalls().Count().ShouldBe(1); }