public async Task GetWishesAsync_Returns_All_Available_Wishes() { var req = TestHelper.CreateHttpRequest(); _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true); _table.SetupSegmentedQuery(new[] { new Wish { Name = "Test", Query = "test", Active = true }, new Wish { Name = "Test 2", Query = "test.2", Active = false }, }.ToList()); var resp = await _function.GetWishesAsync(req, _table.Object, _log.Object); _table.VerifySegmentedQuery <Wish>(); var okResult = Assert.IsType <OkObjectResult>(resp); var providers = Assert.IsAssignableFrom <IEnumerable <WishViewModel> >(okResult.Value); Assert.Collection(providers, p => Assert.Equal("Test", p.Name), p => Assert.Equal("Test 2", p.Name)); }
public async Task RssAsync_Returns_An_Rss_2_Point_0_Feed_And_Passes_The_QueryString_Through_To_Links() { var req = TestHelper.CreateHttpRequest("https://nzb.mtighe.dev/api/cart/rss?del=1"); _cartTable.SetupSegmentedQuery(new[] { new CartEntry { Category = "Cat", Description = "", DetailsUrl = "https://no.where/details/cat", GrabUrl = "https://no.where/nzb/cat", Title = "item 1" }, new CartEntry { Category = "Dog", Description = "", DetailsUrl = "https://no.where/details/dog", GrabUrl = "https://no.where/nzb/dog", Title = "item 2" }, }); var result = await _function.RssAsync(req, _cartTable.Object); var cr = Assert.IsType <ContentResult>(result); var doc = XDocument.Parse(cr.Content); var items = doc.Root.Element("channel").Elements("item"); Assert.Equal(200, cr.StatusCode); Assert.Equal("text/xml", cr.ContentType); Assert.Equal("rss", doc.Root.Name.LocalName); Assert.Equal("2.0", doc.Root.Attribute("version").Value); Assert.Equal(2, items.Count()); Assert.All(items, x => { Assert.EndsWith("?del=1", x.Element("link").Value); Assert.EndsWith("?del=1", x.Element("enclosure").Attribute("url").Value); }); }
public async Task GetProvidersAsync_Returns_Available_Providers() { var req = TestHelper.CreateHttpRequest(); _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true); _table.SetupSegmentedQuery(new[] { new Provider { Name = "Test", ApiKey = "key", ApiUrl = "url" }, new Provider { Name = "Test 2", ApiKey = "key", ApiUrl = "url" }, }.ToList()); var resp = await _function.GetProvidersAsync(req, _table.Object, _log.Object); _table.VerifySegmentedQuery <Provider>(); var okResult = Assert.IsType <OkObjectResult>(resp); var providers = Assert.IsAssignableFrom <IEnumerable <ProviderViewModel> >(okResult.Value); Assert.Collection(providers, p => Assert.Equal("Test", p.Name), p => Assert.Equal("Test 2", p.Name)); }
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 ExecuteAsync_Returns_All_Providers() { var providers = new List <Provider> { new Provider(), new Provider() }; _table.SetupSegmentedQuery(providers); var cmd = new GetProvidersQuery(); var results = await cmd.ExecuteAsync(_table.Object); _table.VerifySegmentedQuery <Provider>(); Assert.Equal(2, results.Count()); }
public async Task ExecuteAsync_Returns_All_Cart_Entries() { var entries = new List <CartEntry> { new CartEntry(), new CartEntry() }; _table.SetupSegmentedQuery(entries); var cmd = new GetCartQuery(); var results = await cmd.ExecuteAsync(_table.Object); _table.VerifySegmentedQuery <CartEntry>(); Assert.Equal(2, results.Count()); }
public async Task ExecuteAsync_Returns_All_Results_For_A_Wish() { var providers = new List <WishResult> { new WishResult(), new WishResult(), new WishResult() }; _table.SetupSegmentedQuery(providers); var cmd = new GetWishResultsQuery("123"); var results = await cmd.ExecuteAsync(_table.Object); _table.VerifySegmentedQuery <WishResult>(); Assert.Equal(3, results.Count()); }
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>(); }
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()); }