当前位置: 首页>>代码示例>>C#>>正文


C# List.MongoFind方法代码示例

本文整理汇总了C#中NUnit.Framework.List.MongoFind方法的典型用法代码示例。如果您正苦于以下问题:C# List.MongoFind方法的具体用法?C# List.MongoFind怎么用?C# List.MongoFind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.MongoFind方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAddingSaveToQueue

        public void TestAddingSaveToQueue()
        {
            Helper.DropAllCollections();

            using (var t = new MongoMapperTransaction())
            {
                var c = new Country {Code = "NL", Name = "Holanda"};
                c.Save();
                var countries1 = new List<Country>();
                countries1.MongoFind();
                Assert.AreEqual(0, countries1.Count);

                var c2 = new Country {Code = "ES", Name = "España"};
                c2.Save();
                var countries2 = new List<Country>();
                countries2.MongoFind();
                Assert.AreEqual(0, countries2.Count);

                var c3 = new Country {Code = "US", Name = "USA"};
                c3.Save();
                var countries3 = new List<Country>();
                countries3.MongoFind();
                Assert.AreEqual(0, countries3.Count);

                Assert.AreEqual(3, t.QueueLenght);

                t.RollBack();

                Assert.AreEqual(0, t.QueueLenght);
            }

            var countries = new List<Country>();
            countries.MongoFind();
            Assert.AreEqual(0, countries.Count);
        }
开发者ID:zhongshuiyuan,项目名称:MongoMapper.NET,代码行数:35,代码来源:TransactionTest.cs

