Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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());
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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"));
        }
Exemplo n.º 9
0
        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"));
        }
Exemplo n.º 10
0
        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"));
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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"));
        }
Exemplo n.º 13
0
        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));
            }
        }
Exemplo n.º 14
0
        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"));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
            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);
            }
Exemplo n.º 17
0
        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);
        }