Ejemplo n.º 1
0
        public void SaveTest()
        {
            Member submittedMember = null;
            var    mockRepos       = new Mock <IMemberRepository>();

            mockRepos.Setup(r => r.Save(It.IsAny <Member>()))
            .Callback((Member m) => submittedMember = m);

            var controller = new HomeController(mockRepos.Object);

            const string firstNameTestValue = "Bill";
            const string lastNameTestValue  = "Smith";
            var          idString           = ObjectId.GenerateNewId().ToString();

            var memberAddEditVM = new MemberAddEditVM {
                FirstName = firstNameTestValue, LastName = lastNameTestValue
            };

            var redirectResult = controller.Save(memberAddEditVM, idString) as RedirectToRouteResult;

            Assert.IsNotNull(redirectResult);

            Assert.AreEqual(firstNameTestValue, submittedMember.FirstName);
            Assert.AreEqual(lastNameTestValue, submittedMember.LastName);
            Assert.AreEqual(ObjectId.Parse(idString), submittedMember.Id);
        }
Ejemplo n.º 2
0
        public ActionResult Save(MemberAddEditVM vm, string id)
        {
            //TODO: Do some validation here and return if something is wrong


            var objectId = ObjectId.Parse(id);

            vm.Id = objectId;

            var member = Mapper.Map <Member>(vm);

            _memberRepository.Save(member);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Add()
        {
            var vm = new MemberAddEditVM();

            return(View("AddEdit", vm));
        }