コード例 #1
0
        public void ReadEditLinkShouldBeOmittedWhenNeitherSetInAtom()
        {
            DateTimeOffset updatedTime = DateTimeOffset.UtcNow;
            var            entry       = new ODataEntry
            {
                Id = new Uri("http://test.org/EntitySet('1')")
            };

            entry.SetAnnotation(new AtomEntryMetadata()
            {
                Updated = updatedTime
            });
            string actual   = this.WriteAtomEntry(entry);
            string expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                              "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://temp.org/$metadata#EntitySet/$entity\">" +
                              "<id>http://test.org/EntitySet('1')</id>" +
                              "<title />" +
                              "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                              "<author>" +
                              "<name />" +
                              "</author>" +
                              "<content type=\"application/xml\" />" +
                              "</entry>";

            Assert.Equal(expected, actual);
        }
コード例 #2
0
        public void FlagsEnumAsEntityProperty_NullAsValue_NoTypeName()
        {
            DateTimeOffset updatedTime = DateTimeOffset.UtcNow;
            string         payload     = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                         "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\">" +
                                         "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                         "<id />" +
                                         "<title />" +
                                         "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                         "<author>" +
                                         "<name />" +
                                         "</author>" +
                                         "<content type=\"application/xml\">" +
                                         "<m:properties>" +
                                         "<d:Color m:null=\"true\" />" +
                                         "</m:properties>" +
                                         "</content>" +
                                         "</entry>";
            ODataEntry expectedEntry = new ODataEntry
            {
                TypeName   = "NS.MyEntityType",
                Properties = new[]
                {
                    new ODataProperty
                    {
                        Name  = "Color",
                        Value = null
                    }
                }
            };

            this.ReadEntryPayloadAndVerify(payload, expectedEntry);
        }
コード例 #3
0
        public void FlagsEnumAsEntityProperty_NullAsValue_ButNonNullable_GetNullError()
        {
            DateTimeOffset    updatedTime = DateTimeOffset.UtcNow;
            Func <ODataEntry> entryClone  = () =>
            {
                var tmp = new ODataEntry
                {
                    TypeName   = "NS.MyEntityType",
                    Properties = new[]
                    {
                        new ODataProperty
                        {
                            Name  = "ColorFlags",
                            Value = null
                        }
                    },
                    SerializationInfo = MySerializationInfo
                };

                tmp.SetAnnotation(new AtomEntryMetadata()
                {
                    Updated = updatedTime
                });
                return(tmp);
            };

            string fullName = this.entityType.FindProperty("ColorFlags").Type.FullName();

            // model-request
            Action action = () => this.WriteRequestWithModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: "");

            action.ShouldThrow <ODataException>().WithMessage(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue("ColorFlags", fullName));

            // model-reseponse
            action = () => this.WriteResponseWithModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: "");
            action.ShouldThrow <ODataException>().WithMessage(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue("ColorFlags", fullName));

            // NoModel-request
            string expectedPayload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                     "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " +
                                     "xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/test/$metadata#MySet/$entity\">" +
                                     "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                     "<id />" +
                                     "<title />" +
                                     "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                     "<author><name /></author>" +
                                     "<content type=\"application/xml\">" +
                                     "<m:properties>" +
                                     "<d:ColorFlags m:null=\"true\" />" +
                                     "</m:properties>" +
                                     "</content>" +
                                     "</entry>";

            this.WriteRequestWithoutModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // NoModel-response
            this.WriteResponseWithoutModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);
        }
