• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MockHttpRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MockHttpRequest的典型用法代码示例。如果您正苦于以下问题:C# MockHttpRequest类的具体用法?C# MockHttpRequest怎么用?C# MockHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockHttpRequest类属于命名空间,在下文中一共展示了MockHttpRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Can_deserialize_TestRequest_QueryStringSerializer_output

        public void Can_deserialize_TestRequest_QueryStringSerializer_output()
        {
            // Setup
            new BasicAppHost(new Container(), typeof(TestService).Assembly).Init();
            var restPath = new RestPath(typeof(TestRequest), "/service", "GET");
            var restHandler = new RestHandler { RestPath = restPath };

            var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}";
            NameValueCollection queryString = HttpUtility.ParseQueryString(requestString);
            var httpReq = new MockHttpRequest("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection());

            var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service");

            Assert.That(request2.ListOfA.Count, Is.EqualTo(1));
            Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2));
        }
开发者ID:ELHANAFI,项目名称:ServiceStack,代码行数:16,代码来源:QueryStringSerializerTests.cs


示例17: CanOptimizeResult

        private static void CanOptimizeResult(string contentType, IPlugin pluginFormat)
        {
            using (var appHost = new BasicAppHost().Init())
            {
                var dto = new TestDto { Name = "test" };

                var httpReq = new MockHttpRequest();
                httpReq.Headers.Add(HttpHeaders.AcceptEncoding, "gzip,deflate,sdch");
                httpReq.ResponseContentType = contentType;

                if (pluginFormat != null) pluginFormat.Register(appHost);

                object result = httpReq.ToOptimizedResult(dto);
                Assert.IsNotNull(result);
                Assert.IsTrue(result is CompressedResult);
            }
        }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:17,代码来源:RequestContextExtensionsTest.cs


示例18: GetHtml

        public string GetHtml(object dto, string format)
        {
            var httpReq = new MockHttpRequest
            {
                Headers = PclExportClient.Instance.NewNameValueCollection(),
                OperationName = "OperationName",
                QueryString = PclExportClient.Instance.NewNameValueCollection(),
            };
            httpReq.QueryString.Add("format", format);
            using (var ms = new MemoryStream())
            {
                var httpRes = new HttpResponseStreamWrapper(ms, httpReq);
                appHost.ViewEngines[0].ProcessRequest(httpReq, httpRes, dto);

                var utf8Bytes = ms.ToArray();
                var html = utf8Bytes.FromUtf8Bytes();
                return html;
            }
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:19,代码来源:ViewTests.cs


示例19: CanOptimizeResult

        private static void CanOptimizeResult(string contentType, IPlugin pluginFormat)
        {
            var dto = new TestDto {Name = "test"};

            var httpReq = new MockHttpRequest();
            httpReq.Headers.Add(HttpHeaders.AcceptEncoding, "gzip,deflate,sdch");
            httpReq.ResponseContentType = contentType;
            var httpRes = new ViewTests.MockHttpResponse();

            var httpRequestContext = new HttpRequestContext(httpReq, httpRes, dto);

            var appHost = new TestAppHost();
            if (pluginFormat != null) pluginFormat.Register(appHost);

            EndpointHost.ContentTypeFilter = appHost.ContentTypeFilters;

            object result = httpRequestContext.ToOptimizedResult(dto);
            Assert.IsNotNull(result);
            Assert.IsTrue(result is CompressedResult);
        }
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:20,代码来源:RequestContextExtensionsTest.cs


示例20: Can_send_ResponseText_test_with_StatusDescription

        public void Can_send_ResponseText_test_with_StatusDescription()
        {
            var mockRequest = new MockHttpRequest { ContentType = MimeTypes.Json };
            var mockResponse = mockRequest.Response;

            var customStatus = "Custom Status Description";

            var httpResult = new HttpResult(System.Net.HttpStatusCode.Accepted, customStatus)
            {
                RequestContext = mockRequest
            };

            var reponseWasAutoHandled = mockResponse.WriteToResponse(httpResult, MimeTypes.Html);

            Assert.That(reponseWasAutoHandled.Result, Is.True);

            var statusDesc = mockResponse.StatusDescription;
            Assert.That(mockResponse.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.Accepted));
            Assert.That(statusDesc, Is.EqualTo(customStatus));
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:20,代码来源:HttpResultTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MockLogger类代码示例发布时间:2022-05-24
下一篇:
C# MockHeaders类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap