public async Task SearchOrchestrationAsync_Starts_The_Provider_Sub_Orchestration_And_Sets_Wish_LastSearchDate()
        {
            var providers = new[]
            {
                new Provider {
                    ApiKey = "key", ApiUrl = "https://no.where"
                },
                new Provider {
                    ApiKey = "key2", ApiUrl = "https://no2.where"
                },
            };
            var searchContext = new SearchContext
            {
                Providers = providers,
                Wishes    = new[] { new Wish {
                                        Name = "wish", Query = "query", LastSearchDate = DateTime.UtcNow.AddDays(-2)
                                    } }
            };
            var context       = new Mock <DurableOrchestrationContextBase>(MockBehavior.Strict);
            var notifications = new Mock <IAsyncCollector <PushoverNotification> >(MockBehavior.Strict);

            context.Setup(c => c.GetInput <SearchContext>()).Returns(searchContext);
            context.Setup(c => c.CallSubOrchestratorAsync <IEnumerable <WishResult> >("ProviderOrchestration", It.IsAny <object>()))
            .ReturnsAsync(Enumerable.Empty <WishResult>());
            _wishTable.SetupBatch();

            await _function.SearchOrchestrationAsync(context.Object, _wishTable.Object, notifications.Object);

            context.Verify(c => c.GetInput <SearchContext>(), Times.Once());
            context.Verify(c => c.CallSubOrchestratorAsync <IEnumerable <WishResult> >("ProviderOrchestration", It.IsAny <object>()), Times.Exactly(2));
            notifications.Verify(n => n.AddAsync(It.IsAny <PushoverNotification>(), CancellationToken.None), Times.Never());
            _wishTable.VerifyBatch();
        }
        public async Task ExecuteAsync_Persists_Results_In_Batches()
        {
            _table.SetupBatch();
            var w = new Wish()
            {
                Name = "I Wish"
            };
            var wr = new WishResult();

            wr.BelongsTo(w);
            var results = new[] { wr };
            var cmd     = new AddWishResultsCommand(results);

            await cmd.ExecuteAsync(_table.Object);

            _table.VerifyBatch();
        }
Beispiel #3
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 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>();
        }