public void CanCreateActionWithComplexReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration createAddress   = builder.Action("CreateAddress").Returns <Address>();
            ActionConfiguration createAddresses = builder.Action("CreateAddresses").ReturnsCollection <Address>();

            // Assert
            ComplexTypeConfiguration address = createAddress.ReturnType as ComplexTypeConfiguration;

            Assert.NotNull(address);
            Assert.Equal(typeof(Address).FullName, address.FullName);
            Assert.Null(createAddress.NavigationSource);

            CollectionTypeConfiguration addresses = createAddresses.ReturnType as CollectionTypeConfiguration;

            Assert.NotNull(addresses);
            Assert.Equal(string.Format("Collection({0})", typeof(Address).FullName), addresses.FullName);
            address = addresses.ElementType as ComplexTypeConfiguration;
            Assert.NotNull(address);
            Assert.Equal(typeof(Address).FullName, address.FullName);
            Assert.Null(createAddresses.NavigationSource);
        }
        public void CanCreateActionWithNoArguments()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.Namespace     = "MyNamespace";
            builder.ContainerName = "MyContainer";
            ActionConfiguration action   = builder.Action("Format");
            ActionConfiguration actionII = builder.Action("FormatII");

            actionII.Namespace = "MyNamespaceII";

            // Assert
            Assert.Equal("Format", action.Name);
            Assert.Equal(OperationKind.Action, action.Kind);
            Assert.NotNull(action.Parameters);
            Assert.Empty(action.Parameters);
            Assert.Null(action.ReturnType);
            Assert.True(action.IsSideEffecting);
            Assert.False(action.IsComposable);
            Assert.False(action.IsBindable);
            Assert.Equal("MyNamespace", action.Namespace);
            Assert.Equal("MyNamespace.Format", action.FullyQualifiedName);
            Assert.Equal("MyNamespaceII", actionII.Namespace);
            Assert.Equal("MyNamespaceII.FormatII", actionII.FullyQualifiedName);
            Assert.NotNull(builder.Operations);
            Assert.Equal(2, builder.Operations.Count());
        }
        public void CanCreateActionWithNoArguments()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            builder.Namespace = "MyNamespace";
            builder.ContainerName = "MyContainer";
            ActionConfiguration action = builder.Action("Format");
            ActionConfiguration actionII = builder.Action("FormatII");
            actionII.Namespace = "MyNamespaceII";

            // Assert
            Assert.Equal("Format", action.Name);
            Assert.Equal(ProcedureKind.Action, action.Kind);
            Assert.NotNull(action.Parameters);
            Assert.Empty(action.Parameters);
            Assert.Null(action.ReturnType);
            Assert.True(action.IsSideEffecting);
            Assert.False(action.IsComposable);
            Assert.False(action.IsBindable);
            Assert.Equal("MyNamespace", action.Namespace);
            Assert.Equal("MyNamespace.Format", action.FullyQualifiedName);
            Assert.Equal("MyNamespaceII", actionII.Namespace);
            Assert.Equal("MyNamespaceII.FormatII", actionII.FullyQualifiedName);
            Assert.NotNull(builder.Procedures);
            Assert.Equal(2, builder.Procedures.Count());
        }
        public void CanCreateActionWithEntityReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration createGoodCustomer = builder.Action("CreateGoodCustomer").ReturnsFromEntitySet <Customer>("GoodCustomers");
            ActionConfiguration createBadCustomers = builder.Action("CreateBadCustomers").ReturnsCollectionFromEntitySet <Customer>("BadCustomers");

            // Assert
            EntityTypeConfiguration customer = createGoodCustomer.ReturnType as EntityTypeConfiguration;

            Assert.NotNull(customer);
            Assert.Equal(typeof(Customer).FullName, customer.FullName);
            EntitySetConfiguration goodCustomers = builder.EntitySets.SingleOrDefault(s => s.Name == "GoodCustomers");

            Assert.NotNull(goodCustomers);
            Assert.Same(createGoodCustomer.NavigationSource, goodCustomers);

            CollectionTypeConfiguration customers = createBadCustomers.ReturnType as CollectionTypeConfiguration;

            Assert.NotNull(customers);
            customer = customers.ElementType as EntityTypeConfiguration;
            Assert.NotNull(customer);
            EntitySetConfiguration badCustomers = builder.EntitySets.SingleOrDefault(s => s.Name == "BadCustomers");

            Assert.NotNull(badCustomers);
            Assert.Same(createBadCustomers.NavigationSource, badCustomers);
        }
        private static IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            builder
            .Entity <Vehicle>()
            .HasKey(v => v.Name)
            .HasKey(v => v.Model)
            .Property(v => v.WheelCount);

            builder
            .Entity <Motorcycle>()
            .DerivesFrom <Vehicle>()
            .Property(m => m.CanDoAWheelie);

            builder
            .Entity <Car>()
            .DerivesFrom <Vehicle>()
            .Property(c => c.SeatingCapacity);

            builder.EntitySet <Vehicle>("vehicles").HasIdLink(
                (v) => "http://localhost/vehicles/" + v.GetPropertyValue("Name"), followsConventions: false);
            builder.EntitySet <Motorcycle>("motorcycles").HasIdLink(
                (m) => "http://localhost/motorcycles/" + m.GetPropertyValue("Name"), followsConventions: false);
            builder.EntitySet <Car>("cars");

            builder
            .Action("GetCarAsVehicle")
            .ReturnsFromEntitySet <Vehicle>("vehicles");
            builder
            .Action("GetMotorcycleAsVehicle")
            .ReturnsFromEntitySet <Vehicle>("vehicles");
            builder
            .Action("GetSportBikeAsVehicle")
            .ReturnsFromEntitySet <Vehicle>("vehicles");
            builder
            .Action("GetVehicles")
            .ReturnsFromEntitySet <Vehicle>("vehicles");

            builder
            .Action("PatchMotorcycle_When_Expecting_Motorcycle")
            .ReturnsFromEntitySet <Motorcycle>("motorcycles");
            builder
            .Action("PostMotorcycle_When_Expecting_Motorcycle")
            .ReturnsFromEntitySet <Motorcycle>("motorcycles");
            builder
            .Action("PatchMotorcycle_When_Expecting_Vehicle")
            .ReturnsFromEntitySet <Vehicle>("vehicles");
            builder
            .Action("PostMotorcycle_When_Expecting_Vehicle")
            .ReturnsFromEntitySet <Vehicle>("vehicles");
            builder
            .Action("PostMotorcycle_When_Expecting_Car")
            .ReturnsFromEntitySet <Car>("cars");
            builder
            .Action("PatchMotorcycle_When_Expecting_Car")
            .ReturnsFromEntitySet <Car>("cars");

            return(builder.GetEdmModel());
        }
        public void CanBuildBoundProcedureCacheForIEdmModel()
        {
            // Arrange            
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration<Customer> customer = builder.EntitySet<Customer>("Customers").EntityType;
            customer.HasKey(c => c.ID);
            customer.Property(c => c.Name);
            customer.ComplexProperty(c => c.Address);

            EntityTypeConfiguration<Movie> movie = builder.EntitySet<Movie>("Movies").EntityType;
            movie.HasKey(m => m.ID);
            movie.HasKey(m => m.Name);
            EntityTypeConfiguration<Blockbuster> blockBuster = builder.Entity<Blockbuster>().DerivesFrom<Movie>();
            EntityTypeConfiguration movieConfiguration = builder.StructuralTypes.OfType<EntityTypeConfiguration>().Single(t => t.Name == "Movie");

            // build actions that are bindable to a single entity
            customer.Action("InCache1_CustomerAction");
            customer.Action("InCache2_CustomerAction");
            movie.Action("InCache3_MovieAction");
            ActionConfiguration incache4_MovieAction = builder.Action("InCache4_MovieAction");
            incache4_MovieAction.SetBindingParameter("bindingParameter", movieConfiguration, true);
            blockBuster.Action("InCache5_BlockbusterAction");

            // build actions that are either: bindable to a collection of entities, have no parameter, have only complex parameter 
            customer.Collection.Action("NotInCache1_CustomersAction");
            movie.Collection.Action("NotInCache2_MoviesAction");
            ActionConfiguration notInCache3_NoParameters = builder.Action("NotInCache3_NoParameters");
            ActionConfiguration notInCache4_AddressParameter = builder.Action("NotInCache4_AddressParameter");
            notInCache4_AddressParameter.Parameter<Address>("address");

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Customer");
            IEdmEntityType movieType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Movie");
            IEdmEntityType blockBusterType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Blockbuster");

            // Act 
            BindableProcedureFinder annotation = new BindableProcedureFinder(model);
            IEdmAction[] movieActions = annotation.FindProcedures(movieType)
                .OfType<IEdmAction>()
                .ToArray();
            IEdmAction[] customerActions = annotation.FindProcedures(customerType)
                .OfType<IEdmAction>()
                .ToArray();
            IEdmAction[] blockBusterActions = annotation.FindProcedures(blockBusterType)
                .OfType<IEdmAction>()
                .ToArray();

            // Assert
            Assert.Equal(2, customerActions.Length);
            Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache1_CustomerAction"));
            Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache2_CustomerAction"));
            Assert.Equal(2, movieActions.Length);
            Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction"));
            Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction"));
            Assert.Equal(3, blockBusterActions.Length);
            Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction"));
            Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction"));
            Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache5_BlockbusterAction"));
        }
