Exemple #1
0
        public ActionResult ConfirmRequestBook(int id, FormCollection formCollection, IPrincipal admin)
        {
            if (!membershipService.IsAdmin(admin.Identity.Name))
            {
                return(View("NotAuthorized"));
            }

            InsertRequest insertRequest = insertRequestService.GetById(id);

            if (insertRequest == null)
            {
                return(View("NotFound"));
            }

            Book book = insertRequest.Media as Book;

            if (book == null)
            {
                return(View("NotFound"));
            }

            if (TryUpdateModel <Book>(book))
            {
                book.Pending = false;
                insertRequestService.Delete(insertRequest);
                insertRequestService.Save();
                return(RedirectToAction("MediaRequests"));
            }

            return(View("MediaRequests", CreateErrorRequest(insertRequest)));
        }
Exemple #2
0
        public void ConfirmRequestBookShouldReturnRedirectToResult()
        {
            AdminController adminController = new AdminController(membershipService, insertRequestService, mediaService);

            InsertRequest insertRequest = TestUtil.generateInsertRequest();

            insertRequest.Media = TestUtil.generateBook();

            Expect.Call(membershipService.IsAdmin(fakeAdmin.Identity.Name)).Return(true);
            Expect.Call(insertRequestService.GetById(7)).Return(insertRequest);
            Expect.Call(delegate { insertRequestService.Delete(insertRequest); });
            Expect.Call(delegate { insertRequestService.Save(); });
            mocks.SetFakeControllerContext(adminController);
            mocks.ReplayAll();

            FormCollection formCollection = new FormCollection();

            formCollection["Title"]         = "Title";
            formCollection["OriginalTitle"] = "OriginalTitle";
            formCollection["Genre"]         = "Action";
            formCollection["Isbn"]          = "1234567890";

            adminController.ValueProvider = formCollection.ToValueProvider();

            RedirectToRouteResult result = adminController.ConfirmRequestBook(7, formCollection, fakeAdmin) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(mediaRequests_ViewName, result.RouteValues["action"]);
        }