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


C# List.Any方法代码示例

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


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

示例1: SessionGracefullyWaitsPendingOperations

        public void SessionGracefullyWaitsPendingOperations()
        {
            Logger.Info("Starting SessionGracefullyWaitsPendingOperations");
            var localCluster = Cluster.Builder().AddContactPoint(IpPrefix + "1").Build();
            try
            {
                var localSession = (Session)localCluster.Connect();

                //Create more async operations that can be finished
                var taskList = new List<Task>();
                for (var i = 0; i < 1000; i++)
                {
                    taskList.Add(localSession.ExecuteAsync(new SimpleStatement("SELECT * FROM system.schema_columns")));
                }
                //Most task should be pending
                Assert.True(taskList.Any(t => t.Status == TaskStatus.WaitingForActivation), "Most task should be pending");
                //Wait for finish
                Assert.True(localSession.WaitForAllPendingActions(60000), "All handles have received signal");

                Assert.False(taskList.Any(t => t.Status == TaskStatus.WaitingForActivation), "All task should be completed (not pending)");

                if (taskList.Any(t => t.Status == TaskStatus.Faulted))
                {
                    throw taskList.First(t => t.Status == TaskStatus.Faulted).Exception;
                }
                Assert.True(taskList.All(t => t.Status == TaskStatus.RanToCompletion), "All task should be completed");

                localSession.Dispose();
            }
            finally
            {
                localCluster.Shutdown(1000);
            }
        }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:34,代码来源:SessionTests.cs

