Exemple #1
0
        public void ComplexValueTest()
        {
            EdmModel model = new EdmModel();

            var emptyComplexType = new EdmComplexType(DefaultNamespaceName, "EmptyComplexType");

            model.AddElement(emptyComplexType);

            var complexTypeWithStringProperty = new EdmComplexType(DefaultNamespaceName, "ComplexTypeWithStringProperty");

            complexTypeWithStringProperty.AddStructuralProperty("stringProperty", EdmCoreModel.Instance.GetString(isNullable: true));
            complexTypeWithStringProperty.AddStructuralProperty("numberProperty", EdmCoreModel.Instance.GetInt32(isNullable: false));
            model.AddElement(complexTypeWithStringProperty);

            model.Fixup();


            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Empty element is a valid complex value
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue("TestModel.EmptyComplexType")
                                     .XmlValueRepresentation(new XNode[0])
                                     .WithTypeAnnotation(emptyComplexType),
                    PayloadEdmModel = model
                },
            };

            testDescriptors = testDescriptors.Concat(
                PropertiesElementAtomValues.CreatePropertiesElementPaddingPayloads <ComplexInstance>(
                    new PayloadReaderTestDescriptor(this.Settings)
            {
                PayloadElement = PayloadBuilder.ComplexValue("TestModel.ComplexTypeWithStringProperty")
                                 .WithTypeAnnotation(complexTypeWithStringProperty),
                PayloadEdmModel = model
            },
                    (complexInstance, xmlValue) => complexInstance.XmlValueRepresentation(xmlValue)));

            testDescriptors = testDescriptors.Select(td => td.InProperty());

            testDescriptors = testDescriptors.Concat(new []
            {
                // Top-level property without expected type and no type name - this is read as primitive string!
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property(null, PayloadBuilder.PrimitiveValue(string.Empty))
                                     .XmlRepresentation("<m:value/>"),
                    PayloadEdmModel = model,
                },
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }
Exemple #2
0
        public void ComplexValuePropertyOrderingTest()
        {
            EdmModel model = new EdmModel();

            var complexType = new EdmComplexType(DefaultNamespaceName, "ComplexType");

            complexType.AddStructuralProperty("stringProperty", EdmCoreModel.Instance.GetString(isNullable: false));
            complexType.AddStructuralProperty("numberProperty", EdmCoreModel.Instance.GetInt32(isNullable: false));
            complexType.AddStructuralProperty("nullProperty", EdmCoreModel.Instance.GetString(isNullable: true));
            model.AddElement(complexType);

            model.Fixup();

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors =
                PropertiesElementAtomValues.CreatePropertiesElementOrderingPayloads <ComplexInstance>(
                    new PayloadReaderTestDescriptor(this.Settings)
            {
                PayloadElement  = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                PayloadEdmModel = model
            },
                    (complexInstance, xmlNodes) => complexInstance.XmlValueRepresentation(xmlNodes)).Select(td =>
                                                                                                            new PayloadReaderTestDescriptor(td)
            {
                PayloadElement = PayloadBuilder.Property(null, td.PayloadElement).ExpectedPropertyType(new EdmComplexTypeReference(complexType, isNullable: false)),
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }