public static BsonType Create(BsonDataType type) { BsonType ret = null; if(type == BsonDataType.Number){ ret = new BsonNumber(); }else if(type == BsonDataType.Number){ throw new NotImplementedException(); }else if(type == BsonDataType.String){ ret = new BsonString(); }else if(type == BsonDataType.Obj){ ret = new BsonDocument(); }else if(type == BsonDataType.Array){ ret = new BsonArray(); }else if(type == BsonDataType.Integer){ ret = new BsonInteger(); }else if(type == BsonDataType.Long){ ret = new BsonLong(); }else if(type == BsonDataType.Boolean){ ret = new BsonBoolean(); }else if(type == BsonDataType.Oid){ ret = new BsonOid(); }else if(type == BsonDataType.Date){ ret = new BsonDate(); }else if(type == BsonDataType.Regex){ ret = new BsonRegex(); }else{ throw new ArgumentOutOfRangeException("Type: " + type + " not recognized"); } return ret; }
public void TestSizeWithUKPound() { UTF8Encoding encoding = new UTF8Encoding(); int baseSize = 5; String test = "1£"; BsonString bstr = new BsonString(test); Assert.AreEqual(baseSize + encoding.GetByteCount(test), bstr.Size, "Size didn't count the double wide pound symbol correctly"); }
public void TestBsonString() { InitStreams(); BsonString w = new BsonString("test"); w.Write(writer); FlushAndGotoBegin(); BsonString r = new BsonString(); r.Read(reader); Assert.AreEqual(w.Val, r.Val); }
public void TestFormattingWithUKPound() { BsonString str = new BsonString("1234£56"); MemoryStream buf = new MemoryStream(); BsonWriter writer = new BsonWriter(buf); str.Write(writer); writer.Flush(); Byte[] output = buf.ToArray(); String hexdump = BitConverter.ToString(output); hexdump = hexdump.Replace("-",""); Assert.AreEqual("0900000031323334C2A3353600",hexdump, "Dump not correct"); Assert.AreEqual(9,output[0],"Size didn't take into account size of pound symbol"); }
public void TestFormatting() { BsonString str = new BsonString("test"); MemoryStream buf = new MemoryStream(); BsonWriter writer = new BsonWriter(buf); str.Write(writer); writer.Flush(); Byte[] output = buf.ToArray(); String hexdump = BitConverter.ToString(output); hexdump = hexdump.Replace("-",""); Assert.AreEqual(5,output[0],"Size didn't take into count null terminator"); Assert.AreEqual("050000007465737400",hexdump, "Dump not correct"); }
public static BsonType Create(BsonDataType type) { BsonType ret = null; if(type == BsonDataType.Number){ ret = new BsonNumber(); }else if(type == BsonDataType.Number){ throw new NotImplementedException(); }else if(type == BsonDataType.String){ ret = new BsonString(); }else if(type == BsonDataType.Obj){ ret = new BsonDocument(); }else if(type == BsonDataType.Array){ ret = new BsonArray(); }else if(type == BsonDataType.Integer){ ret = new BsonInteger(); }else if(type == BsonDataType.Long){ ret = new BsonLong(); }else if(type == BsonDataType.Boolean){ ret = new BsonBoolean(); }else if(type == BsonDataType.Oid){ ret = new BsonOid(); }else if(type == BsonDataType.Date){ ret = new BsonDate(); }else if(type == BsonDataType.Regex){ ret = new BsonRegex(); }else if(type == BsonDataType.Undefined){ ret = new BsonUndefined(); }else if(type == BsonDataType.Null){ ret = new BsonNull(); }else if(type == BsonDataType.Code){ ret = new BsonCode(); }else if(type == BsonDataType.CodeWScope){ ret = new BsonCodeWScope(); }else{ string typename = Enum.GetName(typeof(BsonDataType), type); throw new ArgumentOutOfRangeException("type",typename + "is not recognized"); } return ret; }
public void TestSize() { BsonString str = new BsonString("test"); Assert.AreEqual(9,str.Size); }