本文整理汇总了C#中MockHttpRequest类的典型用法代码示例。如果您正苦于以下问题:C# MockHttpRequest类的具体用法?C# MockHttpRequest怎么用?C# MockHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockHttpRequest类属于命名空间,在下文中一共展示了MockHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Benchmark_Razor_vs_Markdown
public void Benchmark_Razor_vs_Markdown()
{
var iterations = 10000;
var razorFormat = RazorFormat.Instance;
var markdownFmt = MarkdownFormat.Instance;
var dto = new RockstarsResponse { Results = Rockstar.SeedData.ToList() };
"Warm up MVC Razor...".Print();
var mockReq = new MockHttpRequest { OperationName = "RockstarsRazor" };
var mockRes = new MockHttpResponse(mockReq);
razorFormat.ProcessRequest(mockReq, mockRes, dto);
mockRes.ReadAsString().Print();
"Warm up Markdown Razor...".Print();
mockReq = new MockHttpRequest { OperationName = "RockstarsMark" };
mockRes = new MockHttpResponse(mockReq);
markdownFmt.ProcessRequest(mockReq, mockRes, dto);
mockRes.ReadAsString().Print();
"\n\nRunning for {0} times...".Fmt(iterations).Print();
CompareRuns(iterations,
"MVC Razor", () => {
mockReq = new MockHttpRequest { OperationName = "RockstarsRazor" };
mockRes = new MockHttpResponse(mockReq);
razorFormat.ProcessRequest(mockReq, mockRes, dto);
},
"Markdown Razor", () => {
mockReq = new MockHttpRequest { OperationName = "RockstarsMark" };
mockRes = new MockHttpResponse(mockReq);
markdownFmt.ProcessRequest(mockReq, mockRes, dto);
});
}
示例2: Can_mock_uploading_files
public void Can_mock_uploading_files()
{
using (new BasicAppHost
{
ConfigureAppHost = host => host.VirtualFiles = new InMemoryVirtualPathProvider(host),
}.Init())
{
var ms = new MemoryStream("mocked".ToUtf8Bytes());
var httpFile = new HttpFile
{
ContentType = "application/x-msaccess",
FileName = "C:\\path\\to\\file.txt",
InputStream = ms,
ContentLength = ms.ToArray().Length,
};
var mockReq = new MockHttpRequest
{
Files = new IHttpFile[] { httpFile },
};
//Mock Session
mockReq.Items[Keywords.Session] = new AuthUserSession { Id = "sess-id" };
var service = new UploadFileService
{
Request = mockReq
};
service.Any(new MockUploadFile());
var files = HostContext.VirtualFiles.GetAllFiles().ToList();
Assert.That(files[0].ReadAllText(), Is.EqualTo("mocked"));
}
}
示例3: CreateRequest
/// <summary>Creates a request.</summary>
///
/// <param name="userHostAddress">The user host address.</param>
///
/// <returns>The new request.</returns>
public IHttpRequest CreateRequest(string userHostAddress)
{
var httpReq = new MockHttpRequest("test", HttpMethods.Get, ContentType.Json, "/", null, null, null) {
UserHostAddress = userHostAddress
};
return httpReq;
}
示例4: GetRequestCorrelationId_ReturnsRequestFromHeader
public void GetRequestCorrelationId_ReturnsRequestFromHeader(string header)
{
var request = new MockHttpRequest();
request.Headers.Add("x-mac-requestid", header);
var value = request.GetRequestCorrelationId();
value.Should().Be(header);
}
示例5: ProcessRequest_CallsGetLimits
public void ProcessRequest_CallsGetLimits()
{
var mockHttpRequest = new MockHttpRequest();
A.CallTo(() => limitProvider.GetLimits(mockHttpRequest)).Returns(null);
var feature = GetSut();
feature.ProcessRequest(mockHttpRequest, new MockHttpResponse(), null);
A.CallTo(() => limitProvider.GetLimits(mockHttpRequest)).MustHaveHappened();
}
示例6: MockControllerContext
/// <summary>
/// Mock a controller context
/// </summary>
public MockControllerContext(
IController ControllerToSet,
MockPrincipal PrincipalToSet,
MockIdentity IdentityToSet,
MockHttpRequest RequestToSet,
MockHttpResponse ResponseToSet,
MockHttpSessionState SessionStateToSet)
: base(new MockHttpContext(PrincipalToSet, RequestToSet, ResponseToSet, SessionStateToSet), new RouteData(), (ControllerBase)ControllerToSet)
{
}
示例7: IsMatch_ExactTextRuleInversedWithNonMatchingString_ReturnsTrue
public void IsMatch_ExactTextRuleInversedWithNonMatchingString_ReturnsTrue()
{
var request = new MockHttpRequest
{
HttpMethod = "GET"
};
var rule = new HttpMethodRule("not:POST");
Assert.IsTrue(rule.IsMatch(request));
}
示例8: HealthCheckServiceTests
public HealthCheckServiceTests(AppHostFixture fixture)
{
this.fixture = fixture;
this.fixture.Host.Container.RegisterAutoWired<HealthCheckService>();
consulFeature = fixture.Host.GetPlugin<ConsulFeature>();
var mockHttpRequest = new MockHttpRequest("Heartbeat", "GET", "json", "heartbeat", null, null, null);
service = new HealthCheckService { Request = mockHttpRequest };
}
示例9: MockHttpContext
/// <summary>
/// Constructor
/// </summary>
/// <param name="PrincipalToSet">Principal</param>
/// <param name="RequestToSet">Request to mock</param>
/// <param name="ResponseToSet">Response to mock</param>
/// <param name="SessionStateToSet">Mocked session state</param>
public MockHttpContext(MockPrincipal PrincipalToSet,
MockHttpRequest RequestToSet,
MockHttpResponse ResponseToSet,
MockHttpSessionState SessionStateToSet)
{
Principal = PrincipalToSet;
MockedSessionState = SessionStateToSet;
MockedHttpResponse = ResponseToSet;
MockedHttpRequest = RequestToSet;
}
示例10: GetConsumerId_ReturnsUserId_IfAuthenticated
public void GetConsumerId_ReturnsUserId_IfAuthenticated(string userAuthId)
{
MockHttpRequest request = new MockHttpRequest();
var authSession = SetupAuthenticatedSession(userAuthId, request);
var keyGenerator = GetGenerator();
var consumerId = keyGenerator.GetConsumerId(request);
consumerId.Should().Be(authSession.UserAuthId.ToLower());
}
示例11: GetRazorInstanceHtml
private static string GetRazorInstanceHtml()
{
var razorFormat = RazorFormat.Instance;
var mockReq = new MockHttpRequest { OperationName = "RazorInstance" };
var mockRes = new MockHttpResponse();
var dto = new RockstarsResponse { Results = Rockstar.SeedData.ToList() };
razorFormat.ProcessRequest(mockReq, mockRes, dto);
var html = mockRes.ReadAsString();
return html;
}
示例12: IsMatch_ExactTextRuleInversedWithNonMatchingString_ReturnsTrue
public void IsMatch_ExactTextRuleInversedWithNonMatchingString_ReturnsTrue()
{
var request = new MockHttpRequest
{
RawUrl = "/passed/"
};
var rule = new UrlRule("not:/failed/");
Assert.IsTrue(rule.IsMatch(request));
}
示例13: GetConfigKeysForRequest_ReturnsCorrectNumberOfKeys
public void GetConfigKeysForRequest_ReturnsCorrectNumberOfKeys()
{
MockHttpRequest request = new MockHttpRequest();
SetupAuthenticatedSession("123", request);
var keyGenerator = GetGenerator();
var keys = keyGenerator.GetConfigKeysForRequest(request);
keys.Count().Should().Be(3);
}
示例14: GetRequestCorrelationId_UsesHeaderNameFromFeature
public void GetRequestCorrelationId_UsesHeaderNameFromFeature(string header)
{
string defaultHeaderName = RateLimitFeature.CorrelationIdHeader;
const string headerName = "sunkilmoon";
RateLimitFeature.CorrelationIdHeader = headerName;
var request = new MockHttpRequest();
request.Headers.Add(headerName, header);
var value = request.GetRequestCorrelationId();
value.Should().Be(header);
RateLimitFeature.CorrelationIdHeader = defaultHeaderName;
}
示例15: Does_process_Markdown_pages
public void Does_process_Markdown_pages()
{
var markdownHandler = new MarkdownHandler("/AppData/NoTemplate/Static")
{
MarkdownFormat = markdownFormat,
};
var httpReq = new MockHttpRequest { QueryString = PclExportClient.Instance.NewNameValueCollection() };
var httpRes = new MockHttpResponse();
markdownHandler.ProcessRequestAsync(httpReq, httpRes, "Static").Wait();
var expectedHtml = markdownFormat.Transform(
File.ReadAllText("~/AppData/NoTemplate/Static.md".MapProjectPath()));
httpRes.Close();
Assert.That(httpRes.Contents, Is.EqualTo(expectedHtml));
}