public void TestFillByKeyExtension() { Helper.DropAllCollections(); //Insert de Paises var c = new Country { Code = "ES", Name = "España" }; c.Save(); var country = new Country(); country.FillByKey("ES"); Assert.AreEqual(country.Code, "ES"); //Insert de personas var p = new Person { Name = "Pepito Perez", Age = 35, BirthDate = DateTime.Now.AddDays(57).AddYears(-35), Married = true, Country = "ES", BankBalance = decimal.Parse("3500,00") }; p.Childs.Add( new Child { ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez" }); p.Childs.Add( new Child { ID = 2, Age = 7, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez" }); p.Save(); long id = p.m_id; p = new Person(); p.FillByKey(id); }
public void TestFindByPk() { //Llenamos datos Helper.DropAllCollections(); ConfigManager.Out = Console.Out; var c = new Country {Code = "ES", Name = "España"}; c.Save(); //Insert de personas var p = new Person { Name = "Pepito Perez", Age = 35, BirthDate = DateTime.Now.AddDays(57).AddYears(-35), Married = true, Country = "ES", BankBalance = decimal.Parse("3500,00") }; p.Childs.Add( new Child {ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez"}); p.Childs.Add( new Child {ID = 2, Age = 7, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez"}); p.Save(); p = new Person { Name = "Juanito Sanchez", Age = 25, BirthDate = DateTime.Now.AddDays(52).AddYears(-38), Married = true, Country = "ES", BankBalance = decimal.Parse("1500,00") }; p.Childs.Add( new Child {ID = 1, Age = 5, BirthDate = DateTime.Now.AddDays(7).AddYears(-5), Name = "Toni Sanchez"}); p.Save(); p = new Person { Name = "Andres Perez", Age = 25, BirthDate = DateTime.Now.AddDays(25).AddYears(-25), Married = false, Country = "ES", BankBalance = decimal.Parse("500,00") }; p.Save(); p = new Person { Name = "Marta Serrano", Age = 28, BirthDate = DateTime.Now.AddDays(28).AddYears(-28), Married = false, Country = "ES", BankBalance = decimal.Parse("9500,00") }; p.Childs.Add( new Child {ID = 1, Age = 2, BirthDate = DateTime.Now.AddDays(2).AddYears(-2), Name = "Toni Serrano"}); p.Save(); p = new Person { Name = "Jonh Smith", Age = 21, BirthDate = DateTime.Now.AddDays(21).AddYears(-21), Married = false, Country = "ES", BankBalance = decimal.Parse("100,00") }; p.Save(); List<Person> plist = MongoMapperCollection<Person>.Instance.Find().ToList(); var p2 = new Person(); p2.FillByKey(plist[0].m_id); p2.Name = "FindBYKey Name"; p2.Save(); var Persons = MongoMapperCollection<Person>.Instance; plist = Persons.Find(x=>x.m_id, p2.m_id).ToList(); Assert.AreEqual(1, plist.Count); Assert.AreEqual(plist[0].Name, "FindBYKey Name"); c = new Country(); //Assert.Throws(typeof(FindByKeyNotFoundException), c.FillByKey("XXXXXX")); }
public void TestFillByKeyExtension() { Helper.DropAllCollections(); //Insert de Paises var c = new Country {Code = "ES", Name = "España"}; c.Save(); var country = new Country(); country.FillByKey("ES"); Assert.AreEqual(country.Code, "ES"); //Insert de personas var p = new Person { Name = "Pepito Perez", Age = 35, BirthDate = DateTime.Now.AddDays(57).AddYears(-35), Married = true, Country = "ES", BankBalance = decimal.Parse("3500,00") }; p.Childs.Add( new Child {ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez"}); p.Childs.Add( new Child {ID = 2, Age = 7, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez"}); p.Save(); long id = p.m_id; p = new Person(); p.FillByKey(id); }
public void TestFindByPk() { //Llenamos datos Helper.DropAllCollections(); ConfigManager.Out = Console.Out; var c = new Country { Code = "ES", Name = "España" }; c.Save(); //Insert de personas var p = new Person { Name = "Pepito Perez", Age = 35, BirthDate = DateTime.Now.AddDays(57).AddYears(-35), Married = true, Country = "ES", BankBalance = decimal.Parse("3500,00") }; p.Childs.Add( new Child { ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez" }); p.Childs.Add( new Child { ID = 2, Age = 7, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez" }); p.Save(); p = new Person { Name = "Juanito Sanchez", Age = 25, BirthDate = DateTime.Now.AddDays(52).AddYears(-38), Married = true, Country = "ES", BankBalance = decimal.Parse("1500,00") }; p.Childs.Add( new Child { ID = 1, Age = 5, BirthDate = DateTime.Now.AddDays(7).AddYears(-5), Name = "Toni Sanchez" }); p.Save(); p = new Person { Name = "Andres Perez", Age = 25, BirthDate = DateTime.Now.AddDays(25).AddYears(-25), Married = false, Country = "ES", BankBalance = decimal.Parse("500,00") }; p.Save(); p = new Person { Name = "Marta Serrano", Age = 28, BirthDate = DateTime.Now.AddDays(28).AddYears(-28), Married = false, Country = "ES", BankBalance = decimal.Parse("9500,00") }; p.Childs.Add( new Child { ID = 1, Age = 2, BirthDate = DateTime.Now.AddDays(2).AddYears(-2), Name = "Toni Serrano" }); p.Save(); p = new Person { Name = "Jonh Smith", Age = 21, BirthDate = DateTime.Now.AddDays(21).AddYears(-21), Married = false, Country = "ES", BankBalance = decimal.Parse("100,00") }; p.Save(); List <Person> plist = MongoMapperCollection <Person> .Instance.Find().ToListAsync().Result; var p2 = new Person(); p2.FillByKey(plist[0].m_id); p2.Name = "FindBYKey Name"; p2.Save(); var Persons = MongoMapperCollection <Person> .Instance; plist = Persons.Find(x => x.m_id, p2.m_id).ToListAsync().Result; Assert.AreEqual(1, plist.Count); Assert.AreEqual(plist[0].Name, "FindBYKey Name"); c = new Country(); //Assert.Throws(typeof(FindByKeyNotFoundException), c.FillByKey("XXXXXX")); }