public void Test_CreatePost_InvalidModelState_ReturnsViewWithFund()
        {
            controller.ModelState.AddModelError("test", "test");
            var fund = new SavingsFund();

            var result = controller.Create(fund) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(fund, result.Model);
        }
Exemplo n.º 2
0
        public ActionResult Edit(SavingsFund fund)
        {
            if (!ModelState.IsValid)
            {
                return(View(fund));
            }

            db.SetEntityState(fund, EntityState.Modified);
            db.SaveChanges();
            return(RedirectToAction("Breakdown", "SavingsAccount", new { id = fund.AccountID }));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Balance,AccountID")] SavingsFund fund)
        {
            if (!ModelState.IsValid)
            {
                return(View(fund));
            }

            db.SavingsFunds.Add(fund);
            db.SaveChanges();
            return(RedirectToAction("Breakdown", "SavingsAccount", new { id = fund.AccountID }));
        }
        public void Test_EditGet_ValidId_ReturnsViewWithFund()
        {
            var fund = new SavingsFund {
                Id = 7
            };

            mockFunds.Setup(a => a.Find(It.IsAny <int>())).Returns(fund);

            var result = controller.Edit(fund.Id) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(fund, result.Model);
        }
Exemplo n.º 5
0
        public ActionResult Create(int accountID)
        {
            if (db.SavingsAccounts.Find(accountID) == null)
            {
                return(HttpNotFound());
            }

            var fund = new SavingsFund {
                AccountID = accountID
            };

            return(View(fund));
        }
        public void Test_EditPost_ValidModelState_SavesToDB()
        {
            controller.ModelState.Clear();
            var fund = new SavingsFund {
                AccountID = 1, Balance = 50, Name = "Test Fund"
            };

            var result = controller.Edit(fund) as RedirectToRouteResult;

            mockDbContext.Verify(c => c.SaveChanges(), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteValues["action"], "Breakdown");
            Assert.AreEqual(result.RouteValues["controller"], "SavingsAccount");
            Assert.AreEqual(result.RouteValues["id"], fund.AccountID);
        }
        public void Test_DeleteConfirmed_RemovesFundAndSaves()
        {
            var fund = new SavingsFund {
                Id = 7
            };

            mockFunds.Setup(a => a.Find(It.IsAny <int>())).Returns(fund);

            var result = controller.DeleteConfirmed(fund.Id) as RedirectToRouteResult;

            mockFunds.Verify(f => f.Remove(fund), Times.Once);
            mockDbContext.Verify(c => c.SaveChanges(), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteValues["action"], "Breakdown");
            Assert.AreEqual(result.RouteValues["controller"], "SavingsAccount");
            Assert.AreEqual(result.RouteValues["id"], fund.AccountID);
        }
        public void Test_Validate_NormalWithdrawal_NoErrors()
        {
            var fund = new SavingsFund {
                Balance = 50
            };
            var transaction = new Transaction
            {
                SavingsFund = fund,
                Type        = Transaction.TransactionType.Withdraw,
                Amount      = 50
            };
            var validator = new TransactionValidator();

            validator.Validate(transaction);

            Assert.IsFalse(validator.HasErrors);
        }
        public void Test_Validate_WithdrawMoreThanBalance_ResultsInError()
        {
            var fund = new SavingsFund {
                Balance = 50
            };
            var transaction = new Transaction
            {
                SavingsFund = fund,
                Type        = Transaction.TransactionType.Withdraw,
                Amount      = 100
            };
            var validator = new TransactionValidator();

            validator.Validate(transaction);

            Assert.IsTrue(validator.HasErrors);
            Assert.Contains(TransactionValidator.INSUFFICIENT_FUNDS_ERROR_MESSAGE, validator.ErrorMessages);
        }
Exemplo n.º 10
0
 public void SetUp()
 {
     fund = new SavingsFund();
 }