本文整理汇总了C#中System.Net.Http.HttpRequestMessage.GetETag方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.GetETag方法的具体用法?C# HttpRequestMessage.GetETag怎么用?C# HttpRequestMessage.GetETag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.GetETag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetETagTEntity_Returns_ETagInHeader
public void GetETagTEntity_Returns_ETagInHeader()
{
// Arrange
HttpRequestMessage request = new HttpRequestMessage();
HttpConfiguration cofiguration = new HttpConfiguration();
request.SetConfiguration(cofiguration);
Dictionary<string, object> properties = new Dictionary<string, object> { { "City", "Foo" } };
EntityTagHeaderValue etagHeaderValue = new DefaultODataETagHandler().CreateETag(properties);
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
Mock<ODataPathSegment> mockSegment = new Mock<ODataPathSegment> { CallBase = true };
mockSegment.Setup(s => s.GetEdmType(null)).Returns(model.Customer);
mockSegment.Setup(s => s.GetNavigationSource(null)).Returns((IEdmNavigationSource)null);
ODataPath odataPath = new ODataPath(new[] { mockSegment.Object });
request.ODataProperties().Path = odataPath;
// Act
ETag<Customer> result = request.GetETag<Customer>(etagHeaderValue);
dynamic dynamicResult = result;
// Assert
Assert.Equal("Foo", result["City"]);
Assert.Equal("Foo", dynamicResult.City);
}
示例2: GetETagTEntity_Returns_ETagAny
public void GetETagTEntity_Returns_ETagAny()
{
// Arrange
var request = new HttpRequestMessage();
var etagHeaderValue = EntityTagHeaderValue.Any;
// Act
var result = request.GetETag<Customer>(etagHeaderValue);
// Assert
Assert.True(result.IsAny);
}
示例3: GetETag_ThrowsInvalidOperation_EmptyRequest
public void GetETag_ThrowsInvalidOperation_EmptyRequest()
{
// Arrange
HttpRequestMessage request = new HttpRequestMessage();
EntityTagHeaderValue headerValue = new EntityTagHeaderValue("\"any\"");
// Act & Assert
Assert.Throws<InvalidOperationException>(() => request.GetETag(headerValue),
"Request message does not contain an HttpConfiguration object.");
}
示例4: GetETag_Returns_ETagInHeader_ForInteger
public void GetETag_Returns_ETagInHeader_ForInteger(byte byteValue, short shortValue, long longValue)
{
// Arrange
Dictionary<string, object> properties = new Dictionary<string, object>
{
{ "ByteVal", byteValue },
{ "LongVal", longValue },
{ "ShortVal", shortValue }
};
EntityTagHeaderValue etagHeaderValue = new DefaultODataETagHandler().CreateETag(properties);
var builder = new ODataConventionModelBuilder();
builder.EntitySet<MyEtagOrder>("Orders");
IEdmModel model = builder.GetEdmModel();
IEdmEntityType order = model.SchemaElements.OfType<IEdmEntityType>().FirstOrDefault(e => e.Name == "MyEtagOrder");
IEdmEntitySet orders = model.FindDeclaredEntitySet("Orders");
Mock<ODataPathSegment> mockSegment = new Mock<ODataPathSegment> { CallBase = true };
mockSegment.Setup(s => s.GetEdmType(null)).Returns(order);
mockSegment.Setup(s => s.GetNavigationSource(null)).Returns(orders);
ODataPath odataPath = new ODataPath(new[] { mockSegment.Object });
HttpRequestMessage request = new HttpRequestMessage();
HttpConfiguration cofiguration = new HttpConfiguration();
request.SetConfiguration(cofiguration);
request.ODataProperties().Path = odataPath;
request.ODataProperties().Model = model;
// Act
ETag result = request.GetETag(etagHeaderValue);
dynamic dynamicResult = result;
// Assert
byte actualByte = Assert.IsType<byte>(result["ByteVal"]);
Assert.Equal(actualByte, dynamicResult.ByteVal);
Assert.Equal(byteValue, actualByte);
short actualShort = Assert.IsType<short>(result["ShortVal"]);
Assert.Equal(actualShort, dynamicResult.ShortVal);
Assert.Equal(shortValue, actualShort);
long actualLong = Assert.IsType<long>(result["LongVal"]);
Assert.Equal(actualLong, dynamicResult.LongVal);
Assert.Equal(longValue, actualLong);
}
示例5: GetETag_Returns_ETagInHeader_ForDouble
public void GetETag_Returns_ETagInHeader_ForDouble(double value, bool isEqual)
{
// Arrange
Dictionary<string, object> properties = new Dictionary<string, object> { { "Version", value } };
EntityTagHeaderValue etagHeaderValue = new DefaultODataETagHandler().CreateETag(properties);
var builder = new ODataConventionModelBuilder();
builder.EntitySet<MyEtagCustomer>("Customers");
IEdmModel model = builder.GetEdmModel();
IEdmEntityType customer = model.SchemaElements.OfType<IEdmEntityType>().FirstOrDefault(e => e.Name == "MyEtagCustomer");
IEdmEntitySet customers = model.FindDeclaredEntitySet("Customers");
Mock<ODataPathSegment> mockSegment = new Mock<ODataPathSegment> { CallBase = true };
mockSegment.Setup(s => s.GetEdmType(null)).Returns(customer);
mockSegment.Setup(s => s.GetNavigationSource(null)).Returns(customers);
ODataPath odataPath = new ODataPath(new[] { mockSegment.Object });
HttpRequestMessage request = new HttpRequestMessage();
HttpConfiguration cofiguration = new HttpConfiguration();
request.SetConfiguration(cofiguration);
request.ODataProperties().Path = odataPath;
request.ODataProperties().Model = model;
// Act
ETag result = request.GetETag(etagHeaderValue);
dynamic dynamicResult = result;
// Assert
double actual = Assert.IsType<double>(result["Version"]);
Assert.Equal(actual, dynamicResult.Version);
if (isEqual)
{
Assert.Equal(value, actual);
}
else
{
Assert.NotEqual(value, actual);
Assert.True(actual - value < 0.0000001);
}
}
示例6: ApplyTo_NewQueryReturned_ForInteger
public void ApplyTo_NewQueryReturned_ForInteger(sbyte byteVal, short shortVal, bool ifMatch, IList<int> expect)
{
// Arrange
var mycustomers = new List<MyETagOrder>
{
new MyETagOrder
{
ID = 1,
ByteVal = 7,
ShortVal = 8
},
new MyETagOrder
{
ID = 2,
ByteVal = SByte.MaxValue,
ShortVal = Int16.MaxValue
},
new MyETagOrder
{
ID = 3,
ByteVal = SByte.MinValue,
ShortVal = Int16.MinValue
},
};
IETagHandler handerl = new DefaultODataETagHandler();
Dictionary<string, object> properties = new Dictionary<string, object>
{
{ "ByteVal", byteVal },
{ "ShortVal", shortVal }
};
EntityTagHeaderValue etagHeaderValue = handerl.CreateETag(properties);
HttpRequestMessage request = new HttpRequestMessage();
HttpConfiguration cofiguration = new HttpConfiguration();
request.SetConfiguration(cofiguration);
var builder = new ODataConventionModelBuilder();
builder.EntitySet<MyETagOrder>("Orders");
IEdmModel model = builder.GetEdmModel();
IEdmEntityType order = model.SchemaElements.OfType<IEdmEntityType>().FirstOrDefault(e => e.Name == "MyETagOrder");
IEdmEntitySet orders = model.FindDeclaredEntitySet("Orders");
Mock<ODataPathSegment> mockSegment = new Mock<ODataPathSegment> { CallBase = true };
mockSegment.Setup(s => s.GetEdmType(null)).Returns(order);
mockSegment.Setup(s => s.GetNavigationSource(null)).Returns(orders);
ODataPath odataPath = new ODataPath(new[] { mockSegment.Object });
request.ODataProperties().Path = odataPath;
request.ODataProperties().Model = model;
ETag etagCustomer = request.GetETag(etagHeaderValue);
etagCustomer.EntityType = typeof(MyETagOrder);
etagCustomer.IsIfNoneMatch = !ifMatch;
// Act
IQueryable queryable = etagCustomer.ApplyTo(mycustomers.AsQueryable());
// Assert
Assert.NotNull(queryable);
IEnumerable<MyETagOrder> actualOrders = Assert.IsAssignableFrom<IEnumerable<MyETagOrder>>(queryable);
Assert.Equal(expect, actualOrders.Select(c => c.ID));
MethodCallExpression methodCall = queryable.Expression as MethodCallExpression;
Assert.NotNull(methodCall);
Assert.Equal(2, methodCall.Arguments.Count);
if (ifMatch)
{
Assert.Equal(
"Param_0 => ((Param_0.ByteVal == value(System.Web.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.SByte]).TypedProperty) " +
"AndAlso (Param_0.ShortVal == value(System.Web.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.Int16]).TypedProperty))",
methodCall.Arguments[1].ToString());
}
else
{
Assert.Equal(
"Param_0 => Not(((Param_0.ByteVal == value(System.Web.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.SByte]).TypedProperty) " +
"AndAlso (Param_0.ShortVal == value(System.Web.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.Int16]).TypedProperty)))",
methodCall.Arguments[1].ToString());
}
}