本文整理汇总了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);
}
}
示例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!"));
}
示例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);
}
}
示例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);
}
示例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);
}
示例6: WaidForThreads
private static void WaidForThreads(List<Thread> threads)
{
while (threads.Any(x => x.IsAlive))
{
Thread.Sleep(5000);
}
}
示例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();
}
示例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);
}
}
示例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));
}
}
示例10: TestAny
public void TestAny ()
{
var foos = new List<string> (){ "fooey" };
Assert.IsTrue (foos.Any (s => s.Equals ("FOOEY",
StringComparison.InvariantCultureIgnoreCase)));
}
示例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)));
}
示例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;
}
}
示例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()"));
}
示例14: Any_FromMsdnExample
public void Any_FromMsdnExample()
{
List<int> numbers = new List<int> { 1, 2 };
bool hasElements = numbers.Any();
Assert.IsTrue(hasElements);
}
示例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();
}