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 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 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 AccessingEntity_NonExistingProperty()
        {
            var model = new StubModel(
                m => m.EntitySet("catalogs", new List <Catalog1>().AsQueryable())
                );

            SegmentParser.parse("/catalogs(1)/Something", String.Empty, model);
        }
 public void AccessingEntityByKey_()
 {
     var model = new StubModel(
         m => m.EntitySet("catalogs", new List<Catalog1>().AsQueryable())
     );
     var segments = SegmentParser.parse("/catalogs(1)", String.Empty, model);
     Asserts.ExpectingSegmentsCount(segments, 1);
     Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);
 }
        public void AccessingEntityByKey_2()
        {
            var model = new StubModel(
                m => m.EntitySet("catalogs", new List <Catalog1>().AsQueryable())
                );
            var segments = SegmentParser.parse("/catalogs(10)", String.Empty, model);

            Asserts.ExpectingSegmentsCount(segments, 1);
            Asserts.IsEntityType(segments.ElementAt(0), Key: "10", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);
        }
 public void AccessingEntityAndPropValue_2()
 {
     var model = new StubModel(
         m => m.EntitySet("catalogs", new List<Catalog1>().AsQueryable())
     );
     var segments = SegmentParser.parse("/catalogs(1)/Name/$value", String.Empty, model);
     Asserts.ExpectingSegmentsCount(segments, 3);
     Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);
     Asserts.IsPropertySingle(segments.ElementAt(1), "Name");
     Asserts.IsMeta_Value(segments.ElementAt(2));
 }
        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 AccessingEntityAndPropValue_2()
        {
            var model = new StubModel(
                m => m.EntitySet("catalogs", new List <Catalog1>().AsQueryable())
                );
            var segments = SegmentParser.parse("/catalogs(1)/Name/$value", String.Empty, model);

            Asserts.ExpectingSegmentsCount(segments, 3);
            Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);
            Asserts.IsPropertySingle(segments.ElementAt(1), "Name");
            Asserts.IsMeta_Value(segments.ElementAt(2));
        }
Esempio n. 10
0
        public void AccessingEntity_And_OneToManyRelationshipWithKey_()
        {
            var model = new StubModel(
                m =>
            {
                m.EntitySet("catalogs", new List <Catalog2>().AsQueryable());
                m.EntitySet("products", new List <Product2>().AsQueryable());
            });
            var segments = SegmentParser.parse("/catalogs(1)/Products(2)/", String.Empty, model);

            Asserts.ExpectingSegmentsCount(segments, 2);
            Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);
            Asserts.IsPropertySingle(segments.ElementAt(1), name: "Products", key: "2");
        }
        public void OnlyWritesEntitySets_()
        {
            var model = new StubModel(m =>
            {
                m.EntitySet("products", new List<Product2>().AsQueryable())
                    .AddAttribute(new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true));
                m.EntitySet("catalogs", new List<Catalog2>().AsQueryable());
                m.EntitySet("suppliers", new List<Supplier2>().AsQueryable());
            });
            var writer = new StringWriter();

            AtomServiceDocSerializer.serialize(writer, new Uri("http://localhost/app"),  new DataServiceMetadataProviderWrapper(model), Encoding.UTF8);

            Console.WriteLine(writer.GetStringBuilder().ToString());
        }
        public void OnlyWritesEntitySets_()
        {
            var model = new StubModel(m =>
            {
                m.EntitySet("products", new List <Product2>().AsQueryable())
                .AddAttribute(new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true));
                m.EntitySet("catalogs", new List <Catalog2>().AsQueryable());
                m.EntitySet("suppliers", new List <Supplier2>().AsQueryable());
            });
            var writer = new StringWriter();

            AtomServiceDocSerializer.serialize(writer, new Uri("http://localhost/app"), new DataServiceMetadataProviderWrapper(model), Encoding.UTF8);

            Console.WriteLine(writer.GetStringBuilder().ToString());
        }
        public void SimpleModel_()
        {
            var model = new StubModel(m => m.EntitySet("catalogs", new List<Catalog1>().AsQueryable()));
            var writer = new StringWriter();

            MetadataSerializer.serialize(writer, new DataServiceMetadataProviderWrapper(model), Encoding.UTF8);

            //			writer.GetStringBuilder().ToString().Should().Be(
            //@"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
            //<edmx:Edmx Version=""1.0"" xmlns:edmx=""http://schemas.microsoft.com/ado/2007/06/edmx"">
            //  <edmx:DataServices xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" m:DataServiceVersion=""2.0"" />
            //</edmx:Edmx>");

            Console.WriteLine(writer.GetStringBuilder().ToString());
        }
