Example #1
0
        public async Task <T> AddAsync(T entity)
        {
            await DbContext.Set <T>().AddAsync(entity);

            await DbContext.SaveChangesAsync();

            return(entity);
        }
        public static async Task SeedAsync(BotCoreTestContext context, ICurrencyService currencyService, int retry = 0)
        {
            var retryForAvailability = retry;

            try
            {
                // TODO: Only run this if using a real database
                await context.Database.MigrateAsync();

                if (!context.Currency.Any())
                {
                    var currencies = await currencyService.GetAllCurrencies();

                    await context.Currency.AddRangeAsync(currencies);

                    await context.Currency.AddAsync(GetByn());

                    await context.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                if (retryForAvailability >= 10)
                {
                    throw;
                }

                retryForAvailability++;
                await SeedAsync(context, currencyService, retryForAvailability);

                throw;
            }
        }