public static DBRef FromDocument(Document doc) { if(IsDocumentDBRef(doc) == false) throw new ArgumentException("Document is not a DBRef"); DBRef ret = new DBRef(); ret.CollectionName = (String)doc["$ref"]; ret.Id = (String)doc["$id"]; return ret; }
public void TestCastsToDocument() { OidGenerator ogen = new OidGenerator(); DBRef dref = new DBRef("tests.dbrefs", ogen.Generate()); Document doc = (Document)dref; Assert.AreEqual(dref.CollectionName, doc[DBRef.RefName]); }
public void DBRefConstructorTest() { IDBCollection collection = Mongo.DefaultDatabase["ref"]; object id = Oid.NewOid(); DBRef target = new DBRef(collection, id); target.ID.Should().Be(id); target.Collection.Should().BeEquivalentTo(collection); }
public void TestFollowNonReference() { Oid id = new Oid("BAD067c30a57000000008ecb"); DBRef rf = new DBRef("refs", id); Document target = DB.FollowReference(rf); Assert.IsNull(target, "FollowReference returned wasn't null"); }
public void TestFromDocument() { String colname = "tests"; String id = "32312312"; Document doc = new Document().Append(DBRef.RefName,colname).Append(DBRef.IdName,id); DBRef expected = new DBRef(colname, id); Assert.AreEqual(expected, DBRef.FromDocument(doc)); }
public override bool Equals(object obj) { if (obj is DBRef) { DBRef comp = (DBRef)obj; return(comp.Id.Equals(this.Id) && comp.CollectionName.Equals(this.CollectionName)); } return(base.Equals(obj)); }
public void TestEqualsUsingSameValues() { String colname = "tests"; String id = "32312312"; DBRef r = new DBRef(colname, id); DBRef r2 = new DBRef(colname, id); Assert.AreEqual(r, r2); }
public void TestEqualsUsingSameValues() { String colname = "tests"; String id = "32312312"; DBRef r = new DBRef(colname,id); DBRef r2 = new DBRef(colname, id); Assert.AreEqual(r,r2); }
/// <summary> /// Gets the document that a reference is pointing to. /// </summary> public Document FollowReference(DBRef reference) { if (reference == null) { throw new ArgumentNullException("reference cannot be null"); } Document query = new Document().Append("_id", reference.Id); return(this[reference.CollectionName].FindOne(query)); }
public void TestFromDocument() { String colname = "tests"; String id = "32312312"; Document doc = new Document().Append(DBRef.RefName, colname).Append(DBRef.IdName, id); DBRef expected = new DBRef(colname, id); Assert.AreEqual(expected, DBRef.FromDocument(doc)); }
public void TestFollowNonReference() { Database tests = mongo["tests"]; Oid id = new Oid("BAD067c30a57000000008ecb"); DBRef rf = new DBRef("reads", id); Document target = tests.FollowReference(rf); Assert.IsNull(target, "FollowReference returned wasn't null"); }
public void TestFromIncompleteDocumentThrowsArguementException() { bool thrown = false; try { DBRef.FromDocument(new Document().Append(DBRef.RefName, "tests")); } catch (ArgumentException) { thrown = true; } Assert.IsTrue(thrown, "ArgumentException should have been thrown when trying to create convert from incomplete document"); }
public void TestFollowReference() { Database tests = mongo["tests"]; Oid id = new Oid("4a7067c30a57000000008ecb"); DBRef rf = new DBRef("reads", id); Document target = tests.FollowReference(rf); Assert.IsNotNull(target, "FollowReference returned null"); Assert.IsTrue(target.Contains("j")); Assert.AreEqual((double)9980, (double)target["j"]); }
public void TestFollowReference() { IMongoCollection refs = DB["refs"]; Oid id = new Oid("4a7067c30a57000000008ecb"); string msg = "this has an oid key"; Document doc = new Document(){{"_id", id},{"msg", msg}}; refs.Insert(doc); DBRef rf = new DBRef("refs", id); Document target = DB.FollowReference(rf); Assert.IsNotNull(target, "FollowReference returned null"); Assert.IsTrue(target.Contains("msg")); Assert.AreEqual(msg, target["msg"]); }
public void TestReferenceNonOid() { Database tests = mongo["tests"]; Collection refs = tests["refs"]; Document doc = new Document().Append("_id",123).Append("msg", "this has a non oid key"); refs.Insert(doc); DBRef rf = new DBRef("refs",123); Document recv = tests.FollowReference(rf); Assert.IsNotNull(recv); Assert.IsTrue(recv.Contains("msg")); Assert.AreEqual(recv["_id"], (long)123); }
public void TestReferenceNonOid() { Database tests = mongo["tests"]; IMongoCollection refs = tests["refs"]; Document doc = new Document().Append("_id", 123).Append("msg", "this has a non oid key"); refs.Insert(doc); DBRef rf = new DBRef("refs", 123); Document recv = tests.FollowReference(rf); Assert.IsNotNull(recv); Assert.IsTrue(recv.Contains("msg")); Assert.AreEqual(recv["_id"], (long)123); }
public void TestIsDocumentDBRef() { Document doc = new Document(); Assert.IsFalse(DBRef.IsDocumentDBRef(null)); Assert.IsFalse(DBRef.IsDocumentDBRef(doc)); doc[DBRef.RefName] = "tests"; Assert.IsFalse(DBRef.IsDocumentDBRef(doc)); doc.Remove(DBRef.RefName); doc[DBRef.IdName] = "12312131"; Assert.IsFalse(DBRef.IsDocumentDBRef(doc)); doc[DBRef.RefName] = "tests"; Assert.IsTrue(DBRef.IsDocumentDBRef(doc)); doc[DBRef.MetaName] = new Document(); Assert.IsTrue(DBRef.IsDocumentDBRef(doc)); }
public void TestEqualsAreSameObject() { DBRef r = new DBRef("tests","2312314"); Assert.AreEqual(r,r); }
private void Write(DBRef dbref) { Write(dbref.FullName, true); Write(dbref.Id); }
/// <summary> /// Gets the document that a reference is pointing to. /// </summary> public Document FollowReference(DBRef reference) { if(reference == null) throw new ArgumentNullException("reference", "cannot be null"); Document query = new Document().Append("_id", reference.Id); return this[reference.CollectionName].FindOne(query); }
void element_object(string name, DBRef reference) { element_type(TypeByte.OBJECT); element_name(name); long sizePos = BaseStream.Position; Write(0); element_string("$ref", reference.Collection.Name); element("$id", reference.ID); Write((byte)TypeByte.EOO); RewindAndWriteSize(sizePos); }
protected DBRef ToDBRef() { DBRef rf = new DBRef(); rf.CollectionName = (String)this["$ref"].Val.ToNative(); rf.Id = this["$id"].Val.ToNative(); return rf; }
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 void TestEqualsAreSameObject() { DBRef r = new DBRef("tests", "2312314"); Assert.AreEqual(r, r); }
public void FetchTest() { 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(); deref.Should().NotBeNull(); deref.ID.Should().Be(obj.ID); }