Пример #1
0
        public async Task ExecuteAsync_Does_Nothing_With_No_Wishes()
        {
            var wishes = Enumerable.Empty <Wish>();

            var cmd = new UpdateLastSearchDateCommand(wishes);
            await cmd.ExecuteAsync(_table.Object);

            _table.Verify(t => t.ExecuteBatchAsync(It.IsAny <TableBatchOperation>()), Times.Never());
        }
Пример #2
0
        public async Task ExecuteAsync_Updates_The_Last_Search_Date_For_Given_Wishes()
        {
            var wishes = new List <Wish>
            {
                new Wish {
                    LastSearchDate = DateTime.MinValue
                },
                new Wish {
                    LastSearchDate = DateTime.MinValue
                }
            };

            _table.SetupBatch();

            var cmd = new UpdateLastSearchDateCommand(wishes);
            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyBatch();
            Assert.All(wishes, w => Assert.NotEqual(w.LastSearchDate, DateTime.MinValue));
        }
        public async Task SearchOrchestrationAsync(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            [Table(Constants.WishTableName)] CloudTable wishTable,
            [Pushover] IAsyncCollector <PushoverNotification> notifications)
        {
            var model   = context.GetInput <SearchContext>();
            var results = new List <WishResult>();

            foreach (var provider in model.Providers)
            {
                var providerResults = await context.CallSubOrchestratorAsync <IEnumerable <WishResult> >(SubOrchestrator, new SearchProviderContext
                {
                    Provider = provider,
                    Wishes   = model.Wishes
                });

                results.AddRange(providerResults);
            }

            if (results.Any())
            {
                var addResultsCmd = new AddWishResultsCommand(results);
                await wishTable.ExecuteAsync(addResultsCmd);

                var wishNames = results.GroupBy(r => r.WishName)
                                .Select(r => r.Key)
                                .Distinct();

                await notifications.AddAsync(new PushoverNotification
                {
                    Title   = "NZB Wishlist",
                    Message = $"Found new results for {string.Join(", ", wishNames)}"
                });
            }

            var updateWishesCmd = new UpdateLastSearchDateCommand(model.Wishes);
            await wishTable.ExecuteAsync(updateWishesCmd);
        }