/// <summary> /// Constructor. /// </summary> /// <param name="jsonLightInputContext">The input to read the payload from.</param> /// <param name="navigationSource">The navigation source we are going to read entities for.</param> /// <param name="expectedEntityType">The expected entity type for the entry to be read (in case of entry reader) or entries in the feed to be read (in case of feed reader).</param> /// <param name="readingFeed">true if the reader is created for reading a feed; false when it is created for reading an entry.</param> /// <param name="readingParameter">true if the reader is created for reading a parameter; false otherwise.</param> /// <param name="listener">If not null, the Json reader will notify the implementer of the interface of relevant state changes in the Json reader.</param> internal ODataJsonLightReader( ODataJsonLightInputContext jsonLightInputContext, IEdmNavigationSource navigationSource, IEdmEntityType expectedEntityType, bool readingFeed, bool readingParameter = false, IODataReaderWriterListener listener = null) : base(jsonLightInputContext, readingFeed, listener) { Debug.Assert(jsonLightInputContext != null, "jsonLightInputContext != null"); Debug.Assert( expectedEntityType == null || jsonLightInputContext.Model.IsUserModel(), "If the expected type is specified we need model as well. We should have verified that by now."); this.jsonLightInputContext = jsonLightInputContext; this.jsonLightEntryAndFeedDeserializer = new ODataJsonLightEntryAndFeedDeserializer(jsonLightInputContext); this.readingParameter = readingParameter; this.topLevelScope = new JsonLightTopLevelScope(navigationSource, expectedEntityType); this.EnterScope(this.topLevelScope); }
/// <summary> /// Constructor. /// </summary> /// <param name="entry">The entry to add operations to.</param> /// <param name="jsonLightEntryAndFeedDeserializer">The deserializer to use.</param> public OperationsDeserializerContext(ODataEntry entry, ODataJsonLightEntryAndFeedDeserializer jsonLightEntryAndFeedDeserializer) { Debug.Assert(entry != null, "entry != null"); Debug.Assert(jsonLightEntryAndFeedDeserializer != null, "jsonLightEntryAndFeedDeserializer != null"); this.entry = entry; this.jsonLightEntryAndFeedDeserializer = jsonLightEntryAndFeedDeserializer; }
private void VerifyInvalidMetadataReferenceProperty(string propertyName) { string jsonInput = string.Format("{{\"" + JsonLightConstants.ODataPropertyAnnotationSeparatorChar + ODataAnnotationNames.ODataContext + "\":\"http://odata.org/$metadata\"," + "\"{0}\":42}}", propertyName); DuplicatePropertyNamesChecker duplicatePropertyNamesChecker = new DuplicatePropertyNamesChecker(false, true); using (ODataJsonLightInputContext inputContext = this.CreateJsonLightInputContext(jsonInput)) { ODataJsonLightEntryAndFeedDeserializer deserializer = new ODataJsonLightEntryAndFeedDeserializer(inputContext); deserializer.ReadPayloadStart(ODataPayloadKind.Unsupported, duplicatePropertyNamesChecker, false, false); Action readEntryContentAction = () => deserializer.ReadEntryContent(new TestJsonLightReaderEntryState()); readEntryContentAction .ShouldThrow<ODataException>("the property name \"{0}\" contains a hash but is not a valid URI or URI fragment", propertyName) .WithMessage(ErrorStrings.ValidationUtils_InvalidMetadataReferenceProperty(propertyName)); } }