private void GenerateCategories() { for (int i = 0; i < CategoryAmount / 2; i++) { Categories[i] = CategoryGenerator.GenerateCategory(); } for (int i = CategoryAmount / 2; i < CategoryAmount; i++) { Categories[i] = CategoryGenerator.GenerateCategory(Categories[i % CategoryAmount / 2]); } }
public ProductViewModelGenerator(ProductContext ctx) { Category category = new CategoryGenerator().Generate(); ctx.Categories.Add(category); ctx.SaveChanges(); this._Faker = new Faker <ProductViewModel>() .RuleFor(ev => ev.Id, faker => faker.Lorem.Sentence(3)) .RuleFor(p => p.Name, faker => faker.Lorem.Sentence(3)) .RuleFor(ev => ev.CategoryId, category.Id); }
public async Task Must_Update() { var category = CategoryGenerator.GenerateAndSave(CategoryRepository); Command.Id = category.Id; var response = await HttpClient.PutAsJsonAsync($"{BasePath}Categories", Command); Output.WriteLine(await response.Content.ReadAsStringAsync()); Assert.Equal(HttpStatusCode.OK, response.StatusCode); category = CategoryRepository.Reload(category); Assert.Equal(Command.Id, category.Id); Assert.Equal(Command.Title, category.Title); }
public ProductTest ( TestWebApplicationFactory factory, ITestOutputHelper output ) : base(factory, output) { var category = CategoryGenerator.GenerateAndSave(CategoryRepository); Command = new ProductCreateCommand { Title = "Product Title", Description = "Product description", Price = 150, Quantity = 10, CategoryId = category.Id }; }
public static IHost MigrateDatabase(this IHost host) { using (var scope = host.Services.CreateScope()) { using (var _context = scope.ServiceProvider.GetRequiredService <BookContext>()) { try { if (_context.Categories.Count() == 0) { Category[] categories = CategoryGenerator.CreateCategories(); _context.Categories.AddRange(categories); _context.SaveChanges(); } if (_context.Authors.Count() == 0) { Author[] authors = AuthorGenerator.CreateAuthors(); _context.Authors.AddRange(authors); _context.SaveChanges(); } if (_context.Books.Count() == 0) { Book[] books = BookGenerator.CreateBooks(); _context.Books.AddRange(books); _context.SaveChanges(); } } catch (Exception ex) { //Log errors or do anything you think it's needed throw; } } } return(host); }