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"));
        }
        public void InitializeControls_WithControlNames_AddsControlsToBody()
        {
            // arrange
            var page = new SubtextMasterPage();
            var context = new Mock<ISubtextContext>();
            page.SubtextContext = context.Object;
            context.Setup(c => c.HttpContext.Request.UrlReferrer).Returns((Uri)null);
            context.Setup(c => c.HttpContext.Request.IsLocal).Returns(false);
            page.SetControls(new[]{"Test"});
            var loader = new Mock<ISkinControlLoader>();
            loader.Setup(l => l.LoadControl("Test")).Returns(new UserControl());

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

            // assert
            loader.Verify(l => l.LoadControl("Test"));
        }
        public void InitializeControls_WithReferrerButOnlyHomepageControl_DoesNotLoadsMoreResultsControl()
        {
            // arrange
            var page = new SubtextMasterPage();
            var context = new Mock<ISubtextContext>();
            page.SubtextContext = context.Object;
            context.Setup(c => c.HttpContext.Request.UrlReferrer).Returns(new Uri("http://bing.com/?q=test"));
            context.Setup(c => c.HttpContext.Request.IsLocal).Returns(false);
            page.SetControls(new[] { "HomePage" });
            var loader = new Mock<ISkinControlLoader>();
            loader.Setup(l => l.LoadControl("MoreResults")).Throws(new InvalidOperationException());

            // act, assert
            page.InitializeControls(loader.Object);
        }