public void RichTextEditor_CreatePlainText_IfPreferenceSet() { using (var httpRequest = new HttpSimulator().SimulateRequest()) { //arrange var context = new Mock <ISubtextContext>(); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns("path"); context.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null)); context.Setup(c => c.Blog).Returns(new Blog { Host = "host" }); var page = new SubtextPage { SubtextContext = context.Object }; var editor = new RichTextEditor { Page = page }; //set use plain text in user preferences Preferences.UsePlainHtmlEditor = true; //act editor.InitControls(new EventArgs()); //post var provider = editor.Provider; Assert.IsTrue(provider is PlainTextBlogEntryEditorProvider, "PlainTextBlogEntryEditorProvider is created if it is selected in user preferences."); } }
public void RichTextEditor_CreateDefaultProvider() { using (var httpRequest = new HttpSimulator().SimulateRequest()) { //arrange var context = new Mock <ISubtextContext>(); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns("path"); context.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null)); context.Setup(c => c.Blog).Returns(new Blog { Host = "host" }); var page = new SubtextPage { SubtextContext = context.Object }; var editor = new RichTextEditor { Page = page }; //act editor.InitControls(new EventArgs()); //post var provider = editor.Provider; Assert.IsTrue(provider is FtbBlogEntryEditorProvider, "FtbBlogEntryEditorProvider is created by default."); } }
public void ShowErrorDetails_ForAdminNonLocalHost_ReturnsTrue() { // arrange var context = new Mock <ISubtextContext>(); context.Setup(c => c.HttpContext.Request.IsLocal).Returns(false); context.Setup(c => c.User.IsInRole("Admins")).Returns(true); var page = new SubtextPage { SubtextContext = context.Object }; var control = new Error { Page = page }; // act bool result = control.ShowErrorDetails; // assert Assert.IsTrue(result); }
public void SettingSubtextContextPopulatesOtherProperties() { //arrange var subtextContext = new Mock <ISubtextContext>(); subtextContext.Setup(c => c.Repository).Returns(new Mock <ObjectRepository>().Object); subtextContext.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(new Mock <HttpContextBase>().Object, new RouteData()), null)); subtextContext.Setup(c => c.Blog).Returns(new Blog()); var subtextPage = new SubtextPage(); //act subtextPage.SubtextContext = subtextContext.Object; //assert Assert.IsNotNull(subtextPage.Repository); Assert.AreSame(subtextPage.SubtextContext.Repository, subtextPage.Repository); Assert.IsNotNull(subtextPage.Url); Assert.AreSame(subtextPage.SubtextContext.UrlHelper, subtextPage.Url); Assert.AreSame(subtextPage.SubtextContext.UrlHelper, subtextPage.AdminUrl.Url); Assert.IsNotNull(subtextPage.Blog); Assert.AreSame(subtextPage.SubtextContext.Blog, subtextPage.Blog); }