Ejemplo n.º 1
0
        public void TestPerfFillByKeyNormalVsExtensionMethod()
        {
            Helper.DropAllCollections();

            //Insert de Paises
            var c = new Country {Code = "ES", Name = "España"};
            c.Save();

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                var country = new Country();
                country.FillByKey("ES");
            }
            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para ExtensionMethod: {0}", timer.Elapsed));
            //Elapsed para ExtensionMethod: 00:04:38.5479462

            timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                MongoMapper<Country>.FindByKey("ES");
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para StaticMethod: {0}", timer.Elapsed));
            //Elapsed para StaticMethod: 00:04:27.1441065
        }
Ejemplo n.º 2
0
        public void TestPerfFillByKeyNormalVsExtensionMethod()
        {
            Helper.DropAllCollections();

            //Insert de Paises
            var c = new Country {
                Code = "ES", Name = "España"
            };

            c.Save();

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                var country = new Country();
                country.FillByKey("ES");
            }
            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para ExtensionMethod: {0}", timer.Elapsed));
            //Elapsed para ExtensionMethod: 00:04:38.5479462

            timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                MongoMapper <Country> .FindByKey("ES");
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para StaticMethod: {0}", timer.Elapsed));
            //Elapsed para StaticMethod: 00:04:27.1441065
        }
Ejemplo n.º 3
0
        public void TestSave()
        {
            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");
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void TestDelete()
        {
            Helper.DropAllCollections();

            //Insert de Paises
            var c = new Country {
                Code = "ES", Name = "España"
            };

            c.Save();

            c.FillByKey("ES");
            c.Delete();

            //TODO: Pruebas Replica Set
            //System.Threading.Thread.Sleep(5000);

            var country = new List <Country>();

            country.MongoFind();
            Assert.AreEqual(0, country.Count);
        }
Ejemplo n.º 6
0
        public void Test()
        {
            Helper.DropAllCollections();

            ConfigManager.Out = Console.Out;

            var c = new Country {Code = "es", Name = "España"};
            try
            {
                c.Save();
                Assert.Fail();
            }
            catch (ValidatePropertyException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof (ValidatePropertyException));
                c.Code = "ES";
                c.Save();
            }

            c = new Country {Code = "UK", Name = "Reino Unido"};
            c.Save();

            c = new Country {Code = "UK", Name = "Reino Unido"};
            try
            {
                c.Save();
                Assert.Fail();
            }
            catch (DuplicateKeyException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof (DuplicateKeyException));
            }

            using (var t = new MongoMapperTransaction())
            {
                var c2 = new Country {Code = "US", Name = "Francia"};
                c2.OnBeforeInsert += (s, e) => { ((Country) s).Name = "Estados Unidos"; };
                c2.Save();

                t.Commit();
            }

            var c3 = new Country();
            c3.FillByKey("US");
            Assert.AreEqual(c3.Name, "Estados Unidos");

            if (!c3.IsLastVersion())
                c3.FillFromLastVersion();

            var countries = new CountryCollection();
            countries.Find();
            Assert.AreEqual(countries.Count, 3);

            countries.Find().Limit(2).Sort(countries.Sort.Ascending(C=>C.Name));
            Assert.AreEqual(countries.Count, 2);
            Assert.AreEqual(countries.Total, 3);

            countries.Find(
                countries.Filter.Or(MongoQuery<Country>.Eq(co => co.Code, "ES"), MongoQuery<Country>.Eq(co => co.Code, "UK")));
            Assert.AreEqual(countries.Count, 2);

            var p = new Person
                {
                    Name = "Pepito Perez",
                    Age = 35,
                    BirthDate = DateTime.Now.AddDays(57).AddYears(-35),
                    Married = true,
                    Country = "XXXXX",
                    BankBalance = decimal.Parse("3500,00")
                };

            p.Childs.Add(
                new Child {ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez"});

            try
            {
                p.Save();
                Assert.Fail();
            }
            catch (ValidateUpRelationException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof (ValidateUpRelationException));
                p.Country = "ES";
                p.Save();
            }

            p.ServerUpdate(
                p.Update.Push(
                    MongoMapperHelper.ConvertFieldName("Person","Childs"),
                    new Child {ID = 2, Age = 2, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez"}));

            var persons = new List<Person>();

            persons.MongoFind();
            
            persons.MongoFind("Childs.Age", 2);
            Assert.AreEqual(1, persons.Count);
        }
Ejemplo n.º 7
0
        public void TestSave()
        {
            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");
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public void TestDelete()
        {
            Helper.DropAllCollections();

            //Insert de Paises
            var c = new Country {Code = "ES", Name = "España"};
            c.Save();

            c.FillByKey("ES");
            c.Delete();

            //TODO: Pruebas Replica Set
            //System.Threading.Thread.Sleep(5000);

            var country = new List<Country>();
            country.MongoFind();
            Assert.AreEqual(0, country.Count);
        }
Ejemplo n.º 10
0
        public void Test()
        {
            Helper.DropAllCollections();

            ConfigManager.Out = Console.Out;

            var c = new Country {
                Code = "es", Name = "España"
            };

            try
            {
                c.Save();
                Assert.Fail();
            }
            catch (ValidatePropertyException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof(ValidatePropertyException));
                c.Code = "ES";
                c.Save();
            }

            c = new Country {
                Code = "UK", Name = "Reino Unido"
            };
            c.Save();

            c = new Country {
                Code = "UK", Name = "Reino Unido"
            };
            try
            {
                c.Save();
                Assert.Fail();
            }
            catch (DuplicateKeyException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof(DuplicateKeyException));
            }

            using (var t = new MongoMapperTransaction())
            {
                var c2 = new Country {
                    Code = "US", Name = "Francia"
                };
                c2.OnBeforeInsert += (s, e) => { ((Country)s).Name = "Estados Unidos"; };
                c2.Save();

                t.Commit();
            }

            var c3 = new Country();

            c3.FillByKey("US");
            Assert.AreEqual(c3.Name, "Estados Unidos");

            if (!c3.IsLastVersion())
            {
                c3.FillFromLastVersion();
            }

            var countries = new CountryCollection();

            countries.Find();
            Assert.AreEqual(countries.Count, 3);

            countries.Find().Limit(2).Sort(countries.Sort.Ascending(C => C.Name));
            Assert.AreEqual(countries.Count, 2);
            Assert.AreEqual(countries.Total, 3);

            countries.Find(
                countries.Filter.Or(MongoQuery <Country> .Eq(co => co.Code, "ES"), MongoQuery <Country> .Eq(co => co.Code, "UK")));
            Assert.AreEqual(countries.Count, 2);

            var p = new Person
            {
                Name        = "Pepito Perez",
                Age         = 35,
                BirthDate   = DateTime.Now.AddDays(57).AddYears(-35),
                Married     = true,
                Country     = "XXXXX",
                BankBalance = decimal.Parse("3500,00")
            };

            p.Childs.Add(
                new Child {
                ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez"
            });

            try
            {
                p.Save();
                Assert.Fail();
            }
            catch (ValidateUpRelationException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof(ValidateUpRelationException));
                p.Country = "ES";
                p.Save();
            }

            p.ServerUpdate(
                p.Update.Push(
                    MongoMapperHelper.ConvertFieldName("Person", "Childs"),
                    new Child {
                ID = 2, Age = 2, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez"
            }));

            var persons = new List <Person>();

            persons.MongoFind();

            persons.MongoFind("Childs.Age", 2);
            Assert.AreEqual(1, persons.Count);
        }