public void TestCastsToDocument()
 {
     var ogen = new OidGenerator();
     var dref = new DBRef("tests.dbrefs", ogen.Generate());
     var doc = (Document)dref;
     Assert.AreEqual(dref.CollectionName, doc[DBRef.RefName]);
 }
        public void TestFollowNonReference(){
            var id = new Oid("BAD067c30a57000000008ecb");
            var rf = new DBRef("refs", id);

            var target = DB.FollowReference(rf);
            Assert.IsNull(target, "FollowReference returned wasn't null");
        }
        public void TestFromDocument()
        {
            const string colname = "tests";
            const string id = "32312312";
            var doc = new Document().Add(DBRef.RefName, colname).Add(DBRef.IdName, id);

            var expected = new DBRef(colname, id);
            Assert.AreEqual(expected, DBRef.FromDocument(doc));
        }
        public void TestEqualsUsingSameValues()
        {
            const string colname = "tests";
            const string id = "32312312";
            var r = new DBRef(colname, id);
            var r2 = new DBRef(colname, id);

            Assert.AreEqual(r, r2);
        }
        public void CanBeXmlSerialized()
        {
            var source = new DBRef("collection", "id");
            var serializer = new XmlSerializer(typeof(DBRef));

            var writer = new StringWriter();
            serializer.Serialize(writer, source);
            var dest = (DBRef)serializer.Deserialize(new StringReader(writer.ToString()));

            Assert.AreEqual(source, dest);
        }
        public void CanBeBinarySerialized()
        {
            var source = new DBRef("collection", "id");
            var formatter = new BinaryFormatter();

            var mem = new MemoryStream();
            formatter.Serialize(mem, source);
            mem.Position = 0;

            var dest = (DBRef)formatter.Deserialize(mem);

            Assert.AreEqual(source, dest);
        }
        public void TestFollowReference(){
            var refs = DB["refs"];
            var id = new Oid("4a7067c30a57000000008ecb");
            var msg = "this has an oid key";
            var doc = new Document {{"_id", id}, {"msg", msg}};
            refs.Insert(doc);

            var rf = new DBRef("refs", id);

            var target = DB.FollowReference(rf);
            Assert.IsNotNull(target, "FollowReference returned null");
            Assert.IsTrue(target.ContainsKey("msg"));
            Assert.AreEqual(msg, target["msg"]);
        }
Example #8
0
        public void Fetch()
        {
            IDBCollection c = Mongo.DefaultDatabase.GetCollection("test");
            c.Drop();

            Document obj = new Document() {{"test","me"}};
            c.Save(obj);

            DBRef r = new DBRef(c, obj.ID);
            IDocument deref = r.Fetch();

            Assert.That(deref, Is.Not.Null);
            Assert.That(deref.ID, Is.EqualTo(obj.ID));
        }
        public void TestReferenceNonOid(){
            var refs = DB["refs"];

            var doc = new Document().Add("_id", 123).Add("msg", "this has a non oid key");
            refs.Insert(doc);

            var rf = new DBRef("refs", 123);

            var recv = DB.FollowReference(rf);

            Assert.IsNotNull(recv);
            Assert.IsTrue(recv.ContainsKey("msg"));
            Assert.AreEqual(recv["_id"], (long)123);
        }
 /// <summary>
 ///   Calculates the size.
 /// </summary>
 /// <param name = "reference">The reference.</param>
 /// <returns></returns>
 public int CalculateSize(DBRef reference)
 {
     return CalculateSizeObject((Document)reference);
 }
 /// <summary>
 ///   Writes the specified reference.
 /// </summary>
 /// <param name = "reference">The reference.</param>
 public void Write(DBRef reference)
 {
     WriteObject((Document)reference);
 }
 public void TestEqualsAreSameObject()
 {
     var r = new DBRef("tests", "2312314");
     Assert.AreEqual(r, r);
 }