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


C# HttpRequestHeaderHelper类代码示例

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


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

示例1: GetHttpHeaderValue_HttpRequestHeaderStringFound_HeaderValue

        public void GetHttpHeaderValue_HttpRequestHeaderStringFound_HeaderValue()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerDefaultValue = "Unknown User Agent";
            var headerValue = "Talifun Browser";
            var headerType = HttpRequestHeader.UserAgent;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);
   
            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var userAgentValue = httpRequestHeaderHelper.GetHttpHeaderValue(httpRequest, headerName, headerDefaultValue);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.AreEqual(headerValue, userAgentValue);
        }
开发者ID:atifaziz,项目名称:talifun-web,代码行数:19,代码来源:HttpRequestHeaderHelperTests.cs

示例2: CheckIfMatch_HasNoIfMatchHeader_Null

        public void CheckIfMatch_HasNoIfMatchHeader_Null()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var entityTag = "1234567";
            var doesEntityExists = true;
            var headerValue = string.Empty;
            var headerType = HttpRequestHeader.IfMatch;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var ifMatchSatisfied = httpRequestHeaderHelper.CheckIfMatch(httpRequest, entityTag, doesEntityExists);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.IsNull(ifMatchSatisfied);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:20,代码来源:HttpRequestHeaderHelperTests.cs

示例3: CheckIfNoneMatch_MatchingWildCardAndEntityDoesNotExist_True

        public void CheckIfNoneMatch_MatchingWildCardAndEntityDoesNotExist_True()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var entityTag = "abcdef";
            var doesEntityExists = false;
            var headerValue = "*";
            var headerType = HttpRequestHeader.IfNoneMatch;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var ifMatchSatisfied = httpRequestHeaderHelper.CheckIfNoneMatch(httpRequest, entityTag, doesEntityExists);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.IsNotNull(ifMatchSatisfied);
            Assert.IsTrue(ifMatchSatisfied.Value);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:21,代码来源:HttpRequestHeaderHelperTests.cs

示例4: IsRangeRequest_HasRangeHeader_True

        public void IsRangeRequest_HasRangeHeader_True()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerValue = "bytes=500-600,601-999";
            var headerType = HttpRequestHeader.Range;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var isRangeRequest = httpRequestHeaderHelper.IsRangeRequest(httpRequest);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.True(isRangeRequest);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:18,代码来源:HttpRequestHeaderHelperTests.cs

示例5: IsRangeRequest_DoesNotHaveRangeHeader_False

        public void IsRangeRequest_DoesNotHaveRangeHeader_False()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerValue = string.Empty;
            var headerType = HttpRequestHeader.Range;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var isRangeRequest = httpRequestHeaderHelper.IsRangeRequest(httpRequest);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.False(isRangeRequest);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:18,代码来源:HttpRequestHeaderHelperTests.cs

示例6: GetRanges_StartRangeLargerThenEntityLength_False

        public void GetRanges_StartRangeLargerThenEntityLength_False()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var contentLength = 10000;
            var headerValue = "bytes=20000-";
            var headerType = HttpRequestHeader.Range;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            IEnumerable<RangeItem> ranges;
            var rangeResult = httpRequestHeaderHelper.GetRanges(httpRequest, contentLength, out ranges);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.NotNull(rangeResult);
            Assert.IsFalse(rangeResult.Value);
            Assert.IsNull(ranges);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:22,代码来源:HttpRequestHeaderHelperTests.cs

示例7: CheckIfModifiedSince_DateModifiedSinceInvalid_False

        public void CheckIfModifiedSince_DateModifiedSinceInvalid_False()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var lastModified = new DateTime(2010, 01, 01, 01, 01, 01, DateTimeKind.Utc);
            var headerValue = "invalid";
            var headerType = HttpRequestHeader.IfModifiedSince;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var hasBeenModifiedSince = httpRequestHeaderHelper.CheckIfModifiedSince(httpRequest, lastModified);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.IsNull(hasBeenModifiedSince);
        }
开发者ID:atifaziz,项目名称:talifun-web,代码行数:19,代码来源:HttpRequestHeaderHelperTests.cs

示例8: CheckUnlessModifiedSince_HasNotBeenModifiedSince_True

        public void CheckUnlessModifiedSince_HasNotBeenModifiedSince_True()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var lastModified = new DateTime(2010, 01, 01, 01, 01, 01);
            var headerValue = lastModified.AddSeconds(1).ToString("r");
            var headerType = HttpRequestHeader.UnlessModifiedSince;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var hasNotBeenModifiedSince = httpRequestHeaderHelper.CheckUnlessModifiedSince(httpRequest, lastModified);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.IsNotNull(hasNotBeenModifiedSince);
            Assert.True(hasNotBeenModifiedSince.Value);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:20,代码来源:HttpRequestHeaderHelperTests.cs

示例9: GetHttpHeaderWithQValues_NoHttpHeaderQValues_EmptyList

        public void GetHttpHeaderWithQValues_NoHttpHeaderQValues_EmptyList()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerValue = string.Empty;
            var headerType = HttpRequestHeader.AcceptEncoding;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var headerValueWithQValues = httpRequestHeaderHelper.GetHttpHeaderWithQValues(httpRequest, headerType);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.IsEmpty(headerValueWithQValues);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:18,代码来源:HttpRequestHeaderHelperTests.cs

