Exemplo n.º 1
0
        public static async Task Run(
            [TimerTrigger("0 0 12 * * SUN")] TimerInfo myTimer,
            //[TimerTrigger("0 * * * * *")]TimerInfo myTimer,
            [Table("chainLinks", Connection = "AzureWebJobsStorage")] CloudTable chainLinksCloudTable,
            ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
            log.LogInformation($"Getting latest feed...");

            var chainLinks = (await new TheChainUkClient().GetFeed())
                             .ExtractTitlesAndDates()
                             .Select(c => c.ToChainLink());

            log.LogInformation("Got latest feed");
            log.LogInformation("Updating data table...");

            var repo = new ChainLinkRepository(chainLinksCloudTable);
            await repo.UpdateChainLinks(chainLinks.ToImmutableList());

            log.LogInformation("Updated data table.");
        }
        public async Task InsertOrMerge_ChainLinks()
        {
            var chainLink1 = new ChainLink {
                RowKey = "1"
            };
            var chainLink2 = new ChainLink {
                RowKey = "2"
            };

            var cloudTableMock = new Mock <CloudTable>(new Uri("http://127.0.0.1:10002/devstoreaccount1/screenSettings"));

            cloudTableMock.Setup(d => d.ExecuteBatchAsync(It.IsAny <TableBatchOperation>()));
            cloudTableMock.Setup(d => d.CreateIfNotExistsAsync());

            var repo = new ChainLinkRepository(cloudTableMock.Object);
            await repo.UpdateChainLinks(new List <ChainLink> {
                chainLink1, chainLink2
            });

            cloudTableMock.Verify(m => m.CreateIfNotExistsAsync(), Times.Once);
            cloudTableMock.Verify(m => m.ExecuteBatchAsync(It.IsAny <TableBatchOperation>()), Times.Once);
        }