Beispiel #7
0
        private static void AddUnboundActionsAndFunctions(ODataModelBuilder odataModelBuilder)
        {
            odataModelBuilder.Action("ResetDataSource");

            ActionConfiguration udpateAddress = odataModelBuilder.Action("UpdateAddressAction");

            udpateAddress.Parameter <Address>("Address");
            udpateAddress.Parameter <int>("ID");
            udpateAddress.Returns <Address>();
        }
 public UnboundActionPathSegmentTest()
 {
     ODataModelBuilder builder = new ODataModelBuilder();
     builder.EntityType<MyCustomer>().HasKey(c => c.Id).Property(c => c.Name);
     builder.EntitySet<MyCustomer>("Customers");
     ActionConfiguration action = builder.Action("CreateCustomer");
     action.ReturnsFromEntitySet<MyCustomer>("Customers");
     builder.Action("MyAction").Returns<string>();
     builder.Action("ActionWithoutReturn");
     _model = builder.GetEdmModel();
     _container = _model.EntityContainers().Single();
 }
        public void GetEdmModel_ThrowsException_WhenUnboundActionOverloaded()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.Action("ActionName").Parameter <int>("Param1");
            builder.Action("ActionName").Returns <string>();

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => builder.GetEdmModel(),
                                                               "Found more than one unbound action with name 'ActionName'. " +
                                                               "Each unbound action must have an unique action name.");
        }
