Ejemplo n.º 1
0
        public void InferSchema()
        {
            var doc = new BSONDocument();

            doc.Set(new BSONStringElement("FullName", "Alex Bobby"));
            doc.Set(new BSONInt32Element("Age", 123));
            doc.Set(new BSONBooleanElement("IsGood", true));

            var c = new DataDocConverter();

            var schema = c.InferSchemaFromBSONDocument(doc);

            Aver.AreEqual(3, schema.FieldCount);

            Aver.AreEqual(0, schema["FullName"].Order);
            Aver.AreEqual(1, schema["Age"].Order);
            Aver.AreEqual(2, schema["IsGood"].Order);

            Aver.AreObjectsEqual(typeof(object), schema["FullName"].NonNullableType);
            Aver.AreObjectsEqual(typeof(object), schema["Age"].NonNullableType);
            Aver.AreObjectsEqual(typeof(object), schema["IsGood"].NonNullableType);

            var row = new DynamicDoc(schema);

            c.BSONDocumentToDataDoc(doc, row, null);

            Aver.AreObjectsEqual("Alex Bobby", row[0]);
            Aver.AreObjectsEqual(123, row[1]);
            Aver.AreObjectsEqual(true, row[2]);

            Aver.AreObjectsEqual("Alex Bobby", row["FullName"]);
            Aver.AreObjectsEqual(123, row["Age"]);
            Aver.AreObjectsEqual(true, row["IsGood"]);
        }