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 ParentChildReference_CustomId_Example() { var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { var entityStore = new SimoEntityStore(session, DbName); //This time we use anonymous type and custom Id's (Guids). var parent = new { _id = Guid.NewGuid(), Name = "Daniel" }; var fatherReference = entityStore.Reference("Parent", parent._id); var child = new { _id = Guid.NewGuid(), 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<Guid> { CollectionName = "Parents", Id = parent._id }; entityStore.Insert("Parent", parent); entityStore.Insert("Child", child); var refetchedChild = entityStore.FindOneInfered(child, entityName: "Child", selector: new { child._id }); Assert.AreEqual(fatherReference.Id, refetchedChild.FatherReference.Id); Assert.AreEqual(fatherReference.CollectionName, refetchedChild.FatherReference.CollectionName); } }
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); } }
public void Find_UsingJsonInOperator_ReturnsTwoOfThree() { var documents = new[] { new Person { Name = "Daniel", Age = 29 }, new Person { Name = "Adam", Age = 55 }, new Person { Name = "Sue", Age = 55 }, }; TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, documents); var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Find <Person>(@"{Name : { $in : [""Daniel"", ""Sue""] } }"); var danielAndSueFound = persons.Where(p => new[] { "Daniel", "Sue" }.Contains(p.Name)).Count() == 2; Assert.AreEqual(2, persons.Count); Assert.IsTrue(danielAndSueFound); } }
public void QueryFor_UsingMultipleInOnDifferentProps_ReturnsOnePerson() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["Name"].In("Daniel").And("Age").In(21)); Assert.AreEqual(1, persons.Count); } }
public void QueryFor_UsingNotExistsQueryWhereMemberExists_ReturnsNoPersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["Tags"].NotExists()); Assert.AreEqual(3, persons.Count); } }
public void QueryFor_UsingSizeQueryOnArrayWithNoInts_ReturnsNoPersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["TimeCodes"].Size(0)); Assert.AreEqual(0, persons.Count); } }
public void Find_UsingWhereWithAnd_ReturnsOnePerson() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q.Where(@"this.Name == 'Daniel' && this.Age == 21")); Assert.AreEqual(1, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); } }
public void QueryFor_UsingNotInQuery_ReturnsOnePerson() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["Name"].NotIn("Daniel", "Sue").And("Age").NotIn(21, 23)); Assert.AreEqual(1, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); } }
public void Find_UsingWhereWithAnd_ReturnsOnePerson() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q.Where(@"this.Name == 'Daniel' && this.Age == 21")); Assert.AreEqual(1, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); } }
public void Insert_Example() { //The hierarchy in MongoDB is: //- Db // - Collection // - Document //By using EntityStore this is somewhat abstracted away. //You do need a connection to create a session //The creating of Connections and Session is something you most likely //will put in a IoC-container or factory or something. var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { var entityStore = new SimoEntityStore(session, DbName); //If you are dealing with typed documents (e.g. Person) //you can use the generic API. //Then the name of the collection is the name of the //type, but pluralized. //If you don't want pluralization, call //session.SimoPluralizer.Disable(), or //replace the implementation of the //SimoIoC.Instance.PluralizerResolver var person = new Person { Name = "Daniel", Age = 29 }; entityStore.Insert(person); //If you are using non-typed documents you have to pass //the entityname string to the method you are using. var anonymousPerson = new { Name = "Daniel" }; entityStore.Insert("Person", anonymousPerson); //So the EntityStore only allows for an abstraction //over the Db, Collection and Document hierarchy //and you can of course access these to. var db = session[DbName]; var persons = db["Person"]; persons.Insert(anonymousPerson); //The EntityStore also holds the Database that it wraps. //Of course you can obtain a collection using generics against the //database. var persons2 = entityStore.Database.GetCollection <Person>(); persons2.Insert(person); var numOfStoredDocuments = entityStore.Count <Person>(); Assert.AreEqual(4, numOfStoredDocuments); } }
public void Find_UsingWhereWithOr_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q.Where(@"this.Name == 'Daniel' || this.Name == 'Sue'")); Assert.AreEqual(6, persons.Count); Assert.AreEqual(3, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(3, persons.Where(p => p.Name == "Sue").Count()); } }
public void FindAll_LimitsTo20Of15_Returns15() { SetupData(15); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll<Person>(opts => opts.Limit(20)); Assert.AreEqual(15, persons.Count); } }
public void FindAll_SkipsThreeOfTwo_ReturnsNoItems() { SetupData(3); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll<Person>(opts => opts.Skip(3)); Assert.AreEqual(0, persons.Count); } }
public void FindAll_SkipsThreeOfTwo_ReturnsNoItems() { SetupData(3); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll <Person>(opts => opts.Skip(3)); Assert.AreEqual(0, persons.Count); } }
public void Find_UsingWhereWithOr_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q.Where(@"this.Name == 'Daniel' || this.Name == 'Sue'")); Assert.AreEqual(6, persons.Count); Assert.AreEqual(3, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(3, persons.Where(p => p.Name == "Sue").Count()); } }
public void FindAll_LimitsTo20Of15_Returns15() { SetupData(15); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll <Person>(opts => opts.Limit(20)); Assert.AreEqual(15, persons.Count); } }
public void QueryFor_UsingSizeQueryOnArrayWithInts_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["TimeCodes"].Size(1)); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void QueryFor_UsingChainedQuery_ReturnsTwoOfThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["Name"].In("Daniel", "Sue").And("Age").Between(22, 28)); Assert.AreEqual(2, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void QueryFor_UsingAllQueryWithStrings_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["Tags"].HasAll("T1", "T2")); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void QueryFor_UsingAllQueryWithInts_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["TimeCodes"].HasAll(100, 200)); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void QueryFor_UsingLtEQuery_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query <Person>(q => q["Age"].LtEq(21)); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void FindAll_Skip10LimitTo10WhenTotalOf100_Returns10() { SetupData(100); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll<Person>(opts => opts.Skip(10).Limit(10)); Assert.AreEqual(10, persons.Count); Assert.AreEqual(11, persons[0].Age); } }
public void FindAll_SkipsTwoOf100_ReturnsRemaining98() { SetupData(100); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll <Person>(opts => opts.Skip(2)); Assert.AreEqual(98, persons.Count); Assert.AreEqual(3, persons[0].Age); } }
public void FindAll_Skip10LimitTo10WhenTotalOf100_Returns10() { SetupData(100); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll <Person>(opts => opts.Skip(10).Limit(10)); Assert.AreEqual(10, persons.Count); Assert.AreEqual(11, persons[0].Age); } }
public void QueryFor_IntervalUsingQueryLtAndGt_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Age"].Gt(21).Lt(29)); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void Insert_Example() { //The hierarchy in MongoDB is: //- Db // - Collection // - Document //By using EntityStore this is somewhat abstracted away. //You do need a connection to create a session //The creating of Connections and Session is something you most likely //will put in a IoC-container or factory or something. var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { var entityStore = new SimoEntityStore(session, DbName); //If you are dealing with typed documents (e.g. Person) //you can use the generic API. //Then the name of the collection is the name of the //type, but pluralized. //If you don't want pluralization, call //session.SimoPluralizer.Disable(), or //replace the implementation of the //SimoIoC.Instance.PluralizerResolver var person = new Person { Name = "Daniel", Age = 29 }; entityStore.Insert(person); //If you are using non-typed documents you have to pass //the entityname string to the method you are using. var anonymousPerson = new { Name = "Daniel" }; entityStore.Insert("Person", anonymousPerson); //So the EntityStore only allows for an abstraction //over the Db, Collection and Document hierarchy //and you can of course access these to. var db = session[DbName]; var persons = db["Person"]; persons.Insert(anonymousPerson); //The EntityStore also holds the Database that it wraps. //Of course you can obtain a collection using generics against the //database. var persons2 = entityStore.Database.GetCollection<Person>(); persons2.Insert(person); var numOfStoredDocuments = entityStore.Count<Person>(); Assert.AreEqual(4, numOfStoredDocuments); } }
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."); } }
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 DisablePluralizer_Example() { var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { //Just call Disable on the Pluralizer //When you want to enable it again, call //Enable(). var entityStore = new SimoEntityStore(session, DbName); entityStore.Session.Pluralizer.Disable(); var person = new Person { Name = "Daniel" }; entityStore.Insert(person); var refetched = entityStore.Database["Person"].FindOne<Person>(new { person.Name }); Assert.IsNotNull(refetched); } }
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."); } }
public void DisablePluralizer_Example() { var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { //Just call Disable on the Pluralizer //When you want to enable it again, call //Enable(). var entityStore = new SimoEntityStore(session, DbName); entityStore.Session.Pluralizer.Disable(); var person = new Person { Name = "Daniel" }; entityStore.Insert(person); var refetched = entityStore.Database["Person"].FindOne <Person>(new { person.Name }); Assert.IsNotNull(refetched); } }
public void Find_UsingJsonWhereOperator_ReturnsTwoOfThree() { var documents = new[] { new Person {Name = "Daniel", Age = 29}, new Person {Name = "Adam", Age = 55}, new Person {Name = "Sue", Age = 55}, }; TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, documents); var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Find<Person>(@"{$where : ""this.Name == 'Daniel' || this.Name == 'Sue'""}"); var danielAndSueFound = persons.Where(p => new[] { "Daniel", "Sue" }.Contains(p.Name)).Count() == 2; Assert.AreEqual(2, persons.Count); Assert.IsTrue(danielAndSueFound); } }
public void QueryFor_UsingNotExistsQueryWhereMemberExists_ReturnsNoPersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Tags"].NotExists()); Assert.AreEqual(3, persons.Count); } }
public void FindAll_SkipsTwoOf100_ReturnsRemaining98() { SetupData(100); using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.FindAll<Person>(opts => opts.Skip(2)); Assert.AreEqual(98, persons.Count); Assert.AreEqual(3, persons[0].Age); } }
public void QueryFor_UsingMultipleInOnDifferentProps_ReturnsOnePerson() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Name"].In("Daniel").And("Age").In(21)); Assert.AreEqual(1, persons.Count); } }
public void QueryFor_UsingBetweenQuery_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Age"].Between(22, 28)); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
public void QueryFor_UsingSizeQueryOnArrayWithStrings_ReturnsThreePersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Tags"].Size(2)); Assert.AreEqual(3, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Daniel").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); Assert.AreEqual(1, persons.Where(p => p.Name == "Sue").Count()); } }
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); } }
public void QueryFor_UsingSizeQueryOnArrayWithNoStrings_ReturnsNoPersons() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Tags"].Size(0)); Assert.AreEqual(0, persons.Count); } }
public void QueryFor_UsingNotInQuery_ReturnsOnePerson() { using (var session = TestHelper.CreateSession()) { var entityStore = new SimoEntityStore(session, DbName); var persons = entityStore.Query<Person>(q => q["Name"].NotIn("Daniel", "Sue").And("Age").NotIn(21, 23)); Assert.AreEqual(1, persons.Count); Assert.AreEqual(1, persons.Where(p => p.Name == "Adam").Count()); } }