static void Main(string[] args) { using (var context = new eShopContext()) { #region pagingtest var produktService = new ListProduktService(context); var produkter = produktService.SortFilterPage(new SortFilterPageOptions { OrderByOptions = OrderByOptions.Navn, FilterBy = ProduktFilterBy.Navn, FilterValue = "A", PageNum = 2, PageSize = 3 }).ToList(); foreach (ProduktListDto produkt in produkter) { Console.WriteLine("\nproduktnavn: {0} \nproduktpris: {1}", produkt.ProduktNavn, produkt.Pris ); } #endregion } }
public void TestMethod1() { // ARRANGE: Create option object with InMemoryDatabase var options = new DbContextOptionsBuilder <eShopContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; // ACT: Run the test against one instance of the context //using (var context = new eShopContext(options)) //{ // var service = new eShopService(context); // service.OpretKategori("unittest2"); //} // ASSERT: Use a separate instance of the context to verify correct data was saved to database using (var context = new eShopContext(options)) { Assert.AreEqual("unittest2", context.Kategorier.Single().KategoriNavn); } }
public EFRepository(eShopContext eShopContext) { _eShopContext = eShopContext; }
public ListProduktService(eShopContext context) { _context = context; }
public OrdersRepository(eShopContext context) { this.context = context; }
public FornecedorsController(eShopContext context) { _context = context; }
public UserRepository(eShopContext context) { this.context = context; }
public eShopService(eShopContext context) { //context.Database.EnsureCreated(); _context = context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IMemoryCache cache, eShopContext db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseMiniProfiler(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } if (!db.Database.CanConnect()) { db.Database.EnsureCreated(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseSession(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); }
public CategoryRepository(eShopContext eShopContext) : base(eShopContext) { }
public BaseService(eShopContext db) { _db = db; }
public ProductsRepository(eShopContext context) { this.context = context; }
public static void Initialize(eShopContext context) { /* context.Database.EnsureCreated(); * bool temp = false; * if (!context.Categories.Any()) * { * temp = true; * context.Categories.AddRange(new List<Category> * { * new Category * { * Id = 1, * Name = "Áo Nam", * Description = "Thời Trang Nam" * * }, * new Category * { * Id = 2, * Name = "Áo Nữ", * Description = "Thời Trang Nữ" * } * }) ; * } * * if(!context.Products.Any()) * { * temp = true; * context.Products.AddRange(new List<Product> { * new Product * { * Id = 1, * Category_Id = 1, * Name = "Áo sơ mi nam trắng Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * }, * new Product * { * Id = 2, * Category_Id = 1, * Name = "Áo sơ mi nam Den Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * }, * new Product * { * Id = 3, * Category_Id = 2, * Name = "Áo sơ mi nữ trắng Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * }, * new Product * { * Id = 4, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * } * ,new Product * { * Id = 5, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * }, * new Product * { * Id = 6, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * }, * new Product * { * Id = 7, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * }, * new Product * { * Id = 8, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * },new Product * { * Id = 9, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * },new Product * { * Id = 10, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * },new Product * { * Id = 11, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * },new Product * { * Id = 12, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * },new Product * { * Id = 13, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * },new Product * { * Id = 14, * Category_Id = 2, * Name = "Áo sơ mi nữ đen Việt Tiến", * DateCreated = DateTime.Now, * OriginalPrice = 100000, * Price = 200000, * Stock = 0, * ViewCount = 0, * IsFeatured = true, * Image = "" * } * * * }) ; * } * if(temp) * { * context.SaveChanges(); * }*/ }
public TBProdutoesController(eShopContext context) { _context = context; }
public CategoryRepository(eShopContext eShopContext) { this.eShopContext = eShopContext; }
public ProductRepository(eShopContext eShopContext) : base(eShopContext) { }
public TBCategoriasController(eShopContext context) { _context = context; }