public void Test_UserAvatarCreate_Validate() { var value = new UserAvatarCreate(); value.Validate(); Assert.AreEqual(1, value.Errors.Count, "Errors"); }
public void Test_AvatarController_Create_Post() { var file = MockRepository.GenerateMock<HttpPostedFileBase>(); file.Stub(x => x.FileName).Return("test.jpg"); file.Stub(x => x.ContentType).Return("image/jpeg"); file.Stub(x => x.ContentLength).Return(12345678); this.AvatarController.Request.Stub(x => x.Files[0]).Return(file); var value = new UserAvatarCreate(); PrincipalHelper.Create(); var redirectToRouteResult = this.AvatarController.Create(value) as RedirectToRouteResult; Assert.IsNotNull(redirectToRouteResult, "RedirectToRouteResult"); Assert.AreEqual(UsersRoutes.AvatarIndex, redirectToRouteResult.RouteName, "RouteName"); PrincipalHelper.Clear(); var notAuthorizedResult = this.AvatarController.Create(value) as NotAuthorizedResult; Assert.IsNotNull(notAuthorizedResult, "NotAuthorizedResult"); }
public ActionResult Create(UserAvatarCreate value) { if (value == null) { throw new ArgumentNullException("value"); } var avatar = this.UserAvatarService.Create(); var privilege = new UserAvatarPrivilege(); if (!privilege.CanCreate(avatar)) { return NotAuthorized(); } value.File = Request.Files[0]; value.Validate(); if (value.IsValid) { this.UserAvatarService.Insert(avatar, value.File); return base.RedirectToRoute(UsersRoutes.AvatarIndex); } value.CopyToModel(ModelState); return base.View(Views.Create, value); }