From a6b49b92ef3c9b30fe1bf193fe838697f76bf0d7 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin Nutiu Date: Sun, 16 Feb 2020 14:58:02 +0200 Subject: [PATCH] NUC-31: Fix parsing of arrayValue in FirebaseRestTranslator --- NucuCar.Domain/Utilities/FirebaseRestTranslator.cs | 10 ++++++++-- .../Utilities/FirebaseRestTranslatorTests.cs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NucuCar.Domain/Utilities/FirebaseRestTranslator.cs b/NucuCar.Domain/Utilities/FirebaseRestTranslator.cs index 30ec6cd..57d1676 100644 --- a/NucuCar.Domain/Utilities/FirebaseRestTranslator.cs +++ b/NucuCar.Domain/Utilities/FirebaseRestTranslator.cs @@ -85,13 +85,19 @@ namespace NucuCar.Domain.Utilities } private static Dictionary BuildArray(List> array) { - var root = new Dictionary(); var values = new List>(); + var root = new Dictionary + { + ["arrayValue"] = new Dictionary + { + ["values"] = values + } + }; + foreach (var entry in array) { values.Add(BuildNode(entry)); } - root["values"] = values; return root; } diff --git a/NucuCar.UnitTests/NucuCar.Domain.Tests/Utilities/FirebaseRestTranslatorTests.cs b/NucuCar.UnitTests/NucuCar.Domain.Tests/Utilities/FirebaseRestTranslatorTests.cs index 6811e25..5436839 100644 --- a/NucuCar.UnitTests/NucuCar.Domain.Tests/Utilities/FirebaseRestTranslatorTests.cs +++ b/NucuCar.UnitTests/NucuCar.Domain.Tests/Utilities/FirebaseRestTranslatorTests.cs @@ -66,7 +66,7 @@ namespace NucuCar.UnitTests.NucuCar.Domain.Tests.Utilities public void Test_FireBaseTranslator_Parse() { var expectedJson = - "{\"name\":\"Test\",\"fields\":{\"source\":{\"stringValue\":\"NucuCar.Sensors\"},\"timestamp\":{\"timestampValue\":\"2019-12-01T23:26:13.5537227+02:00\"},\"data\":{\"values\":[{\"mapValue\":{\"fields\":{\"sensor_state\":{\"integerValue\":2},\"cpu_temperature\":{\"doubleValue\":48.849998474121094},\"_id\":{\"stringValue\":\"CpuTemperature\"}}}},{\"mapValue\":{\"fields\":{\"sensor_state\":{\"integerValue\":2},\"temperature\":{\"doubleValue\":32.65},\"humidity\":{\"doubleValue\":100.0},\"pressure\":{\"doubleValue\":62228.49},\"voc\":{\"doubleValue\":0.0},\"_id\":{\"stringValue\":\"Bme680-Sensor\"}}}}]}}}"; + "{\"name\":\"Test\",\"fields\":{\"source\":{\"stringValue\":\"NucuCar.Sensors\"},\"timestamp\":{\"timestampValue\":\"2019-12-01T23:26:13.5537227+02:00\"},\"data\":{\"arrayValue\":{\"values\":[{\"mapValue\":{\"fields\":{\"sensor_state\":{\"integerValue\":2},\"cpu_temperature\":{\"doubleValue\":48.849998474121094},\"_id\":{\"stringValue\":\"CpuTemperature\"}}}},{\"mapValue\":{\"fields\":{\"sensor_state\":{\"integerValue\":2},\"temperature\":{\"doubleValue\":32.65},\"humidity\":{\"doubleValue\":100.0},\"pressure\":{\"doubleValue\":62228.49},\"voc\":{\"doubleValue\":0.0},\"_id\":{\"stringValue\":\"Bme680-Sensor\"}}}}]}}}}"; var basicTelemetryData = getBasicTelemetryData(); var result = FirebaseRestTranslator.Translate("Test", basicTelemetryData); var json = JsonConvert.SerializeObject(result);