コード例 #4
0
        public void FlagsEnumAsEntityProperty_StrAsValue_StrAsTypeName()
        {
            DateTimeOffset    updatedTime = DateTimeOffset.UtcNow;
            Func <ODataEntry> entryClone  = () =>
            {
                var tmp = new ODataEntry
                {
                    TypeName   = "NS.MyEntityType",
                    Properties = new[]
                    {
                        new ODataProperty
                        {
                            Name  = "ColorFlags",
                            Value = new ODataEnumValue(
                                (ColorFlags.Green | ColorFlags.Red).ToString(CultureInfo.InvariantCulture),
                                "NS.MyEnumTypeName")     // type name
                        }
                    },
                    SerializationInfo = MySerializationInfo
                };
                tmp.SetAnnotation(new AtomEntryMetadata()
                {
                    Updated = updatedTime
                });
                return(tmp);
            };

            // model-request
            string expectedPayload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                     "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " +
                                     "xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/test/$metadata#MySet/$entity\">" +
                                     "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                     "<id />" +
                                     "<title />" +
                                     "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                     "<author><name /></author>" +
                                     "<content type=\"application/xml\">" +
                                     "<m:properties>" +
                                     "<d:ColorFlags m:type=\"#NS.MyEnumTypeName\">Red, Green</d:ColorFlags>" +
                                     "</m:properties>" +
                                     "</content>" +
                                     "</entry>";

            this.WriteRequestWithModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // model-reseponse
            this.WriteResponseWithModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // NoModel-request
            this.WriteRequestWithoutModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // NoModel-response
            this.WriteResponseWithoutModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);
        }
コード例 #5
0
        public void FlagsEnumAsComplexProperty_StrAsValue_StrAsTypeName()
        {
            DateTimeOffset updatedTime = DateTimeOffset.UtcNow;
            string         payload     = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                         "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\">" +
                                         "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                         "<id />" +
                                         "<title />" +
                                         "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                         "<author>" +
                                         "<name />" +
                                         "</author>" +
                                         "<content type=\"application/xml\">" +
                                         "<m:properties>" +
                                         "<d:FloatId m:type=\"Single\">12.3</d:FloatId>" +
                                         "<d:Color m:type=\"#NS.Color\">Green</d:Color>" +
                                         "<d:MyComplexType m:type=\"#NS.MyComplexType\">" +
                                         "<d:MyColorFlags m:type=\"#NS.ColorFlags\">Red</d:MyColorFlags>" +
                                         "<d:Height m:type=\"Double\">98.6</d:Height>" +
                                         "</d:MyComplexType>" +
                                         "</m:properties>" +
                                         "</content>" +
                                         "</entry>";
            ODataEntry expectedEntry = new ODataEntry
            {
                TypeName   = "NS.MyEntityType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "FloatId", Value = new ODataPrimitiveValue(12.3F)
                    },
                    new ODataProperty {
                        Name = "Color", Value = new ODataEnumValue(Color.Green.ToString(), /*reader will get TypeName from model*/ "NS.Color")
                    },
                    new ODataProperty
                    {
                        Name  = "MyComplexType",
                        Value = new ODataComplexValue {
                            TypeName = "NS.MyComplexType", Properties = new[] { new ODataProperty {
                                                                                    Name = "MyColorFlags", Value = new ODataEnumValue(ColorFlags.Red.ToString(), "NS.ColorFlags")
                                                                                }, new ODataProperty {
                                                                                    Name = "Height", Value = 98.6
                                                                                } }
                        }
                    }
                }
            };

            this.ReadEntryPayloadAndVerify(payload, expectedEntry);
        }
コード例 #6
0
        public void FlagsEnumAsEntityProperty_IntAsValue_NoTypeName_Error()
        {
            DateTimeOffset updatedTime = DateTimeOffset.UtcNow;
            string         payload     = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                         "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\">" +
                                         "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                         "<id />" +
                                         "<title />" +
                                         "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                         "<author>" +
                                         "<name />" +
                                         "</author>" +
                                         "<content type=\"application/xml\">" +
                                         "<m:properties>" +
                                         "<d:Color m:type=\"Int32\">16</d:Color>" +
                                         "</m:properties>" +
                                         "</content>" +
                                         "</entry>";
            ODataEntry expectedEntry = null;
            Action     parse         = () => this.ReadEntryPayloadAndVerify(payload, expectedEntry);

            parse.ShouldThrow <ODataException>().WithMessage(Microsoft.OData.Core.Strings.ValidationUtils_IncorrectTypeKind("Edm.Int32", "Enum", "Primitive"));
        }
