private void ReassignPayeesByDate(BudgetCategory fromCategory, BudgetCategory toCategory)
        {
            if (fromCategory.Payees == null)
            {
                return;
            }

            foreach (Payee payee in fromCategory.Payees.Where(p => p.EffectiveFrom >= toCategory.EffectiveFrom))
            {
                payee.BudgetCategoryID = toCategory.ID;
                _context.EditPayee(payee);
            }
        }
Exemple #2
0
        // TODO: add tests for this method
        public async Task <int> UpdatePayeeAsync(int id, string name, DateTime effectiveFrom, string categoryName)
        {
            BudgetCategory category = _context.GetCategories()
                                      .Where(c => c.Name == categoryName)
                                      .OrderByDescending(c => c.EffectiveFrom)
                                      .FirstOrDefault() ?? throw new ModelValidationException(nameof(Payee.BudgetCategoryID), null,
                                                                                              $"There is no Budget Category named '{categoryName}'");

            Payee payee = await _context.GetPayees()
                          .Extension().SingleOrDefaultAsync(p => p.ID == id) ?? throw new NullModelException($"Could not find Payee with Id = {id}");

            try {
                payee.Name             = name;
                payee.EffectiveFrom    = effectiveFrom;
                payee.BudgetCategoryID = category.ID;
                ValidatePayee(payee);
                _context.EditPayee(payee);
                return(await _context.SaveChangesAsync());
            } catch (DbUpdateConcurrencyException) {
                throw new ConcurrencyException();
            }
        }
        public void EditPayee_calls_EFCore_Update()
        {
            // Arrange
            var mockPayeeSet = new Mock <DbSet <Payee> >();

            _mockContext.SetupGet(m => m.Payees).Returns(mockPayeeSet.Object);
            var testPayee = new Payee();

            // Act
            _testRepo.EditPayee(testPayee);

            // Assert
            mockPayeeSet.Verify(m => m.Update(testPayee), Times.Once());
        }