Exemplo n.º 1
0
        public void ShowErrorDetails_ForNonLocalHost_ReturnsFalse()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.HttpContext.Request.IsLocal).Returns(false);
            context.Setup(c => c.User.IsInRole("Admins")).Returns(false);
            var page = new SubtextPage { SubtextContext = context.Object };
            var control = new Error { Page = page };

            // act
            bool result = control.ShowErrorDetails;

            // assert
            Assert.IsFalse(result);
        }
Exemplo n.º 2
0
        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.");
            }
        }
Exemplo n.º 3
0
        public void SettingSubtextContextPopulatesOtherProperties()
        {
            //arrange
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Repository).Returns(new Mock<ObjectProvider>().Object);
            subtextContext.Setup(c => c.UrlHelper).Returns(
                new UrlHelper(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);
        }
Exemplo n.º 4
0
        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.");
            }
        }