Пример #1
0
        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);
            var result = accounController.EditProfile(editProfile);
            result.Should().BeOfType<ViewResult>().Which.ViewData.ModelState.Should().ContainKey("key").WhichValue.Errors.Should().Contain(e => e.ErrorMessage == "error");
              }
        }
Пример #2
0
        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);
            var result = accounController.EditProfile(editProfile);
            result.Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Error);
              }
        }
Пример #3
0
        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);
            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>();
              }
        }
Пример #4
0
        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);
            var result = accounController.EditProfile();
            result.Should().BeOfType<ViewResult>().Which.Model.ShouldBeEquivalentTo(new EditProfile());
              }
        }
Пример #5
0
        public void EditProfilePostShouldUpdateProfile(FakeSiteContext siteContext, 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.ValidateProfile(Arg.Any<EditProfile>(), Arg.Any<ModelStateDictionary>()).Returns(true);

              using (new SiteContextSwitcher(siteContext))
              using (new UserSwitcher(user))
              {
            var accounController = new AccountsController(null, null, null, userProfileService);
            var result = accounController.EditProfile(editProfile);
            userProfileService.Received(1).SetProfile(user.Profile, editProfile);
            result.Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Info);
              }
        }