Пример #1
0
        public void Find_UsingRegex()
        {
            var cn = TestHelper.CreateConnection();

            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                entityStore.Insert(new Person {
                    Name = "Daniel", Age = 29
                });
                entityStore.Insert(new Person {
                    Name = "Daniel1", Age = 45
                });
                entityStore.Insert(new Person {
                    Name = "Daniel1", Age = 55
                });
                entityStore.Insert(new Person {
                    Name = "Daniel2", Age = 65
                });
                entityStore.Insert(new Person {
                    Name = "Sue", Age = 20
                });

                var refetched = entityStore.FindOne <Person>(new { Age = 45, Name = new SimoRegex("^Dan.*1") });

                Assert.AreEqual(45, refetched.Age);
                Assert.AreEqual("Daniel1", refetched.Name);
            }
        }
Пример #2
0
        public void ParentChildReference_Example()
        {
            var cn = TestHelper.CreateConnection();

            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                //The parent generates a new _id when created.
                //That _id is then used in the reference which is attached to the child.
                //After that, you just store the items.
                var parent = new Parent {
                    Name = "Daniel"
                };
                var fatherReference = entityStore.Reference <Parent>(parent._id);
                var child           = new Child {
                    Name = "Isabell", FatherReference = fatherReference
                };

                //You could of course have created the reference manually, but then you loose the
                //use of the pluralizer, and have to role-this on your own.
                //new SimoReference { CollectionName = "Parents", Id = parent._id };

                entityStore.Insert(parent);
                entityStore.Insert(child);

                var refetchedChild = entityStore.FindOne <Child>(new { child._id });

                Assert.AreEqual(fatherReference.Id, refetchedChild.FatherReference.Id);
                Assert.AreEqual(fatherReference.CollectionName, refetchedChild.FatherReference.CollectionName);
            }
        }
Пример #3
0
        public void FindOne_ChildHasNullReferenceToParent_ReturnsChildWithNullReferenceParent()
        {
            var child = new Child { Name = "Isabell" };
            TestHelper.InsertDocument(Constants.Collections.ChildsCollectionName, child);

            var cn = TestHelper.CreateConnection();
            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                var refetchedChild = entityStore.FindOne<Child>(new { _id = child._id });

                Assert.IsNotNull(refetchedChild, "Couldn't refetch child.");
                Assert.IsNull(refetchedChild.FatherReference, "Fatherreference should be null.");
            }
        }
Пример #4
0
        public void Find_UsingRegex()
        {
            var cn = TestHelper.CreateConnection();
            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                entityStore.Insert(new Person { Name = "Daniel", Age = 29 });
                entityStore.Insert(new Person { Name = "Daniel1", Age = 45 });
                entityStore.Insert(new Person { Name = "Daniel1", Age = 55 });
                entityStore.Insert(new Person { Name = "Daniel2", Age = 65 });
                entityStore.Insert(new Person { Name = "Sue", Age = 20 });

                var refetched = entityStore.FindOne<Person>(new { Age = 45, Name = new SimoRegex("^Dan.*1") });

                Assert.AreEqual(45, refetched.Age);
                Assert.AreEqual("Daniel1", refetched.Name);
            }
        }
        public void FindOne_ChildHasNullReferenceToParent_ReturnsChildWithNullReferenceParent()
        {
            var child = new Child {
                Name = "Isabell"
            };

            TestHelper.InsertDocument(Constants.Collections.ChildsCollectionName, child);

            var cn = TestHelper.CreateConnection();

            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                var refetchedChild = entityStore.FindOne <Child>(new { _id = child._id });

                Assert.IsNotNull(refetchedChild, "Couldn't refetch child.");
                Assert.IsNull(refetchedChild.FatherReference, "Fatherreference should be null.");
            }
        }
Пример #6
0
        public void ParentChildReference_Example()
        {
            var cn = TestHelper.CreateConnection();
            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                //The parent generates a new _id when created.
                //That _id is then used in the reference which is attached to the child.
                //After that, you just store the items.
                var parent = new Parent { Name = "Daniel" };
                var fatherReference = entityStore.Reference<Parent>(parent._id);
                var child = new Child { Name = "Isabell", FatherReference = fatherReference };

                //You could of course have created the reference manually, but then you loose the
                //use of the pluralizer, and have to role-this on your own.
                //new SimoReference { CollectionName = "Parents", Id = parent._id };

                entityStore.Insert(parent);
                entityStore.Insert(child);

                var refetchedChild = entityStore.FindOne<Child>(new { child._id });

                Assert.AreEqual(fatherReference.Id, refetchedChild.FatherReference.Id);
                Assert.AreEqual(fatherReference.CollectionName, refetchedChild.FatherReference.CollectionName);
            }
        }