Пример #1
0
        public ActionResult Delete(AttachmentDelete value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var attachment = this.AttachmentService.GetById(value.Id);

            if (attachment == null)
            {
                return base.HttpNotFound();
            }

            var privilege = new AttachmentPrivilege();

            if (!privilege.CanDelete(attachment))
            {
                return NotAuthorized();
            }

            this.AttachmentService.Delete(attachment, value.Soft);

            return base.RedirectToRoute(AdministrationRoutes.AttachmentIndex);
        }
Пример #2
0
        public void Test_AttachmentDelete()
        {
            var value = new AttachmentDelete(
                new Attachment {Id = 1, FileName = "test"}
            );

            Assert.AreEqual(1, value.Id, "Id");
            Assert.AreEqual("test", value.Title, "Title");
            Assert.IsTrue(value.Soft, "Soft");
        }
Пример #3
0
        public void Test_AttachmentController_Delete_Post()
        {
            PrincipalHelper.Create();

            var value = new AttachmentDelete { Id = 0 };
            var notFoundResult = this.AttachmentController.Delete(value) as HttpNotFoundResult;

            Assert.IsNotNull(notFoundResult, "HttpNotFoundResult");

            value.Id = 1;

            var redirectToRouteResult = this.AttachmentController.Delete(value) as RedirectToRouteResult;

            Assert.IsNotNull(redirectToRouteResult, "RedirectToRouteResult");
            Assert.AreEqual(AdministrationRoutes.AttachmentIndex, redirectToRouteResult.RouteName, "RouteName");

            PrincipalHelper.Clear();

            var notAuthorizedResult = this.AttachmentController.Delete(value) as NotAuthorizedResult;

            Assert.IsNotNull(notAuthorizedResult, "NotAuthorizedResult");
        }