Esempio n. 1
0
        public async Task GivenAnItemId_ThenCorrectRequestIsMadeToRetrieveItem(string id, string typeOfItem)
        {
            var queueItem = new QueueItem {
                Id = id
            };
            var message = new CloudQueueMessage(JsonConvert.SerializeObject(queueItem));

            var fileLoaderMessageHandler = new FileLoaderMessageHandler(typeOfItem, "Amazon");

            GetAmazonPriceFunction.Client = new HttpClient(fileLoaderMessageHandler);
            await GetAmazonPriceFunction.Run(message, _tableReference);

            var requests = fileLoaderMessageHandler.GetRequests();

            Assert.Contains($"https://www.amazon.co.uk/dp/{id}", requests);
        }
Esempio n. 2
0
        public async Task GivenAnItemId_ThenCorrectPriceIsEnteredIntoTheDatabase(string id, string expectedPrice, string typeOfItem)
        {
            var queueItem = new QueueItem {
                Id = id
            };
            var message = new CloudQueueMessage(JsonConvert.SerializeObject(queueItem));

            GetAmazonPriceFunction.Client = new HttpClient(new FileLoaderMessageHandler(typeOfItem, "Amazon"));
            await GetAmazonPriceFunction.Run(message, _tableReference);

            var query = new TableQuery <ItemPrice>()
                        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, id));
            var result = await _tableReference.ExecuteQuerySegmentedAsync(query, null);

            var itemPrice = result.Results.First();

            Assert.NotNull(itemPrice);
            Assert.Equal(expectedPrice, itemPrice.Price);
            Assert.Equal(DateTime.UtcNow, itemPrice.PriceDate, TimeSpan.FromSeconds(2));
        }