本文整理汇总了C#中Subtext.Framework.Web.HttpModules.BlogRequest类的典型用法代码示例。如果您正苦于以下问题:C# BlogRequest类的具体用法?C# BlogRequest怎么用?C# BlogRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlogRequest类属于Subtext.Framework.Web.HttpModules命名空间,在下文中一共展示了BlogRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameValueCollection
public void RequestNotMatchingAnyBlog_ButWithASingleBlogInSystemWithLocalHostButNotMatchingSubfolder_ReturnsUpdatesItsHostThenRedirectsToSubfolder()
{
//arrange
var onlyBlog = new Blog { Host = "localhost", Subfolder = "sub" };
var pagedCollection = new PagedCollection<Blog> { onlyBlog };
pagedCollection.MaxItems = 1;
var repository = new Mock<ObjectRepository>();
repository.Setup(r => r.GetBlog("example.com", It.IsAny<string>())).Returns((Blog)null);
repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns(
pagedCollection);
var appSettings = new NameValueCollection();
appSettings.Add("AggregateEnabled", "false");
var hostInfo = new HostInfo(appSettings);
var service = new BlogLookupService(repository.Object, new LazyNotNull<HostInfo>(() => hostInfo));
var blogRequest = new BlogRequest("example.com", string.Empty, new Uri("http://example.com/foo/bar"), false);
//act
BlogLookupResult result = service.Lookup(blogRequest);
//assert
Assert.IsNull(result.Blog);
Assert.IsNotNull(result.AlternateUrl);
Assert.AreEqual("http://example.com/sub/foo/bar", result.AlternateUrl.ToString());
Assert.AreEqual("example.com", onlyBlog.Host);
repository.Verify(r => r.UpdateBlog(It.IsAny<Blog>()));
}
示例2: AuthenticateRequest_WithRequestHavingValidAuthCookies_SetsUserToGenericPrincipalWithRoles
public void AuthenticateRequest_WithRequestHavingValidAuthCookies_SetsUserToGenericPrincipalWithRoles()
{
// arrange
var module = new AuthenticationModule();
const string roles = "Admins|HostAdmins|Users";
var ticket = new FormsAuthenticationTicket(1, ".ASPXAUTH.42", DateTime.Now, DateTime.Now.AddDays(60), true,
roles);
string cookieValue = FormsAuthentication.Encrypt(ticket);
var authCookie = new HttpCookie(".ASPXAUTH.42") { Value = cookieValue };
var cookies = new HttpCookieCollection { authCookie };
var httpContext = new Mock<HttpContextBase>();
httpContext.Stub(c => c.User);
httpContext.Setup(c => c.Request.Path).Returns("/");
httpContext.Setup(c => c.Request.QueryString).Returns(new NameValueCollection());
httpContext.Setup(c => c.Request.Cookies).Returns(cookies);
httpContext.Setup(c => c.Response.Cookies).Returns(cookies);
var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost"), false,
RequestLocation.Blog, "/") { Blog = new Blog { Id = 42 } };
// act
module.AuthenticateRequest(httpContext.Object, blogRequest);
// assert
var principal = httpContext.Object.User as GenericPrincipal;
Assert.IsNotNull(principal);
Assert.IsTrue(principal.IsInRole("Admins"));
Assert.IsTrue(principal.IsInRole("HostAdmins"));
Assert.IsTrue(principal.IsInRole("Users"));
}
示例3: Ctor_WithRequestForInstallation_SetsBlogNotRequiredTrue
public void Ctor_WithRequestForInstallation_SetsBlogNotRequiredTrue()
{
//arrange, act
var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false,
RequestLocation.Installation, "/");
//assert
Assert.IsTrue(blogRequest.BlogNotRequired);
}
示例4: Ctor_WithRequestForInstallDirectoryRoot_SetsRequestLocationToInstallDirectory
public void Ctor_WithRequestForInstallDirectoryRoot_SetsRequestLocationToInstallDirectory()
{
//arrange
Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/Install", true);
//act
var blogRequest = new BlogRequest(request.Object);
//assert
Assert.AreEqual(RequestLocation.Installation, blogRequest.RequestLocation);
}
示例5: Ctor_WithRequestForHostAdmin_SetsRequestLocationToHostAdmin
public void Ctor_WithRequestForHostAdmin_SetsRequestLocationToHostAdmin()
{
//arrange
Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/HostAdmin/anything.aspx", true);
//act
var blogRequest = new BlogRequest(request.Object);
//assert
Assert.AreEqual(RequestLocation.HostAdmin, blogRequest.RequestLocation);
}
示例6: Ctor_WithHostHavingPort_StripsPort
public void Ctor_WithHostHavingPort_StripsPort()
{
//arrange
Mock<HttpRequestBase> request = CreateRequest("example.com:1234", "/", "/foo/bar", true);
//act
var blogRequest = new BlogRequest(request.Object);
//assert
Assert.AreEqual("example.com", blogRequest.Host);
}
示例7: AuthenticateRequest
public void AuthenticateRequest(HttpContextBase httpContext, BlogRequest blogRequest)
{
if(blogRequest.RequestLocation == RequestLocation.StaticFile)
{
return;
}
HttpCookie authCookie = httpContext.Request.SelectAuthenticationCookie(blogRequest.Blog);
FormsAuthenticationTicket authTicket = GetFormsAuthenticationTicket(authCookie);
HandleFormsAuthenticationTicket(blogRequest, httpContext, authTicket);
}
示例8: AuthenticateRequest_WithRequestForStaticFile_ReturnsImmediately
public void AuthenticateRequest_WithRequestForStaticFile_ReturnsImmediately()
{
// arrange
var module = new AuthenticationModule();
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(c => c.Request.Cookies).Throws(new InvalidOperationException());
var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost"), false,
RequestLocation.StaticFile, "/");
// act, assert
module.AuthenticateRequest(httpContext.Object, blogRequest);
}
示例9: GetInstallationRedirectUrl_ForStaticFiles_ReturnsNull
public void GetInstallationRedirectUrl_ForStaticFiles_ReturnsNull()
{
// arrange
var module = new InstallationCheckModule(new Mock<IInstallationManager>().Object, new LazyNotNull<HostInfo>(() => null));
var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/whatever/foo.jpg"),
true, RequestLocation.Blog, "/");
// act
string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);
// assert
Assert.IsNull(redirectUrl);
}
示例10: GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute
public void GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute()
{
//arrange
var route = new DirectoryRoute("dir", new Mock<IServiceLocator>().Object);
;
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/subfolder/dir/foo.aspx");
var blogRequest = new BlogRequest("localhost", "subfolder", new Uri("http://localhost"), false);
//act
RouteData routeData = route.GetRouteData(httpContext.Object, blogRequest);
//assert
Assert.AreEqual(route, routeData.Route);
}
示例11: GetInstallationRedirectUrl_WhenHostInfoNotNullAndInstallRequiredButInInstallDirectory_ReturnsNull
public void GetInstallationRedirectUrl_WhenHostInfoNotNullAndInstallRequiredButInInstallDirectory_ReturnsNull()
{
// arrange
var installManager = new Mock<IInstallationManager>();
installManager.Setup(m => m.InstallationActionRequired(It.IsAny<Version>(), null)).Returns(true);
var module = new InstallationCheckModule(installManager.Object, new LazyNotNull<HostInfo>(CreateHostInfo));
var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/Install/foo.aspx"),
true, RequestLocation.Installation, "/");
// act
string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);
// assert
Assert.IsNull(redirectUrl);
}
示例12: GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute
public void GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute()
{
//arrange
var route = new PageRoute("url", "~/aspx/Dtp.aspx", new[] { "foo" }, new Mock<ISubtextPageBuilder>().Object,
new Mock<IDependencyResolver>().Object);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/subfolder/url");
var blogRequest = new BlogRequest("localhost", "subfolder", new Uri("http://localhost"), false);
//act
RouteData routeData = route.GetRouteData(httpContext.Object, blogRequest);
//assert
Assert.AreEqual(route, routeData.Route);
}
示例13: InstallationCheckModule
public void GetInstallationRedirectUrl_WhenHostInfoNotNullInstallationActionRequiredAndInLoginPage_ReturnsInstallDirectory()
{
// arrange
var installManager = new Mock<IInstallationManager>();
installManager.Setup(m => m.GetInstallationStatus(It.IsAny<Version>())).Returns(
InstallationState.NeedsInstallation);
installManager.Setup(m => m.InstallationActionRequired(It.IsAny<Version>(), null)).Returns(true);
var module = new InstallationCheckModule(installManager.Object, new LazyNotNull<HostInfo>(UnitTestHelper.CreateHostInfo));
var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/Install/foo.aspx"),
true, RequestLocation.LoginPage, "/");
// act
string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);
// assert
Assert.AreEqual("~/install/default.aspx", redirectUrl);
}
示例14: GetRouteData
public virtual RouteData GetRouteData(HttpContextBase httpContext, BlogRequest blogRequest)
{
RouteData routeData;
if (String.IsNullOrEmpty(blogRequest.Subfolder))
{
routeData = base.GetRouteData(httpContext);
if (routeData != null)
{
//Add current subfolder info.
routeData.Values.Add("subfolder", string.Empty);
}
}
else
{
routeData = RouteForSubfolder.GetRouteData(httpContext, blogRequest.Subfolder);
}
return routeData;
}
示例15: ConvertRequestToBlogRequest
public BlogRequest ConvertRequestToBlogRequest(HttpContextBase httpContext)
{
string redirectUrl = httpContext.Request.GetFileNotFoundRedirectUrl(HttpRuntime.UsingIntegratedPipeline);
if (!String.IsNullOrEmpty(redirectUrl))
{
httpContext.Response.Redirect(redirectUrl, true);
return null;
}
// REVIEW: Maybe the BlogLookup.Lookup should take in an HttpContextBase
// and return the BlogRequest as part of the result.
var blogRequest = new BlogRequest(httpContext.Request);
if (blogRequest.BlogNotRequired)
{
return blogRequest;
}
BlogLookupResult result = BlogLookup.Lookup(blogRequest);
if (result == null)
{
if (blogRequest.RequestLocation != RequestLocation.LoginPage)
{
httpContext.Response.Redirect("~/install/BlogNotConfiguredError.aspx", true);
}
return blogRequest;
}
if (result.Blog == null && result.AlternateUrl != null)
{
httpContext.Response.RedirectPermanent(result.AlternateUrl.ToString(), true);
return null;
}
if (result.Blog != null && !result.Blog.IsActive && blogRequest.RequestLocation == RequestLocation.Blog)
{
httpContext.Response.Redirect("~/SystemMessages/BlogNotActive.aspx", true);
return null;
}
blogRequest.Blog = result.Blog;
return blogRequest;
}