Пример #1
0
        public void Reset_CalledWhileFlushIsInProgress_CancelsFlush()
        {
            AsyncContext.Run(async() =>
            {
                var demuxerStub = Substitute.For <IDemuxer>();
                demuxerStub.Completion.Returns(Task.Delay(-1));

                using (var controller = new DemuxerController(demuxerStub))
                {
                    var flushTask = controller.Flush();

                    controller.Reset();

                    try
                    {
                        await flushTask;
                        Assert.Fail();
                    }
                    catch (TaskCanceledException)
                    {
                        // ignored
                    }
                    catch (OperationCanceledException)
                    {
                        // ignored
                    }
                }
            });
        }
Пример #2
0
        public void Flush_Called_ResetsDemuxer()
        {
            AsyncContext.Run(async() =>
            {
                var demuxerMock = Substitute.For <IDemuxer>();
                using (var controller = new DemuxerController(demuxerMock))
                {
                    await controller.Flush();

                    demuxerMock.Received().Reset();
                }
            });
        }
Пример #3
0
        public void Flush_CalledWhileChunkIsPending_ChunkIsDeliveredToDemuxer()
        {
            AsyncContext.Run(async() => {
                var demuxerMock = Substitute.For <IDemuxer>();
                using (var controller = new DemuxerController(demuxerMock))
                {
                    var subject = new Subject <byte[]>();
                    controller.SetDataSource(subject.AsObservable());
                    subject.OnNext(new byte[0]);

                    demuxerMock.When(demuxer => demuxer.Complete())
                    .Do(_ => demuxerMock.Received().PushChunk(Arg.Any <byte[]>()));

                    await controller.Flush();
                }
            });
        }