public void SaveExistingDocument() { Collection collection = new Collection("Test"); DynamicDocument original = new DynamicDocument("Name", "Adam"); collection.Insert(original); DynamicDocument document = new DynamicDocument("Name", "New Adam", "Age", 800) { Id = original.Id }; collection.Save(document); var result = collection.Find(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); var newdocument = result.First(); Assert.IsNotNull(newdocument); Assert.AreEqual(original.Id, newdocument.Id); Assert.AreEqual("New Adam", newdocument.GetMember("Name")); Assert.AreEqual(800, newdocument.GetMember("Age")); }
private void buttonSave_Click(object sender, EventArgs e) { ISetting setting = this.SettingCreate(); using (var dialog = new SaveFileDialog()) { dialog.AddExtension = true; dialog.DefaultExt = "dll"; dialog.Filter = "DLL files (*.dll)|*.dll"; dialog.OverwritePrompt = true; if (dialog.ShowDialog(this) == DialogResult.OK) { try { DynamicDocument.Save(new StringReader(this.textBoxInput.Text), setting, Path.GetFileNameWithoutExtension(dialog.FileName), Path.GetFileName(dialog.FileName)); this.DisplayText("File saved."); } catch (ParseException exception) { this.DisplayError(exception); } } } }
public void SaveNewDocument() { Collection collection = new Collection("Test"); DynamicDocument document = new DynamicDocument(); collection.Save(document); Assert.IsNotNull(document.Id); Assert.AreEqual(document.Id, document.GetMember("Id")); Assert.IsInstanceOfType(document.Id, typeof(Guid)); }
public void FindOneUnknownDocument() { Collection collection = new Collection("Test"); DynamicDocument document1 = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument document2 = new DynamicDocument("Name", "Eve", "Age", 700); collection.Insert(document1); collection.Insert(document2); var result = collection.FindOne(new DynamicDocument("Age", 600)); Assert.IsNull(result); }
private static Collection GetCollection() { Collection collection = new Collection("Test"); DynamicDocument document1 = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument document2 = new DynamicDocument("Name", "Eve", "Age", 700); DynamicDocument document3 = new DynamicDocument("Name", "Abel", "Age", 600); collection.Insert(document1); collection.Insert(document2); collection.Insert(document3); return(collection); }
public void FindOneDocumentUsingQueryWithIdAndDifferentValue() { Collection collection = new Collection("Test"); DynamicDocument document1 = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument document2 = new DynamicDocument("Name", "Eve", "Age", 700); collection.Insert(document1); collection.Insert(document2); var result = collection.Find(new DynamicDocument("Id", document2.GetMember("Id"), "Age", 800)); Assert.AreEqual(0, result.Count()); }
public void Setup() { this.collection = new Collection("People"); this.adam = new DynamicDocument("Name", "Adam", "Age", 800); this.eve = new DynamicDocument("Name", "Eve", "Age", 700); this.cain = new DynamicDocument("Name", "Cain", "Age", 600); this.abel = new DynamicDocument("Name", "Abel", "Age", 500); this.collection.Insert(this.adam); this.collection.Insert(this.eve); this.collection.Insert(this.cain); this.collection.Insert(this.abel); }
public void ProjectNameExcludingId() { DynamicDocument document = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument projection = new DynamicDocument("Name", true, "Id", false); var result = document.Project(projection); Assert.IsNotNull(result); Assert.IsNotNull(result.GetMember("Name")); Assert.AreEqual("Adam", result.GetMember("Name")); Assert.IsNull(result.GetMember("Age")); Assert.AreEqual(1, result.GetMemberNames().Count()); Assert.IsTrue(result.GetMemberNames().Contains("Name")); }
public void GetDocument() { Collection collection = new Collection("Test"); DynamicDocument document = new DynamicDocument("Name", "Adam", "Age", 800); collection.Insert(document); var result = collection.GetDocument((Guid)document.GetMember("Id")); Assert.IsNotNull(result); Assert.AreEqual(document.GetMember("Id"), result.GetMember("Id")); Assert.AreEqual("Adam", result.GetMember("Name")); Assert.AreEqual(800, result.GetMember("Age")); }
public void FindOneDocument() { Collection collection = new Collection("Test"); DynamicDocument document = new DynamicDocument("Name", "Adam", "Age", 800); collection.Insert(document); var result = collection.Find(); Assert.AreEqual(1, result.Count()); Assert.AreEqual(document.GetMember("Id"), result.First().GetMember("Id")); Assert.AreEqual("Adam", result.First().GetMember("Name")); Assert.AreEqual(800, result.First().GetMember("Age")); }
private Collection GetCollection() { var collection = new Collection("People"); this.adam = new DynamicDocument("Name", "Adam", "Age", 800); var eve = new DynamicDocument("Name", "Eve", "Age", 700); var cain = new DynamicDocument("Name", "Cain", "Age", 600); var abel = new DynamicDocument("Name", "Abel", "Age", 500); collection.Insert(this.adam); collection.Insert(eve); collection.Insert(cain); collection.Insert(abel); return(collection); }
public void FindOneDocumentUsingQuery() { Collection collection = new Collection("Test"); DynamicDocument document1 = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument document2 = new DynamicDocument("Name", "Eve", "Age", 700); collection.Insert(document1); collection.Insert(document2); var result = collection.Find(new DynamicDocument("Age", 700)); Assert.AreEqual(1, result.Count()); Assert.AreEqual(document2.GetMember("Id"), result.First().GetMember("Id")); Assert.AreEqual("Eve", result.First().GetMember("Name")); Assert.AreEqual(700, result.First().GetMember("Age")); }
public void InsertAndModifyDocument() { Collection collection = new Collection("Test"); DynamicDocument document = new DynamicDocument("Name", "Adam"); collection.Insert(document); try { document.SetMember("Name", "Eve"); Assert.Fail(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(InvalidOperationException)); } }
public void FindOneDocumentUsingQueryWithId() { Collection collection = new Collection("Test"); DynamicDocument document1 = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument document2 = new DynamicDocument("Name", "Eve", "Age", 700); collection.Insert(document1); collection.Insert(document2); var result = collection.FindOne(new DynamicDocument("Id", document2.GetMember("Id"), "Age", 700)); Assert.IsNotNull(result); Assert.AreEqual(document2.GetMember("Id"), result.GetMember("Id")); Assert.AreEqual("Eve", result.GetMember("Name")); Assert.AreEqual(700, result.GetMember("Age")); }
public void DistinctAgeWithFilter() { Collection collection = new Collection("Test"); DynamicDocument document1 = new DynamicDocument("Name", "Adam", "Age", 800); DynamicDocument document2 = new DynamicDocument("Name", "Eve", "Age", 700); DynamicDocument document3 = new DynamicDocument("Name", "Adam", "Age", 801); DynamicDocument document4 = new DynamicDocument("Name", "Eve", "Age", 701); collection.Insert(document1); collection.Insert(document2); collection.Insert(document3); collection.Insert(document4); var result = collection.Distinct("Age", new DynamicObject("Name", "Adam")); Assert.IsNotNull(result); Assert.AreEqual(2, result.Count()); Assert.IsTrue(result.Contains(800)); Assert.IsTrue(result.Contains(801)); }
public object Apply(IList <object> arguments) { IObject dobj = (IObject)arguments[0]; DynamicDocument doc = new DynamicDocument(); foreach (var name in dobj.GetMemberNames()) { doc.SetMember(name, dobj.GetMember(name)); } if (doc.Id == null) { doc.Id = Guid.NewGuid(); } this.self.Collection.Save(doc); return(null); }
public void SaveNewDocumentWithId() { Collection collection = new Collection("Test"); var id = Guid.NewGuid(); DynamicDocument document = new DynamicDocument() { Id = id }; collection.Save(document); var result = collection.Find(new DynamicDocument() { Id = id }); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); var newdocument = result.First(); Assert.AreEqual(id, newdocument.Id); }