public void apply_should_apply_configured_conventions() { // arrange var controller = new HttpControllerDescriptor(new HttpConfiguration(), "Stub", typeof(StubController)); var action = new ReflectedHttpActionDescriptor(controller, typeof(StubController).GetMethod(nameof(StubController.Get))); var description = new VersionedApiDescription() { ActionDescriptor = action, HttpMethod = HttpMethod.Get, ResponseDescription = new ResponseDescription() { ResponseType = typeof(object), }, Properties = { [typeof(IEdmModel)] = new EdmModel(), } }; var builder = new ODataQueryOptionsConventionBuilder(); var settings = new ODataQueryOptionSettings() { DescriptionProvider = builder.DescriptionProvider }; var convention = new Mock <IODataQueryOptionsConvention>(); convention.Setup(c => c.ApplyTo(It.IsAny <ApiDescription>())); builder.Add(convention.Object); // act builder.ApplyTo(new[] { description }, settings); // assert convention.Verify(c => c.ApplyTo(description), Once()); }
/// <summary> /// Gets the entity set associated with the API description. /// </summary> /// <param name="apiDescription">The <see cref="VersionedApiDescription">API description</see> to get the entity set for.</param> /// <returns>The associated <see cref="IEdmEntitySet">entity set</see> or <c>null</c> if there is no associated entity set.</returns> public static IEdmEntitySet EntitySet(this VersionedApiDescription apiDescription) { Arg.NotNull(apiDescription, nameof(apiDescription)); var key = typeof(IEdmEntitySet); if (apiDescription.Properties.TryGetValue(key, out object value)) { return((IEdmEntitySet)value); } var container = apiDescription.EdmModel()?.EntityContainer; if (container == null) { return(null); } var entitySetName = apiDescription.ActionDescriptor.ControllerDescriptor.ControllerName; var entitySet = container.FindEntitySet(entitySetName); apiDescription.Properties[key] = entitySet; return(entitySet); }
/// <summary> /// Gets a property of the specified type from the API description. /// </summary> /// <typeparam name="T">The <see cref="Type">type</see> of property to retrieve.</typeparam> /// <param name="apiDescription">The <see cref="VersionedApiDescription">API description</see> to get the property from.</param> /// <returns>The value of the property, if present; otherwise, the default value of <typeparamref name="T"/>.</returns> public static T GetProperty <T>(this VersionedApiDescription apiDescription) { Arg.NotNull(apiDescription, nameof(apiDescription)); if (apiDescription.Properties.TryGetValue(typeof(T), out var value)) { return((T)value); } return(default);
public void get_group_name_should_return_property_value() { // arrange var description = new VersionedApiDescription() { GroupName = "v1" }; // act var groupName = description.GetGroupName(); // assert groupName.Should().Be("v1"); }
public void is_deprecated_should_return_property_value() { // arrange var description = new VersionedApiDescription() { IsDeprecated = true }; // act var deprecated = description.IsDeprecated(); // assert deprecated.Should().BeTrue(); }
public void get_api_version_should_return_property_value() { // arrange var apiVersion = new ApiVersion(1, 0); var description = new VersionedApiDescription() { ApiVersion = apiVersion }; // act var result = description.GetApiVersion(); // assert result.Should().Be(apiVersion); }
static VersionedApiDescription CreateApiDescription(IEdmModel model) { var configuration = new HttpConfiguration(); var controllerType = typeof(Microsoft.Web.Http.Simulators.V1.OrdersController); var actionMethod = controllerType.GetRuntimeMethod("Get", new[] { typeof(int) }); var controllerDescriptor = new HttpControllerDescriptor(configuration, "Orders", controllerType); var actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, actionMethod); var apiDescription = new VersionedApiDescription() { ActionDescriptor = actionDescriptor, ApiVersion = new ApiVersion(1, 0), Properties = { [typeof(IEdmModel)] = model } }; return(apiDescription); }
/// <summary> /// Gets the entity type associated with the API description. /// </summary> /// <param name="apiDescription">The <see cref="VersionedApiDescription">API description</see> to get the entity type for.</param> /// <returns>The associated <see cref="IEdmEntityType">entity type</see> or <c>null</c> if there is no associated entity type.</returns> public static IEdmEntityType EntityType(this VersionedApiDescription apiDescription) { Arg.NotNull(apiDescription, nameof(apiDescription)); return(apiDescription.EntitySet()?.EntityType()); }
/// <summary> /// Gets the entity data model (EDM) associated with the API description. /// </summary> /// <param name="apiDescription">The <see cref="VersionedApiDescription">API description</see> to get the model for.</param> /// <returns>The associated <see cref="IEdmModel">EDM model</see> or <c>null</c> if there is no associated model.</returns> public static IEdmModel EdmModel(this VersionedApiDescription apiDescription) => apiDescription.GetProperty <IEdmModel>();
/// <summary> /// Sets a property of the specified type on the API description. /// </summary> /// <typeparam name="T">The <see cref="Type">type</see> of property to set.</typeparam> /// <param name="apiDescription">The <see cref="VersionedApiDescription">API description</see> to set the property on.</param> /// <param name="value">The value to add or update.</param> public static void SetProperty <T>(this VersionedApiDescription apiDescription, T value) { Arg.NotNull(apiDescription, nameof(apiDescription)); apiDescription.Properties[typeof(T)] = value; }