示例2: Should_resolve_policy_violation_handler_for_exception_from_container

        public void Should_resolve_policy_violation_handler_for_exception_from_container()
        {
            // Arrange
            var controllerName = NameHelper.Controller<BlogController>();
            const string actionName = "Index";

            var events = new List<ISecurityEvent>();
            SecurityDoctor.Register(events.Add);
            var expectedActionResult = new ViewResult { ViewName = "SomeViewName" };
            var violationHandler = new DenyAnonymousAccessPolicyViolationHandler(expectedActionResult);
            FakeIoC.GetAllInstancesProvider = () => new List<IPolicyViolationHandler>
            {
                violationHandler
            };

            SecurityConfigurator.Configure(policy =>
            {
                policy.ResolveServicesUsing(FakeIoC.GetAllInstances);
                policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                policy.For<BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            var securityHandler = new SecurityHandler();

            // Act
            var result = securityHandler.HandleSecurityFor(controllerName, actionName, SecurityContext.Current);

            // Assert
            Assert.That(result, Is.EqualTo(expectedActionResult));
            Assert.That(events.Any(e => e.Message == "Handling security for {0} action {1}.".FormatWith(controllerName, actionName)));
            Assert.That(events.Any(e => e.Message == "Finding policy violation handler using convention {0}.".FormatWith(typeof(FindByPolicyNameConvention))));
            Assert.That(events.Any(e => e.Message == "Found policy violation handler {0}.".FormatWith(violationHandler.GetType().FullName)));
            Assert.That(events.Any(e => e.Message == "Handling violation with {0}.".FormatWith(violationHandler.GetType().FullName)));
            Assert.That(events.Any(e => e.Message == "Done enforcing policies. Violation occured!"));
        }
开发者ID:pvivera,项目名称:FluentSecurity,代码行数:35,代码来源:SecurityHandlerSpec.cs

示例3: SessionCancelsPendingWhenDisposed

 public void SessionCancelsPendingWhenDisposed()
 {
     Logger.Info("SessionCancelsPendingWhenDisposed");
     var localCluster = Cluster.Builder().AddContactPoint(IpPrefix + "1").Build();
     try
     {
         var localSession = localCluster.Connect();
         var taskList = new List<Task>();
         for (var i = 0; i < 500; i++)
         {
             taskList.Add(localSession.ExecuteAsync(new SimpleStatement("SELECT * FROM system.schema_columns")));
         }
         //Most task should be pending
         Assert.True(taskList.Any(t => t.Status == TaskStatus.WaitingForActivation), "Most task should be pending");
         //Force it to close connections
         Logger.Info("Start Disposing localSession");
         localSession.Dispose();
         //Wait for the worker threads to cancel the rest of the operations.
         Thread.Sleep(10000);
         Assert.False(taskList.Any(t => t.Status == TaskStatus.WaitingForActivation), "No more task should be pending");
         Assert.True(taskList.All(t => t.Status == TaskStatus.RanToCompletion || t.Status == TaskStatus.Faulted), "All task should be completed or faulted");
     }
     finally
     {
         localCluster.Shutdown(1000);
     }
 }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:27,代码来源:SessionTests.cs

示例4: TestPlayerOrderIsRandom

        public void TestPlayerOrderIsRandom()
        {
            var games = new List<Game>();

            for (var i = 0; i < 50; i++)
                games.Add(new Game(playerIds, turnFactory));

            var playersStartWithZero = games.Any(g => g.PlayerIds.First() == 0);
            var playersStartWithOne = games.Any(g => g.PlayerIds.First() == 1);
            var playersStartWithTwo = games.Any(g => g.PlayerIds.First() == 2);

            Assert.That(playersStartWithZero && playersStartWithOne && playersStartWithTwo, Is.True);
        }
开发者ID:kevPo,项目名称:Monopoly,代码行数:13,代码来源:GameTests.cs

示例5: ListAnyStartsWith

 public void ListAnyStartsWith()
 {
     var orders = new List<SalesOrder>(){
         new SalesOrder{OrderId = "1"},
         new SalesOrder{OrderId = "2"},
         new SalesOrder{OrderId = "2-1"},
         new SalesOrder{OrderId = "3-1"},
     };
     orders.Any(x => x.OrderId == "1").ShouldBe(true);
     orders.Any(x => x.OrderId == "4").ShouldBe(false);
     orders.Any(x => x.OrderId.StartsWith( "4")).ShouldBe(false);
     orders.Any(x => x.OrderId.StartsWith( "1")).ShouldBe(true);
     orders.Any(x => x.OrderId.StartsWith( "3")).ShouldBe(true);
 }
开发者ID:czivko,项目名称:AxIntegrator,代码行数:14,代码来源:OrderServiceIntegrationTest.cs

示例6: WaidForThreads

 private static void WaidForThreads(List<Thread> threads)
 {
     while (threads.Any(x => x.IsAlive))
     {
         Thread.Sleep(5000);
     }
 }
开发者ID:inadler,项目名称:DotNetFlumeNG.Clients,代码行数:7,代码来源:PerformanceTests.cs

示例7: Indicator_Chaining_MAofMA

        public void Indicator_Chaining_MAofMA()
        {
            var results1 = new List<DataPoint<decimal>>();
            var results2 = new List<DataPoint<decimal>>();
            var ma1 = new MovingAverageIndicator(2);
            var ma2 = new MovingAverageIndicator(2);
            ma1.Subscribe(ma2); // ma2 of ma1
            ma1.Subscribe(results1.Add);
            ma2.Subscribe(results2.Add);

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 2));
            Assert.That(results1.Last().Value, Is.EqualTo(1.5));
            Assert.That(results2.Any(), Is.EqualTo(false));

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 3));
            Assert.That(results1.Last().Value, Is.EqualTo(2.5));
            Assert.That(results2.Last().Value, Is.EqualTo(2));

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 4));
            Assert.That(results1.Last().Value, Is.EqualTo(3.5));
            Assert.That(results2.Last().Value, Is.EqualTo(3));

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 5));
            Assert.That(results1.Last().Value, Is.EqualTo(4.5));
            Assert.That(results2.Last().Value, Is.EqualTo(4));

            ma1.Dispose();
            ma2.Dispose();
        }
开发者ID:msxor,项目名称:TradingAtomics,代码行数:30,代码来源:MovingAverageTest.cs

示例8: BootstrapNodeTest

 public void BootstrapNodeTest()
 {
     var policy = new ConstantReconnectionPolicy(500);
     var builder = Cluster.Builder().WithReconnectionPolicy(policy);
     var clusterInfo = TestUtils.CcmSetup(1, builder);
     try
     {
         var session = clusterInfo.Session;
         for (var i = 0; i < 100; i++)
         {
             if (i == 50)
             {
                 TestUtils.CcmBootstrapNode(clusterInfo, 2);
                 TestUtils.CcmStart(clusterInfo, 2);
             }
             session.Execute("SELECT * FROM system.schema_columnfamilies").Count();
         }
         //Wait for the join to be online
         Thread.Sleep(120000);
         var list = new List<IPAddress>();
         for (var i = 0; i < 100; i++)
         {
             var rs = session.Execute("SELECT * FROM system.schema_columnfamilies");
             rs.Count();
             list.Add(rs.Info.QueriedHost);
         }
         Assert.True(list.Any(ip => ip.ToString() == IpPrefix + "2"), "The new node should be queried");
     }
     finally
     {
         TestUtils.CcmRemove(clusterInfo);
     }
 }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:33,代码来源:PoolTests.cs

