public async Task RunShouldRouteTheMessageIfEndOfMessageIsReached( byte[] bytes, uint interval, int sequenceNumber, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Frozen, Substitute] ISerializer serializer, [Frozen, Substitute] IEventRouter router, [Target] DefaultGatewayRxWorker worker ) { var @event = new HelloEvent { HeartbeatInterval = interval }; var message = new GatewayMessage { SequenceNumber = sequenceNumber, Data = @event }; var cancellationToken = new CancellationToken(false); serializer.Deserialize <GatewayMessage>(Any <Stream>(), Any <CancellationToken>()).Returns(message); channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true)); await worker.Start(gateway); await worker.Run(cancellationToken); await router.Received().Route(Is(@event), Is(cancellationToken)); }
async private Task Work() { var module = new Module <Settings>(); await module.Connect(); // Example of receiving initial setting value Console.WriteLine($"testSetting value: {module.settings.testSetting}"); // Example of receiving setting update module.OnSettings((Settings data) => { Console.WriteLine($"testSetting updated: {data.testSetting}"); }); // Example of a module method module.OnMethod <string>("hello", (object args) => { Console.WriteLine($"Hello method called {args}"); return("okay"); }); // Example of receiving a message module.Subscribe <HelloEvent>("Test.Event", (data, type) => { Console.WriteLine($"Event received {type}: hello={data.Hello} id={data.Id}"); }); // Example of broadcasting a message var broadcastTask = Task.Run(async() => { int i = 0; var e = new HelloEvent(); e.Hello = "World"; for (;;) { await Task.Delay(1000); e.Id = i; try { await module.Publish("Test.Event", e); } catch { Console.WriteLine("Cannot broadcast"); } i += 1; } }); }