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


C# Microsoft.VisualStudio.TestTools.UnitTesting.Any方法代码示例

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


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

示例1: ThrowIfComplex

 public void ThrowIfComplex() {
   var s = new[] { "" };
   var sw = Stopwatch.StartNew();
   try {
     Passager.ThrowIf(() => s.Any(), ".{0}", new { s = s[0] });
   } catch (PassagerException exc) {
     Console.WriteLine(new { sw.ElapsedMilliseconds });
     Console.WriteLine(exc.Message);
     Assert.IsTrue(exc.Message.Contains("Any"));
     throw;
   }
 }
开发者ID:dimokgit,项目名称:Passager,代码行数:12,代码来源:PassagerTests.cs

示例2: TestAnyWithLocalCollection

 public void TestAnyWithLocalCollection()
 {
   // get customers for any one of these IDs
   string[] ids = new[] { "ALFKI", "WOLZA", "NOONE" };
   var list = db.Customers.Where(c => ids.Any(id => c.CustomerID == id)).ToList();
   AssertValue(2, list.Count);
 }
开发者ID:dronab,项目名称:DensoDB,代码行数:7,代码来源:LinqTests.cs

示例3: EnumerableTest

        public void EnumerableTest()
        {
            using (var db = new LiteDatabase(new MemoryStream()))
            {
                var col = db.GetCollection<User>("Users");

                col.EnsureIndex(x => x.Name, true);
                col.EnsureIndex(x => x.Age);

                col.Insert(new[] { new User() { Id = 1, Name = "John Smith", Age = 10 },
                                   new User() { Id = 2, Name = "Jane Smith", Age = 12 },
                                   new User() { Id = 3, Name = "John Doe", Age = 24 },
                                   new User() { Id = 4, Name = "Jane Doe", Age = 42 } });

                var empty = new string[] { };
                Assert.AreEqual(0, col.Count(user => empty.All(name => user.Name.Contains(name))));
                Assert.AreEqual(0, col.Count(user => empty.Any(name => user.Name.Contains(name))));

                var firstNames = new[] { "John", "Jane", "Jon", "Janet" };
                Assert.AreEqual(0, col.Count(user => firstNames.All(name => user.Name.StartsWith(name))));
                Assert.AreEqual(4, col.Count(user => firstNames.Any(name => user.Name.StartsWith(name))));

                var surnames = new[] { "Smith", "Doe", "Mason", "Brown" };
                Assert.AreEqual(0, col.Count(user => surnames.All(name => user.Name.Contains(name))));
                Assert.AreEqual(4, col.Count(user => surnames.Any(name => user.Name.Contains(name))));

                var johnSmith = new[] { "John", "Smith" };
                Assert.AreEqual(1, col.Count(user => johnSmith.All(name => user.Name.Contains(name))));
                Assert.AreEqual(3, col.Count(user => johnSmith.Any(name => user.Name.Contains(name))));

                var janeDoe = new[] { "Jane", "Doe" };
                Assert.AreEqual(1, col.Count(user => janeDoe.All(name => user.Name.Contains(name))));
                Assert.AreEqual(3, col.Count(user => janeDoe.Any(name => user.Name.Contains(name))));

                var numRange = new[] { new { Min = 10, Max = 12 },
                                       new { Min = 21, Max = 33 } };
                var numQuery = numRange.Select(num => Query.And(Query.GTE("Age", num.Min), Query.LTE("Age", num.Max)));
                var queryResult = col.Find(numQuery.Aggregate((lhs, rhs) => Query.Or(lhs, rhs)));
                var lambdaResult = col.Find(p => numRange.Any(num => p.Age >= num.Min && p.Age <= num.Max));
                Assert.IsTrue(queryResult.OrderBy(u => u.Name).SequenceEqual(lambdaResult.OrderBy(u => u.Name)));
            }
        }
开发者ID:ChrisCross67,项目名称:LiteDB,代码行数:42,代码来源:LinqTest.cs


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