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


C# DefaultHttpContext.GetFeature方法代码示例

本文整理汇总了C#中Microsoft.AspNet.Http.Internal.DefaultHttpContext.GetFeature方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultHttpContext.GetFeature方法的具体用法?C# DefaultHttpContext.GetFeature怎么用?C# DefaultHttpContext.GetFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNet.Http.Internal.DefaultHttpContext的用法示例。


在下文中一共展示了DefaultHttpContext.GetFeature方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadFormAsync_SimpleData_ReturnsParsedFormCollection

        public async Task ReadFormAsync_SimpleData_ReturnsParsedFormCollection()
        {
            // Arrange
            var formContent = Encoding.UTF8.GetBytes("foo=bar&baz=2");
            var context = new DefaultHttpContext();
            context.Request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            context.Request.Body = new MemoryStream(formContent);

            // Not cached yet
            var formFeature = context.GetFeature<IFormFeature>();
            Assert.Null(formFeature);

            // Act
            var formCollection = await context.Request.ReadFormAsync();

            // Assert
            Assert.Equal("bar", formCollection["foo"]);
            Assert.Equal("2", formCollection["baz"]);

            // Cached
            formFeature = context.GetFeature<IFormFeature>();
            Assert.NotNull(formFeature);
            Assert.NotNull(formFeature.Form);
            Assert.Same(formFeature.Form, formCollection);
        }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:25,代码来源:FormFeatureTests.cs

示例2: ExpectedKeysAreAvailable

        public Task ExpectedKeysAreAvailable()
        {
            var handler = new ClientHandler(env =>
            {
                var context = new DefaultHttpContext((IFeatureCollection)env);

                // TODO: Assert.True(context.RequestAborted.CanBeCanceled);
                Assert.Equal("HTTP/1.1", context.Request.Protocol);
                Assert.Equal("GET", context.Request.Method);
                Assert.Equal("https", context.Request.Scheme);
                Assert.Equal("/A/Path", context.Request.PathBase.Value);
                Assert.Equal("/and/file.txt", context.Request.Path.Value);
                Assert.Equal("?and=query", context.Request.QueryString.Value);
                Assert.NotNull(context.Request.Body);
                Assert.NotNull(context.Request.Headers);
                Assert.NotNull(context.Response.Headers);
                Assert.NotNull(context.Response.Body);
                Assert.Equal(200, context.Response.StatusCode);
                Assert.Null(context.GetFeature<IHttpResponseFeature>().ReasonPhrase);
                Assert.Equal("example.com", context.Request.Host.Value);

                return Task.FromResult(0);
            }, new PathString("/A/Path/"));
            var httpClient = new HttpClient(handler);
            return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query");
        }
开发者ID:humblelistener,项目名称:Hosting,代码行数:26,代码来源:ClientHandlerTests.cs

示例3: SetItems_NewCollectionUsed

 public void SetItems_NewCollectionUsed()
 {
     var context = new DefaultHttpContext(new FeatureCollection());
     Assert.Null(context.GetFeature<IItemsFeature>());
     var items = new Dictionary<object, object>();
     context.Items = items;
     Assert.NotNull(context.GetFeature<IItemsFeature>());
     Assert.Same(items, context.Items);
     var item = new object();
     items["foo"] = item;
     Assert.Same(item, context.Items["foo"]);
 }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:12,代码来源:DefaultHttpContextTests.cs

示例4: GetItems_DefaultCollectionProvided

 public void GetItems_DefaultCollectionProvided()
 {
     var context = new DefaultHttpContext(new FeatureCollection());
     Assert.Null(context.GetFeature<IItemsFeature>());
     var items = context.Items;
     Assert.NotNull(context.GetFeature<IItemsFeature>());
     Assert.NotNull(items);
     Assert.Same(items, context.Items);
     var item = new object();
     context.Items["foo"] = item;
     Assert.Same(item, context.Items["foo"]);
 }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:12,代码来源:DefaultHttpContextTests.cs

示例5: CreateRequest

 private static HttpRequest CreateRequest(IDictionary<string, string[]> headers)
 {
     var context = new DefaultHttpContext();
     context.GetFeature<IHttpRequestFeature>().Headers = headers;
     return context.Request;
 }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:6,代码来源:DefaultHttpRequestTests.cs

示例6: ReadFormAsync_MultipartWithFieldAndFile_ReturnsParsedFormCollection

        public async Task ReadFormAsync_MultipartWithFieldAndFile_ReturnsParsedFormCollection()
        {
            var formContent = Encoding.UTF8.GetBytes(MultipartFormWithFieldAndFile);
            var context = new DefaultHttpContext();
            context.Request.ContentType = MultipartContentType;
            context.Request.Body = new MemoryStream(formContent);

            // Not cached yet
            var formFeature = context.GetFeature<IFormFeature>();
            Assert.Null(formFeature);

            var formCollection = await context.Request.ReadFormAsync();

            Assert.NotNull(formCollection);

            // Cached
            formFeature = context.GetFeature<IFormFeature>();
            Assert.NotNull(formFeature);
            Assert.NotNull(formFeature.Form);
            Assert.Same(formFeature.Form, formCollection);
            Assert.Same(formCollection, context.Request.Form);

            // Content
            Assert.Equal(1, formCollection.Count);
            Assert.Equal("Foo", formCollection["description"]);

            Assert.NotNull(formCollection.Files);
            Assert.Equal(1, formCollection.Files.Count);

            var file = formCollection.Files["myfile1"];
            Assert.Equal("text/html", file.ContentType);
            Assert.Equal(@"form-data; name=""myfile1""; filename=""temp.html""", file.ContentDisposition);
            var body = file.OpenReadStream();
            using (var reader = new StreamReader(body))
            {
                var content = reader.ReadToEnd();
                Assert.Equal(content, "<html><body>Hello World</body></html>");
            }
        }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:39,代码来源:FormFeatureTests.cs

示例7: ReadForm_MultipartWithField_ReturnsParsedFormCollection

        public async Task ReadForm_MultipartWithField_ReturnsParsedFormCollection()
        {
            var formContent = Encoding.UTF8.GetBytes(MultipartFormWithField);
            var context = new DefaultHttpContext();
            context.Request.ContentType = MultipartContentType;
            context.Request.Body = new MemoryStream(formContent);

            // Not cached yet
            var formFeature = context.GetFeature<IFormFeature>();
            Assert.Null(formFeature);

            var formCollection = context.Request.Form;

            Assert.NotNull(formCollection);

            // Cached
            formFeature = context.GetFeature<IFormFeature>();
            Assert.NotNull(formFeature);
            Assert.NotNull(formFeature.Form);
            Assert.Same(formCollection, formFeature.Form);
            Assert.Same(formCollection, await context.Request.ReadFormAsync());

            // Content
            Assert.Equal(1, formCollection.Count);
            Assert.Equal("Foo", formCollection["description"]);

            Assert.NotNull(formCollection.Files);
            Assert.Equal(0, formCollection.Files.Count);
        }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:29,代码来源:FormFeatureTests.cs


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