示例10: GetHttpHeaderWithQValues_MultipleHttpHeaderWithQValueSet_List

        public void GetHttpHeaderWithQValues_MultipleHttpHeaderWithQValueSet_List()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var identity1 = "gzip";
            var qValue1 = 0.5f;

            var identity2 = "deflate";
            var qValue2 = 0.8f;

            var headerValue = identity1 + ";q=" + qValue1.ToString("N1") + "," + identity2 + ";q=" + qValue2.ToString("N1");
            var headerType = HttpRequestHeader.AcceptEncoding;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var headerValueWithQValues = httpRequestHeaderHelper.GetHttpHeaderWithQValues(httpRequest, headerType);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.AreEqual(2, headerValueWithQValues.Count);

            Assert.AreEqual(identity1, headerValueWithQValues[0].Identity);
            Assert.IsNotNull(headerValueWithQValues[0].QValue);
            Assert.AreEqual(qValue1, headerValueWithQValues[0].QValue.Value);

            Assert.AreEqual(identity2, headerValueWithQValues[1].Identity);
            Assert.IsNotNull(headerValueWithQValues[1].QValue);
            Assert.AreEqual(qValue2, headerValueWithQValues[1].QValue.Value);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:32,代码来源:HttpRequestHeaderHelperTests.cs

示例11: GetHttpHeaderWithQValues_IsCaseSensitive_List

        public void GetHttpHeaderWithQValues_IsCaseSensitive_List()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerValue = "abcdeF";
            var headerType = HttpRequestHeader.AcceptEncoding;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var headerValueWithQValues = httpRequestHeaderHelper.GetHttpHeaderWithQValues(httpRequest, headerType);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.AreEqual(1, headerValueWithQValues.Count);
            Assert.AreEqual(headerValue, headerValueWithQValues[0].Identity);
            Assert.IsNull(headerValueWithQValues[0].QValue);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:20,代码来源:HttpRequestHeaderHelperTests.cs

示例12: GetHttpHeaderWithQValues_InvalidQValueNotANumber_List

        public void GetHttpHeaderWithQValues_InvalidQValueNotANumber_List()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerValue = "gzip, deflate, x-gzip, identity; q=moo";
            var headerType = HttpRequestHeader.AcceptEncoding;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var headerValueWithQValues = httpRequestHeaderHelper.GetHttpHeaderWithQValues(httpRequest, headerType);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.AreEqual(5, headerValueWithQValues.Count);
            Assert.AreEqual("identity", headerValueWithQValues[3].Identity);
            Assert.IsNull(headerValueWithQValues[3].QValue);
            Assert.AreEqual("q=moo", headerValueWithQValues[4].Identity);
            Assert.IsNull(headerValueWithQValues[4].QValue);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:22,代码来源:HttpRequestHeaderHelperTests.cs

示例13: GetHttpHeaderValues_MultipleHttpHeaderWithValuesSetWithSpacing_List

        public void GetHttpHeaderValues_MultipleHttpHeaderWithValuesSetWithSpacing_List()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var identity1 = "gzip";
            var identity2 = "deflate";
            var headerValue = identity1 + " , " + identity2;
            var headerType = HttpRequestHeader.IfMatch;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var headerValues = httpRequestHeaderHelper.GetHttpHeaderValues(httpRequest, headerType);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.AreEqual(2, headerValues.Count);
            Assert.AreEqual(identity1, headerValues[0]);
            Assert.AreEqual(identity2, headerValues[1]);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:22,代码来源:HttpRequestHeaderHelperTests.cs

示例14: GetHttpHeaderValues_HttpHeaderWithOneValueSet_List

        public void GetHttpHeaderValues_HttpHeaderWithOneValueSet_List()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headerValue = "1234567";
            var headerType = HttpRequestHeader.IfMatch;
            var headerName = (string)headerType;

            httpRequest.Expect(x => x.Headers[headerName]).Return(headerValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var headerValues = httpRequestHeaderHelper.GetHttpHeaderValues(httpRequest, headerType);

            //Assert
            httpRequest.VerifyAllExpectations();
            Assert.AreEqual(1, headerValues.Count);
            Assert.AreEqual(headerValue.ToLowerInvariant(), headerValues[0]);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:19,代码来源:HttpRequestHeaderHelperTests.cs

示例15: CheckIfRange_CheckOnLastModifiedIfRangeHeader_True

        public void CheckIfRange_CheckOnLastModifiedIfRangeHeader_True()
        {
            //Arrange
            var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();
            var headers = MockRepository.GenerateMock<NameValueCollection>();
            httpRequest.Stub(x => x.Headers).Return(headers);

            var lastModified = new DateTime(2010, 01, 01, 01, 01, 01);
            var etag = "1234567";

            var rangeRequestHeaderValue = "bytes=500-600,601-999";
            var rangeRequestHeaderType = HttpRequestHeader.Range;
            var rangeRequestHeaderName = (string)rangeRequestHeaderType;

            var ifRangeHeaderValue = lastModified.ToString("r");
            var ifRangeHeaderType = HttpRequestHeader.IfRange;
            var ifRangeHeaderName = (string)ifRangeHeaderType;

            httpRequest.Headers.Expect(x => x[rangeRequestHeaderName]).Return(rangeRequestHeaderValue);
            httpRequest.Headers.Expect(x => x[ifRangeHeaderName]).Return(ifRangeHeaderValue);

            //Act
            var httpRequestHeaderHelper = new HttpRequestHeaderHelper();
            var satisfiesRangeCheck = httpRequestHeaderHelper.CheckIfRange(httpRequest, etag, lastModified);

            //Assert
            headers.VerifyAllExpectations();
            httpRequest.VerifyAllExpectations();
            Assert.IsNotNull(satisfiesRangeCheck);
            Assert.True(satisfiesRangeCheck.Value);
        }
开发者ID:CSharpDev,项目名称:talifun-web,代码行数:31,代码来源:HttpRequestHeaderHelperTests.cs


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