public void TestAdds() { BsonDocument doc = new BsonDocument(); for(int i = 1; i < 6; i++){ BsonElement be = new BsonElement(Convert.ToString(i),new BsonInteger(i)); doc.Add(be.Name, be); } Assert.AreEqual(5,doc.Count,"Not all elements there"); doc.Add(new BsonElement("6", new BsonInteger(6))); Assert.AreEqual(6,doc.Count,"Not all elements there"); doc.Add("7", new BsonInteger(7)); Assert.AreEqual(7,doc.Count,"Not all elements there"); }
protected QueryMessage generateQueryMessage() { BsonDocument qdoc = new BsonDocument(); qdoc.Add("listDatabases", new BsonNumber(1.0)); //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces"); QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd"); qmsg.NumberToReturn = -1; return qmsg; }
public void TestSendQueryMessage() { //Connection conn = new Connection("10.141.153.2"); Connection conn = new Connection(); conn.Open(); BsonDocument qdoc = new BsonDocument(); qdoc.Add("listDatabases", new BsonNumber(1.0)); //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces"); QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd"); qmsg.NumberToReturn = -1; conn.SendTwoWayMessage(qmsg); conn.Close(); }
public void TestAllBytesWritten() { BsonDocument query = new BsonDocument(); query.Add("col1", BsonConvert.From(1)); QueryMessage msg = new QueryMessage(query,"TestDB.TestCol"); MemoryStream buffer = new MemoryStream(); msg.Write(buffer); Byte[] output = buffer.ToArray(); String hexdump = BitConverter.ToString(output); //Console.WriteLine("Dump: " + hexdump); Assert.IsTrue(output.Length > 0); Assert.AreEqual("3A-00-00-00-00-00-00-00-00-00-00-00-D4-07-00-00-00-00-00-00-54-65-73-74-44-42-2E-54-65-73-74-43-6F-6C-00-00-00-00-00-00-00-00-00-0F-00-00-00-10-63-6F-6C-31-00-01-00-00-00-00", hexdump); }
public void TestWriteMessageTwice() { string expectedHex = "3A-00-00-00-00-00-00-00-00-00-00-00-D4-07-00-00-00-00-00-00-54-65-73-74-44-42-2E-54-65-73-74-43-6F-6C-00-00-00-00-00-00-00-00-00-0F-00-00-00-10-63-6F-6C-31-00-01-00-00-00-00"; BsonDocument query = new BsonDocument(); query.Add("col1", BsonConvert.From(1)); QueryMessage msg = new QueryMessage(query,"TestDB.TestCol"); MemoryStream buffer = new MemoryStream(); msg.Write(buffer); Byte[] output = buffer.ToArray(); String hexdump = BitConverter.ToString(output); MemoryStream buffer2 = new MemoryStream(); msg.Write(buffer2); Byte[] output2 = buffer.ToArray(); String hexdump2 = BitConverter.ToString(output2); Assert.AreEqual(expectedHex,hexdump); Assert.AreEqual(hexdump,hexdump2); }
public static BsonDocument From(DBRef val) { BsonDocument ret = new BsonDocument(); ret.Add(new BsonElement("$ref", new BsonString(val.CollectionName))); ret.Add(new BsonElement("$id", From(val.Id))); return ret; }
public static BsonDocument From(Document doc) { BsonDocument bdoc = new BsonDocument(); foreach(String key in doc.Keys){ bdoc.Add(key, From(doc[key])); } return bdoc; }
public void TestSize() { BsonDocument doc = new BsonDocument(); Assert.AreEqual(5, doc.Size); doc.Add("test", new BsonString("test")); Assert.AreEqual(20, doc.Size); for(int i = 1; i < 6; i++){ doc.Add(Convert.ToString(i),new BsonInteger(i)); } Assert.AreEqual(55, doc.Size); BsonDocument sub = new BsonDocument(); sub.Add("test", new BsonString("sub test")); Assert.AreEqual(24,sub.Size); doc.Add("sub",sub); Assert.AreEqual(84,doc.Size); }
public void TestFormattingWithUKPound() { BsonDocument doc = new BsonDocument(); MemoryStream buf = new MemoryStream(); BsonWriter writer = new BsonWriter(buf); doc.Add("_id", new BsonOid(new Oid("4ABBED9D1D8B0F0218000001"))); doc.Add("test", new BsonString("1234£56")); doc.Write(writer); writer.Flush(); Byte[] output = buf.ToArray(); String hexdump = BitConverter.ToString(output); hexdump = hexdump.Replace("-",""); //Assert.AreEqual(20,output[0],"Size didn't take into count null terminator"); Assert.AreEqual("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000",hexdump, "Dump not correct"); }
public void TestFormatting() { BsonDocument doc = new BsonDocument(); MemoryStream buf = new MemoryStream(); BsonWriter writer = new BsonWriter(buf); doc.Add("test", new BsonString("test")); doc.Write(writer); writer.Flush(); Byte[] output = buf.ToArray(); String hexdump = BitConverter.ToString(output); hexdump = hexdump.Replace("-",""); Assert.AreEqual(20,output[0],"Size didn't take into count null terminator"); Assert.AreEqual("1400000002746573740005000000746573740000",hexdump, "Dump not correct"); }