public async Task Errors()
        {
            controller.StartTimeout = null;
            OnActivate = null;

            var adSource = GetLinearAdSource();

            CancellationTokenSource cts = new CancellationTokenSource();
            var progress = new Progress<AdStatus>();

            // adsource cancel
            var errorAdSource = new Mockups.ErrorAdSource(new NotImplementedException()) { Type = "vast" };
            GetPlayer = () => { Assert.Fail(); return null; }; // this should not get hit
            await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(errorAdSource).AsTask(cts.Token, progress));
            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // handshake error: should not throw
            GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Handshake };
            await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // initad error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Init };
            //await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.InitAsync };
            await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // startad error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Start };
            //await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.StartAsync };
            await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // playing error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Play };
            //await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.PlayAsync };
            await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // stopping error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Stop };
            //await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.StopAsync };
            await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);
        }
示例#2
0
        public async Task Errors()
        {
            controller.StartTimeout = null;
            OnActivate = null;

            var adSource = GetLinearAdSource();

            CancellationTokenSource cts = new CancellationTokenSource();
            var progress = new Progress <AdStatus>();

            // adsource cancel
            var errorAdSource = new Mockups.ErrorAdSource(new NotImplementedException())
            {
                Type = "vast"
            };

            GetPlayer = () => { Assert.Fail(); return(null); }; // this should not get hit
            await UnitTestExtensions.ThrowsExceptionAsync <NotImplementedException>(async() => await controller.PlayAdAsync(errorAdSource).AsTask(cts.Token, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // handshake error: should not throw
            GetPlayer = () => new Mockups.Vpaid()
            {
                ErrorPlacement = Mockups.ErrorPlacement.Handshake
            };
            await UnitTestExtensions.ThrowsExceptionAsync <Exception>(async() => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // initad error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Init };
            //await UnitTestExtensions.ThrowsExceptionAsync<Exception>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid()
            {
                ErrorPlacement = Mockups.ErrorPlacement.InitAsync
            };
            await UnitTestExtensions.ThrowsExceptionAsync <Exception>(async() => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // startad error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Start };
            //await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid()
            {
                ErrorPlacement = Mockups.ErrorPlacement.StartAsync
            };
            await UnitTestExtensions.ThrowsExceptionAsync <Exception>(async() => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // playing error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Play };
            //await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid()
            {
                ErrorPlacement = Mockups.ErrorPlacement.PlayAsync
            };
            await UnitTestExtensions.ThrowsExceptionAsync <Exception>(async() => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);

            // stopping error: should not throw
            //GetPlayer = () => new Mockups.Vpaid() { ErrorPlacement = Mockups.ErrorPlacement.Stop };
            //await UnitTestExtensions.ThrowsExceptionAsync<NotImplementedException>(async () => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));
            GetPlayer = () => new Mockups.Vpaid()
            {
                ErrorPlacement = Mockups.ErrorPlacement.StopAsync
            };
            await UnitTestExtensions.ThrowsExceptionAsync <Exception>(async() => await controller.PlayAdAsync(adSource).AsTask(cts.Token, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);
        }