public void ComplexType_()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("supplier", new List <Supplier4>().AsQueryable());
            });
            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            result.Count().Should().Be(2);

            var addressRT = result.FirstOrDefault(rt => rt.Name == "Address4");

            addressRT.Should().NotBeNull();
            addressRT.ResourceTypeKind.Should().Be(ResourceTypeKind.ComplexType);

            var supplierRT = result.FirstOrDefault(rt => rt.Name == "supplier");

            supplierRT.Should().NotBeNull();

            var productsProp = supplierRT.Properties.FirstOrDefault(p => p.Name == "Address");

            productsProp.Should().NotBeNull();
            productsProp.Kind.Should().Be(ResourcePropertyKind.ComplexType);
            productsProp.ResourceType.Should().BeSameAs(addressRT);
        }
        public void TwoEntitiesReferencingEachOther_CardinalityOneAndMany_BuildsTwoResources()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("product", new List <Product3>().AsQueryable());
                t.EntitySet("supplier", new List <Supplier3>().AsQueryable());
            });
            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            result.Count().Should().Be(2);

            var productRT = result.FirstOrDefault(rt => rt.Name == "product");

            productRT.Should().NotBeNull();
            var supplierRT = result.FirstOrDefault(rt => rt.Name == "supplier");

            supplierRT.Should().NotBeNull();

            var productsProp = supplierRT.Properties.FirstOrDefault(p => p.Name == "Products");

            productsProp.Should().NotBeNull();
            productsProp.Kind.Should().Be(ResourcePropertyKind.ResourceSetReference);
            productsProp.ResourceType.Should().BeSameAs(productRT);
        }
        public void TwoEntitiesNotRelated_BuildsTwoResources()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("name1", new List <EntWithKey>().AsQueryable());
                t.EntitySet("name2", new List <EntWithPropsKey>().AsQueryable());
            });
            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            result.Count().Should().Be(2);
        }
        public void SingleEntityWith0PropsWithKey_BuildsResource()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("name", new List <EntWithKey>().AsQueryable());
            });

            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            var resType = result.ElementAt(0);

            resType.Should().NotBeNull();
            resType.Name.Should().Be("name");
            resType.Namespace.Should().Be("TestNamespace");
            resType.ResourceTypeKind.Should().Be(ResourceTypeKind.EntityType);
            resType.Properties.Count.Should().Be(1);
            resType.Properties.ElementAt(0).Kind.Should().Be(ResourcePropertyKind.Primitive | ResourcePropertyKind.Key);
            resType.Properties.ElementAt(0).Name.Should().Be("Id");
        }
        public void SingleEntityWithPrimitivePropertiesAndAttributes_BuildsResource()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("name", new List <EntWithPropsKey>().AsQueryable()).AddAttribute(
                    new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true));
            });
            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            var resType = result.ElementAt(0);

            resType.Should().NotBeNull();
            resType.Name.Should().Be("name");
            resType.Namespace.Should().Be("TestNamespace");
            resType.ResourceTypeKind.Should().Be(ResourceTypeKind.EntityType);
            resType.Properties.Count.Should().Be(4);
            ;
            var d = resType.OwnEpmAttributes.Should().HaveCount(1);

            var id = resType.Properties.FirstOrDefault(p => p.Name == "Id");

            id.Kind.Should().Be(ResourcePropertyKind.Primitive | ResourcePropertyKind.Key);
            id.ResourceType.InstanceType.Should().Be <int>();

            var name = resType.Properties.FirstOrDefault(p => p.Name == "Name");

            name.Kind.Should().Be(ResourcePropertyKind.Primitive);
            name.ResourceType.InstanceType.Should().Be <string>();


            var age = resType.Properties.FirstOrDefault(p => p.Name == "Age");

            age.Kind.Should().Be(ResourcePropertyKind.Primitive);
            age.ResourceType.InstanceType.Should().Be <int>();

            var dob = resType.Properties.FirstOrDefault(p => p.Name == "DoB");

            dob.Kind.Should().Be(ResourcePropertyKind.Primitive);
            dob.ResourceType.InstanceType.Should().Be <DateTime>();
        }
        public void SingleEntityWithComplexTypeProperty_BuildsResource()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("name", new List <EntWithComplexPropKey>().AsQueryable());
            });
            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            var resType = result.ElementAt(0);

            resType.Should().NotBeNull();
            resType.Name.Should().Be("name");
            resType.Namespace.Should().Be("TestNamespace");
            resType.ResourceTypeKind.Should().Be(ResourceTypeKind.EntityType);
            resType.Properties.Count.Should().Be(2);

            var id = resType.Properties.FirstOrDefault(p => p.Name == "Id");

            id.Kind.Should().Be(ResourcePropertyKind.Primitive | ResourcePropertyKind.Key);
            id.ResourceType.InstanceType.Should().Be <int>();

            var address = resType.Properties.FirstOrDefault(p => p.Name == "AddressProp");

            address.Kind.Should().Be(ResourcePropertyKind.ComplexType);
            address.ResourceType.InstanceType.Should().Be <Address>();

            address.ResourceType.Properties.Count.Should().Be(2);
            var address1 = address.ResourceType.Properties.FirstOrDefault(p => p.Name == "Address1");

            address1.Should().NotBeNull();
            address1.Kind.Should().Be(ResourcePropertyKind.Primitive);
            address1.ResourceType.InstanceType.Should().Be <string>();

            var city = address.ResourceType.Properties.FirstOrDefault(p => p.Name == "City");

            city.Should().NotBeNull();
            city.Kind.Should().Be(ResourcePropertyKind.Primitive);
            city.ResourceType.InstanceType.Should().Be <string>();
        }
        public void SingleEntityWithPrimitiveProperties_BuildsResource()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("name", new List <EntWithPropsKey>().AsQueryable());
            });
            var result = ResourceMetadataBuilder.build(model.SchemaNamespace, model.Entities);

            result.Should().NotBeNull();
            var resType = result.ElementAt(0);

            resType.Should().NotBeNull();
            resType.Name.Should().Be("name");
            resType.Namespace.Should().Be("TestNamespace");
            resType.ResourceTypeKind.Should().Be(ResourceTypeKind.EntityType);
            resType.Properties.Count.Should().Be(4);

            var id = resType.Properties.FirstOrDefault(p => p.Name == "Id");

            id.Kind.Should().Be(ResourcePropertyKind.Primitive | ResourcePropertyKind.Key);
            id.ResourceType.InstanceType.Should().Be <int>();

            var name = resType.Properties.FirstOrDefault(p => p.Name == "Name");

            name.Kind.Should().Be(ResourcePropertyKind.Primitive);
            name.ResourceType.InstanceType.Should().Be <string>();

            var age = resType.Properties.FirstOrDefault(p => p.Name == "Age");

            age.Kind.Should().Be(ResourcePropertyKind.Primitive);
            age.ResourceType.InstanceType.Should().Be <int>();

            var dob = resType.Properties.FirstOrDefault(p => p.Name == "DoB");

            dob.Kind.Should().Be(ResourcePropertyKind.Primitive);
            dob.ResourceType.InstanceType.Should().Be <DateTime>();
        }