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)); }
public async Task RunShouldNotUpdateSequenceNumberIfEndOfMessageIsReachedButSequenceNumberIsNull( byte[] bytes, int sequenceNumber, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Frozen, Substitute] ISerializer serializer, [Target] DefaultGatewayRxWorker worker ) { var message = new GatewayMessage { SequenceNumber = null }; serializer.Deserialize <GatewayMessage>(Any <Stream>(), Any <CancellationToken>()).Returns(message); channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true)); gateway.SequenceNumber = sequenceNumber; await worker.Start(gateway); await worker.Run(); gateway.SequenceNumber.Should().Be(sequenceNumber); }
public async Task RunShouldNotTruncateTheStreamIfEndOfMessageIsNotReached( byte[] bytes, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Target] DefaultGatewayRxWorker worker ) { channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, false)); await worker.Start(gateway); await worker.Run(); stream.DidNotReceive().SetLength(0); }
public async Task RunShouldCreateAStream( byte[] bytes, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Target] DefaultGatewayRxWorker worker ) { channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, 0, true)); await worker.Start(gateway); await worker.Run(); factory.Received().CreateStream(); }
public async Task RunShouldWriteTheBytesToTheStream( byte[] bytes, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Target] DefaultGatewayRxWorker worker ) { var cancellationToken = new CancellationToken(false); channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true)); await worker.Start(gateway); await worker.Run(cancellationToken); await stream.Received().WriteAsync(Is <ReadOnlyMemory <byte> >(givenBytes => Encoding.UTF8.GetString(bytes) == Encoding.UTF8.GetString(bytes)), Is(cancellationToken)); }
public async Task RunShouldNotReadFromTheChannelIfWaitToReadReturnedFalse( byte[] bytes, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Target] DefaultGatewayRxWorker worker ) { var cancellationToken = new CancellationToken(false); channel.WaitToRead(Any <CancellationToken>()).Returns(false); await worker.Start(gateway); await worker.Run(cancellationToken); await channel.DidNotReceive().Read(Is(cancellationToken)); }
public async Task RunShouldNotDeserializeTheMessageIfEndOfMessageIsNotReached( byte[] bytes, [Frozen, Substitute] Stream stream, [Frozen, Substitute] IChannel <GatewayMessageChunk> channel, [Frozen, Substitute] IGatewayUtilsFactory factory, [Frozen, Substitute] IGatewayService gateway, [Frozen, Substitute] ISerializer serializer, [Target] DefaultGatewayRxWorker worker ) { var cancellationToken = new CancellationToken(false); channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, false)); await worker.Start(gateway); await worker.Run(cancellationToken); await serializer.DidNotReceive().Deserialize <GatewayMessage>(Is(stream), Is(cancellationToken)); }
public async Task RunShouldNotRouteTheMessageIfEndOfMessageIsReachedButEventDataIsNull( 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 ) { channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true)); await worker.Start(gateway); await worker.Run(); await router.DidNotReceive().Route(Any <IGatewayEvent>(), Any <CancellationToken>()); }