Esempio n. 14
0
        public void SimpleModel_()
        {
            var model  = new StubModel(m => m.EntitySet("catalogs", new List <Catalog1>().AsQueryable()));
            var writer = new StringWriter();

            MetadataSerializer.serialize(writer, new DataServiceMetadataProviderWrapper(model), Encoding.UTF8);

//			writer.GetStringBuilder().ToString().Should().Be(
//@"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
//<edmx:Edmx Version=""1.0"" xmlns:edmx=""http://schemas.microsoft.com/ado/2007/06/edmx"">
//  <edmx:DataServices xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" m:DataServiceVersion=""2.0"" />
//</edmx:Edmx>");

            Console.WriteLine(writer.GetStringBuilder().ToString());
        }
Esempio n. 15
0
        public void AccessingEntity_And_OneToManyRelationship_1()
        {
            var model = new StubModel(
                m =>
            {
                m.EntitySet("catalogs", new List <Catalog2>().AsQueryable());
                m.EntitySet("products", new List <Product2>().AsQueryable());
            });
            var segments = SegmentParser.parse("/catalogs(1)/Products/", String.Empty, model);

            Asserts.ExpectingSegmentsCount(segments, 2);
            Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);

            // Not sure which one this should be? Products or catalog?
            Asserts.IsPropertyCollection(segments.ElementAt(1), Name: "Products", resource: model.GetResourceType("products").Value);
        }
        public void EntityType_View_Atom_Atom_Success2()
        {
            var model = new StubModel(
                m =>
                {
                    m.EntitySet("catalogs", _catalog1Set);
                    m.EntitySet("products", _product1Set);
                    m.EntitySet("suppliers", _supplier1Set);
                });

            Process("/suppliers(1)/", SegmentOp.View, model);

            Console.WriteLine(_body.ToString());
            var entry = SyndicationItem.Load(XmlReader.Create(new StringReader(_body.ToString())));
            entry.Should().NotBeNull();

            _accessSingle.Should().HaveCount(1);
        }
Esempio n. 17
0
        public void EntityType_View_Atom_Atom_Success2()
        {
            var model = new StubModel(
                m =>
            {
                m.EntitySet("catalogs", _catalog1Set);
                m.EntitySet("products", _product1Set);
                m.EntitySet("suppliers", _supplier1Set);
            });

            Process("/suppliers(1)/", SegmentOp.View, model);

            Console.WriteLine(_body.ToString());
            var entry = SyndicationItem.Load(XmlReader.Create(new StringReader(_body.ToString())));

            entry.Should().NotBeNull();

            _accessSingle.Should().HaveCount(1);
        }
        public void EntitySet_WithPropMappingToTitle_View_Atom_Atom_Success()
        {
            var model = new StubModel(
                m =>
                {
                    m.EntitySet("catalogs", _catalog1Set).
                        AddAttribute(new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Xhtml, false));
                    m.EntitySet("products", _product1Set);
                    m.EntitySet("suppliers", _supplier1Set);
                });

            Process("/catalogs/", SegmentOp.View, model);

            // Console.WriteLine(_body.ToString());
            var feed = SyndicationFeed.Load(XmlReader.Create(new StringReader(_body.ToString())));
            feed.Items.Should().HaveCount(2);

            _accessMany.Should().HaveCount(1);
        }
        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 EntitySet_WithPropMappingToTitle_View_Atom_Atom_Success()
        {
            var model = new StubModel(
                m =>
            {
                m.EntitySet("catalogs", _catalog1Set).
                AddAttribute(new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Xhtml, false));
                m.EntitySet("products", _product1Set);
                m.EntitySet("suppliers", _supplier1Set);
            });

            Process("/catalogs/", SegmentOp.View, model);

            // Console.WriteLine(_body.ToString());
            var feed = SyndicationFeed.Load(XmlReader.Create(new StringReader(_body.ToString())));

            feed.Items.Should().HaveCount(2);

            _accessMany.Should().HaveCount(1);
        }
        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>();
        }