Beispiel #10
0
        public UnboundActionPathSegmentTest()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <MyCustomer>().HasKey(c => c.Id).Property(c => c.Name);
            builder.EntitySet <MyCustomer>("Customers");
            ActionConfiguration action = builder.Action("CreateCustomer");

            action.ReturnsFromEntitySet <MyCustomer>("Customers");
            builder.Action("MyAction").Returns <string>();
            builder.Action("ActionWithoutReturn");
            _model     = builder.GetEdmModel();
            _container = _model.EntityContainer;
        }
        public void RemoveProcedureByNameThrowsWhenAmbiguous()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration action1 = builder.Action("Format");
            ActionConfiguration action2 = builder.Action("Format");
            action2.Parameter<int>("SegmentSize");

            Assert.Throws<InvalidOperationException>(() =>
            {
                builder.RemoveProcedure("Format");
            });
        }
        public void RemoveOperationByNameThrowsWhenAmbiguous()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration action1 = builder.Action("Format");
            ActionConfiguration action2 = builder.Action("Format");

            action2.Parameter <int>("SegmentSize");

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                builder.RemoveOperation("Format");
            });
        }
        public void AnnotationsAreAddedToModelOnBuild()
        {
            var modelBuilder        = new ODataModelBuilder();
            var actionConfiguration = modelBuilder.Action("MyAction");

            var operationRestrictionsBuilder = actionConfiguration
                                               .HasOperationRestrictions()
                                               .IsFilterSegmentSupported(true);

            var model  = modelBuilder.GetServiceModel();
            var action = model.SchemaElements.OfType <IEdmAction>().Single();

            var term       = model.FindTerm("Org.OData.Capabilities.V1.OperationRestrictions");
            var annotation = action.VocabularyAnnotations(model).FirstOrDefault(a => a.Term == term);

            Assert.NotNull(annotation);

            var annotationValue = annotation.Value as EdmRecordExpression;

            Assert.NotNull(annotationValue);

            var filterSegmentSupportedValue = GetRecordValue <EdmBooleanConstant>(annotationValue, "FilterSegmentSupported");

            Assert.True(filterSegmentSupportedValue.Value);
        }
Beispiel #14
0
        public ActionConfiguration Action(string name)
        {
            var action = Builder.Action(name);

            action.Namespace = Namespace;
            return(action);
        }
Beispiel #15
0
        private static void AddUnboundActionsAndFunctions(ODataModelBuilder odataModelBuilder)
        {
            var actionConfiguration = odataModelBuilder.Action("SetAccessLevel");

            actionConfiguration.Parameter <int>("ID");
            actionConfiguration.Parameter <AccessLevel>("accessLevel");
            actionConfiguration.Returns <AccessLevel>();

            var functionConfiguration = odataModelBuilder.Function("HasAccessLevel");

            functionConfiguration.Parameter <int>("ID");
            functionConfiguration.Parameter <AccessLevel>("AccessLevel");
            functionConfiguration.Returns <bool>();

            var actionConfiguration2 = odataModelBuilder.Action("ResetDataSource");
        }
        public void CanCreateEdmModel_WithNonBindableAction()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            // Act
            ActionConfiguration actionConfiguration = builder.Action("ActionName");

            actionConfiguration.ReturnsFromEntitySet <Customer>("Customers");

            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityContainer container = model.EntityContainer;

            Assert.NotNull(container);
            Assert.Single(container.Elements.OfType <IEdmActionImport>());
            Assert.Single(container.Elements.OfType <IEdmEntitySet>());
            IEdmActionImport action = container.Elements.OfType <IEdmActionImport>().Single();

            Assert.False(action.Action.IsBound);
            Assert.Equal("ActionName", action.Name);
            Assert.NotNull(action.Action.ReturnType);
            Assert.NotNull(action.EntitySet);
            Assert.Equal("Customers", (action.EntitySet as IEdmPathExpression).Path);
            Assert.Empty(action.Action.Parameters);
        }
        public void PermissionsCanBeAddedToOperation()
        {
            var modelBuilder        = new ODataModelBuilder();
            var actionConfiguration = modelBuilder.Action("MyAction");

            var operationRestrictionsBuilder = actionConfiguration
                                               .HasOperationRestrictions()
                                               .IsFilterSegmentSupported(true)
                                               .HasPermissions(
                new PermissionTypeConfiguration()
                .HasSchemeName(SchemeName)
                .HasScopes(
                    new ScopeTypeConfiguration()
                    .HasScope(CustomerReadWriteAllScope)
                    .HasRestrictedProperties("*")));

            var model  = modelBuilder.GetServiceModel();
            var action = model.SchemaElements.OfType <IEdmAction>().Single();

            var term       = model.FindTerm("Org.OData.Capabilities.V1.OperationRestrictions");
            var annotation = action.VocabularyAnnotations(model).FirstOrDefault(a => a.Term == term);

            Assert.NotNull(annotation);

            var annotationValue = annotation.Value as EdmRecordExpression;

            Assert.NotNull(annotationValue);

            var permissionsCollection = GetRecordValue <EdmCollectionExpression>(annotationValue, "Permissions");

            Assert.NotNull(permissionsCollection);

            var singlePermission = Assert.Single(permissionsCollection.Elements) as EdmRecordExpression;

            Assert.NotNull(singlePermission);

            var schemeNameValue = GetRecordValue <EdmStringConstant>(singlePermission, "SchemeName");

            Assert.NotNull(schemeNameValue);

            Assert.Equal(SchemeName, schemeNameValue.Value);

            var scopesProperty = GetRecordValue <EdmCollectionExpression>(singlePermission, "Scopes");

            Assert.NotNull(scopesProperty);

            var singleScope = Assert.Single(scopesProperty.Elements) as EdmRecordExpression;

            Assert.NotNull(singleScope);

            var scopeValue = GetRecordValue <EdmStringConstant>(singleScope, "Scope");

            Assert.Equal(CustomerReadWriteAllScope, scopeValue.Value);

            var restrictedPropertiesValue = GetRecordValue <EdmStringConstant>(singleScope, "RestrictedProperties");

            Assert.Equal("*", restrictedPropertiesValue.Value);
        }
        public void CanCreateActionWithReturnTypeAsNullableByDefault()
        {
            // Arrange & Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction").Returns <Address>();

            // Assert
            Assert.True(action.ReturnNullable);
        }
        public void ReturnsCollectionFromEntitySet_ThrowsArgumentNull_EntitySetConfiguration()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var action = builder.Action("action");

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => action.ReturnsCollectionFromEntitySet <Movie>(entitySetConfiguration: null),
                                               "entitySetConfiguration");
        }
        private static void BuildActions(ODataModelBuilder builder)
        {
            ActionConfiguration action = builder.EntityType <DCustomer>().Action("BoundAction");

            action.Parameter <Date>("modifiedDate");
            action.Parameter <TimeOfDay>("modifiedTime");
            action.Parameter <Date?>("nullableModifiedDate");
            action.Parameter <TimeOfDay?>("nullableModifiedTime");
            action.CollectionParameter <Date>("dates");

            action = builder.Action("UnboundAction");
            action.Parameter <Date>("modifiedDate");
            action.Parameter <TimeOfDay>("modifiedTime");
            action.Parameter <Date?>("nullableModifiedDate");
            action.Parameter <TimeOfDay?>("nullableModifiedTime");
            action.CollectionParameter <Date>("dates");

            // just for reset the data source
            builder.Action("ResetDataSource");
        }
        public void CanRemoveOperationByName()
        {
            // Arrange
            // Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("Format");
            bool removed = builder.RemoveOperation("Format");

            // Assert
            Assert.Empty(builder.Operations);
        }
        public void CanRemoveProcedureByName()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("Format");
            bool removed = builder.RemoveProcedure("Format");

            // Assert      
            Assert.Equal(0, builder.Procedures.Count());
        }
