public void InitializeControls_WithReferrer_LoadsMoreResultsControl()
        {
            // arrange
            var page = new SubtextMasterPage();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog {Id = 123});
            context.Setup(c => c.HttpContext.Request.UrlReferrer).Returns(new Uri("http://bing.com/?q=test"));
            context.Setup(c => c.HttpContext.Request.IsLocal).Returns(false);
            context.Setup(c => c.HttpContext.Request.Url).Returns(new Uri("http://example.com/"));

            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/the-slug.aspx");

            var routeData = new RouteData();
            routeData.Values.Add("slug", "the-slug");

            context.SetupRequestContext(httpContext, routeData)
                .SetupBlog(new Blog { Id = 1, TimeZoneId = TimeZonesTest.PacificTimeZoneId /* pacific */})
                .Setup(c => c.Repository.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" });

            page.SubtextContext = context.Object;
            page.SetControls(new[] { "Test" });
            var searchEngine = new Mock<ISearchEngineService>();
            searchEngine.Setup(s => s.Search(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())).Returns(new[]{new SearchEngineResult()});
            page.SearchEngineService = searchEngine.Object;
            var loader = new Mock<ISkinControlLoader>();
            loader.Setup(l => l.LoadControl("MoreResults")).Returns(new UserControl());

            // act
            page.InitializeControls(loader.Object);

            // assert
            loader.Verify(l => l.LoadControl("Test"));
        }
Example #2
0
        public void GetEntryFromRequest_WithSlugInRouteDataMatchingEntryInRepository_ReturnsEntry()
        {
            //arrange
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/the-slug.aspx");
            var routeData = new RouteData();
            routeData.Values.Add("slug", "the-slug");
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.SetupRequestContext(httpContext, routeData)
                .SetupBlog(new Blog { Id = 1, TimeZoneId = TimeZonesTest.PacificTimeZoneId /* pacific */})
                .Setup(c => c.Repository.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" });

            //act
            Entry entry = Cacher.GetEntryFromRequest(true, subtextContext.Object);

            //assert
            Assert.AreEqual(123, entry.Id);
            Assert.AreEqual("Testing 123", entry.Title);
            Assert.AreEqual("the-slug", entry.EntryName);
        }
Example #3
0
        public void GetEntryFromRequest_WithIdInRouteDataMatchingEntryInRepository_ReturnsEntry()
        {
            //arrange
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/123.aspx");
            var routeData = new RouteData();
            routeData.Values.Add("id", "123");
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.SetupRequestContext(httpContext, routeData, new Blog { Id = 123 })
                .Setup(c => c.Repository.GetEntry(123, true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, Title = "Testing 123" });

            //act
            Entry entry = Cacher.GetEntryFromRequest(true, subtextContext.Object);

            //assert
            Assert.AreEqual(123, entry.Id);
            Assert.AreEqual("Testing 123", entry.Title);
        }
Example #4
0
        public void GetEntryFromRequest_WithNonExistentEntry_DoesNotThrowNullReferenceException()
        {
            //arrange
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/99999.aspx");
            var routeData = new RouteData();
            routeData.Values.Add("id", "999999");
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.SetupRequestContext(httpContext, routeData)
                .Setup(c => c.Repository.GetEntry(It.IsAny<int>(), true, true)).Returns((Entry)null);

            //act
            Cacher.GetEntryFromRequest(true, subtextContext.Object);

            //assert
            //None needed.
        }
Example #5
0
        public void GetEntryFromRequest_WithEntryHavingEntryNameButIdInRouteDataMatchingEntryInRepository_RedirectsToUrlWithSlug()
        {
            //arrange
            var repository = new Mock<ObjectRepository>();

            var entry = new Entry(PostType.BlogPost) { Id = 123, EntryName = "testing-slug", Title = "Testing 123" };
            repository.Setup(r => r.GetEntry(123, true, true)).Returns(entry);
            var urlHelper = new Mock<BlogUrlHelper>();
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/archive/testing-slug.aspx");
            UnitTestHelper.SetupBlog();
            var response = new Mock<HttpResponseBase>();
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/testing-slug.aspx");
            httpContext.Setup(c => c.Response).Returns(response.Object);

            var routeData = new RouteData();
            routeData.Values.Add("id", "123");
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.SetupRequestContext(httpContext, routeData)
                .SetupUrlHelper(urlHelper)
                .SetupRepository(repository.Object)
                .SetupBlog(new Blog { Host = "localhost" });
            subtextContext.Setup(c => c.HttpContext).Returns(httpContext.Object);

            //act
            Entry cachedEntry = Cacher.GetEntryFromRequest(true /* allowRedirect */, subtextContext.Object);

            //assert
            response.Verify(r => r.RedirectPermanent("http://localhost/archive/testing-slug.aspx", true));
            Assert.AreEqual(123, cachedEntry.Id);
            Assert.AreEqual("Testing 123", cachedEntry.Title);
        }