public async Task GetPagedTodos() { var options = new DbContextOptionsBuilder <PostgresContext>() .UseInMemoryDatabase("GetPagedTodos") .Options; // Insert seed data into the database using one instance of the context await using (var context = new PostgresContext(options)) { await context.Todos.AddAsync(new Todo { Id = 1, Name = "Milk" }); await context.Todos.AddAsync(new Todo { Id = 2, Name = "Chocolate" }); await context.Todos.AddAsync(new Todo { Id = 3, Name = "Gym" }); await context.Todos.AddAsync(new Todo { Id = 4, Name = "Pickup" }); await context.SaveChangesAsync(); } // Use a clean instance of the context to run the test await using (var context = new PostgresContext(options)) { var repository = new TodoRepository(context); var todos = await new TodoController().Get(repository, 1, 2) as OkObjectResult; Assert.NotNull(todos); Assert.Equal(2, ((PagedData <Todo>)todos.Value).Value.Count()); } }
public SaleController(ISaleService saleService, IBaseObjectService <User> userService, IBaseObjectService <SaleProduct> saleProductService, IInfoMoneyService infoMoneyService, IBaseObjectService <Partner> partnerService, IBaseObjectService <ProductInformation> productInformationService, IBaseObjectService <SupplyProduct> supplyProductService, IBaseObjectService <Supplier> supplierService, IBaseObjectService <Shop> shopService, IMoneyOperationService moneyOperationService, ShopContext db, ISaleStatisticService saleStatisticService, ISaleInfoService saleInfoService, IProductOperationService productOperationService, IBookingProductInformationService bookingProductInformationService, PostgresContext postgresContext) { _saleService = saleService; _userService = userService; _saleProductService = saleProductService; _infoMoneyService = infoMoneyService; _partnerService = partnerService; _productInformationService = productInformationService; _supplyProductService = supplyProductService; _supplierService = supplierService; _db = db; _shopService = shopService; _moneyOperationService = moneyOperationService; _saleStatisticService = saleStatisticService; _saleInfoService = saleInfoService; _productOperationService = productOperationService; _bookingProductInformationService = bookingProductInformationService; _postgresContext = postgresContext; }
public static void InitializeDbForTests(PostgresContext db) { db.Users.Add(BuildUser()); db.Recipes.Add(BuildRecipe()); db.Lists.Add(BuildShoppingList()); db.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PostgresContext context, ILogger <Startup> logger) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/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(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); try { context.Database.Migrate(); } catch (Exception ex) { logger.LogWarning("LogWarning ", ex.Message); } }
public async Task <T> GetOne(Guid id) { using (var db = new PostgresContext()) { return(await db.Set <T>().FindAsync(id)); } }
public DbOperations(string connectionString) { DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); builder.UseNpgsql(connectionString); Context = new PostgresContext(builder.Options); }
public async Task <List <T> > GetAll() { using (var db = new PostgresContext()) { return(await db.Set <T>().ToListAsync()); } }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseCors("fiver"); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Luiza Labs Wishlist - v1"); }); using (var context = new PostgresContext()) { context.Database.Migrate(); } }
public async Task GetOneTodo() { var options = new DbContextOptionsBuilder <PostgresContext>() .UseInMemoryDatabase("GetOneTodo") .Options; // Insert seed data into the database using one instance of the context await using (var context = new PostgresContext(options)) { await context.Todos.AddAsync(new Todo { Id = 1, Name = "Milk" }); await context.Todos.AddAsync(new Todo { Id = 2, Name = "Chocolate" }); await context.Todos.AddAsync(new Todo { Id = 3, Name = "Gym" }); await context.SaveChangesAsync(); } // Use a clean instance of the context to run the test await using (var context = new PostgresContext(options)) { var repository = new TodoRepository(context); var todo = await new TodoController().GetFromId(repository, 2) as OkObjectResult; Assert.NotNull(todo); Assert.Equal("Chocolate", ((Todo)todo.Value).Name); } }
public static async Task <int> Handler(this ShopCreate command, PostgresContext db) { var createTask = await db.Shops.AddAsync(new Shop(command.Title)); await db.SaveChangesAsync(); return(createTask.Entity.Id); }
public async Task <int> Update(T entity) { using (var db = new PostgresContext()) { db.Set <T>(); db.Update(entity); return(await db.SaveChangesAsync()); } }
public static void Execute(EditScheduledDelivery command, PostgresContext postgresContext) { foreach (var scheduledDeliveryProduct in command.Products) { EditProduct(scheduledDeliveryProduct, postgresContext); } postgresContext.SaveChanges(); }
public SupplierController(IBaseObjectService <Supplier> supplierService, IBaseObjectService <SupplyProduct> supplyProductService, PostgresContext postgresContext, ShopContext shopContext) { _supplierService = supplierService; _supplyProductService = supplyProductService; _postgresContext = postgresContext; _shopContext = shopContext; }
public CardKeeperController(IBaseObjectService <CardKeeper> cardKeeperService, IInfoMoneyService infoMoneyService, ShopContext db, PostgresContext postgresContext) { _cardKeeperService = cardKeeperService; _infoMoneyService = infoMoneyService; _db = db; _postgresContext = postgresContext; }
public CalculatedScoreController(IBaseObjectService <CalculatedScore> calculatedScoreService, IInfoMoneyService infoMoneyService, ShopContext db, PostgresContext postgresContext) { _calculatedScoreService = calculatedScoreService; _infoMoneyService = infoMoneyService; _db = db; _postgresContext = postgresContext; }
public static async Task <User> Execute(PostgresContext db, UserCreate command) { var id = Guid.NewGuid(); var userCreate = await db.Users.AddAsync( new User(id, command.Login, command.Password, command.Role)); await db.SaveChangesAsync(); return(userCreate.Entity); }
public static async Task <User> Execute(PostgresContext db, string login, string password) { var user = await db.Users .FirstOrDefaultAsync(x => x.Login == login && x.Password == password); if (user == null) { throw new Exception("Неверные логин или пароль"); } return(user); }
public async Task CreateNullOption() { using (var db = new PostgresContext(Utilities.DB.TestDbContextOptions())) { Option option = new Option(); var createModel = new Pages.Options.CreateModel(db); createModel.Option = option; var result = await createModel.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); } }
public void ShowSubjects() { using (var db = new PostgresContext()) { var links = db.Links.ToList(); var sb = new StringBuilder(); foreach (var link in links) { sb.AppendLine(link.SubjectName); } SendMessage(sb.ToString()); } }
private static ICollection <(int, string)> DebtRepaymentOperations( PostgresContext postgresContext, ShopContext shopContext) { var repaidDebts = postgresContext.RepaidDebtsOld.ToList() .Join(shopContext.Suppliers, repaid => repaid.SupplierId, supplier => supplier.Id, (repaid, supplier) => (repaid.InfoMoneyId, supplier.Title)) .ToList(); return(repaidDebts); }
public async Task CreateOption() { using (var db = new PostgresContext(Utilities.DB.TestDbContextOptions())) { Option option = new Option(); option.Name = "Unit Test Option"; option.Description = "First Test for create metod"; var createModel = new Pages.Options.CreateModel(db); createModel.Option = option; var result = await createModel.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PostgresContext context, DialogsContext dialogsContext, ILog4netProvider log4Net, ILoggerFactory loggerFactory) { loggerFactory.AddLog4Net(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/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(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); try { context.Database.Migrate(); } catch (Exception ex) { log4Net.Error(typeof(Startup).ToString(), ex.Message, ex.StackTrace); } try { dialogsContext.Database.Migrate(); } catch (Exception ex) { log4Net.Error(typeof(Startup).ToString(), ex.Message, ex.StackTrace); } }
public ManagerController(IBaseObjectService <Partner> partnerService, IBaseObjectService <User> userService, ISaleService saleService, IInfoMoneyService infoMoneyService, IProductService productService, IBaseObjectService <Booking> bookingService, IShopService shopService, IBaseObjectService <BookingProduct> bookingProductService, IBaseObjectService <Category> categoryService, IBaseObjectService <SupplyProduct> supplyProduct, IBaseObjectService <SaleProduct> saleProductService, IBaseObjectService <SaleInformation> saleInformationService, IBaseObjectService <ExpenseCategory> expenseCategoryService, IBaseObjectService <Expense> expenseService, IBaseObjectService <ProductInformation> productInformation, ShopContext db, IProductOperationService productOperationService, IMoneyOperationService moneyOperationService, IMoneyStatisticService moneyStatisticService, IBookingProductInformationService bookingProductInformationService, ISaleInfoService saleInfoService, PostgresContext postgresContext) { _partnerService = partnerService; _userService = userService; _saleService = saleService; _infoMoneyService = infoMoneyService; _productService = productService; _bookingService = bookingService; _shopService = shopService; _bookingProductService = bookingProductService; _categoryService = categoryService; _supplyProduct = supplyProduct; _saleProductService = saleProductService; _saleInformationService = saleInformationService; _expenseCategoryService = expenseCategoryService; _expenseService = expenseService; _productInformation = productInformation; _productOperationService = productOperationService; _db = db; _moneyOperationService = moneyOperationService; _moneyStatisticService = moneyStatisticService; _bookingProductInformationService = bookingProductInformationService; _saleInfoService = saleInfoService; _postgresContext = postgresContext; }
public ProductService(ShopContext context, IInfoMoneyService infoMoneyService, IBaseObjectService <SupplyProduct> supplyProductService, IBaseObjectService <Supplier> supplierService, IBaseObjectService <BookingProduct> bookingProductsService, IBaseObjectService <ProductInformation> productInformationService, IBaseObjectService <Booking> bookingService, PostgresContext postgresContext) : base(context) { _context = context; _infoMoneyService = infoMoneyService; _supplyProductService = supplyProductService; _supplierService = supplierService; _productInformationService = productInformationService; _bookingProductService = bookingProductsService; _bookingService = bookingService; _postgresContext = postgresContext; }
public async Task CreateTodo() { var options = new DbContextOptionsBuilder <PostgresContext>() .UseInMemoryDatabase("CreateTodo") .Options; // Use a clean instance of the context to run the test await using var context = new PostgresContext(options); var repository = new TodoRepository(context); var todo = await new TodoController().Create(repository, new TodoCreateDto { Name = "Shopping" }) as OkObjectResult; Assert.NotNull(todo); Assert.Equal("Shopping", ((Todo)todo.Value).Name); }
public ProductOperationService(IProductService productService, IBaseObjectService <SupplyHistory> supplyHistory, IBaseObjectService <SupplyProduct> supplyProductService, IBaseObjectService <DeferredSupplyProduct> deferredSupplyProductService, IInfoProductService infoProductService, IBaseObjectService <Supplier> supplierService, IBaseObjectService <ProductInformation> productInformationService, PostgresContext postgresContext) { _productService = productService; _supplyHistoryService = supplyHistory; _supplyProductService = supplyProductService; _deferredSupplyProductService = deferredSupplyProductService; _infoProductService = infoProductService; _supplierService = supplierService; _productInformationService = productInformationService; _postgresContext = postgresContext; }
public static void Execute(int deliveryId, PostgresContext postgresContext, ShopContext shopContext) { var deliveredProducts = postgresContext.ScheduledProductDeliveries .Where(x => x.ScheduledDeliveryId == deliveryId && x.SupplyProductId == null && x.DeliveryType == ScheduledProductDeliveryType.Delivered) .ToList(); var supplyHistory = shopContext.SupplyHistories.Add(new SupplyHistory()).Entity; foreach (var deliveredProduct in deliveredProducts) { DeliverProduct(deliveredProduct, supplyHistory, postgresContext, shopContext); } postgresContext.SaveChanges(); shopContext.SaveChanges(); }
public static void DeliverProduct(ScheduledProductDelivery deliveredProduct, SupplyHistory supplyHistory, PostgresContext postgresContext, ShopContext shopContext) { var product = GetProduct(deliveredProduct.ProductId, deliveredProduct.ShopId, shopContext); shopContext.InfoProducts.Add(new InfoProduct() { Amount = deliveredProduct.Amount, Date = DateTime.Now.AddHours(3), Product = product, SupplierId = deliveredProduct.SupplierId, Type = InfoProductType.Supply, ShopId = deliveredProduct.ShopId, SupplyHistory = supplyHistory }); var supplyProduct = shopContext.SupplyProducts.Add(new SupplyProduct() { Product = product, SupplierId = deliveredProduct.SupplierId, RealizationAmount = 0, TotalAmount = deliveredProduct.Amount, AdditionalCost = 0, ProcurementCost = deliveredProduct.ProcurementCost, FinalCost = deliveredProduct.ProcurementCost, StockAmount = deliveredProduct.Amount, SupplyHistory = supplyHistory }); shopContext.SaveChanges(); deliveredProduct.SupplyProductId = supplyProduct.Entity.Id; postgresContext.ProductOperations.Add(new ProductOperation( supplyProduct.Entity.Id, deliveredProduct.Amount, DateTime.Now.AddHours(3), deliveredProduct.ProcurementCost, false, deliveredProduct.SupplierId, StorageType.Shop)); }
public ProductController(IProductService productService, IBaseObjectService <Category> categoryService, IShopService shopService, IBaseObjectService <SupplyProduct> supplierProductService, IBaseObjectService <User> userService, IBaseObjectService <BookingProduct> bookingProductService, IProductOperationService productOperationService, ShopContext db, PostgresContext postgresContext) { _productService = productService; _categoryService = categoryService; _shopService = shopService; _supplyProductService = supplierProductService; _userService = userService; _bookingProductService = bookingProductService; _productOperationService = productOperationService; _db = db; _postgresContext = postgresContext; }
public void Expense(PostgresContext postgresContext, int moneyWorkerId, decimal sum, PaymentType paymentType, int categoryId, string comment, int forId) { var createdInfoMoney = _infoMoneyService.Create(new InfoMoney() { MoneyWorkerId = moneyWorkerId, Sum = -sum, MoneyOperationType = MoneyOperationType.Expense, PaymentType = paymentType, Comment = comment }); var expense = _expenseService.Create(new Expense() { InfoMoneyId = createdInfoMoney.Id, ExpenseCategoryId = categoryId, }); postgresContext.ExpensesOld.Add(new ExpenseOld(expense.Id, forId)); postgresContext.SaveChanges(); }