public async Task DebitorsCasesExpensesAllTest() { var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb05"); var dbContext = new ApplicationDbContext(optionBuilder.Options); var service = new DebitorsCasesService(dbContext); var model = new LawCase { AbNumber = "13000300401", DebitorId = 11, Date = DateTime.UtcNow.Date, Value = 100, }; dbContext.LawCases.Add(model); await dbContext.SaveChangesAsync(); var expense = new ExpenseInputViewModel { ExpenceDate = DateTime.UtcNow.Date, Payee = "РРС", ExpenceDescription = "Депозит ВЛ", ExpenceValue = 200, LawCaseId = 1, }; await service.CreateExpense(expense); var x = dbContext.LawCases.Where(x => x.DebitorId == 11).Select(x => x.AbNumber).FirstOrDefault(); var result = service.AllExpenses(1); Assert.NotNull(result); Assert.Equal("13000300401", x); }
public IActionResult Create() { var viewModel = new ExpenseInputViewModel { LawCases = this.expenseService.GetAllLawCases() }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(ExpenseInputViewModel model) { if (!ModelState.IsValid) { return(this.View(model)); } await this.expenseService.CreateAsync(model); return(this.RedirectToAction("All")); }
public IActionResult CreateExpense(int?id) { if (id == null) { return(NotFound()); } var expense = new ExpenseInputViewModel { LawCaseId = (int)id, ExpenceDate = DateTime.UtcNow.Date, }; return(this.View(expense)); }
public async Task CreateExpense(ExpenseInputViewModel model) { var expense = new Expense { LawCaseId = model.LawCaseId, ExpenceDate = DateTime.UtcNow.Date, ExpenceValue = model.ExpenceValue, ExpenceDescription = model.ExpenceDescription, Payee = model.Payee, }; await this.dbContext.Expenses.AddAsync(expense); await this.dbContext.SaveChangesAsync(); }
public async Task CreateAsync(ExpenseInputViewModel model) { //model.LawCases = this.GetAllLawCases(); var expense = new Expense { Payee = model.Payee, ExpenceDate = model.ExpenceDate, ExpenceDescription = model.ExpenceDescription, ExpenceValue = model.ExpenceValue, LawCaseId = model.LawCaseId, }; await this.dbContext.Expenses.AddAsync(expense); await this.dbContext.SaveChangesAsync(); }
public async Task <IActionResult> CreateExpense(ExpenseInputViewModel model) { if (ModelState.IsValid) { try { await this.service.CreateExpense(model); //return this.Redirect($"https://localhost:44342/DebitorsCases/Home/Details/{model.LawCaseId}"); return(this.RedirectToAction("AllExpenses", new { id = model.LawCaseId })); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); this.ViewData["Message"] = "Възникна грешка при създаването на запис."; } } return(this.View(model)); }
public async Task ExpenseDeleteTest() { // Arrange var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb2"); var dbContext = new ApplicationDbContext(optionBuilder.Options); var service = new ExpenseService(dbContext); var model = new ExpenseInputViewModel { ExpenceDate = DateTime.UtcNow.Date, ExpenceDescription = "заповед за изпълнение", Payee = "РРС100", ExpenceValue = 27 }; await service.CreateAsync(model); var result = await service.Delete(1); Assert.NotNull(result); Assert.Equal(1, result.Id); }
public void ExpenseCreateTest() { // Arrange var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb"); var dbContext = new ApplicationDbContext(optionBuilder.Options); var service = new ExpenseService(dbContext); var model = new ExpenseInputViewModel { ExpenceDate = DateTime.UtcNow.Date, ExpenceDescription = "заповед за изпълнение", Payee = "РРС100", ExpenceValue = 27 }; // Act var result = service.CreateAsync(model); // Assert Assert.NotNull(result); Assert.True(result.IsCompletedSuccessfully); }
public async Task ExpenseEditTest() { // Arrange var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb"); var dbContext = new ApplicationDbContext(optionBuilder.Options); var service = new ExpenseService(dbContext); var model = new ExpenseInputViewModel { ExpenceDate = DateTime.UtcNow.Date, ExpenceDescription = "заповед за изпълнение", Payee = "РРС100", ExpenceValue = 27 }; await service.CreateAsync(model); int modelId = await dbContext.Expenses.Where(x => x.Id != 0).Select(x => x.Id).FirstOrDefaultAsync(); var editModel = new ExpenseEditViewModel { Id = modelId, ExpenceDate = model.ExpenceDate.AddYears(1), ExpenceDescription = "заповед за изпълнение+editted", ExpenceValue = model.ExpenceValue + 100, Payee = "РРС100+editted", }; // Act var result = service.Edit(editModel); // Assert Assert.NotNull(result); // Assert.True(result.IsCompletedSuccessfully); }