public void WritingAnAnnotationWithExpectedDecimalTypeShouldUseAttributeValueNotation() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.decimal", new ODataPrimitiveValue((decimal)4.2)), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"custom.decimal\" decimal=\"4.2\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\" />"); }
public void WritingANullValuedAnnotationThatIsOfNonNullableTypeInMetadataShouldThrow() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.int", new ODataNullValue()), /*target*/ null); Action test = () => this.serializer.WriteInstanceAnnotation(annotation); test.ShouldThrow <ODataException>().WithMessage(Strings.ODataAtomPropertyAndValueSerializer_NullValueNotAllowedForInstanceAnnotation("custom.int", "Edm.Int32")); }
public void WriteInstanceAnnotationsShouldWriteAllAnnotationsInTheEnumerable() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.primitive", new ODataPrimitiveValue(123)), /*target*/ null); var complex = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.complex", new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "p1", Value = 123 } }, TypeName = "ns.complex1" }), /*target*/ null); var collection = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.collection", new ODataCollectionValue { Items = new[] { 123 } }), /*target*/ null); var instanceAnnotationWriteTracker = new InstanceAnnotationWriteTracker(); this.serializer.XmlWriter.WriteStartElement("wrapper"); this.serializer.WriteInstanceAnnotations(new[] { primitive, complex, collection }, instanceAnnotationWriteTracker); this.serializer.XmlWriter.WriteEndElement(); this.ValidatePayload( "<wrapper>" + "<annotation term=\"ns.primitive\" int=\"123\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\" />" + "<annotation term=\"ns.complex\" m:type=\"#ns.complex1\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><d:p1 m:type=\"Int32\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\">123</d:p1></annotation>" + "<annotation term=\"ns.collection\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:element m:type=\"Int32\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\">123</m:element></annotation>" + "</wrapper>"); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.primitive").Should().BeTrue(); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.complex").Should().BeTrue(); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.collection").Should().BeTrue(); }
public void WriteInstanceAnnotationsShouldIncludeTypeByte() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.term", new ODataPrimitiveValue(Byte.Parse("12"))), /*target*/ null); this.serializer.WriteInstanceAnnotations(new[] { primitive }, instanceAnnotationWriteTracker); this.ValidatePayloadShouldContain("m:type=\"Byte\""); }
public void WritingANullValuedAnnotationThatIsOfNullableTypeInMetadataShouldWork() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.bool", new ODataNullValue()), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"custom.bool\" m:null=\"true\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\" />"); }
public void WriteInstanceAnnotationsShouldNotIncludeTypeDoubleForNaN() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.term", new ODataPrimitiveValue(Double.NaN)), /*target*/ null); this.serializer.WriteInstanceAnnotations(new[] { primitive }, instanceAnnotationWriteTracker); this.ValidatePayloadShouldNotContain("m:type=\"Double\""); }
public void WriteInstanceAnnotationsShouldIncludeTypeDateTimeOffset() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.term", new ODataPrimitiveValue(new DateTimeOffset(2013, 11, 28, 12, 12, 12, TimeSpan.Zero))), /*target*/ null); this.serializer.WriteInstanceAnnotations(new[] { primitive }, instanceAnnotationWriteTracker); this.ValidatePayloadShouldContain("m:type=\"DateTimeOffset\""); }
public void IfNullAttributeIsPresentAndFalseStringValueShouldBeRead() { AtomInstanceAnnotation testResult = ReadAnnotation("<m:annotation term=\"my.namespace.term\" m:null=\"false\" string=\"something\" />"); testResult.Value.Should().BeOfType <ODataPrimitiveValue>(); testResult.Value.As <ODataPrimitiveValue>().Value.Should().Be("something"); }
public void IfNullAttributeIsPresentAndTrueStringValueShouldBeIgnored() { // We ignore this (instead of fail) to be consistent with ignoring element content (see above). AtomInstanceAnnotation testResult = ReadAnnotation("<m:annotation term=\"my.namespace.term\" m:null=\"true\" string=\"something\" />"); testResult.Value.Should().BeOfType <ODataNullValue>(); }
public void WritingANonAttributeValueNotationAnnotationWithMismatchedMetadataShouldThrow() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.guid", new ODataPrimitiveValue(new TimeSpan(123456))), /*target*/ null); Action test = () => this.serializer.WriteInstanceAnnotation(annotation); test.ShouldThrow <ODataException>().WithMessage(Strings.ValidationUtils_IncompatiblePrimitiveItemType("Edm.Duration", "False", "Edm.Guid", "False")); }
public void WritingAnAnnotationWithExpectedGuidTypeShouldNotUseAttributeValueNotation() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.guid", new ODataPrimitiveValue(Guid.Empty)), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"custom.guid\" m:type=\"Guid\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">00000000-0000-0000-0000-000000000000</annotation>"); }
public void WritingAnAnnotationWithExpectedDurationTypeShouldNotUseAttributeValueNotation() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.duration", new ODataPrimitiveValue(new TimeSpan(123456))), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"custom.duration\" m:type=\"Duration\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">PT0.0123456S</annotation>"); }
public void WritingAStringValuedAnnotationShouldUseAttributeValueNotation() { var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("Namespace.TermName", new ODataPrimitiveValue("string value")), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"Namespace.TermName\" string=\"string value\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\" />"); }
public void WriteInstanceAnnotationsShouldTrackWhichAnnotationHasBeenWriten() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.primitive", new ODataPrimitiveValue(123)), /*target*/ null); var instanceAnnotationWriteTracker = new InstanceAnnotationWriteTracker(); this.serializer.WriteInstanceAnnotations(new[] { primitive }, instanceAnnotationWriteTracker); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.primitive").Should().BeTrue(); }
public void LookupEdmTypeByAttributeValueNotationNameShouldReturnNonNullableTypeReferences() { AtomInstanceAnnotation.LookupEdmTypeByAttributeValueNotationName("int").IsNullable.Should().BeFalse(); AtomInstanceAnnotation.LookupEdmTypeByAttributeValueNotationName("string").IsNullable.Should().BeFalse(); AtomInstanceAnnotation.LookupEdmTypeByAttributeValueNotationName("float").IsNullable.Should().BeFalse(); AtomInstanceAnnotation.LookupEdmTypeByAttributeValueNotationName("bool").IsNullable.Should().BeFalse(); AtomInstanceAnnotation.LookupEdmTypeByAttributeValueNotationName("decimal").IsNullable.Should().BeFalse(); }
public void ShouldThrowIfElementContentIsNotPrimitiveAndNoTypeAvailable() { // Comment: not the most intuitive error message if a user runs into this scenario. AtomInstanceAnnotation tmp = ReadAnnotation("<m:annotation term=\"my.namespace.term\"><d:element>42</d:element></m:annotation>"); tmp.TermName.Should().Be("my.namespace.term"); tmp.Value.As <ODataComplexValue>().Properties.Select(s => s.Value).Cast <string>().Single().Should().Be("42"); }
public void IfNullAttributeIsPresentAndTrueElementContentShouldBeIgnored() { // Note: we ignore element content (instead of failing) when m:null is true to be consistent with the decision // made to have this behavior when reading properties. AtomInstanceAnnotation testResult = ReadAnnotation("<m:annotation term=\"my.namespace.term\" m:null=\"true\">Some content that doesn't make sense if the value is null</m:annotation>"); testResult.Value.Should().BeOfType <ODataNullValue>(); }
public void WritingAPrimitiveCollectionValuedAnnotationWithMetadataShouldWork() { ODataCollectionValue collection = new ODataCollectionValue { Items = new[] { 123 } }; var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.primitiveCollection", collection), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"custom.primitiveCollection\" m:type=\"#Collection(Int32)\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:element>123</m:element></annotation>"); }
public void WritingAPrimitiveCollectionValuedAnnotationWithMismatchedMetadataShouldThrow() { ODataCollectionValue collection = new ODataCollectionValue { Items = new[] { 123.4 } }; var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.primitiveCollection", collection), /*target*/ null); Action test = () => this.serializer.WriteInstanceAnnotation(annotation); test.ShouldThrow <ODataException>().WithMessage(Strings.CollectionWithoutExpectedTypeValidator_IncompatibleItemTypeName("Edm.Double", "Edm.Int32")); }
public void WritingAComplexValuedAnnotationWithMismatchedMetadataShouldThrow() { ODataComplexValue complex = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "p1", Value = 123 } }, TypeName = "ns.complex1" }; Action test = () => this.serializer.WriteInstanceAnnotation(AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.complex", complex), /*target*/ null)); test.ShouldThrow <ODataException>().WithMessage(Strings.ValidationUtils_IncompatibleType("ns.complex1", "ns.complex2")); }
public void WritingAComplexValuedAnnotationWithMetadataShouldWork() { ODataComplexValue complex = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "p1", Value = 123 } }, TypeName = "ns.complex2" }; var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.complex", complex), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"custom.complex\" m:type=\"#ns.complex2\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><d:p1 m:type=\"Int32\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\">123</d:p1></annotation>"); }
public void WriteInstanceAnnotationsShouldIncludeTypeComplexType() { ODataComplexValue complexValue = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "StringProperty", Value = "StringValue1" } }, TypeName = "ns.complex" }; var complex = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.term", complexValue), /*target*/ null); this.serializer.WriteInstanceAnnotations(new[] { complex }, instanceAnnotationWriteTracker); this.ValidatePayloadShouldContain("m:type=\"#ns.complex\""); }
public void WriteInstanceAnnotationShouldSkipAnnotationBaseOnAnnotationFilter() { this.settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, ShouldIncludeAnnotation = name => false }; this.serializer = new ODataAtomPropertyAndValueSerializer(this.CreateAtomOutputContext(EdmCoreModel.Instance, this.stream)); var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("Namespace.TermName", new ODataPrimitiveValue("string value")), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload(""); }
public void WritingAComplexCollectionValuedAnnotationWithoutMetadataShouldWork() { ODataComplexValue complex = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "p1", Value = 123 } } }; ODataCollectionValue collection = new ODataCollectionValue { Items = new[] { complex }, TypeName = "Collection(ns.complex1)" }; var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("Namespace.TermName", collection), /*target*/ null); this.serializer.WriteInstanceAnnotation(annotation); this.ValidatePayload("<annotation term=\"Namespace.TermName\" m:type=\"#Collection(ns.complex1)\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:element><d:p1 m:type=\"Int32\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\">123</d:p1></m:element></annotation>"); }
public void WriteInstanceAnnotationsShouldThrowWhenThereAreDuplicatedTermNames() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.term", new ODataPrimitiveValue(123)), /*target*/ null); var complex = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.term", new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "p1", Value = 123 } }, TypeName = "ns.complex1" }), /*target*/ null); var instanceAnnotationWriteTracker = new InstanceAnnotationWriteTracker(); instanceAnnotationWriteTracker.MarkAnnotationWritten("ns.term"); Action test = () => this.serializer.WriteInstanceAnnotations(new[] { primitive, complex }, instanceAnnotationWriteTracker); test.ShouldThrow <ODataException>().WithMessage(Strings.JsonLightInstanceAnnotationWriter_DuplicateAnnotationNameInCollection("ns.term")); }
public void WriteInstanceAnnotationsShouldNotWriteAnnotationsThatHasAlreadyBeenWriten() { var primitive = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.primitive", new ODataPrimitiveValue(123)), /*target*/ null); var complex = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.complex", new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "p1", Value = 123 } }, TypeName = "ns.complex1" }), /*target*/ null); var collection = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("ns.collection", new ODataCollectionValue { Items = new[] { 123 } }), /*target*/ null); var instanceAnnotationWriteTracker = new InstanceAnnotationWriteTracker(); instanceAnnotationWriteTracker.MarkAnnotationWritten("ns.primitive"); instanceAnnotationWriteTracker.MarkAnnotationWritten("ns.collection"); this.serializer.WriteInstanceAnnotations(new[] { primitive, complex, collection }, instanceAnnotationWriteTracker); this.ValidatePayload("<annotation term=\"ns.complex\" m:type=\"#ns.complex1\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><d:p1 m:type=\"Int32\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\">123</d:p1></annotation>"); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.primitive").Should().BeTrue(); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.complex").Should().BeTrue(); instanceAnnotationWriteTracker.IsAnnotationWritten("ns.collection").Should().BeTrue(); }
public void IfNullAttributeIsPresentAndTrueAttributeValueShouldBeNull() { AtomInstanceAnnotation testResult = ReadAnnotation("<m:annotation term=\"my.namespace.term\" m:null=\"true\" />"); testResult.Value.Should().BeOfType <ODataNullValue>(); }