コード例 #1
0
 public ActionResult AddItem(LogEntry item)
 {
     if (ModelState.IsValid)
     {
         _moneyService.AddItem(UserId, item);
         return RedirectToAction("MoneyLog");
     }
     return View(item);
 }
コード例 #2
0
        public void AddItem_WithValidItem_CallsServiceMethod()
        {
            // Arrange
            var item = new LogEntry {Description = "description", Value = 1, Category = "Category", Subcategory = "Subcategory", Direction = "In"};
            _moneyService.Setup(m => m.AddItem(UserId, item));
            // Act
            var result = _controller.AddItem(item);

            // Assert
            result.ShouldBeRedirectionTo(new { action = "MoneyLog"});
            _moneyService.Verify(m => m.AddItem(UserId, item),Times.Once());
        }
コード例 #3
0
        public void AddItem_WithValidLogEntry_CallsRep()
        {
            // Arrange
            _moneyRepo.Setup(r => r.SaveItem(It.IsAny<int>(), It.IsAny<MoneyFlow>()));
            var service = new MoneyService(_moneyRepo.Object);
            var item = new LogEntry { Description = "description", Value = 1, Category = "Category", Subcategory = "Subcategory"};

            // Act
            service.AddItem(1, item);

            // Assert
            _moneyRepo.Verify(r => r.SaveItem(It.IsAny<int>(), It.IsAny<MoneyFlow>()), Times.Once());
        }
コード例 #4
0
 public void AddItem(int userId, LogEntry item)
 {
     var entry = new MoneyFlow
     {
         Id = 0,
         Category = item.Category.ToTitleCase(),
         Subcategory = (string.IsNullOrEmpty(item.Subcategory)) ? string.Empty : item.Subcategory.ToTitleCase(),
         Credit = (item.Direction == "credit") ? item.Value : 0m,
         Debit = (item.Direction == "debit") ? item.Value : 0m,
         Date = DateTime.Now,
         Item = item.Description
     };
     _moneyFlowRepository.SaveItem(userId, entry);
 }