public async Task Can_publish_on_various_channel_types() { NdmConsumerChannelManager manager = new NdmConsumerChannelManager(); ISocketsClient client = Substitute.For <ISocketsClient>(); INdmConsumerChannel[] channels = new INdmConsumerChannel[] { new JsonRpcNdmConsumerChannel(LimboLogs.Instance), new GrpcNdmConsumerChannel(Substitute.For <IGrpcServer>()), new NdmWebSocketsConsumerChannel(client), }; ((JsonRpcNdmConsumerChannel)channels[0]).Pull(Keccak.Zero).Should().BeNull(); for (int i = 0; i < 3; i++) { manager.Add(channels[i]); } channels[0].Type.Should().Be(NdmConsumerChannelType.JsonRpc); channels[1].Type.Should().Be(NdmConsumerChannelType.Grpc); await manager.PublishAsync(Keccak.Zero, "client1", "data1"); await manager.PublishAsync(Keccak.Zero, "client2", "data2"); for (int i = 0; i < 3; i++) { manager.Remove(channels[i]); } await manager.PublishAsync(Keccak.Zero, "client3", "data3"); for (int i = 0; i < 3; i++) { await client.Received().SendAsync(Arg.Is <SocketsMessage>(wm => wm.Client == "client1")); await client.Received().SendAsync(Arg.Is <SocketsMessage>(wm => wm.Client == "client2")); await client.DidNotReceive().SendAsync(Arg.Is <SocketsMessage>(wm => wm.Client == "client3")); } ((JsonRpcNdmConsumerChannel)channels[0]).Pull(Keccak.Zero).Should().NotBeNull(); ((JsonRpcNdmConsumerChannel)channels[0]).Pull(Keccak.Zero).Should().NotBeNull(); ((JsonRpcNdmConsumerChannel)channels[0]).Pull(Keccak.Zero).Should().BeNull(); }
public void Can_publish() { ISocketsClient webSocketsClient = Substitute.For <ISocketsClient>(); NdmWebSocketsConsumerChannel channel = new NdmWebSocketsConsumerChannel(webSocketsClient); channel.PublishAsync(Keccak.Zero, "client", "data"); webSocketsClient.Received().SendAsync(Arg.Is <SocketsMessage>(ws => ws.Client == "client" && ws.Type == "data_received")); }