private EditProfile ( ) : System.Web.Mvc.ActionResult | ||
return | System.Web.Mvc.ActionResult |
public void EditProfilePostShouldUpdateProfile(FakeSiteContext siteContext, string profileItemId, [Substitute] EditProfile editProfile, [Frozen]IUserProfileService userProfileService) { var user = Substitute.For<User>("extranet/John", true); user.Profile.Returns(Substitute.For<UserProfile>()); user.Profile.ProfileItemId = profileItemId; userProfileService.GetUserDefaultProfileId().Returns(profileItemId); userProfileService.ValidateProfile(Arg.Any<EditProfile>(), Arg.Any<ModelStateDictionary>()).Returns(true); using (new SiteContextSwitcher(siteContext)) using (new UserSwitcher(user)) { var accountsController = new AccountsController(null, null, null, userProfileService, null); accountsController.ControllerContext = Substitute.For<ControllerContext>(); accountsController.ControllerContext.HttpContext.Returns(Substitute.For<HttpContextBase>()); accountsController.ControllerContext.HttpContext.Session.Returns(Substitute.For<HttpSessionStateBase>()); accountsController.ControllerContext.HttpContext.Request.Returns(Substitute.For<HttpRequestBase>()); accountsController.ControllerContext.HttpContext.Request.RawUrl.Returns("/"); var result = accountsController.EditProfile(editProfile); userProfileService.Received(1).SetProfile(user.Profile, editProfile); accountsController.Session["EditProfileMessage"].Should().BeOfType<InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Info); result.Should().BeOfType<RedirectResult>(); } }
public void EditProfilePostShouldReturnModelErrors(FakeSiteContext siteContext, ModelStateDictionary modelState, string profileItemId, IEnumerable<string> interests, [Substitute] EditProfile editProfile, IUserProfileService userProfileService) { var user = Substitute.For<User>("extranet/John", true); user.Profile.Returns(Substitute.For<UserProfile>()); user.Profile.ProfileItemId = profileItemId; userProfileService.GetUserDefaultProfileId().Returns(profileItemId); userProfileService.GetInterests().Returns(interests); userProfileService.ValidateProfile(Arg.Any<EditProfile>(), Arg.Do<ModelStateDictionary>(x => x.AddModelError("key", "error"))).Returns(false); using (new SiteContextSwitcher(siteContext)) using (new UserSwitcher(user)) { var accounController = new AccountsController(null, null, null, userProfileService, null); var result = accounController.EditProfile(editProfile); result.Should().BeOfType<ViewResult>().Which.ViewData.ModelState.Should().ContainKey("key").WhichValue.Errors.Should().Contain(e => e.ErrorMessage == "error"); } }
public void EditProfileShouldReturnEmptyViewForEditMode(Database db, IUserProfileService userProfileService) { userProfileService.GetEmptyProfile().Returns(new EditProfile()); var fakeSite = new FakeSiteContext(new StringDictionary { {"rootPath", "/sitecore/content"} }) as SiteContext; fakeSite.Database = db; typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(fakeSite, DisplayMode.Edit); Language.Current = Language.Invariant; using (new SiteContextSwitcher(fakeSite)) { var accounController = new AccountsController(null, null, null, userProfileService, null); var result = accounController.EditProfile(); result.Should().BeOfType<ViewResult>().Which.Model.ShouldBeEquivalentTo(new EditProfile()); } }
public void EditProfilePostShouldReturnInfoMessageIfProfileDoesntMatch(string siteProfileId, string profileItemId, [Substitute] EditProfile editProfile, IUserProfileService userProfileService) { var user = Substitute.For<User>("extranet/John", true); user.Profile.Returns(Substitute.For<UserProfile>()); user.Profile.ProfileItemId = profileItemId; userProfileService.GetUserDefaultProfileId().Returns(siteProfileId); var fakeSite = new FakeSiteContext(new StringDictionary { {"displayMode", "normal"} }) as SiteContext; using (new SiteContextSwitcher(fakeSite)) using (new UserSwitcher(user)) { var accounController = new AccountsController(null, null, null, userProfileService, null); var result = accounController.EditProfile(editProfile); result.Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Error); } }
public void EditProfile_DefaultState_ShouldReturnProfileModel(string profileItemId, [Substitute] EditProfile editProfile, IUserProfileService userProfileService) { var user = Substitute.For<User>("extranet/John", true); user.Profile.Returns(Substitute.For<UserProfile>()); user.Profile.ProfileItemId = profileItemId; userProfileService.GetUserDefaultProfileId().Returns(profileItemId); userProfileService.GetProfile(Arg.Any<UserProfile>()).Returns(editProfile); userProfileService.ValidateUser(Arg.Any<User>()).ReturnsForAnyArgs(true); var fakeSite = new FakeSiteContext(new StringDictionary { {"displayMode", "normal"}, {"domain", "extranet"} }) as SiteContext; using (new SiteContextSwitcher(fakeSite)) using (new UserSwitcher(user)) { var accounController = new AccountsController(null, null, null, userProfileService, null); var result = accounController.EditProfile(); result.Should().BeOfType<ViewResult>().Which.Model.Should().Be(editProfile); } }