Beispiel #23
0
        public void CanCreateActionWithReturnTypeAsNullableByOptionalReturn()
        {
            // Arrange & Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction").Returns <Address>();

            action.OptionalReturn = false;

            // Assert
            Assert.False(action.OptionalReturn);
        }
        public void OperationRestrictionsChainsToSameInstance()
        {
            // Arrange
            var modelBuilder        = new ODataModelBuilder();
            var actionConfiguration = modelBuilder.Action("MyAction");

            var builder1 = actionConfiguration.HasOperationRestrictions();
            var builder2 = builder1.IsFilterSegmentSupported(false);

            Assert.Same(builder1, builder2);
        }
        public void CanCreateActionWithPrimitiveCollectionReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("CreateMessages");
            action.ReturnsCollection<string>();

            // Assert
            Assert.NotNull(action.ReturnType);
            Assert.Equal("Collection(Edm.String)", action.ReturnType.FullName);
        }
        public void HasFeedActionLink_ThrowsException_OnNonBindableActions()
        {
            // Arrange
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("NoBindableAction");

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(
                () => action.HasFeedActionLink(ctx => new Uri("http://any"), followsConventions: false),
                "To register an action link factory, actions must be bindable to the collection of entity. " +
                "Action 'NoBindableAction' 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
            ExceptionAssert.Throws <InvalidOperationException>(() => action.ReturnsCollection <Movie>(),
                                                               "The EDM type 'Microsoft.AspNet.OData.Test.Builder.Movie' is already declared as an entity type. Use the " +
                                                               "method 'ReturnsCollectionFromEntitySet' if the return type is an entity collection.");
        }
        public void CanRemoveProcedure()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("Format");
            ProcedureConfiguration procedure = builder.Procedures.SingleOrDefault();
            bool removed = builder.RemoveProcedure(procedure);

            // Assert
            Assert.True(removed);
            Assert.Equal(0, builder.Procedures.Count());
        }
        public void CanCreateActionWithPrimitiveCollectionReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("CreateMessages");

            action.ReturnsCollection <string>();

            // Assert
            Assert.NotNull(action.ReturnType);
            Assert.Equal("Collection(Edm.String)", action.ReturnType.FullName);
        }
        public void CanRemoveOperation()
        {
            // Arrange
            // Act
            ODataModelBuilder      builder   = new ODataModelBuilder();
            ActionConfiguration    action    = builder.Action("Format");
            OperationConfiguration operation = builder.Operations.SingleOrDefault();
            bool removed = builder.RemoveOperation(operation);

            // Assert
            Assert.True(removed);
            Assert.Empty(builder.Operations);
        }
Beispiel #31
0
        private static IEdmModel CreateModel()
        {
            var builder = new ODataModelBuilder();

            builder.Namespace = "HS";

            var personType = builder.EntityType <Person>()
                             .HasKey(p => p.Id);

            personType.Property(p => p.Name);
            personType.Property(p => p.Age);
            personType.OrderBy().Select().Filter().Expand().Count();

            personType.Action("Mark").Parameter <string>("comment");

            // Entity Function
            var function = personType
                           .Function("ToLongString");

            function.Parameter <string>("prefix");
            function.Returns <string>();

            // Collection Functions
            var allAdultsFunction = personType
                                    .Collection
                                    .Function("AllAdults");

            allAdultsFunction.ReturnsCollectionFromEntitySet <Person>("Persons");

            var allChildrenFunction = personType
                                      .Collection
                                      .Function("AllChildren");

            allChildrenFunction.ReturnsCollectionFromEntitySet <Person>("Persons");

            // Unbound Function
            var addFunction = builder.Function("Add");

            addFunction.Parameter <int>("z1");
            addFunction.Parameter <int>("z2");
            addFunction.Returns <int>();

            // Unbound Action
            var clearAction = builder.Action("ClearLoggingTable");

            clearAction.Parameter <int>("days");

            builder.EntitySet <Person>("Persons");

            return(builder.GetEdmModel());
        }
        public void Parameter_ThrowsInvalidOperationIfGenericArgumentIsDateTime(Type type)
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("Format");
            MethodInfo method = typeof(ActionConfiguration)
                .GetMethod("Parameter", new[] { typeof(string) })
                .MakeGenericMethod(type);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                () => method.Invoke(action, new[] { "test" }),
                string.Format("The type '{0}' is not a supported parameter type for the parameter test.", type.FullName));
        }
