Exemple #1
0
        public async Task AddWishAsync_Returns_Created_With_The_New_Wish()
        {
            var reqModel = new WishViewModel
            {
                Name   = "a thing",
                Query  = "a.thing",
                Active = false
            };
            var req = TestHelper.CreateHttpRequest(reqModel);

            _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true);
            _table.SetupOperation(TableOperationType.Insert, () => new Wish
            {
                Name   = reqModel.Name,
                Query  = reqModel.Query,
                Active = reqModel.Active.Value
            });

            var resp = await _function.AddWishAsync(req, _table.Object, _log.Object);

            _table.VerifyOperation(TableOperationType.Insert);
            var cr    = Assert.IsType <CreatedResult>(resp);
            var model = Assert.IsType <WishViewModel>(cr.Value);

            Assert.NotNull(model.Id);
            Assert.Equal(reqModel.Name, model.Name);
            Assert.Equal(reqModel.Query, model.Query);
            Assert.Equal(reqModel.Active, model.Active);
        }
Exemple #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);
        }
Exemple #3
0
        public async Task AddProviderAsync_Returns_A_Created_Result_With_The_New_Provider()
        {
            var reqModel = new ProviderViewModel
            {
                Name        = "Provider",
                ApiKey      = "abc-123",
                ApiUrl      = "https://no.where",
                ImageDomain = "images.no.where"
            };
            var req = TestHelper.CreateHttpRequest(reqModel);

            _table.SetupOperation(TableOperationType.Insert, () => new Provider
            {
                Name        = reqModel.Name,
                ApiKey      = reqModel.ApiKey,
                ApiUrl      = reqModel.ApiUrl,
                ImageDomain = reqModel.ImageDomain
            });
            _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true);

            var resp = await _function.AddProviderAsync(req, _table.Object, _log.Object);

            _table.VerifyOperation(TableOperationType.Insert);
            var cr    = Assert.IsType <CreatedResult>(resp);
            var model = Assert.IsType <ProviderViewModel>(cr.Value);

            Assert.NotNull(model.Id);
            Assert.Equal(reqModel.Name, model.Name);
            Assert.Equal(reqModel.ApiKey, model.ApiKey);
            Assert.Equal(reqModel.ApiUrl, model.ApiUrl);
            Assert.Equal(reqModel.ImageDomain, model.ImageDomain);
        }
        public async Task ExecuteAsync_Persists_A_New_CartEntry()
        {
            var e = new CartEntry();

            _table.SetupOperation(e, TableOperationType.Insert);
            var cmd = new AddToCartCommand(e);

            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyOperation(e, TableOperationType.Insert);
        }
        public async Task ExecuteAsync_Persists_A_New_Provider()
        {
            var p = new Provider();

            _table.SetupOperation(p, TableOperationType.Insert);
            var cmd = new AddProviderCommand(p);

            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyOperation(p, TableOperationType.Insert);
        }
Exemple #6
0
        public async Task ExecuteAsync_Persists_A_New_Wish()
        {
            var w   = new Wish();
            var cmd = new AddWishCommand(w);

            _table.SetupOperation(w, TableOperationType.Insert);

            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyOperation(w, TableOperationType.Insert);
        }
        public async Task ExecuteAsync_Returns_The_Specified_Wish_Result()
        {
            var wr = new WishResult {
                RowKey = "000_123"
            };

            _table.SetupOperation(TableOperationType.Retrieve, () => wr);

            var query  = new GetWishResultQuery(wr.RowKey);
            var result = await query.ExecuteAsync(_table.Object);

            _table.VerifyOperation(TableOperationType.Retrieve);
            Assert.Equal(wr.RowKey, result.RowKey);
        }
        public async Task ExecuteAsync_Deletes_The_Given_Provider()
        {
            var id       = "123456";
            var provider = new Provider {
                RowKey = id
            };

            _table.SetupOperation(provider, TableOperationType.Delete);

            var cmd = new DeleteProviderCommand(id);

            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyOperation(provider, TableOperationType.Delete);
        }
        public async Task ExecuteAsync_Deletes_Results_For_The_Wish_And_The_Wish_Itself()
        {
            var w = new Wish {
                RowKey = "123"
            };
            var wishResultId = "456";
            var queryResult  = new List <DynamicTableEntity>
            {
                new DynamicTableEntity(nameof(WishResult), $"{w.RowKey}_{wishResultId}", "*", new Dictionary <string, EntityProperty>())
            };

            _table.SetupSegmentedQuery(queryResult);
            _table.SetupBatch();
            _table.SetupOperation(w, TableOperationType.Delete);
            var cmd = new DeleteWishCommand(w.RowKey);

            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyBatch();
            _table.VerifyOperation(w, TableOperationType.Delete);
            _table.VerifySegmentedQuery <DynamicTableEntity>();
        }