public void HasActionLink_ThrowsException_OnNoBoundToEntityActions() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); ActionConfiguration action = customer.Collection.Action("CollectionAction"); // Act & Assert InvalidOperationException exception = Assert.Throws <InvalidOperationException>( () => action.HasActionLink(ctx => new Uri("http://any"), followsConventions: false)); Assert.Equal(exception.Message, "To register an action link factory, actions must be bindable to a single entity. " + "Action 'CollectionAction' does not meet this requirement."); }
public void ReturnsCollection_ThrowsInvalidOperationException_IfReturnTypeIsEntity() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); builder.EntityType <Movie>(); var action = builder.Action("action"); // Act & Assert InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => action.ReturnsCollection <Movie>()); Assert.Equal(exception.Message, "The EDM type 'Microsoft.AspNetCore.OData.Builder.Movie' is already declared as an entity type. Use the " + "method 'ReturnsCollectionFromEntitySet' if the return type is an entity collection."); }
public void CanCreateActionThatBindsToEntityCollection() { // Arrange // Act ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); ActionConfiguration sendEmail = customer.Collection.Action("SendEmail"); // Assert Assert.True(sendEmail.IsBindable); Assert.NotNull(sendEmail.Parameters); Assert.Single(sendEmail.Parameters); Assert.Equal(BindingParameterConfiguration.DefaultBindingParameterName, sendEmail.Parameters.Single().Name); Assert.Equal(string.Format("Collection({0})", typeof(Customer).FullName), sendEmail.Parameters.Single().TypeConfiguration.FullName); }
public void GetEdmModel_ThrowsException_WhenBoundActionOverloaded() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); customer.HasKey(c => c.CustomerId); customer.Property(c => c.Name); customer.Action("ActionOnCustomer"); customer.Action("ActionOnCustomer").Returns <string>(); // Act & Assert InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => builder.GetEdmModel()); Assert.Equal(exception.Message, "Found more than one action with name 'ActionOnCustomer' " + "bound to the same type 'Microsoft.AspNetCore.OData.Models.Customer'. " + "Each bound action must have a different binding type or name."); }
public NavigationPropertyBindingConfiguration HasManyBinding <TTargetType, TDerivedEntityType>( Expression <Func <TDerivedEntityType, IEnumerable <TTargetType> > > navigationExpression, string entitySetName) where TTargetType : class where TDerivedEntityType : class, TEntityType { if (navigationExpression == null) { throw Error.ArgumentNull("navigationExpression"); } if (String.IsNullOrEmpty(entitySetName)) { throw Error.ArgumentNullOrEmpty("entitySetName"); } EntityTypeConfiguration <TDerivedEntityType> derivedEntityType = _modelBuilder.EntityType <TDerivedEntityType>().DerivesFrom <TEntityType>(); return(this.Configuration.AddBinding(derivedEntityType.HasMany(navigationExpression), _modelBuilder.EntitySet <TTargetType>(entitySetName)._configuration)); }
public void CanCreateEdmModel_WithBindableAction() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); customer.HasKey(c => c.CustomerId); customer.Property(c => c.Name); // Act customer.Action("ActionName"); IEdmModel model = builder.GetEdmModel(); // Assert IEdmAction action = Assert.Single(model.SchemaElements.OfType <IEdmAction>()); Assert.True(action.IsBound); Assert.Equal("ActionName", action.Name); Assert.Null(action.ReturnType); Assert.Single(action.Parameters); Assert.Equal(BindingParameterConfiguration.DefaultBindingParameterName, action.Parameters.Single().Name); Assert.Equal(typeof(Customer).FullName, action.Parameters.Single().Type.FullName()); }