public void AddPostValidModel_ReturnsRedirect()
        {
            var volunteerFake = new Volunteer
                                    {
                                        Id = Guid.NewGuid(),
                                    };

            var recipientFake = new Recipient
                                    {
                                        Active = true,
                                        FirstName = "Dan",
                                        Id = Guid.NewGuid(),
                                    };

            var dataServiceMock = new Mock<IDataService<Recipient>>();
            dataServiceMock.Setup(d => d.Insert(It.IsAny<Recipient>(), It.IsAny<Guid>())).Verifiable();

            var formsAuthenticationServiceMock = new Mock<IFormsAuthenticationService>();
            formsAuthenticationServiceMock.Setup(f => f.GetVolunteerID(null))
                .Returns(volunteerFake.Id);

            var controller = new RecipientController(dataServiceMock.Object,
                                                     new Mock<IDataService<Volunteer>>().Object,
                                                     formsAuthenticationServiceMock.Object);

            ActionResult result = controller.Add(recipientFake);

            dataServiceMock.VerifyAll();

            Assert.IsInstanceOf(typeof (RedirectToRouteResult), result);
        }
예제 #2
0
        public ActionResult Add()
        {
            var model = new Recipient
                            {
                                ContactDate = DateTime.Now,
                                RecipientStatus = "2",
                                State = "CO",
                            };

            return View(model);
        }
예제 #3
0
        public ActionResult Add(Recipient model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var volunteer = volunteerDataService.SelectOne(v => v.Id == formsAuthenticationService.GetVolunteerID(User));

            model.Active = true;
            model.CreateDate = DateTime.Now;
            model.CreatedByVolunteer = volunteer;
            model.Id = Guid.NewGuid();
            model.LastModifiedByVolunteer = volunteer;
            model.LastModifiedDate = DateTime.Now;

            recipientDataService.Insert(model, model.Id);

            return RedirectToAction("Index");
        }
예제 #4
0
        public ActionResult Edit(Recipient model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var originalRecipeint = recipientDataService.SelectOne(r => r.Id == model.Id);

            var volunteer = volunteerDataService.SelectOne(v => v.Id == formsAuthenticationService.GetVolunteerID(User));

            model.Active = originalRecipeint.Active;
            model.CreateDate = originalRecipeint.CreateDate;
            model.CreatedByVolunteer = originalRecipeint.CreatedByVolunteer;
            model.LastModifiedByVolunteer = volunteer;
            model.LastModifiedDate = DateTime.Now;

            recipientDataService.Update(model);

            return RedirectToAction("Index");
        }