public async Task FailWithNonStorageError()
        {
            var func = MockCloudTable.GetSafeCreateMethod();

            // Completely different exception  Storage error

            var exception = new InvalidOperationException("other");

            try
            {
                var table = new MockCloudTable();
                table.Func = new Action[]
                {
                    () => { throw exception; }  // terminal abort
                };

                await func(table);

                Assert.True(false); // should have thrown
            }
            catch (Exception e)
            {
                Assert.True(object.ReferenceEquals(e, exception));
            }
        }
Beispiel #2
0
        public async Task AddToCartAsync_Returns_CreatedResult()
        {
            var id         = "123";
            var req        = TestHelper.CreateHttpRequest($"https://nzb.mtighe.dev/api/cart/add/{id}");
            var wishTable  = new MockCloudTable();
            var wishResult = new WishResult
            {
                Category   = "Cat",
                DetailsUrl = "https://no.where/details/123",
                Title      = "wish result",
                NzbUrl     = "https://no.where/nzb/123",
                PubDate    = DateTime.UtcNow.AddDays(-10)
            };

            wishTable.SetupOperation(TableOperationType.Retrieve, () => wishResult);
            _cartTable.SetupOperation <CartEntry>(TableOperationType.Insert);
            _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true);

            var result = await _function.AddToCartAsync(req, wishTable.Object, _cartTable.Object, _log.Object, id);

            wishTable.VerifyOperation(TableOperationType.Retrieve);
            _cartTable.VerifyOperation(TableOperationType.Insert);
            var created = Assert.IsType <CreatedResult>(result);

            Assert.Equal("https://nzb.mtighe.dev:443/api/cart/rss", created.Location);
            var vm = Assert.IsType <CartEntryViewModel>(created.Value);

            Assert.Equal(wishResult.Category, vm.Category);
            Assert.Equal(wishResult.DetailsUrl, vm.DetailsUrl);
            Assert.Equal(wishResult.Title, vm.Title);
            Assert.Equal($"https://nzb.mtighe.dev:443/api/cart/nzb/{vm.Id}", vm.GrabUrl);
            Assert.Equal(wishResult.PubDate, vm.PublishDate);
            Assert.Equal("", vm.Description);
        }
        public async Task CreateNormal()
        {
            var func = MockCloudTable.GetSafeCreateMethod();

            var table = new MockCloudTable();

            table.Func = new Action[]
            {
                () => { } // Nop, success
            };

            await func(table);
        }
Beispiel #4
0
        public async Task AddToCartAsync_Returns_Unprocessable_When_Exceptions_Are_Thrown()
        {
            var req = TestHelper.CreateHttpRequest("https://nzb.mtighe.dev/api/cart/add/123");

            _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true);
            var wishTable = new MockCloudTable();

            wishTable.SetupOperationToThrow();

            var result = await _function.AddToCartAsync(req, wishTable.Object, _cartTable.Object, _log.Object, "123");

            _log.VerifyLoggedException("Cart-Add caused an exception");
            Assert.IsType <UnprocessableEntityObjectResult>(result);
        }
        public async Task CreateWithConflict()
        {
            var func = MockCloudTable.GetSafeCreateMethod();
            {
                var table = new MockCloudTable();
                table.Func = new Action[]
                {
                    () => { throw Error(HttpStatusCode.Conflict); },
                    () => { },  // success
                };

                await func(table);
            }
        }
        public async Task SearchAsync_Does_Nothing_When_There_Are_No_Active_Wishes()
        {
            var client        = new Mock <DurableOrchestrationClientBase>(MockBehavior.Strict);
            var timer         = new TimerInfo(new TimerScheduleStub(), new ScheduleStatus());
            var providerTable = new MockCloudTable();

            providerTable.SetupSegmentedQuery(Enumerable.Empty <Provider>());
            _wishTable.SetupSegmentedQuery(new[]
            {
                new Wish {
                    Active = false
                }
            });

            await _function.SearchAsync(timer, providerTable.Object, _wishTable.Object, client.Object);

            providerTable.VerifySegmentedQuery <Provider>();
            _wishTable.VerifySegmentedQuery <Wish>();
            client.Verify(c => c.StartNewAsync("SearchOrchestration", It.IsAny <object>()), Times.Never());
        }
        public async Task FailWithStorageError()
        {
            var func = MockCloudTable.GetSafeCreateMethod();

            var exception = Error(HttpStatusCode.BadRequest);

            try
            {
                var table = new MockCloudTable();
                table.Func = new Action[]
                {
                    () => { throw exception; }    // terminal abort
                };

                await func(table);

                Assert.True(false); // should have thrown
            }
            catch (StorageException e)
            {
                Assert.True(object.ReferenceEquals(e, exception));
            }
        }
        public async Task FailWithTimeout()
        {
            var func = MockCloudTable.GetSafeCreateMethod();

            try
            {
                var table = new MockCloudTable();
                table.Func = new Action[]
                {
                    () => { throw Error(HttpStatusCode.Conflict); },
                    () => { throw Error(HttpStatusCode.Conflict); },
                    () => { throw Error(HttpStatusCode.Conflict); },
                    () => { throw Error(HttpStatusCode.Conflict); },
                };

                await func(table);

                Assert.True(false); // should have thrown
            }
            catch (StorageException)
            {
                // Success
            }
        }
        public async Task SearchAsync_Starts_The_Search_Orchestration()
        {
            var client        = new Mock <DurableOrchestrationClientBase>(MockBehavior.Strict);
            var timer         = new TimerInfo(new TimerScheduleStub(), new ScheduleStatus());
            var providerTable = new MockCloudTable();

            providerTable.SetupSegmentedQuery(new[]
            {
                new Provider()
            });
            _wishTable.SetupSegmentedQuery(new[]
            {
                new Wish {
                    Active = true
                }
            });
            client.Setup(c => c.StartNewAsync("SearchOrchestration", It.IsAny <object>())).ReturnsAsync("newid");

            await _function.SearchAsync(timer, providerTable.Object, _wishTable.Object, client.Object);

            providerTable.VerifySegmentedQuery <Provider>();
            _wishTable.VerifySegmentedQuery <Wish>();
            client.Verify(c => c.StartNewAsync("SearchOrchestration", It.IsAny <object>()), Times.Once());
        }