private void Debit(Account account, Account internalAccount, Movement movement) { MovementHelpers.Debit(HistoricMovementRepository, movement.Amount, account.Id, ObjectType.Account, account.CurrentBalance, internalAccount.Id, ObjectType.Account, internalAccount.CurrentBalance); account.CurrentBalance -= movement.Amount; BankAccountRepository.Update(account); internalAccount.CurrentBalance += movement.Amount; BankAccountRepository.Update(internalAccount); if (!movement.TargetAccountId.HasValue) { throw new ArgumentException("Target Income ID should not be null."); } var income = new Income { Description = "Transfer: " + movement.Description, Cost = movement.Amount, AccountId = movement.TargetAccountId.Value, DateIncome = movement.Date }; var mappedIncome = IncomeRepository.Create(income); movement.TargetIncomeId = mappedIncome.Id; }
public void Create(Income newIncome) { Contract.Requires <ArgumentNullException>(newIncome != null, "The income must not be null"); Contract.Requires <ArgumentNullException>(newIncome.CategoryId > 0, "There must be a category selected"); Contract.Requires <ArgumentNullException>(newIncome.PaymentMethodId > 0, "There must be a payment method selected"); _repository.Create(newIncome); }
public void Create(Income newIncome) { Contract.Requires <ArgumentNullException>(newIncome != null, "The income must not be null"); // ReSharper disable once PossibleNullReferenceException Contract.Requires <ArgumentException>(newIncome.CategoryId > 0, "There must be a category selected"); Contract.Requires <ArgumentException>(newIncome.PaymentMethodId > 0, "There must be a payment method selected"); _repository.Create(newIncome); }
public void Can_Retrieve_All_Saved_Income_From_Database() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); var manager = _context.Staffs.Single(); repo.Create(new Income("income1", 2300, manager.Id)); //repo.Create(new Income("income2", 4300, manager.Id)); Assert.AreEqual(2, repo.GetAllIncome().Count()); } }
public void Can_Retrieve_Saved_Income_From_Database() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); Staff manager = _context.Staffs.Single(); Income income = new Income("Web_Adverts", 2300, manager.Id); repo.Create(income); Income retrievedIncome = repo.GetIncome(manager.Incomes.Single().Id); Assert.AreEqual(2300, retrievedIncome.Amount); } }
public void Can_Retrieve_DateCreated_From_Saved_Income() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); Staff manager = _context.Staffs.Single(); Income income = new Income("IMF_Grant", 45000, manager.Id); string currentDate = DateTime.Now.ToString("yyyy-MM-dd-HH"); repo.Create(income); Income retrievedIncome = manager.Incomes.Single(); Assert.AreEqual(currentDate, retrievedIncome.DateCreated.ToString("yyyy-MM-dd-HH")); } }
public void Can_Update_Saved_Income() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); var manager = _context.Staffs.Single(); repo.Create(new Income("income1", 2300, manager.Id)); Income savedIncome = manager.Incomes.Single(); savedIncome.Description = ".Net_Conference_Revenues"; savedIncome.Amount = 3400; repo.Update(savedIncome); Assert.AreEqual(".Net_Conference_Revenues", manager.Incomes.Single().Description); } }
public void Can_Successfully_Create_New_Income_In_DataBase() { using (CashFlowEntities context = new CashFlowEntities()) using (var repo = new IncomeRepository(context)) using (var staffRepo = new StaffRepository(context)) using (DbContextTransaction transaction = context.Database.BeginTransaction()) { context.Staffs.Add(sampleManager); context.SaveChanges(); Income income = new Income("Web_Advertisment", 3000, sampleManager.Id); repo.Create(income); var dbIncome = sampleManager.Incomes.SingleOrDefault(); Assert.AreEqual(3000, dbIncome.Amount); transaction.Rollback(); } }
public void Create(Income newIncome) { _repository.Create(newIncome); }