示例9: ExtractCashtagsWithIndicesTest

 public void ExtractCashtagsWithIndicesTest()
 {
     List<string> failures = new List<string>();
     foreach (dynamic test in LoadTestSection<dynamic>("cashtags_with_indices"))
     {
         try
         {
             List<Extractor.Entity> actual = extractor.ExtractCashtagsWithIndices(test.text);
             for (int i = 0; i < actual.Count; i++)
             {
                 Extractor.Entity entity = actual[i];
                 Assert.AreEqual(test.expected[i].cashtag, entity.Value);
                 Assert.AreEqual(test.expected[i].indices[0], entity.Start);
                 Assert.AreEqual(test.expected[i].indices[1], entity.End);
             }
         }
         catch (Exception)
         {
             failures.Add(test.description + ": " + test.text);
         }
     }
     if (failures.Any())
     {
         Assert.Fail(string.Join("\n", failures));
     }
 }
开发者ID:dghry,项目名称:twitter-text-cs,代码行数:26,代码来源:ExtractorTests.cs

示例10: TestAny

		public void TestAny ()
		{
			var foos = new List<string> (){ "fooey" };

			Assert.IsTrue (foos.Any (s => s.Equals ("FOOEY", 
				StringComparison.InvariantCultureIgnoreCase)));
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:7,代码来源:ListExampleTests.cs

示例11: WhatIsAItem

 public void WhatIsAItem()
 {
     var closedCandle = new Waterskin();
     var it = new List<IItems>();
     it.Add(closedCandle);
     Assert.That(it.Any(x => string.Equals("Waterskin", x.Name)));
 } 
开发者ID:Kursledare,项目名称:Mookieraw,代码行数:7,代码来源:Inventorytest.cs

示例12: Succeed

        public static void Succeed(params Action[] assertions)
        {
            var errors = new List<Exception>();

            foreach (var assertion in assertions)
                try
                {
                    assertion();
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }

            if (errors.Any())
            {
                var ex = new AssertionException(
                    string.Join(Environment.NewLine, errors.Select(e => e.Message)),
                    errors.First());

                // Use stack trace from the first exception to ensure first failed Assert is one click away
                ReplaceStackTrace(ex, errors.First().StackTrace);

                throw ex;
            }
        }
开发者ID:peterbartels,项目名称:Informedica.GenPres.System,代码行数:26,代码来源:AssertAll.cs

示例13: does_not_detect_a_private_static_method

 public void does_not_detect_a_private_static_method()
 {
     var list = new List<MemberReference>();
     var def = assembly.GetTypeDefinition<TestType>();
     def.GetPublicsAndProtectedsFromType(list);
     Assert.That(!list.Any(x => x.FullName == "System.Int32 AutoTest.Minimizer.Tests.TestType::staticprivatemethod()"));
 }
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:7,代码来源:PubliclyVisibleTypeInfoTests.cs

示例14: Any_FromMsdnExample

        public void Any_FromMsdnExample()
        {
            List<int> numbers = new List<int> { 1, 2 };
            bool hasElements = numbers.Any();

            Assert.IsTrue(hasElements);
        }
开发者ID:olivierdagenais,项目名称:softwareninjas,代码行数:7,代码来源:Enumerable.cs

示例15: GetSearchResult

        private static string GetSearchResult(List<Package> packages)
        {
            Uri uri = new Uri(BaseUrl);
            string baseUri = uri.Scheme + "://" + uri.Host + ":" + uri.Port;
            string apiUri = baseUri + "/api/v2/";

            DateTime updated = packages.Any()
                                   ? packages.OrderByDescending(p => p.DateUpdated).First().DateUpdated
                                   : DateTime.UtcNow;

            SeachFeed.feed feed = new SeachFeed.feed
            {
                @base = apiUri,
                count = packages.Count,
                updated = updated,
                link = new SeachFeed.feedLink(apiUri + "Packages"),
                entry = packages.Select(p => Search.GetPackageEntry(p, uri)).ToArray()
            };

            XmlSerializer serializer = new XmlSerializer(typeof(SeachFeed.feed));
            MemoryStream ms = new MemoryStream();
            serializer.Serialize(ms, feed);
            ms.Position = 0;
            return new StreamReader(ms).ReadToEnd();
        }
开发者ID:abelsilva,项目名称:nugetory,代码行数:25,代码来源:SearchControllerGetTests.cs


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