public IEnumerable <Category> Get() { using (var context = new MMTContext()) { return(context.Categories.ToList()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MMTContext mmtContext) { mmtContext.Database.Migrate(); var seeder = new MMTContextSeed(); seeder.Seed(mmtContext); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API"); }); app.UseMiddleware <CustomExceptionMiddleware>(); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void AddProduct_Success() { using (var context = new MMTContext(this.dbContextOptions)) { // Arrange var productRep = new ProductRepository(context); var product = new Product(10000, "Test", "Test", 100, true); // Act var result = productRep.AddProduct(product); // Assert Assert.AreEqual(product.Id, result.Id); } }
public void AddCategory_Success() { using (var context = new MMTContext(this.dbContextOptions)) { // Arrange var categoryRep = new CategoryRepository(context); var category = new Category("Test", 60000, 70000, true); // Act var result = categoryRep.AddCategory(category); // Assert Assert.AreEqual(category.Id, result.Id); } }
protected void SeedDb() { using (var context = new MMTContext(dbContextOptions)) { if (!context.Category.Any()) { context.Category.AddRange(FakeCategories()); } if (!context.Product.Any()) { context.Product.AddRange(FakeProducts()); } context.SaveChanges(); } }
public void Setup() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); var builder = new DbContextOptionsBuilder <MMTContext>(); builder.UseSqlServer($"Server=(localdb)\\mssqllocaldb;Database=MMTShop_db_{Guid.NewGuid()};Trusted_Connection=True;MultipleActiveResultSets=true") .UseInternalServiceProvider(serviceProvider); _context = new MMTContext(builder.Options); _context.Database.Migrate(); var seeder = new MMTContextSeed(); seeder.Seed(_context); }
public void GetCategories_Success(int skuStart, int skuEnd) { using (var context = new MMTContext(this.dbContextOptions)) { // Arrange var categoryRep = new CategoryRepository(context); var expected = FakeCategories().Where(category => category.SKUStart <= skuEnd && category.SKUEnd >= skuStart); // Act var result = categoryRep.GetCategories(new CategorySKURangeOverlapSpec(skuStart, skuEnd)); // Assert foreach (var item in expected) { Assert.IsTrue(result.Any(a => a.Name == item.Name && a.SKUStart == item.SKUStart && a.SKUEnd == item.SKUEnd && a.CanBeFeatured == item.CanBeFeatured)); } } }
public void GetAllCategories_Success() { using (var context = new MMTContext(this.dbContextOptions)) { // Arrange var categoryRep = new CategoryRepository(context); var expected = FakeCategories(); // Act var result = categoryRep.GetAllCategories(); // Assert foreach (var item in expected) { Assert.IsTrue(result.Any(a => a.Name == item.Name && a.SKUStart == item.SKUStart && a.SKUEnd == item.SKUEnd && a.CanBeFeatured == item.CanBeFeatured)); } } }
public void GetProductsInSKURange_Success() { using (var context = new MMTContext(this.dbContextOptions)) { // Arrange var productRep = new ProductRepository(context); var skuStart = 10000; var skuEnd = 30000; var expectedProducts = FakeProducts().Where(a => a.SKU >= skuStart && a.SKU < skuEnd); // Act var result = productRep.GetProductsInSKURange(10000, 30000); // Assert Assert.AreEqual(expectedProducts.Count(), result.Count()); foreach (var item in expectedProducts) { Assert.IsTrue(result.Any(a => a.Name == item.Name && a.SKU == item.SKU && a.Price == item.Price && a.IsFeatured == item.IsFeatured)); } } }
/// <summary> /// Initializes the CategoryRepository <see cref="CategoryRepository"/> /// </summary> /// <param name="context">The db context</param> public CategoryRepository(MMTContext context) { _context = context ?? throw new MMTArgumentNullException(nameof(context)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHttpContextAccessor accessor, MMTContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseRouting(); // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); context.Database.Migrate(); InMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; }
public MmtRepository(MMTContext context, ILogger <MmtRepository> logger) { _context = context; _logger = logger; }
public CellChangesRepository(MMTContext context) : base(context) { }
public DamageTypeRepository(MMTContext context) : base(context) { }
/// <summary> /// Inject Titan databese context /// </summary> /// <param name="context"></param> public Repository(MMTContext context) { this.context = context; DbSet = context.Set <TEntity>(); }
public UnitOfWork(MMTContext context) { _context = context; }
public CellRepository(MMTContext context) : base(context) { }
public BagReplacementRepository(MMTContext context) : base(context) { }