public static async Task Run([QueueTrigger("SalesFileEntriesQueue")] GithubFileEntry fileEntry, TraceWriter log,
                                     [Queue("SalesDataQueue")] ICollector <SaleDataObtainmentResult> saleDataQueue)
        {
            log.Info($"C# Queue trigger function processed: SalesDataLoaderFunction");

            string          token          = ConfigurationManager.AppSettings["token"];
            ISaleDataSource saleDataSource = DependencyContainer.Container.Resolve <ISaleDataSource>(new ResolverOverride[]
            {
                new ParameterOverride("fileEntry", fileEntry),
                new ParameterOverride("githubRepoToken", token)
            });

            SaleDataObtainmentResult obtainmentResult = await saleDataSource.GetSaleDataAsync().ConfigureAwait(false);

            if (obtainmentResult.Success)
            {
                log.Info($"[SalesDataLoaderFunction]: loaded {fileEntry.Url}");
            }
            else
            {
                log.Error($"[SalesDataLoaderFunction]: ERROR loading {fileEntry.Url} Reason: {obtainmentResult.ErrorMessage}");
            }

            saleDataQueue.Add(obtainmentResult);
        }
示例#2
0
        public void SaleFileHandling_ErrorRemovedWhenDataHandled_And_SecondTimeSameDataReplacedOld()
        {
            string url = "https://api.github.com/repos/NAlex2004/SalesData/contents/Manager_2/AlNaz_04032019.json";

            lock (lockObject)
            {
                ISalesDataManager manager = DependencyContainer.Container.Resolve <ISalesDataManager>();
                using (GithubSalesHandler fileHandler = new GithubSalesHandler(manager))
                {
                    using (ISalesUnitOfWork unitOfWork = DependencyContainer.Container.Resolve <ISalesUnitOfWork>())
                    {
                        var errorAdded = manager.ErrorManager.AddErrorAsync(new SaleManagementResult()
                        {
                            FileName = "AlNaz_04032019.json", ErrorMessage = "Test error"
                        }).GetAwaiter().GetResult();
                        int             errors         = unitOfWork.ErrorFiles.Get().Count();
                        ISaleDataSource saleDataSource = DependencyContainer.Container.Resolve <ISaleDataSource>(new ResolverOverride[]
                        {
                            new ParameterOverride("fileEntry", new GithubFileEntry()
                            {
                                Url = url, CommitDate = DateTime.Now
                            }),
                            new ParameterOverride("githubRepoToken", Token)
                        });

                        var fileLoadResult = saleDataSource.GetSaleDataAsync().GetAwaiter().GetResult();
                        fileHandler.HandleSaleDataAsync(fileLoadResult).GetAwaiter().GetResult();
                        int errorsAfter = unitOfWork.ErrorFiles.Get().Count();

                        Assert.IsTrue(errorAdded.Succeeded);
                        Assert.AreEqual(errors - 1, errorsAfter);

                        // Second time same data

                        fileHandler.HandleSaleDataAsync(fileLoadResult).GetAwaiter().GetResult();

                        var sourceFile  = unitOfWork.SourceFiles.Get(f => f.FileName.Equals("AlNaz_04032019.json")).Single();
                        int salesCount  = unitOfWork.Sales.Get(s => s.SourceFileId == sourceFile.Id).Count();
                        int errorsCount = unitOfWork.ErrorFiles.Get(e => e.FileName.Equals("AlNaz_04032019.json")).Count();
                        Assert.AreEqual(5, salesCount);
                        Assert.AreEqual(0, errorsCount);
                    }
                }
            }
        }