예제 #1
0
        public void LocateTypes()
        {
            const string csdl =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""Grumble"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <EntityType Name=""Person"">
    <Key>
      <PropertyRef Name=""Id"" />
    </Key>
    <Property Name=""Id"" Type=""Int32"" Nullable=""false"" />
    <Property Name=""Address"" Type=""String"" MaxLength=""100"" />
  </EntityType>
  <ComplexType Name=""Smod"">
    <Property Name=""Id"" Type=""Edm.Int32"" />
    <Property Name=""Collection"" Type=""Collection(Edm.Int32)"" />
    <Property Name=""ref"" Type=""Ref(Grumble.Person)"" />
  </ComplexType>
</Schema>";
            IEdmModel model;
            IEnumerable <EdmError> error;
            bool parsed = SchemaReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(csdl)) }, out model, out error);

            Assert.IsTrue(parsed, "parsed");

            IEdmComplexType   complexType     = (IEdmComplexType)model.FindType("Grumble.Smod");
            IEdmTypeReference primitive       = complexType.FindProperty("Id").Type;
            IEdmTypeReference collection      = complexType.FindProperty("Collection").Type;
            IEdmTypeReference entityReference = complexType.FindProperty("ref").Type;

            AssertCorrectLocation((CsdlLocation)primitive.Location(), csdl, @"Property Name=""Id"" Type=""Edm.Int32"" ");
            AssertCorrectLocation((CsdlLocation)collection.Location(), csdl, @"Property Name=""Collection"" Type=""Collection(Edm.Int32)"" ");
            AssertCorrectLocation((CsdlLocation)entityReference.Location(), csdl, @"Property Name=""ref"" Type=""Ref(Grumble.Person)"" ");
        }
        public void CustomizedUriPathParserTest()
        {
            var container = ContainerBuilderHelper.BuildContainer(builder => builder.AddService <UriPathParser, MultipleSegmentUriPathParser>(ServiceLifetime.Scoped));
            Uri fullUri   = new Uri("https://serviceRoot/drives('b!3195njZm9ECS0rQfW5QyZ0iJh-jL7uZGn60CTehSbIwT3VAIax8sRKiyg_aD0HNV'):/items('01VL3Q7L36JOJUAPXGDNAZ4FVIGCTMLL46')/folder/childCount");
            var uriParser = new ODataUriParser(oneDriveModel, ServiceRoot, fullUri, container);

            var path = uriParser.ParsePath();

            var childCountProp = folderType.FindProperty("childCount");

            path.LastSegment.ShouldBePropertySegment(childCountProp);
        }
예제 #3
0
        public async Task CanRenamePropertiesInConventionModelBuilder()
        {
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, BaseAddress + "/convention/$metadata");
            HttpResponseMessage response = await Client.SendAsync(request);

            IEdmModel model = CsdlReader.Parse(XmlReader.Create(await response.Content.ReadAsStreamAsync()));
            // Can change the name of regular, complex and navigation properties.
            IEdmEntityType customer = model.FindDeclaredType("ModelAliasing.Customer") as IEdmEntityType;

            Assert.NotNull(customer);
            Assert.NotNull(customer.FindProperty("FinancialAddress"));
            Assert.NotNull(customer.FindProperty("ClientName"));
            Assert.NotNull(customer.FindProperty("Purchases"));
            // Can change the name of properties on complex objects
            IEdmComplexType address = model.FindDeclaredType("Location.Direction") as IEdmComplexType;

            Assert.NotNull(address);
            Assert.NotNull(address.FindProperty("Reign"));
            //Can change the name of properties on derived entities.
            IEdmEntityType expressOrder = model.FindDeclaredType("Purchasing.ExpressOrder") as IEdmEntityType;

            Assert.NotNull(expressOrder);
            //Can change the name of properties on derived entities when added explicitly.
            Assert.NotNull(expressOrder.FindProperty("Fee"));
            //Can change the name of properties on derived entities using data contract attribute.
            Assert.NotNull(expressOrder.FindProperty("DeliveryDate"));
            // Can change the name of the properties using DataContract attribute
            IEdmEntityType ordersLines = model.FindDeclaredType("Billing.OrderLine") as IEdmEntityType;

            Assert.NotNull(ordersLines);
            Assert.NotNull(ordersLines.FindProperty("Product"));
            // Data contract attribute override any explicit configuration on the model builder
            Assert.NotNull(ordersLines.FindProperty("Cost"));
        }