コード例 #7
0
        public void FlagsEnumAsEntityProperty_NullAsValue_NoNullable_Error()
        {
            DateTimeOffset updatedTime = DateTimeOffset.UtcNow;
            string         payload     = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                         "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\">" +
                                         "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                         "<id />" +
                                         "<title />" +
                                         "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                         "<author>" +
                                         "<name />" +
                                         "</author>" +
                                         "<content type=\"application/xml\">" +
                                         "<m:properties>" +
                                         "<d:ColorFlags m:null=\"true\" />" +
                                         "</m:properties>" +
                                         "</content>" +
                                         "</entry>";
            ODataEntry expectedEntry = null;
            Action     parse         = () => this.ReadEntryPayloadAndVerify(payload, expectedEntry);
            string     fullName      = this.entityType.FindProperty("ColorFlags").Type.FullName();

            parse.ShouldThrow <ODataException>().WithMessage(Microsoft.OData.Core.Strings.ReaderValidationUtils_NullNamedValueForNonNullableType("ColorFlags", fullName));
        }
コード例 #8
0
        public void FlagsEnumAsCollectionElement_StrAsValue_StrAsTypeName()
        {
            DateTimeOffset    updatedTime = DateTimeOffset.UtcNow;
            Func <ODataEntry> entryClone  = () =>
            {
                var tmp = new ODataEntry
                {
                    TypeName   = "NS.MyEntityType",
                    Properties = new[]
                    {
                        new ODataProperty {
                            Name = "FloatId", Value = new ODataPrimitiveValue(12.3D)
                        },
                        new ODataProperty {
                            Name = "Color", Value = new ODataEnumValue(Color.Green.ToString(), "NS.Color")
                        },
                        new ODataProperty
                        {
                            Name  = "MyCollectionType",
                            Value = new ODataCollectionValue {
                                Items = new[] { new ODataEnumValue(Color.Red.ToString(), "NS.EnumUndefinedTypename"), new ODataEnumValue(Color.Green.ToString(), "NS.EnumUndefinedTypename") }
                            }
                        }
                    },
                    SerializationInfo = MySerializationInfo
                };
                tmp.SetAnnotation(new AtomEntryMetadata()
                {
                    Updated = updatedTime
                });
                return(tmp);
            };

            // model-request
            string expectedPayload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                     "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/test/$metadata#MySet/$entity\">" +
                                     "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                                     "<id />" +
                                     "<title />" +
                                     "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                                     "<author>" +
                                     "<name />" +
                                     "</author>" +
                                     "<content type=\"application/xml\">" +
                                     "<m:properties>" +
                                     "<d:FloatId m:type=\"Double\">12.3</d:FloatId>" +
                                     "<d:Color m:type=\"#NS.Color\">Green</d:Color>" +
                                     "<d:MyCollectionType m:type=\"#Collection(NS.ColorFlags)\">" +
                                     "<m:element m:type=\"#NS.EnumUndefinedTypename\">Red</m:element>" +
                                     "<m:element m:type=\"#NS.EnumUndefinedTypename\">Green</m:element>" +
                                     "</d:MyCollectionType>" +
                                     "</m:properties>" +
                                     "</content>" +
                                     "</entry>";

            this.WriteRequestWithModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // model-reseponse
            this.WriteResponseWithModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // NoModel-request
            expectedPayload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                              "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/test/$metadata#MySet/$entity\">" +
                              "<category term=\"#NS.MyEntityType\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                              "<id />" +
                              "<title />" +
                              "<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
                              "<author>" +
                              "<name />" +
                              "</author>" +
                              "<content type=\"application/xml\">" +
                              "<m:properties>" +
                              "<d:FloatId m:type=\"Double\">12.3</d:FloatId>" +
                              "<d:Color m:type=\"#NS.Color\">Green</d:Color>" +
                              "<d:MyCollectionType>" +
                              "<m:element m:type=\"#NS.EnumUndefinedTypename\">Red</m:element>" +
                              "<m:element m:type=\"#NS.EnumUndefinedTypename\">Green</m:element>" +
                              "</d:MyCollectionType>" +
                              "</m:properties>" +
                              "</content>" +
                              "</entry>";
            this.WriteRequestWithoutModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);

            // NoModel-response
            this.WriteResponseWithoutModelAndValidatePayload(nestedItemToWrite: new[] { entryClone() }, expectedPayload: expectedPayload);
        }