Contains either a JSON Object, a JSON array, or a string on error.
Exemplo n.º 1
0
        public void MetadataTest()
        {
            var testMessage = new InMemoryResponse();

            var converter = new SodaToODataConverter(testMessage, new Uri("http://fake"), TestData.TopLevelSodaResponse);
            var payload = new JsonPayload(TestData.SodaResponseFor(TestData.TopLevelSodaResponse));
            converter.ConvertMetadata(RelativeUriOData, RelativeUriSoda, payload);

            ApproveResponse(testMessage);
        }
Exemplo n.º 2
0
        public void ConvertFeed(Uri relativeODataUri, Uri relativeSodaUri, JsonPayload jsonPayload,
		                        DateTimeOffset feedUpdateTime)
        {
            var jsonObject = jsonPayload.JsonObject;

            var entries = jsonObject.PropertyValue<JArray>("entries");
            var meta = jsonObject.PropertyValue<JObject>("meta");
            var view = meta.PropertyValue<JObject>("view");

            IList<string> fieldsToIgnore;
            var model = BuildModel(view, out fieldsToIgnore);

            var entitySet = model.EntityContainers.Single().EntitySets().Single();

            var settings = new ODataMessageWriterSettings
                           	{
                           		Indent = true,
                           	};

            using (var writer = new ODataMessageWriter(Message, settings, model))
            {
                var feedWriter = writer.CreateODataFeedWriter();

                var feed = new ODataFeed();

                feed.SetAnnotation(new AtomFeedMetadata
                                   	{
                                   		Updated = feedUpdateTime,
                                   	});

                feed.Id = new Uri(ODataEndpointUri, relativeODataUri.OriginalString).OriginalString;

                feedWriter.WriteStart(feed);
                foreach (var entry in entries.Cast<JObject>())
                {
                    var entryMetadata = new ODataEntry();
                    entryMetadata.Id = (string) ((JValue) entry.Property("id").Value).Value;
                    entryMetadata.TypeName = entitySet.ElementType.FullName();

                    entryMetadata.Properties = ConvertProperties(entry, fieldsToIgnore);

                    entryMetadata.SetAnnotation(new AtomEntryMetadata
                                                    {
                                                        Updated = ConvertDateTimeOffset(entry.PrimitivePropertyValue<long>("updated_at")),
                                                        Published = ConvertDateTimeOffset(entry.PrimitivePropertyValue<long>("created_at")),
                                                    });

                    feedWriter.WriteStart(entryMetadata);
                    feedWriter.WriteEnd();
                }

                feedWriter.WriteEnd();
            }
        }
Exemplo n.º 3
0
        public void FeedTestJson()
        {
            var testMessage = new InMemoryResponse();
            testMessage.SetHeader("Content-Type", "application/json");

            var converter = new SodaToODataConverter(testMessage, new Uri("http://fake"), TestData.TopLevelSodaResponse);
            var payload = new JsonPayload(TestData.SodaResponseFor(TestData.TopLevelSodaResponse));
            converter.ConvertFeed(RelativeUriOData, RelativeUriSoda, payload, FeedUpdateTime);

            ApproveResponse(testMessage);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks response object to see if any errors are present
        /// </summary>
        /// <param name="response">The JSON response returned from the server</param>
        /// <returns>True if no errors, false otherwise</returns>
        protected bool responseIsClean(JsonPayload response)
        {
            if (response == null) {
                return false;
            }

            if (response.Message != null && response.Message.Length > 0) {
                _log.Warn("Non-JSON response: " + response.Message);
                return false;
            }
            else if (response.JsonObject != null && response.JsonObject["error"] != null) {
                    _log.Error("Error in response: " + (string)response.JsonObject["error"]);
                    return false;
            }
            return true;
        }
Exemplo n.º 5
0
        public void ConvertMetadata(Uri relativeODataUri, Uri relativeSodaUri, JsonPayload jsonPayload)
        {
            var jsonObject = jsonPayload.JsonObject;

            var meta = jsonObject.PropertyValue<JObject>("meta");
            var view = meta.PropertyValue<JObject>("view");

            IList<string> fieldsToIgnore;
            var model = BuildModel(view, out fieldsToIgnore);

            var settings = new ODataMessageWriterSettings
                           	{
                           		Indent = true,
                           	};

            using (var writer = new ODataMessageWriter(Message, settings, model))
            {
                writer.WriteMetadataDocument();
            }
        }
Exemplo n.º 6
0
        public void MetadataTest()
        {
            var stream = new MemoryStream();
            var testMessage = new TestMessage() { Stream = stream };

            var converter = new SodaToODataConverter(testMessage, new Uri("http://fake"), new Uri("http://data.cityofchicago.org/views/z8bn-74gv"));
            var payload = new JsonPayload(JsonText);
            converter.ConvertMetadata(new Uri("/SomethingOData", UriKind.Relative), new Uri("/SomethingSoda", UriKind.Relative), payload);

            var text = Encoding.UTF8.GetString(stream.ToArray());
            Console.WriteLine(text);
        }
Exemplo n.º 7
0
        public void FeedTestJson()
        {
            var stream = new MemoryStream();
            var testMessage = new TestMessage() { Stream = stream };
            testMessage.SetHeader("Content-Type", "application/json");

            var converter = new SodaToODataConverter(testMessage, new Uri("http://fake"), new Uri("http://data.cityofchicago.org/views/z8bn-74gv"));
            var payload = new JsonPayload(JsonText);
            converter.ConvertFeed(new Uri("/SomethingOData", UriKind.Relative), new Uri("/SomethingSoda", UriKind.Relative), payload);

            var text = Encoding.UTF8.GetString(stream.ToArray());
            Console.WriteLine(text);
        }