예제 #4
0
        public void CanRenamePropertiesInRegularModelBuilder()
        {
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, BaseAddress + "/explicit/$metadata");
            HttpResponseMessage response = Client.SendAsync(request).Result;
            IEdmModel           model    = CsdlReader.Parse(XmlReader.Create(response.Content.ReadAsStreamAsync().Result));
            // Can change the name of regular, complex and navigation properties.
            IEdmEntityType customer = model.FindDeclaredType("ModelAliasing.Customer") as IEdmEntityType;

            Assert.NotNull(customer);
            Assert.NotNull(customer.FindProperty("FinancialAddress"));
            Assert.NotNull(customer.FindProperty("ClientName"));
            Assert.NotNull(customer.FindProperty("Purchases"));
            // Can change the name of properties on complex objects
            IEdmComplexType address = model.FindDeclaredType("Location.Direction") as IEdmComplexType;

            Assert.NotNull(address);
            Assert.NotNull(address.FindProperty("Reign"));
            //Can change the name of properties on derived entities.
            IEdmEntityType expressOrder = model.FindDeclaredType("Purchasing.ExpressOrder") as IEdmEntityType;

            Assert.NotNull(expressOrder);
            //Can change the name of properties on derived entities when added explicitly.
            Assert.NotNull(expressOrder.FindProperty("Fee"));
            //Data contract attribute doesn't change the name of the property.
            Assert.Null(expressOrder.FindProperty("DeliveryDate"));
            Assert.Null(expressOrder.FindProperty("GuanteedDeliveryDate"));
            // Data contract attribute doesn't change the names of the properties
            IEdmEntityType ordersLines = model.FindDeclaredType("WebStack.QA.Test.OData.ModelAliasing.ModelAliasingMetadataOrderLine") as IEdmEntityType;

            Assert.NotNull(ordersLines);
            Assert.Null(ordersLines.FindProperty("Product"));
            Assert.NotNull(ordersLines.FindProperty("Item"));
            // Data contract attribute doesn't override any explicit configuration on the model builder
            Assert.NotNull(ordersLines.FindProperty("Cost"));
        }
예제 #5
0
        public void ReadPropertyArgumentTest()
        {
            IEdmEntityType      entityType  = null;
            IEdmComplexType     complexType = null;
            IEdmModel           model       = this.CreateTestMetadata(out entityType, out complexType);
            IEdmEntityContainer container   = model.FindEntityContainer("TestContainer");
            IEdmOperationImport entityValueFunctionImport           = container.FindOperationImports("EntityValueFunctionImport").Single();
            IEdmOperationImport entityCollectionValueFunctionImport = container.FindOperationImports("CollectionOfEntitiesFunctionImport").Single();

            IEdmStructuralProperty entityValueStructuralProperty           = (IEdmStructuralProperty)complexType.FindProperty("EntityProp");
            IEdmStructuralProperty entityCollectionValueStructuralProperty = (IEdmStructuralProperty)complexType.FindProperty("EntityCollectionProp");

            this.CombinatorialEngineProvider.RunCombinations(
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testConfiguration) =>
            {
                TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration);

                ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(new EdmComplexTypeReference(complexType, false)),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "expectedPropertyTypeReference"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(new EdmEntityTypeReference(entityType, false)),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)).ToTypeReference()),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityValueFunctionImport),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityCollectionValueFunctionImport),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityValueStructuralProperty),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityCollectionValueStructuralProperty),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"),
                    this.ExceptionVerifier);
            });
        }