当前位置: 首页>>代码示例>>C#>>正文


C# MockHttpRequest类代码示例

本文整理汇总了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);
                });
        }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:32,代码来源:Benchmarks.cs

示例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"));
            }
        }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:33,代码来源:EndpointHandlerBaseTests.cs

示例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;
 }
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:12,代码来源:EndpointHandlerBaseTests.cs

示例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);
        }
开发者ID:yonglehou,项目名称:servicestack-ratelimit-redis,代码行数:8,代码来源:RequestExtensionsTests.cs

示例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();
        }
开发者ID:yonglehou,项目名称:servicestack-ratelimit-redis,代码行数:10,代码来源:RateLimitFeatureTests.cs

示例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)
 {
 }
开发者ID:dibiancoj,项目名称:ToracLibrary,代码行数:13,代码来源:MockControllerContext.cs

示例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));
        }
开发者ID:Cayan-LLC,项目名称:stumps,代码行数:10,代码来源:HttpMethodRuleTests.cs

示例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 };
        }
开发者ID:MacLeanElectrical,项目名称:servicestack-discovery-consul,代码行数:10,代码来源:HealthCheckServiceTests.cs

示例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;
 }
开发者ID:dibiancoj,项目名称:ToracLibrary,代码行数:17,代码来源:MockHttpContext.cs

示例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());
        }
开发者ID:yonglehou,项目名称:servicestack-ratelimit-redis,代码行数:10,代码来源:LimitKeyGeneratorTests.cs

示例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;
 }
开发者ID:remkoboschker,项目名称:ServiceStack,代码行数:10,代码来源:RazorRockstars_FilesTests.cs

示例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));
        }
开发者ID:Cayan-LLC,项目名称:stumps,代码行数:10,代码来源:UrlRuleTests.cs

示例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);
        }
开发者ID:yonglehou,项目名称:servicestack-ratelimit-redis,代码行数:10,代码来源:LimitKeyGeneratorTests.cs

示例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;
        }
开发者ID:yonglehou,项目名称:servicestack-ratelimit-redis,代码行数:15,代码来源:RequestExtensionsTests.cs

示例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));
        }
开发者ID:HarmenGrosseDeters,项目名称:ServiceStack,代码行数:16,代码来源:ViewTests.cs


注:本文中的MockHttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。