本文整理汇总了C#中System.Web.OData.TestCommon.CustomersModelWithInheritance类的典型用法代码示例。如果您正苦于以下问题:C# CustomersModelWithInheritance类的具体用法?C# CustomersModelWithInheritance怎么用?C# CustomersModelWithInheritance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CustomersModelWithInheritance类属于System.Web.OData.TestCommon命名空间,在下文中一共展示了CustomersModelWithInheritance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AttriubteRouting_SelectsExpectedControllerAndAction
[InlineData("GET", "http://localhost/Customers(12)/NS.SpecialCustomer/NS.GetSalary()", "GetSalaryFromSpecialCustomer_12")] // call function on derived entity type
public async Task AttriubteRouting_SelectsExpectedControllerAndAction(string method, string requestUri,
string expectedResult)
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
var controllers = new[] { typeof(CustomersController), typeof(MetadataAndServiceController), typeof(OrdersController) };
TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers));
HttpConfiguration config = new HttpConfiguration();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Services.Replace(typeof(IAssembliesResolver), resolver);
config.MapODataServiceRoute("odata", "", model.Model);
HttpServer server = new HttpServer(config);
config.EnsureInitialized();
HttpClient client = new HttpClient(server);
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(method), requestUri);
// Act
var response = await client.SendAsync(request);
// Assert
if (!response.IsSuccessStatusCode)
{
Assert.False(true, await response.Content.ReadAsStringAsync());
}
var result = await response.Content.ReadAsAsync<AttributeRoutingTestODataResponse>();
Assert.Equal(expectedResult, result.Value);
}
开发者ID:richarddwelsh,项目名称:aspnetwebstack,代码行数:33,代码来源:AttributeRoutingTest.cs
示例2: SelectAction_OnEntitySetPath_Returns_ExpectedMethodOnBaseType
public void SelectAction_OnEntitySetPath_Returns_ExpectedMethodOnBaseType(string method, string[] methodsInController,
string expectedSelectedAction)
{
// Arrange
const string key = "42";
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
var ordersProperty = model.Customer.FindProperty("Orders") as IEdmNavigationProperty;
ODataPath odataPath = new ODataPath(new EntitySetPathSegment(model.Customers), new KeyValuePathSegment(key),
new NavigationPathSegment(ordersProperty));
HttpControllerContext controllerContext = CreateControllerContext(method);
var actionMap = GetMockActionMap(methodsInController);
// Act
string selectedAction = new NavigationRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Assert
Assert.Equal(expectedSelectedAction, selectedAction);
if (expectedSelectedAction == null)
{
Assert.Empty(controllerContext.RouteData.Values);
}
else
{
Assert.Equal(1, controllerContext.RouteData.Values.Count);
Assert.Equal(key, controllerContext.RouteData.Values["key"]);
}
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:27,代码来源:NavigationRoutingConventionTest.cs
示例3: Ctor_ThatBuildsNestedContext_CopiesProperties
public void Ctor_ThatBuildsNestedContext_CopiesProperties()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataSerializerContext context = new ODataSerializerContext
{
NavigationSource = model.Customers,
MetadataLevel = ODataMetadataLevel.FullMetadata,
Model = model.Model,
Path = new ODataPath(),
Request = new HttpRequestMessage(),
RootElementName = "somename",
SelectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true),
SkipExpensiveAvailabilityChecks = true,
Url = new UrlHelper()
};
EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = context };
SelectExpandClause selectExpand = new SelectExpandClause(new SelectItem[0], allSelected: true);
IEdmNavigationProperty navProp = model.Customer.NavigationProperties().First();
// Act
ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpand, navProp);
// Assert
Assert.Equal(context.MetadataLevel, nestedContext.MetadataLevel);
Assert.Same(context.Model, nestedContext.Model);
Assert.Same(context.Path, nestedContext.Path);
Assert.Same(context.Request, nestedContext.Request);
Assert.Equal(context.RootElementName, nestedContext.RootElementName);
Assert.Equal(context.SkipExpensiveAvailabilityChecks, nestedContext.SkipExpensiveAvailabilityChecks);
Assert.Same(context.Url, nestedContext.Url);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:32,代码来源:ODataSerializerContextTest.cs
示例4: AttributeRouting_QueryProperty_AfterCallBoundFunction
public async Task AttributeRouting_QueryProperty_AfterCallBoundFunction()
{
// Arrange
const string RequestUri = @"http://localhost/Customers(12)/NS.GetOrder(orderId=4)/Amount";
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
HttpConfiguration config = new[] { typeof(CustomersController) }.GetHttpConfiguration();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.MapODataServiceRoute("odata", "", model.Model);
HttpServer server = new HttpServer(config);
config.EnsureInitialized();
HttpClient client = new HttpClient(server);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri);
// Act
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
// Assert
Assert.True(response.IsSuccessStatusCode);
Assert.Equal("{\r\n \"@odata.context\":\"http://localhost/$metadata#Edm.Int32\",\"value\":56\r\n}",
responseString);
}
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:25,代码来源:AttributeRoutingTest.cs
示例5: ODataSwaggerUtilitiesTest
public ODataSwaggerUtilitiesTest()
{
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
_customer = model.Customer;
_customers = model.Customers;
IEdmAction action = new EdmAction("NS", "GetCustomers", null, false, null);
_getCustomers = new EdmActionImport(model.Container, "GetCustomers", action);
_isAnyUpgraded = model.Model.SchemaElements.OfType<IEdmFunction>().FirstOrDefault(e => e.Name == "IsAnyUpgraded");
_isCustomerUpgradedWithParam = model.Model.SchemaElements.OfType<IEdmFunction>().FirstOrDefault(e => e.Name == "IsUpgradedWithParam");
}
开发者ID:Gebov,项目名称:WebApi,代码行数:12,代码来源:ODataSwaggerUtilitiesTest.cs
示例6: ApplyTo_OnSingleEntity_WithUnTypedContext_Throws_InvalidOperation
public void ApplyTo_OnSingleEntity_WithUnTypedContext_Throws_InvalidOperation()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer);
SelectExpandQueryOption selectExpand = new SelectExpandQueryOption(select: "ID", expand: null, context: context);
object entity = new object();
// Act & Assert
Assert.Throws<NotSupportedException>(() => selectExpand.ApplyTo(entity, new ODataQuerySettings()),
"The query option is not bound to any CLR type. 'ApplyTo' is only supported with a query option bound to a CLR type.");
}
开发者ID:genusP,项目名称:WebApi,代码行数:12,代码来源:SelectExpandQueryOptionTest.cs
示例7: SelectController_RetrunsSingletonName_ForSingletonRequest
public void SelectController_RetrunsSingletonName_ForSingletonRequest()
{
// Arrange
Mock<HttpRequestMessage> request = new Mock<HttpRequestMessage>();
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://any/", "VipCustomer");
// Act
string controller = new MockNavigationSourceRoutingConvention().SelectController(odataPath, request.Object);
// Assert
Assert.Equal("VipCustomer", controller);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:13,代码来源:NavigationSourceRoutingConventionTest.cs
示例8: ValidateThrowException_IfNotNavigable
public void ValidateThrowException_IfNotNavigable()
{
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(Customer)));
ODataQueryContext queryContext = new ODataQueryContext(model.Model, typeof(Customer));
model.Model.SetAnnotationValue(model.Customer.FindProperty("Orders"), new QueryableRestrictionsAnnotation(new QueryableRestrictions{NotNavigable=true}));
string select = "Orders";
SelectExpandQueryValidator validator = new SelectExpandQueryValidator();
SelectExpandQueryOption selectExpandQueryOption = new SelectExpandQueryOption(select, null, queryContext);
Assert.Throws<ODataException>(
() => validator.Validate(selectExpandQueryOption, new ODataValidationSettings()),
"The property 'Orders' cannot be used for navigation.");
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:14,代码来源:SelectExpandQueryValidatorTest.cs
示例9: ValidateThrowException_IfBaseOrDerivedClassPropertyNotNavigable
public void ValidateThrowException_IfBaseOrDerivedClassPropertyNotNavigable(string className, string propertyName)
{
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
model.Model.SetAnnotationValue(model.SpecialCustomer, new ClrTypeAnnotation(typeof(Customer)));
ODataQueryContext queryContext = new ODataQueryContext(model.Model, typeof(Customer));
EdmEntityType classType = (className == "Customer") ? model.Customer : model.SpecialCustomer;
model.Model.SetAnnotationValue(classType.FindProperty(propertyName), new QueryableRestrictionsAnnotation(new QueryableRestrictions { NotNavigable = true }));
string select = "NS.SpecialCustomer/" + propertyName;
SelectExpandQueryValidator validator = new SelectExpandQueryValidator();
SelectExpandQueryOption selectExpandQueryOption = new SelectExpandQueryOption(select, null, queryContext);
Assert.Throws<ODataException>(
() => validator.Validate(selectExpandQueryOption, new ODataValidationSettings()),
String.Format(CultureInfo.InvariantCulture, "The property '{0}' cannot be used for navigation.", propertyName));
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:15,代码来源:SelectExpandQueryValidatorTest.cs
示例10: SelectExpandBinderTest
public SelectExpandBinderTest()
{
_settings = new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.False };
_model = new CustomersModelWithInheritance();
_model.Model.SetAnnotationValue<ClrTypeAnnotation>(_model.Customer, new ClrTypeAnnotation(typeof(Customer)));
_model.Model.SetAnnotationValue<ClrTypeAnnotation>(_model.SpecialCustomer, new ClrTypeAnnotation(typeof(SpecialCustomer)));
_context = new ODataQueryContext(_model.Model, typeof(Customer));
_binder = new SelectExpandBinder(_settings, new DefaultAssembliesResolver(), new SelectExpandQueryOption("*", "", _context));
Customer customer = new Customer();
Order order = new Order { Customer = customer };
customer.Orders.Add(order);
_queryable = new[] { customer }.AsQueryable();
}
开发者ID:shailendra9,项目名称:WebApi,代码行数:15,代码来源:SelectExpandBinderTest.cs
示例11: Ctor_TakingOrderByClause_InitializesProperty_Property
public void Ctor_TakingOrderByClause_InitializesProperty_Property()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
IEdmProperty property = model.Customer.FindProperty("ID");
EntityRangeVariable variable = new EntityRangeVariable("it", model.Customer.AsReference(), model.Customers);
SingleValuePropertyAccessNode node = new SingleValuePropertyAccessNode(new EntityRangeVariableReferenceNode("it", variable), property);
OrderByClause orderBy = new OrderByClause(thenBy: null, expression: node, direction: OrderByDirection.Ascending, rangeVariable: variable);
// Act
OrderByPropertyNode orderByNode = new OrderByPropertyNode(orderBy);
// Assert
Assert.Equal(property, orderByNode.Property);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:15,代码来源:OrderByPropertyNodeTest.cs
示例12: SelectAction_ReturnsNull_ForInvalidHttpMethods
public void SelectAction_ReturnsNull_ForInvalidHttpMethods(string httpMethod)
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "VipCustomer");
ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null);
HttpControllerContext controllerContext = new HttpControllerContext();
controllerContext.Request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/");
controllerContext.Request.SetRouteData(new HttpRouteData(new HttpRoute()));
// Act
string actionName = new SingletonRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Act & Assert
Assert.Null(actionName);
}
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:16,代码来源:SingletonRoutingConventionTest.cs
示例13: GenerateODataLink_ThrowsIdLinkNullForEntityIdHeader_IfEntitySetLinkBuilderReturnsNull
public void GenerateODataLink_ThrowsIdLinkNullForEntityIdHeader_IfEntitySetLinkBuilderReturnsNull()
{
// Arrange
var linkBuilder = new Mock<NavigationSourceLinkBuilderAnnotation>();
var model = new CustomersModelWithInheritance();
model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder.Object);
var path = new ODataPath(new EntitySetPathSegment(model.Customers));
var request = new HttpRequestMessage();
request.ODataProperties().Model = model.Model;
request.ODataProperties().Path = path;
// Act & Assert
Assert.Throws<InvalidOperationException>(
() => ResultHelpers.GenerateODataLink(request, _entity, isEntityId: true),
"The Id link builder for the entity set 'Customers' returned null. An Id link is required for the OData-EntityId header.");
}
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:17,代码来源:ResultHelpersTest.cs
示例14: SelectAction_OnSingletonPath_Returns_ExpectedMethodOnBaseType
public void SelectAction_OnSingletonPath_Returns_ExpectedMethodOnBaseType(string method, string[] methodsInController,
string expectedSelectedAction)
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
var ordersProperty = model.Customer.FindProperty("Orders") as IEdmNavigationProperty;
ODataPath odataPath = new ODataPath(new SingletonPathSegment(model.VipCustomer),
new NavigationPathSegment(ordersProperty));
HttpControllerContext controllerContext = CreateControllerContext(method);
var actionMap = GetMockActionMap(methodsInController);
// Act
string selectedAction = new NavigationRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Assert
Assert.Equal(expectedSelectedAction, selectedAction);
Assert.Empty(controllerContext.RouteData.Values);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:18,代码来源:NavigationRoutingConventionTest.cs
示例15: Ctor_ThatBuildsNestedContext_InitializesRightValues
public void Ctor_ThatBuildsNestedContext_InitializesRightValues()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
SelectExpandClause selectExpand = new SelectExpandClause(new SelectItem[0], allSelected: true);
IEdmNavigationProperty navProp = model.Customer.NavigationProperties().First();
ODataSerializerContext context = new ODataSerializerContext { NavigationSource = model.Customers, Model = model.Model };
EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = context };
// Act
ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpand, navProp);
// Assert
Assert.Same(entity, nestedContext.ExpandedEntity);
Assert.Same(navProp, nestedContext.NavigationProperty);
Assert.Same(selectExpand, nestedContext.SelectExpandClause);
Assert.Same(model.Orders, nestedContext.NavigationSource);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:18,代码来源:ODataSerializerContextTest.cs
示例16: SelectAction_ReturnsExpectedActionName_DollarCount
public void SelectAction_ReturnsExpectedActionName_DollarCount(string method, string expected)
{
// Arrange
var model = new CustomersModelWithInheritance();
var odataPath = new ODataPath(new EntitySetPathSegment(model.Customers), new CountPathSegment());
HttpControllerContext controllerContext = new HttpControllerContext()
{
Request = new HttpRequestMessage(new HttpMethod(method), "http://localhost/"),
RouteData = new HttpRouteData(new HttpRoute())
};
ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => expected);
// Act
string actionName = new EntitySetRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Assert
Assert.Equal(expected, actionName);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:20,代码来源:EntitySetRoutingConventionTest.cs
示例17: SelectAction_ReturnsTheActionName_ForValidHttpMethods
public void SelectAction_ReturnsTheActionName_ForValidHttpMethods(string httpMethod, string httpMethodNamePrefix)
{
// Arrange
const string SingletonName = "VipCustomer";
string actionName = httpMethodNamePrefix + SingletonName;
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, SingletonName);
ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => actionName);
HttpControllerContext controllerContext = new HttpControllerContext();
controllerContext.Request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/");
controllerContext.Request.SetRouteData(new HttpRouteData(new HttpRoute()));
// Act
string selectedAction = new SingletonRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Assert
Assert.NotNull(selectedAction);
Assert.Equal(actionName, selectedAction);
Assert.Empty(controllerContext.Request.GetRouteData().Values);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:20,代码来源:SingletonRoutingConventionTest.cs
示例18: SelectAction_ReturnsNull_IfActionIsMissing
public void SelectAction_ReturnsNull_IfActionIsMissing()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://localhost/", "Customers(10)/Account/Tax");
ILookup<string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null);
HttpRequestContext requestContext = new HttpRequestContext();
HttpControllerContext controllerContext = new HttpControllerContext
{
Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"),
RequestContext = requestContext,
RouteData = new HttpRouteData(new HttpRoute())
};
controllerContext.Request.SetRequestContext(requestContext);
// Act
string selectedAction = _routingConvention.SelectAction(odataPath, controllerContext, emptyActionMap);
// Assert
Assert.Null(selectedAction);
Assert.Empty(controllerContext.Request.GetRouteData().Values);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:22,代码来源:DynamicPropertyRoutingConventionTest.cs
示例19: SelectAction_OnSingletonPath_ReturnsTheActionName
public void SelectAction_OnSingletonPath_ReturnsTheActionName()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "VipCustomer/Address");
ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => "GetAddress");
HttpRequestContext requestContext = new HttpRequestContext();
HttpControllerContext controllerContext = new HttpControllerContext
{
Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"),
RequestContext = requestContext,
RouteData = new HttpRouteData(new HttpRoute())
};
controllerContext.Request.SetRequestContext(requestContext);
// Act
string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Assert
Assert.NotNull(selectedAction);
Assert.Equal("GetAddress", selectedAction);
Assert.Empty(controllerContext.Request.GetRouteData().Values);
}
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:23,代码来源:PropertyRoutingConventionTests.cs
示例20: SelectAction_OnEntitySetPath_ReturnsTheActionName
public void SelectAction_OnEntitySetPath_ReturnsTheActionName(string httpMethod, string prefix)
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers(7)/Name");
ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => prefix + "NameFromCustomer");
HttpRequestContext requestContext = new HttpRequestContext();
HttpControllerContext controllerContext = new HttpControllerContext
{
Request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/"),
RequestContext = requestContext,
RouteData = new HttpRouteData(new HttpRoute())
};
controllerContext.Request.SetRequestContext(requestContext);
// Act
string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);
// Assert
Assert.NotNull(selectedAction);
Assert.Equal(prefix + "NameFromCustomer", selectedAction);
Assert.Equal(1, controllerContext.Request.GetRouteData().Values.Count);
Assert.Equal("7", controllerContext.Request.GetRouteData().Values["key"]);
}
开发者ID:joshcomley,项目名称:WebApi,代码行数:24,代码来源:PropertyRoutingConventionTests.cs
注:本文中的System.Web.OData.TestCommon.CustomersModelWithInheritance类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论