Beispiel #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
                    }
                }
            });
        }
Beispiel #2
0
        public void Reset_Called_ResetsDemuxer()
        {
            var demuxerMock = Substitute.For <IDemuxer>();

            using (var controller = new DemuxerController(demuxerMock))
            {
                controller.Reset();

                demuxerMock.Received().Reset();
            }
        }
Beispiel #3
0
        public void Reset_CalledWhileDataSourcePublishedChunk_SkipsPublishedChunk()
        {
            AsyncContext.Run(async() => {
                var demuxerMock = Substitute.For <IDemuxer>();

                using (var dataSource = new Subject <byte[]>())
                    using (var controller = new DemuxerController(demuxerMock))
                    {
                        controller.SetDataSource(dataSource);

                        dataSource.OnNext(new byte[1]);
                        controller.Reset();
                        await Task.Yield();

                        demuxerMock.DidNotReceive().PushChunk(Arg.Any <byte[]>());
                    }
            });
        }
Beispiel #4
0
        public void Reset_Called_NextPacketNotCalledAfter(StartType startType)
        {
            AsyncContext.Run(async() =>
            {
                var demuxerMock = Substitute.For <IDemuxer>();
                var tcs         = new TaskCompletionSource <Packet>();
                demuxerMock.NextPacket().Returns(tcs.Task);
                demuxerMock.IsInitialized().Returns(true);

                using (var controller = new DemuxerController(demuxerMock))
                {
                    StartController(controller, startType);
                    await Task.Yield(); // Demuxer.InitFor completes, first Demuxer.NextPacket is called

                    controller.Reset();
                    tcs.SetResult(new Packet());

                    await Task.Yield(); // first Demuxer.NextPacket completes and another Demuxer.NextPacket is
                                        // not called
                    await demuxerMock.Received(1).NextPacket();
                }
            });
        }