Ejemplo n.º 1
0
        public void CheckIsFlattenedWeirdNamesExport()
        {
            string json      = "{ \"a.\": { \"b \": true, \"c$%^&\": { \"...\": true } } }";
            var    documents = new List <BsonDocument>()
            {
                BsonDocument.Parse(json),
            };

            string flattened = ExportTests.ToFlatJson(documents);
            var    parsed    = BsonDocument.Parse($"{{ \"wrapper\": {flattened} }}");

            Assert.True(parsed["wrapper"][0]["a..b "].AsBoolean, "Json structure is not flattened properly.");
            Assert.True(parsed["wrapper"][0]["a..c$%^&...."].AsBoolean, "Json structure is not flattened properly.");

            Assert.Throws <KeyNotFoundException>(() =>
            {
                _ = parsed["wrapper"][0]["a.b"];
            });

            Assert.Throws <KeyNotFoundException>(() =>
            {
                _ = parsed["wrapper"][0]["a.b "];
            });

            Assert.Throws <KeyNotFoundException>(() =>
            {
                _ = parsed["wrapper"][0]["a.c"];
            });

            Assert.Throws <KeyNotFoundException>(() =>
            {
                _ = parsed["wrapper"][0]["a.cc$%^&"];
            });
        }
Ejemplo n.º 2
0
        public void CheckIsFlattenedManyExport()
        {
            string json      = "{ \"a\": { \"b\": { \"c\": { \"d\": { \"e\": { \"f\": { \"g\": { \"h\": { \"i\": true } } } } } } } } }";
            var    documents = new List <BsonDocument>()
            {
                BsonDocument.Parse(json),
            };

            string flattened = ExportTests.ToFlatJson(documents);
            var    parsed    = BsonDocument.Parse($"{{ \"wrapper\": {flattened} }}");

            Assert.True(parsed["wrapper"][0]["a.b.c.d.e.f.g.h.i"].AsBoolean, "Json structure is not flattened.");
        }
Ejemplo n.º 3
0
        public void CheckIsFlattenedTypesExport()
        {
            string json      = "{ \"a\": { \"b\": true, \"c\": 1, \"d\": \"test\", \"e\": null } }";
            var    documents = new List <BsonDocument>()
            {
                BsonDocument.Parse(json),
            };

            string flattened = ExportTests.ToFlatJson(documents);
            var    parsed    = BsonDocument.Parse($"{{ \"wrapper\": {flattened} }}");

            Assert.True(parsed["wrapper"][0]["a.b"].AsBoolean, "Json structure is not flattened properly.");
            Assert.True(parsed["wrapper"][0]["a.c"].AsInt32 == 1, "Json structure is not flattened properly.");
            Assert.True(parsed["wrapper"][0]["a.d"].AsString == "test", "Json structure is not flattened properly.");
            Assert.True(parsed["wrapper"][0]["a.e"].BsonType == BsonType.Null, "Json structure is not flattened properly.");
        }