Exemplo n.º 1
0
        public void JsonString_ImplicitFromJson_EqualsJsonValue()
        {
            var jsonString = @"{ Name : ""Daniel""}";
            var json = new SimoJson(jsonString);

            string resultingString = json;

            Assert.AreEqual(jsonString, resultingString);
        }
Exemplo n.º 2
0
        public void ToKeyValue_WithManyProps_AllAreMapped()
        {
            var json = new SimoJson(@"{ Name : ""Daniel"", Age : 29, TimeStamp : ""\/Date(1262350073000+0100)\/""}");

            Assert.AreEqual(3, json.ToKeyValue().Count);
        }
Exemplo n.º 3
0
        public void ToKeyValue_DateTime_Equals()
        {
            var json = new SimoJson(@"{TimeStamp : ""\/Date(1262350073000+0100)\/""}");

            Assert.AreEqual(new DateTime(2010, 1, 1, 13, 47, 53), json.ToKeyValue()["TimeStamp"]);
        }
Exemplo n.º 4
0
        public void ToKeyValue_Int_Equals()
        {
            var json = new SimoJson(@"{ Age : 29 }");

            Assert.AreEqual(29, Convert.ToInt32(json.ToKeyValue()["Age"]));
        }
Exemplo n.º 5
0
        public void ToKeyValue_String_Equals()
        {
            var json = new SimoJson(@"{ Name : ""Daniel""}");

            Assert.AreEqual("Daniel", json.ToKeyValue()["Name"]);
        }
Exemplo n.º 6
0
 private void WriteJson(SimoJson json, ISimoBsonWriter writer)
 {
     WriteAsBson(json.ToKeyValue(), writer);
 }
Exemplo n.º 7
0
        private void WriteJson(SimoJson json, ISimoBsonWriter writer)
        {
            var dval = json.ToKeyValue();
            Dictionary<string, object> dvalTo = new Dictionary<string, object>();
            foreach (KeyValuePair<string, object> kv in dval)
            {
                if ((kv.Key == "_id" || kv.Key[0] == '!') && kv.Value.GetType() == typeof(string))
                {
                    string val = kv.Value as string;
                    if (val.StartsWith("-oid-"))
                    {
                        val = val.Substring(5);
                        byte[] nv = Convert.FromBase64String(val);

                        dvalTo.Add((kv.Key[0] == '!') ? kv.Key.Substring(1) : "_id", new Newtonsoft.Json.Bson.BsonObjectId(nv));
                    }
                }
                else
                {
                    dvalTo.Add(kv.Key, kv.Value);
                }
            }
            WriteAsBson(dvalTo, writer);
        }