Esempio n. 23
0
        public void ModelWithRelationship_()
        {
            var model = new StubModel(m =>
            {
                m.EntitySet("products", new List <Product2>().AsQueryable())
                .AddAttribute(new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true));
                m.EntitySet("catalogs", new List <Catalog2>().AsQueryable());
                m.EntitySet("suppliers", new List <Supplier2>().AsQueryable());
            });
            var writer = new StringWriter();

            MetadataSerializer.serialize(writer, new DataServiceMetadataProviderWrapper(model), Encoding.UTF8);

//			writer.GetStringBuilder().ToString().Should().Be(
//@"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
//<edmx:Edmx Version=""1.0"" xmlns:edmx=""http://schemas.microsoft.com/ado/2007/06/edmx"">
//  <edmx:DataServices xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" m:DataServiceVersion=""2.0"" />
//</edmx:Edmx>");

            Console.WriteLine(writer.GetStringBuilder().ToString());
        }
        public void ModelWithRelationship_()
        {
            var model = new StubModel(m =>
            {
                m.EntitySet("products", new List<Product2>().AsQueryable())
                    .AddAttribute(new EntityPropertyMappingAttribute("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true));
                m.EntitySet("catalogs", new List<Catalog2>().AsQueryable());
                m.EntitySet("suppliers", new List<Supplier2>().AsQueryable());
            });
            var writer = new StringWriter();

            MetadataSerializer.serialize(writer, new DataServiceMetadataProviderWrapper(model), Encoding.UTF8);

            //			writer.GetStringBuilder().ToString().Should().Be(
            //@"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
            //<edmx:Edmx Version=""1.0"" xmlns:edmx=""http://schemas.microsoft.com/ado/2007/06/edmx"">
            //  <edmx:DataServices xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" m:DataServiceVersion=""2.0"" />
            //</edmx:Edmx>");

            Console.WriteLine(writer.GetStringBuilder().ToString());
        }
        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 Init()
        {
            _accessSingle = new List<Tuple<ResourceType, object>>();
            _accessMany = new List<Tuple<ResourceType, IEnumerable>>();
            _created = new List<Tuple<ResourceType, object>>();
            _updated = new List<Tuple<ResourceType, object>>();
            _removed = new List<Tuple<ResourceType, object>>();

            _product1Set = new List<Product1>
                           	{
                           		new Product1() { Id = 1, Name = "Product1" },
                                new Product1() { Id = 2, Name = "Product2" },
                           	}.AsQueryable();
            _catalog1Set = new List<Catalog1>
                           	{
                           		new Catalog1() { Id = 1, Name = "Cat1"},
                                new Catalog1() { Id = 2, Name = "Cat2" }
                           	}.AsQueryable();

            _supplier1Set = new List<Supplier1>
                            {
                                new Supplier1() { Id = 1, Address = new Address1() { Street = "wilson ave", Zip = "vxxxx", Country = "canada"} },
                                new Supplier1() { Id = 2, Address = new Address1() { Street = "kingsway ave", Zip = "zxxxx", Country = "canada"} },
                            }.AsQueryable();

            _catalog1Set.ElementAt(0).Products = new List<Product1>(_product1Set);
            _catalog1Set.ElementAt(1).Products = new List<Product1>(_product1Set);
            _product1Set.ElementAt(0).Catalog = _catalog1Set.ElementAt(0);
            _product1Set.ElementAt(1).Catalog = _catalog1Set.ElementAt(1);

            _model = new StubModel(
                m =>
                {
                    m.EntitySet("catalogs", _catalog1Set);
                    m.EntitySet("products", _product1Set);
                    m.EntitySet("suppliers", _supplier1Set);
                });

            _body = new StringBuilder();
        }
        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 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>();
        }
        public void TwoEntitiesRelatedByDirectResourceRef_CardinalityOne_BuildsTwoResources()
        {
            var model = new StubModel(t =>
            {
                t.EntitySet("product", new List<Product1>().AsQueryable());
                t.EntitySet("supplier", new List<Supplier1>().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 supplierProp = productRT.Properties.FirstOrDefault(p => p.Name == "Supplier");
            supplierProp.Should().NotBeNull();
            supplierProp.Kind.Should().Be(ResourcePropertyKind.ResourceReference);
            supplierProp.ResourceType.Should().BeSameAs(supplierRT);
        }
        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 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>();
        }
 public void AccessingEntity_NonExistingProperty()
 {
     var model = new StubModel(
         m => m.EntitySet("catalogs", new List<Catalog1>().AsQueryable())
     );
     SegmentParser.parse("/catalogs(1)/Something", String.Empty, model);
 }
        public void AccessingEntity_And_OneToManyRelationship_1()
        {
            var model = new StubModel(
                m =>
                    {
                        m.EntitySet("catalogs", new List<Catalog2>().AsQueryable());
                        m.EntitySet("products", new List<Product2>().AsQueryable());
                    });
            var segments = SegmentParser.parse("/catalogs(1)/Products/", String.Empty, model);
            Asserts.ExpectingSegmentsCount(segments, 2);
            Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);

            // Not sure which one this should be? Products or catalog?
            Asserts.IsPropertyCollection(segments.ElementAt(1), Name: "Products", resource: model.GetResourceType("products").Value);
        }
 public void AccessingEntity_And_OneToManyRelationshipWithKey_And_Property()
 {
     var model = new StubModel(
         m =>
         {
             m.EntitySet("catalogs", new List<Catalog2>().AsQueryable());
             m.EntitySet("products", new List<Product2>().AsQueryable());
         });
     var segments = SegmentParser.parse("/catalogs(1)/Products(2)/Name", String.Empty, model);
     Asserts.ExpectingSegmentsCount(segments, 3);
     Asserts.IsEntityType(segments.ElementAt(0), Key: "1", Name: "catalogs", resource: model.GetResourceType("catalogs").Value);
     Asserts.IsPropertySingle(segments.ElementAt(1), name: "Products", key: "2");
     Asserts.IsPropertySingle(segments.ElementAt(2), name: "Name");
 }
        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 Init()
        {
            _accessSingle = new List <Tuple <ResourceType, object> >();
            _accessMany   = new List <Tuple <ResourceType, IEnumerable> >();
            _created      = new List <Tuple <ResourceType, object> >();
            _updated      = new List <Tuple <ResourceType, object> >();
            _removed      = new List <Tuple <ResourceType, object> >();


            _product1Set = new List <Product1>
            {
                new Product1()
                {
                    Id = 1, Name = "Product1"
                },
                new Product1()
                {
                    Id = 2, Name = "Product2"
                },
            }.AsQueryable();
            _catalog1Set = new List <Catalog1>
            {
                new Catalog1()
                {
                    Id = 1, Name = "Cat1"
                },
                new Catalog1()
                {
                    Id = 2, Name = "Cat2"
                }
            }.AsQueryable();

            _supplier1Set = new List <Supplier1>
            {
                new Supplier1()
                {
                    Id = 1, Address = new Address1()
                    {
                        Street = "wilson ave", Zip = "vxxxx", Country = "canada"
                    }
                },
                new Supplier1()
                {
                    Id = 2, Address = new Address1()
                    {
                        Street = "kingsway ave", Zip = "zxxxx", Country = "canada"
                    }
                },
            }.AsQueryable();

            _catalog1Set.ElementAt(0).Products = new List <Product1>(_product1Set);
            _catalog1Set.ElementAt(1).Products = new List <Product1>(_product1Set);
            _product1Set.ElementAt(0).Catalog  = _catalog1Set.ElementAt(0);
            _product1Set.ElementAt(1).Catalog  = _catalog1Set.ElementAt(1);

            _model = new StubModel(
                m =>
            {
                m.EntitySet("catalogs", _catalog1Set);
                m.EntitySet("products", _product1Set);
                m.EntitySet("suppliers", _supplier1Set);
            });

            _body = new StringBuilder();
        }