Esempio n. 1
0
        public Country()
        {
            //Paris
            var ParisArea = new GeoArea();
            ParisArea.type = "Polygon";
            var coordinates = new List<double[]>();
            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            coordinates.Add(new double[] { 48.972555195463336, 2.5982666015625 });
            coordinates.Add(new double[] { 48.683254235765325, 2.603759765625 });
            coordinates.Add(new double[] { 48.66874533279169, 2.120361328125 });
            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            ParisArea.coordinates = new[] { coordinates.ToArray() };

            this.Area = ParisArea;
        }
Esempio n. 2
0
        public Country()
        {
            //Paris
            var ParisArea = new GeoArea();

            ParisArea.type = "Polygon";
            var coordinates = new List <double[]>();

            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            coordinates.Add(new double[] { 48.972555195463336, 2.5982666015625 });
            coordinates.Add(new double[] { 48.683254235765325, 2.603759765625 });
            coordinates.Add(new double[] { 48.66874533279169, 2.120361328125 });
            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            ParisArea.coordinates = new[] { coordinates.ToArray() };

            this.Area = ParisArea;
        }
        public void TestInsert()
        {
            Helper.DropAllCollections();


            //Paris
            var geoArea = new GeoArea();
            geoArea.type = "Polygon";            
            var coordinates = new List<double[]>();
            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            coordinates.Add(new double[] { 48.972555195463336, 2.5982666015625 });
            coordinates.Add(new double[] { 48.683254235765325, 2.603759765625 });
            coordinates.Add(new double[] { 48.66874533279169, 2.120361328125 });
            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            geoArea.coordinates = new [] {coordinates.ToArray()};

            //Insert de Paises
            var c = new Country {Code = "es", Name = "España", Area = geoArea};
            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", Area = geoArea};
            c.Save();

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

            c = new Country { Code = "US", Name = "Estados Unidos", Area = geoArea };
            c.Save();

            var countries = new CountryCollection();

            countries.Find(x=>x.Code, "ES");
            Assert.AreEqual(countries.Count, 1);

            countries.Find(x=>x.Code, "UK");
            Assert.AreEqual(countries.Count, 1);

            countries.Find(x=>x.Code, "US");
            Assert.AreEqual(countries.Count, 1);

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

            //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 = "US",
                    BankBalance = decimal.Parse("10000,00")
                };

            p.Save();

            var persons = new List<Person>();
            persons.MongoFind();

            Assert.AreEqual(persons.Count, 5);
        }
        public void TestInsert()
        {
            Helper.DropAllCollections();


            //Paris
            var geoArea = new GeoArea();

            geoArea.type = "Polygon";
            var coordinates = new List <double[]>();

            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            coordinates.Add(new double[] { 48.972555195463336, 2.5982666015625 });
            coordinates.Add(new double[] { 48.683254235765325, 2.603759765625 });
            coordinates.Add(new double[] { 48.66874533279169, 2.120361328125 });
            coordinates.Add(new double[] { 48.979766324449706, 2.098388671875 });
            geoArea.coordinates = new [] { coordinates.ToArray() };

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

            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", Area = geoArea
            };
            c.Save();

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

            c = new Country {
                Code = "US", Name = "Estados Unidos", Area = geoArea
            };
            c.Save();

            var countries = new CountryCollection();

            countries.Find(x => x.Code, "ES");
            Assert.AreEqual(countries.Count, 1);

            countries.Find(x => x.Code, "UK");
            Assert.AreEqual(countries.Count, 1);

            countries.Find(x => x.Code, "US");
            Assert.AreEqual(countries.Count, 1);

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

            //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     = "US",
                BankBalance = decimal.Parse("10000,00")
            };

            p.Save();

            var persons = new List <Person>();

            persons.MongoFind();

            Assert.AreEqual(persons.Count, 5);
        }