public IActionResult Add(SpendItemViewModel viewModel)
 {
     _spendItemService.Add(new SpendItem()
     {
         AmountSpent  = viewModel.SpendItem.AmountSpent,
         Category     = viewModel.SpendItem.Category,
         Description  = viewModel.SpendItem.Description,
         EmailAddress = User.Identity.Name,
         Date         = viewModel.SpendItem.Date
     });
     return(RedirectToAction("Index"));
 }
예제 #2
0
        public void GivenIAddASpendItem_WhenICallAdd_ThenTheSpendItemIsInTheDatabase()
        {
            const decimal  amountSpent = (decimal)1.25;
            const Category category    = Category.Snacks;
            const string   description = "Sour Cream and Onion Pringles";


            _sut.Add(new Models.SpendItem()
            {
                AmountSpent  = (decimal)amountSpent,
                Category     = category,
                Description  = description,
                EmailAddress = MarkEmail
            });

            var spendItem = _spendItemRepository.List().First();
            var user      = _userRepository.List(u => u.EmailAddress == MarkEmail).First();

            Assert.AreEqual(amountSpent, spendItem.AmountSpent);
            Assert.AreEqual(category, spendItem.Category);
            Assert.AreEqual(description, spendItem.Description);
            Assert.AreEqual(user.Id, spendItem.UserId);
            Assert.IsNotNull(spendItem.Id);
        }