Beispiel #33
0
        private static void AddUnboundActionsAndFunctions(ODataModelBuilder odataModelBuilder)
        {
            var actionConfiguration = odataModelBuilder.Action("SetAccessLevel");
            actionConfiguration.Parameter<int>("ID");
            actionConfiguration.Parameter<AccessLevel>("accessLevel");
            actionConfiguration.Returns<AccessLevel>();

            var functionConfiguration = odataModelBuilder.Function("HasAccessLevel");
            functionConfiguration.Parameter<int>("ID");
            functionConfiguration.Parameter<AccessLevel>("AccessLevel");
            functionConfiguration.Returns<bool>();

            var actionConfiguration2 = odataModelBuilder.Action("ResetDataSource");
        }
        public void GetEdmModel_CreatesOperationImports_For_UnboundedOperations()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.Function("Function").Returns <bool>();
            builder.Action("Action").Returns <bool>();

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            Assert.Equal(2, model.EntityContainer.OperationImports().Count());
        }
        public void ReturnsCollectionFromEntitySet_Sets_EntitySetAndReturnType()
        {
            // Arrange
            string            entitySetName = "movies";
            ODataModelBuilder builder       = new ODataModelBuilder();
            var movies = builder.EntitySet <Movie>(entitySetName);
            var action = builder.Action("Action");

            // Act
            action.ReturnsCollectionFromEntitySet(movies);

            // Assert
            Assert.Equal(entitySetName, action.NavigationSource.Name);
            Assert.Equal(typeof(IEnumerable <Movie>), action.ReturnType.ClrType);
        }
        public void AttemptToRemoveNonExistantEntityReturnsFalse()
        {
            // Arrange
            ODataModelBuilder      builder  = new ODataModelBuilder();
            ODataModelBuilder      builder2 = new ODataModelBuilder();
            OperationConfiguration toRemove = builder2.Action("ToRemove");

            // Act
            bool removedByName = builder.RemoveOperation("ToRemove");
            bool removed       = builder.RemoveOperation(toRemove);

            //Assert
            Assert.False(removedByName);
            Assert.False(removed);
        }
        public void AttemptToRemoveNonExistantEntityReturnsFalse()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            ODataModelBuilder builder2 = new ODataModelBuilder();
            ProcedureConfiguration toRemove = builder2.Action("ToRemove");

            // Act
            bool removedByName = builder.RemoveProcedure("ToRemove");
            bool removed = builder.RemoveProcedure(toRemove);

            //Assert
            Assert.False(removedByName);
            Assert.False(removed);
        }
        public void CanCreateActionWithNonbindingParameters()
        {
            // Arrange
            // Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction");

            action.Parameter <string>("p0");
            action.Parameter <int>("p1");
            action.Parameter <Address>("p2");
            action.CollectionParameter <string>("p3");
            action.CollectionParameter <int>("p4");
            action.CollectionParameter <ZipCode>("p5");
            action.EntityParameter <Customer>("p6");
            action.CollectionEntityParameter <Employee>("p7");
            ParameterConfiguration[]   parameters   = action.Parameters.ToArray();
            ComplexTypeConfiguration[] complexTypes = builder.StructuralTypes.OfType <ComplexTypeConfiguration>().ToArray();
            EntityTypeConfiguration[]  entityTypes  = builder.StructuralTypes.OfType <EntityTypeConfiguration>().ToArray();

            // Assert
            Assert.Equal(2, complexTypes.Length);
            Assert.Equal(typeof(Address).FullName, complexTypes[0].FullName);
            Assert.Equal(typeof(ZipCode).FullName, complexTypes[1].FullName);

            Assert.Equal(2, entityTypes.Length);
            Assert.Equal(typeof(Customer).FullName, entityTypes[0].FullName);
            Assert.Equal(typeof(Employee).FullName, entityTypes[1].FullName);

            Assert.Equal(8, parameters.Length);
            Assert.Equal("p0", parameters[0].Name);
            Assert.Equal("Edm.String", parameters[0].TypeConfiguration.FullName);
            Assert.Equal("p1", parameters[1].Name);
            Assert.Equal("Edm.Int32", parameters[1].TypeConfiguration.FullName);
            Assert.Equal("p2", parameters[2].Name);
            Assert.Equal(typeof(Address).FullName, parameters[2].TypeConfiguration.FullName);
            Assert.Equal("p3", parameters[3].Name);
            Assert.Equal("Collection(Edm.String)", parameters[3].TypeConfiguration.FullName);
            Assert.Equal("p4", parameters[4].Name);
            Assert.Equal("Collection(Edm.Int32)", parameters[4].TypeConfiguration.FullName);
            Assert.Equal("p5", parameters[5].Name);
            Assert.Equal(string.Format("Collection({0})", typeof(ZipCode).FullName), parameters[5].TypeConfiguration.FullName);

            Assert.Equal("p6", parameters[6].Name);
            Assert.Equal(typeof(Customer).FullName, parameters[6].TypeConfiguration.FullName);

            Assert.Equal("p7", parameters[7].Name);
            Assert.Equal(string.Format("Collection({0})", typeof(Employee).FullName), parameters[7].TypeConfiguration.FullName);
        }
        private static void AddBoundActionsAndFunctions(ODataModelBuilder builder)
        {
            var paymentInstrumentType = builder.EntityType<PaymentInstrument>();

            var actionConfiguration = paymentInstrumentType.Collection.Action("Clear");
            actionConfiguration.Parameter<string>("nameContains");
            actionConfiguration.Returns<int>();// deleted count

            // Bug 2021-Should support Action/Function returns contained entities.
            //paymentInstrumentType.Action("Duplicate").Returns<PaymentInstrument>();

            paymentInstrumentType.Action("Delete");

            var functionConfiguration = paymentInstrumentType.Collection.Function("GetCount");
            functionConfiguration.Parameter<string>("nameContains");
            functionConfiguration.Returns<int>();

            builder.Action("ResetDataSource");
        }
        private static void BuildActions(ODataModelBuilder builder)
        {
            ActionConfiguration action = builder.EntityType<DCustomer>().Action("BoundAction");
            action.Parameter<Date>("modifiedDate");
            action.Parameter<TimeOfDay>("modifiedTime");
            action.Parameter<Date?>("nullableModifiedDate");
            action.Parameter<TimeOfDay?>("nullableModifiedTime");
            action.CollectionParameter<Date>("dates");

            action = builder.Action("UnboundAction");
            action.Parameter<Date>("modifiedDate");
            action.Parameter<TimeOfDay>("modifiedTime");
            action.Parameter<Date?>("nullableModifiedDate");
            action.Parameter<TimeOfDay?>("nullableModifiedTime");
            action.CollectionParameter<Date>("dates");

            // just for reset the data source
            builder.Action("ResetDataSource");
        }
        public void Cant_SetActionTile_OnNonBindableActions()
        {
            // Arrange
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction");

            action.Returns <int>();
            action.Title = "My Action";

            // Act
            IEdmModel           model        = builder.GetEdmModel();
            IEdmOperationImport actionImport = model.EntityContainer.OperationImports().OfType <IEdmActionImport>().Single();

            Assert.NotNull(actionImport);
            OperationTitleAnnotation actionTitleAnnotation = model.GetOperationTitleAnnotation(actionImport.Operation);

            // Assert
            Assert.Null(actionTitleAnnotation);
        }
        public void CanCreateActionWithNonbindingParametersAsNullable()
        {
            // Arrange & Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction");

            action.Parameter <string>("p0");
            action.Parameter <string>("p1").Nullable = false;
            action.Parameter <int>("p2").Nullable    = true;
            action.Parameter <int>("p3");
            action.Parameter <Address>("p4");
            action.Parameter <Address>("p5").Nullable = false;

            action.CollectionParameter <ZipCode>("p6");
            action.CollectionParameter <ZipCode>("p7").Nullable = false;

            action.EntityParameter <Customer>("p8");
            action.EntityParameter <Customer>("p9").Nullable = false;

            action.CollectionEntityParameter <Customer>("p10");
            action.CollectionEntityParameter <Customer>("p11").Nullable = false;
            Dictionary <string, ParameterConfiguration> parameters = action.Parameters.ToDictionary(e => e.Name, e => e);

            // Assert
            Assert.True(parameters["p0"].Nullable);
            Assert.False(parameters["p1"].Nullable);

            Assert.True(parameters["p2"].Nullable);
            Assert.False(parameters["p3"].Nullable);

            Assert.True(parameters["p4"].Nullable);
            Assert.False(parameters["p5"].Nullable);

            Assert.True(parameters["p6"].Nullable);
            Assert.False(parameters["p7"].Nullable);

            Assert.True(parameters["p8"].Nullable);
            Assert.False(parameters["p9"].Nullable);

            Assert.True(parameters["p10"].Nullable);
            Assert.False(parameters["p11"].Nullable);
        }
 private static void BuildAction(ODataModelBuilder builder)
 {
     builder.Action("ResetDataSource");
     builder.Action("ResetDataSourceNonCacade");
 }
        public void ReturnsFromEntitySet_Sets_NavigationSourceAndReturnType()
        {
            // Arrange
            string entitySetName = "movies";
            ODataModelBuilder builder = new ODataModelBuilder();
            var movies = builder.EntitySet<Movie>(entitySetName);
            var action = builder.Action("Action");

            // Act
            action.ReturnsFromEntitySet(movies);

            // Assert
            Assert.Equal(entitySetName, action.NavigationSource.Name);
            Assert.Equal(typeof(Movie), action.ReturnType.ClrType);
        }
        public void CanCreateEdmModel_WithNonBindableAction()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            ActionConfiguration actionConfiguration = builder.Action("ActionName");
            actionConfiguration.ReturnsFromEntitySet<Customer>("Customers");

            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityContainer container = model.EntityContainers().SingleOrDefault();
            Assert.NotNull(container);
            Assert.Equal(1, container.Elements.OfType<IEdmActionImport>().Count());
            Assert.Equal(1, container.Elements.OfType<IEdmEntitySet>().Count());
            IEdmActionImport action = container.Elements.OfType<IEdmActionImport>().Single();
            Assert.False(action.Action.IsBound);
            Assert.False(model.IsAlwaysBindable(action.Action));
            Assert.Equal("ActionName", action.Name);
            Assert.NotNull(action.Action.ReturnType);
            Assert.NotNull(action.EntitySet);
            Assert.Equal("Customers", (action.EntitySet as IEdmEntitySetReferenceExpression).ReferencedEntitySet.Name);
            Assert.Equal(typeof(Customer).FullName, (action.EntitySet as IEdmEntitySetReferenceExpression).ReferencedEntitySet.ElementType.FullName());
            Assert.Empty(action.Action.Parameters);
        }
        private static IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            builder
                .Entity<Vehicle>()
                .HasKey(v => v.Name)
                .HasKey(v => v.Model)
                .Property(v => v.WheelCount);

            builder
                .Entity<Motorcycle>()
                .DerivesFrom<Vehicle>()
                .Property(m => m.CanDoAWheelie);

            builder
                .Entity<Car>()
                .DerivesFrom<Vehicle>()
                .Property(c => c.SeatingCapacity);

            builder.EntitySet<Vehicle>("vehicles").HasIdLink(
                (v) => "http://localhost/vehicles/" + v.GetPropertyValue("Name"), followsConventions: false);
            builder.EntitySet<Motorcycle>("motorcycles").HasIdLink(
                (m) => "http://localhost/motorcycles/" + m.GetPropertyValue("Name"), followsConventions: false);
            builder.EntitySet<Car>("cars");

            builder
                .Action("GetCarAsVehicle")
                .ReturnsFromEntitySet<Vehicle>("vehicles");
            builder
                .Action("GetMotorcycleAsVehicle")
                .ReturnsFromEntitySet<Vehicle>("vehicles");
            builder
                .Action("GetSportBikeAsVehicle")
                .ReturnsFromEntitySet<Vehicle>("vehicles");
            builder
                .Action("GetVehicles")
                .ReturnsFromEntitySet<Vehicle>("vehicles");

            builder
                .Action("PatchMotorcycle_When_Expecting_Motorcycle")
                .ReturnsFromEntitySet<Motorcycle>("motorcycles");
            builder
                .Action("PostMotorcycle_When_Expecting_Motorcycle")
                .ReturnsFromEntitySet<Motorcycle>("motorcycles");
            builder
                .Action("PatchMotorcycle_When_Expecting_Vehicle")
                .ReturnsFromEntitySet<Vehicle>("vehicles");
            builder
                .Action("PostMotorcycle_When_Expecting_Vehicle")
                .ReturnsFromEntitySet<Vehicle>("vehicles");
            builder
                .Action("PostMotorcycle_When_Expecting_Car")
                .ReturnsFromEntitySet<Car>("cars");
            builder
                .Action("PatchMotorcycle_When_Expecting_Car")
                .ReturnsFromEntitySet<Car>("cars");

            return builder.GetEdmModel();
        }
        public void GetEdmModel_ThrowsException_WhenUnboundActionOverloaded()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            builder.Action("ActionName").Parameter<int>("Param1");
            builder.Action("ActionName").Returns<string>();

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => builder.GetEdmModel(),
                "Found more than one unbound action with name 'ActionName'. " +
                "Each unbound action must have an unique action name.");
        }
        public void ReturnsCollectionFromEntitySet_Sets_EntitySetAndReturnType()
        {
            // Arrange
            string entitySetName = "movies";
            ODataModelBuilder builder = new ODataModelBuilder();
            var movies = builder.EntitySet<Movie>(entitySetName);
            var action = builder.Action("Action");

            // Act
            action.ReturnsCollectionFromEntitySet(movies);

            // Assert
            Assert.Equal(entitySetName, action.EntitySet.Name);
            Assert.Equal(typeof(IEnumerable<Movie>), action.ReturnType.ClrType);
        }
        public void CanCreateActionWithNonbindingParameters()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("MyAction");
            action.Parameter<string>("p0");
            action.Parameter<int>("p1");
            action.Parameter<Address>("p2");
            action.CollectionParameter<string>("p3");
            action.CollectionParameter<int>("p4");
            action.CollectionParameter<ZipCode>("p5");
            ParameterConfiguration[] parameters = action.Parameters.ToArray();
            ComplexTypeConfiguration[] complexTypes = builder.StructuralTypes.OfType<ComplexTypeConfiguration>().ToArray();

            // Assert
            Assert.Equal(2, complexTypes.Length);
            Assert.Equal(typeof(Address).FullName, complexTypes[0].FullName);
            Assert.Equal(typeof(ZipCode).FullName, complexTypes[1].FullName);
            Assert.Equal(6, parameters.Length);
            Assert.Equal("p0", parameters[0].Name);
            Assert.Equal("Edm.String", parameters[0].TypeConfiguration.FullName);
            Assert.Equal("p1", parameters[1].Name);
            Assert.Equal("Edm.Int32", parameters[1].TypeConfiguration.FullName);
            Assert.Equal("p2", parameters[2].Name);
            Assert.Equal(typeof(Address).FullName, parameters[2].TypeConfiguration.FullName);
            Assert.Equal("p3", parameters[3].Name);
            Assert.Equal("Collection(Edm.String)", parameters[3].TypeConfiguration.FullName);
            Assert.Equal("p4", parameters[4].Name);
            Assert.Equal("Collection(Edm.Int32)", parameters[4].TypeConfiguration.FullName);
            Assert.Equal("p5", parameters[5].Name);
            Assert.Equal(string.Format("Collection({0})", typeof(ZipCode).FullName), parameters[5].TypeConfiguration.FullName);
        }
        public void CanCreateActionWithNonbindingParameters_AddParameterNonGenericMethod()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("MyAction");
            action.Parameter(typeof(string), "p0");
            action.Parameter(typeof(int), "p1");
            action.Parameter(typeof(Address), "p2");
            ParameterConfiguration[] parameters = action.Parameters.ToArray();

            // Assert
            Assert.Equal(3, parameters.Length);
            Assert.Equal("p0", parameters[0].Name);
            Assert.Equal("Edm.String", parameters[0].TypeConfiguration.FullName);
            Assert.Equal("p1", parameters[1].Name);
            Assert.Equal("Edm.Int32", parameters[1].TypeConfiguration.FullName);
            Assert.Equal("p2", parameters[2].Name);
            Assert.Equal(typeof(Address).FullName, parameters[2].TypeConfiguration.FullName);
        }
        public void CanCreateActionWithReturnTypeAsNullableByOptionalReturn()
        {
            // Arrange & Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("MyAction").Returns<Address>();
            action.OptionalReturn = false;

            // Assert
            Assert.False(action.OptionalReturn);
        }
        public void Cant_SetActionTile_OnNonBindableActions()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("MyAction");
            action.Returns<int>();
            action.Title = "My Action";

            // Act
            IEdmModel model = builder.GetEdmModel();
            IEdmOperationImport actionImport = model.EntityContainers().First().OperationImports().OfType<IEdmActionImport>().Single();
            Assert.NotNull(actionImport);
            OperationTitleAnnotation actionTitleAnnotation = model.GetOperationTitleAnnotation(actionImport.Operation);
            
            // Assert
            Assert.Null(actionTitleAnnotation);
        }
        public void GetEdmModel_CreatesOperationImports_For_UnboundedOperations()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            builder.Function("Function").Returns<bool>();
            builder.Action("Action").Returns<bool>();

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            Assert.Equal(2, model.EntityContainer.OperationImports().Count());
        }
        public void HasFeedActionLink_ThrowsException_OnNonBindableActions()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("NoBindableAction");

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                () => action.HasFeedActionLink(ctx => new Uri("http://any"), followsConventions: false),
                "To register an action link factory, actions must be bindable to the collection of entity. " +
                "Action 'NoBindableAction' does not meet this requirement.");
        }
        public void CanCreateActionWithEntityReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration createGoodCustomer = builder.Action("CreateGoodCustomer").ReturnsFromEntitySet<Customer>("GoodCustomers");
            ActionConfiguration createBadCustomers = builder.Action("CreateBadCustomers").ReturnsCollectionFromEntitySet<Customer>("BadCustomers");

            // Assert
            EntityTypeConfiguration customer = createGoodCustomer.ReturnType as EntityTypeConfiguration;
            Assert.NotNull(customer);
            Assert.Equal(typeof(Customer).FullName, customer.FullName);
            EntitySetConfiguration goodCustomers = builder.EntitySets.SingleOrDefault(s => s.Name == "GoodCustomers");
            Assert.NotNull(goodCustomers);
            Assert.Same(createGoodCustomer.EntitySet, goodCustomers);

            CollectionTypeConfiguration customers = createBadCustomers.ReturnType as CollectionTypeConfiguration;
            Assert.NotNull(customers);
            customer = customers.ElementType as EntityTypeConfiguration;
            Assert.NotNull(customer);
            EntitySetConfiguration badCustomers = builder.EntitySets.SingleOrDefault(s => s.Name == "BadCustomers");
            Assert.NotNull(badCustomers);
            Assert.Same(createBadCustomers.EntitySet, badCustomers);
        }
        public void ReturnsCollectionFromEntitySet_ThrowsArgumentNull_EntitySetConfiguration()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var action = builder.Action("action");

            // Act & Assert
            Assert.ThrowsArgumentNull(() => action.ReturnsCollectionFromEntitySet<Movie>(entitySetConfiguration: null),
                "entitySetConfiguration");
        }
        public void CanCreateActionWithComplexReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration createAddress = builder.Action("CreateAddress").Returns<Address>();
            ActionConfiguration createAddresses = builder.Action("CreateAddresses").ReturnsCollection<Address>();

            // Assert
            ComplexTypeConfiguration address = createAddress.ReturnType as ComplexTypeConfiguration;
            Assert.NotNull(address);
            Assert.Equal(typeof(Address).FullName, address.FullName);
            Assert.Null(createAddress.EntitySet);

            CollectionTypeConfiguration addresses = createAddresses.ReturnType as CollectionTypeConfiguration;
            Assert.NotNull(addresses);
            Assert.Equal(string.Format("Collection({0})", typeof(Address).FullName), addresses.FullName);
            address = addresses.ElementType as ComplexTypeConfiguration;
            Assert.NotNull(address);
            Assert.Equal(typeof(Address).FullName, address.FullName);
            Assert.Null(createAddresses.EntitySet);
        }
        public void CanCreateActionWithNonbindingParametersAsNullable()
        {
            // Arrange & Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = builder.Action("MyAction");
            action.Parameter<string>("p0");
            action.Parameter<string>("p1").OptionalParameter = false;
            action.Parameter<int>("p2").OptionalParameter = true;
            action.Parameter<int>("p3");
            action.Parameter<Address>("p4");
            action.Parameter<Address>("p5").OptionalParameter = false;

            action.CollectionParameter<ZipCode>("p6");
            action.CollectionParameter<ZipCode>("p7").OptionalParameter = false;

            action.EntityParameter<Customer>("p8");
            action.EntityParameter<Customer>("p9").OptionalParameter = false;

            action.CollectionEntityParameter<Customer>("p10");
            action.CollectionEntityParameter<Customer>("p11").OptionalParameter = false;
            Dictionary<string, ParameterConfiguration> parameters = action.Parameters.ToDictionary(e => e.Name, e => e);

            // Assert
            Assert.True(parameters["p0"].OptionalParameter);
            Assert.False(parameters["p1"].OptionalParameter);

            Assert.True(parameters["p2"].OptionalParameter);
            Assert.False(parameters["p3"].OptionalParameter);

            Assert.True(parameters["p4"].OptionalParameter);
            Assert.False(parameters["p5"].OptionalParameter);

            Assert.True(parameters["p6"].OptionalParameter);
            Assert.False(parameters["p7"].OptionalParameter);

            Assert.True(parameters["p8"].OptionalParameter);
            Assert.False(parameters["p9"].OptionalParameter);

            Assert.True(parameters["p10"].OptionalParameter);
            Assert.False(parameters["p11"].OptionalParameter);
        }
