Ejemplo n.º 1
0
        public async Task PopulateData(int amount)
        {
            if (_shortenerContext.Shortcuts.Count() >= amount)
            {
                throw new Exception("You have already populated data. Comment PopulateData method.");
            }

            var redirectFaker = new Faker <Redirect>()
                                .RuleFor(a => a.Url, f => f.Internet.Url());

            var redirectExtendedFaker = new Faker <RedirectExtended>()
                                        .RuleFor(a => a.Url, f => f.Internet.Url());

            var shortcutFakerOne = new Faker <Shortcut>()
                                   .RuleFor(a => a.Alias, f => f.Random.AlphaNumeric(new Random().Next(5, 30)))
                                   .RuleFor(a => a.TimesRedirect, f => f.Random.Long(min: 0, max: 999999999));


            for (var i = 0; i < amount; i++)
            {
                if (i % 2 == 0)
                {
                    Redirect redirect = redirectFaker.Generate();
                    Shortcut shortcut = shortcutFakerOne.Generate();

                    redirect.Shortcut = shortcut;
                    shortcut.Redirect = redirect;

                    await _shortenerContext.AddAsync(redirect);

                    await _shortenerContext.AddAsync(shortcut);
                }
                else
                {
                    RedirectExtended redirectExtended = redirectExtendedFaker.Generate();
                    Shortcut         shortcut         = shortcutFakerOne.Generate();

                    redirectExtended.Shortcut = shortcut;
                    shortcut.RedirectExtended = redirectExtended;

                    await _shortenerContext.AddAsync(redirectExtended);

                    await _shortenerContext.AddAsync(shortcut);
                }
            }

            await _shortenerContext.SaveChangesAsync();
        }
Ejemplo n.º 2
0
 public async Task DeleteAsync(RedirectExtended redirectExtended)
 {
     _shortenerContext.RedirectExtendeds
     .Remove(redirectExtended);
 }
Ejemplo n.º 3
0
 public async Task UpdateAsync(RedirectExtended redirectExtended)
 {
     _shortenerContext.RedirectExtendeds
     .Update(redirectExtended);
 }
Ejemplo n.º 4
0
 public async Task InsertAsync(RedirectExtended redirectExtended)
 {
     await _shortenerContext.RedirectExtendeds
     .AddAsync(redirectExtended);
 }