示例2: TestChildIncrementalId

        public void TestChildIncrementalId()
        {
            Helper.DropAllCollections();

            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();

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

            long index = 1;
            foreach (Person person in Persons)
            {
                foreach (Child child in person.Childs)
                {
                    Assert.AreEqual(child._id, index);
                    index ++;
                }
            }
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:53,代码来源:IncrementalIdTest.cs

示例3: TestVersionInc

        public void TestVersionInc()
        {
            Helper.DropAllCollections();

            var countries = new List<Country>();

            var c = new Country {Code = "NL", Name = "Holanda"};
            c.Save();
            Assert.AreEqual(1, c.m_dv);
            countries.MongoFind();
            Assert.AreEqual(1, countries.Count);

            c.Save();
            Assert.AreEqual(2, c.m_dv);
            countries.MongoFind();
            Assert.AreEqual(1, countries.Count);

            c.Save();
            Assert.AreEqual(3, c.m_dv);
            countries.MongoFind();
            Assert.AreEqual(1, countries.Count);
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:22,代码来源:VersionTest.cs

示例4: TestPerfMongoFindNormalVsExtensionMethods

        public void TestPerfMongoFindNormalVsExtensionMethods()
        {
            Helper.DropAllCollections();

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

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                var countries = new List<Country>();
                countries.MongoFind(
                    Builders<Country>.Filter.Or(MongoQuery<Country>.Eq(co => co.Code, "ES"), MongoQuery<Country>.Eq(co => co.Code, "UK")));
            }
            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para ExtensionMethod: {0}", timer.Elapsed));
            //Elapsed para ExtensionMethod: 00:04:29.8042031

            timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                CountryCollection mongoCol = new CountryCollection();
                mongoCol.Find(
                    mongoCol.Filter.Or(MongoQuery<Country>.Eq(co=>co.Code, "ES"), MongoQuery<Country>.Eq(co => co.Code, "UK")));
                mongoCol.ToList();
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para StaticMethod: {0}", timer.Elapsed));
            //Elapsed para StaticMethod: 00:04:10.1821050
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:38,代码来源:ExtensionTest.cs

示例5: TestRelations

        public void TestRelations()
        {
            Helper.DropAllCollections();

            var c = new Country {Code = "ES", Name = "España"};
            c.Save();
            c = new Country {Code = "UK", Name = "Reino Unido"};
            c.Save();

            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"});
            p.Childs.Add(
                new Child {ID = 2, Age = 7, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez"});

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

            c = MongoMapper<Country>.FindByKey("ES");
            try
            {
                c.Delete();
                Assert.Fail();
            }
            catch (ValidateDownRelationException ex)
            {
                Assert.AreEqual(ex.GetBaseException().GetType(), typeof (ValidateDownRelationException));
                List<Person> persons = new List<Person>();
                persons.MongoFind(C => C.Country, "ES");
                foreach (Person p2 in persons)
                {
                    p2.Country = "UK";
                    p2.Save();
                }
                c.Delete();
            }            

            List<Person> personsInUk = new List<Person>();
            personsInUk.MongoFind(C => C.Country, "UK");
            foreach (Person personInUk in personsInUk)
            {
                Assert.AreEqual(personInUk.Country, "UK");                
            }
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:62,代码来源:RelationsTest.cs

示例6: Test

        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);
        }
开发者ID:emiliotorrens,项目名称:MongoMapper.NET,代码行数:98,代码来源:ReadmeTest.cs

示例7: TestCollectionExtensions

        public void TestCollectionExtensions()
        {
            Helper.DropAllCollections();

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

            var countries = new List<Country>();
            countries.MongoFind();
            Assert.AreEqual(countries.Count, 3);

            countries.MongoFind(MongoQuery<Country>.Eq(co => co.Code, "ES"));
            Assert.AreEqual(countries.Count, 1);
            Assert.AreEqual(countries[0].Code, "ES");

            countries.MongoFind(
                Builders<Country>.Filter.Or(MongoQuery<Country>.Eq(co => co.Code, "ES"), MongoQuery<Country>.Eq(co => co.Code, "UK")));
            Assert.AreEqual(countries.Count, 2);
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:24,代码来源:ExtensionTest.cs

示例8: TestInsert

        public void TestInsert()
        {
            Helper.DropAllCollections();

            //Insert de Paises
            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));
            }

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

            var Countries = new List<Country>();
            Countries.MongoFind(C=>C.Code, "ES");
            Assert.AreEqual(Countries.Count, 1);

            Countries.MongoFind(C=>C.Code, "UK");
            Assert.AreEqual(Countries.Count, 1);

            Countries.MongoFind(C=>C.Code, "US");
            Assert.AreEqual(Countries.Count, 1);

            Countries.MongoFind();
            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",
//.........这里部分代码省略.........
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:101,代码来源:ExtensionTest.cs

示例9: TestDelete

        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);
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:18,代码来源:ExtensionTest.cs

示例10: TestErrorInCommitingQueue

        public void TestErrorInCommitingQueue()
        {
            Helper.DropAllCollections();

            using (var t = new MongoMapperTransaction())
            {
                try
                {
                    var c = new Country {Code = "NL", Name = "Holanda"};
                    c.Save();
                    var countries1 = new List<Country>();

                    countries1.MongoFind();
                    Assert.AreEqual(0, countries1.Count);

                    //Lanzara excepcion porque us esta en minusculas
                    var c3 = new Country {Code = "us", Name = "USA"};
                    c3.Save();

                    var countries3 = new List<Country>();
                    countries3.MongoFind();
                    Assert.AreEqual(0, countries3.Count);
                    Assert.AreEqual(2, t.QueueLenght);

                    t.Commit();
                }
                catch
                {
                }
            }

            //No deberia haber guardado nada
            var countries = new List<Country>();
            countries.MongoFind();
            Assert.AreEqual(0, countries.Count);
        }
开发者ID:zhongshuiyuan,项目名称:MongoMapper.NET,代码行数:36,代码来源:TransactionTest.cs

示例11: TestInsert


//.........这里部分代码省略.........
                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);
        }
开发者ID:jango2015,项目名称:MongoMapper.NET,代码行数:101,代码来源:InsertModifyDeleteTest.cs


注:本文中的NUnit.Framework.List.MongoFind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。