예제 #1
0
        public ActionResult Create(DebtorEditModel editModelDebtor)
        {
            if (ModelState.IsValid)
            {
                var domainDebtor = new Debtor(editModelDebtor.Id);
                Mapper.Map(editModelDebtor, domainDebtor);
                _debtorRepository.MakePersistent(domainDebtor);
                return RedirectToAction("Index");
            }

            return View("CreateOrEdit", editModelDebtor);
        }
예제 #2
0
 // GET: /Debtors/Create
 public ActionResult Create()
 {
     var editModelDebtor = new DebtorEditModel { Debts = new DebtEditModel[4]};
     ViewBag.Title = "Create a new debtor";
     return View("CreateOrEdit", editModelDebtor);
 }
예제 #3
0
        public void EditMethodPost_GivenInvalidEditModel_DoesNotCallMakePersistentOnTheDebtorRepository()
        {
            // Arrange
            var fakeDebtorRepository = A.Fake<IDebtorRepository>();
            var controller = new DebtorsController(fakeDebtorRepository);
            var editModelDebtor = new DebtorEditModel {CompanyName = "MoneyHelper"};
            controller.ModelState.AddModelError("some_key", @"some_error_message");

            // Act
            var viewResult = controller.Edit(editModelDebtor) as ViewResult;

            // Assert
            A.CallTo(() => fakeDebtorRepository.MakePersistent(A<Debtor>.Ignored)).MustNotHaveHappened();
            Assert.That(viewResult.ViewName, Is.EqualTo("CreateOrEdit"));
        }