public void Test_UserAvatarDelete()
        {
            var value = new UserAvatarDelete(
                new UserAvatar { Id = 1 }
            );

            Assert.AreEqual(1, value.Id, "Id");
        }
        public void Test_AvatarController_Delete_Post()
        {
            var value = new UserAvatarDelete
            {
                Id = 1
            };

            PrincipalHelper.Create();

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

            Assert.IsNotNull(redirectToRouteResult, "RedirectToRouteResult");
            Assert.AreEqual(UsersRoutes.AvatarIndex, redirectToRouteResult.RouteName, "RouteName");

            PrincipalHelper.Clear();

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

            Assert.IsNotNull(notAuthorizedResult, "NotAuthorizedResult");

            value.Id = 0;

            var notFoundResult = this.AvatarController.Delete(value) as HttpNotFoundResult;

            Assert.IsNotNull(notFoundResult, "HttpNotFoundResult");
        }
        public ActionResult Delete(UserAvatarDelete value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var avatar = this.UserAvatarService.GetById(value.Id);

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

            var privilege = new UserAvatarPrivilege();

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

            var user = this.UserService.GetById(Identity.Id);
            var matched = this.UserAvatarService.RemoveFromUserOnMatch(user, avatar);

            if (matched)
            {
                this.UserService.Update(user);
            }

            this.UserAvatarService.Delete(avatar);

            return base.RedirectToRoute(UsersRoutes.AvatarIndex);
        }