예제 #1
0
 public ProductsRepository(PurchaseOrdersDb dbContext, ILogger <ProductsRepository> logger)
 {
     _context     = dbContext;
     _logger      = logger;
     _retryPolicy = Policy
                    .Handle <Exception>()
                    .WaitAndRetryAsync(
         5,
         retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
         (exception, timeSpan, context) =>
     {
         var methodThatRaisedException = context["methodName"];
         _logger.LogError("Exception in " + methodThatRaisedException + " " + exception + exception.StackTrace);
     });
 }
예제 #2
0
        private PurchaseOrdersDb GetInMemoryContextWithSeedData()
        {
            var options = new DbContextOptionsBuilder <PurchaseOrdersDb>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new PurchaseOrdersDb(options);

            context.PurchaseStatus.Add(_stubPurchaseStatusDto);
            context.PaymentInformation.Add(_stubPaymentInformationDto);
            context.PurchaseOrders.Add(_stubPurchaseOrderDto);

            context.SaveChanges();

            return(context);
        }