Beispiel #59
0
        public void UnboundAction_ForEnumTypeInODataModelBuilder()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder().Add_Color_EnumType();
            ActionConfiguration actionConfiguration = builder.Action("UnboundAction");
            actionConfiguration.Parameter<Color>("Color");
            actionConfiguration.Returns<Color>();

            // Act & Assert
            IEdmModel model = builder.GetEdmModel();
            IEdmActionImport actionImport = model.EntityContainer.OperationImports().Single(o => o.Name == "UnboundAction") as IEdmActionImport;

            IEdmTypeReference color = actionImport.Action.Parameters.Single(p => p.Name == "Color").Type;
            IEdmTypeReference returnType = actionImport.Action.ReturnType;
            IEdmEnumType colorType = model.SchemaElements.OfType<IEdmEnumType>().Single(e => e.Name == "Color");

            Assert.False(color.IsNullable);
            Assert.Same(colorType, color.Definition);
            Assert.False(returnType.IsNullable);
            Assert.Same(colorType, returnType.Definition);
        }
        public void ReturnsCollection_ThrowsInvalidOperationException_IfReturnTypeIsEntity()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            builder.Entity<Movie>();
            var action = builder.Action("action");

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => action.ReturnsCollection<Movie>(),
                "The EDM type 'System.Web.OData.Builder.Movie' is already declared as an entity type. Use the " +
                "method 'ReturnsCollectionFromEntitySet' if the return type is an entity collection.");
        }