本文整理汇总了C#中NUnit.Framework.List.All方法的典型用法代码示例。如果您正苦于以下问题:C# List.All方法的具体用法?C# List.All怎么用?C# List.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.All方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DelegateAsync_Run_Function
public void DelegateAsync_Run_Function() {
Func<int, double> @power = x => {
Thread.Sleep(Rnd.Next(Rnd.Next(1, 10), Rnd.Next(11, 50)));
var result = Math.Pow(x, 5);
if(IsDebugEnabled)
log.Debug("@power({0}) = {1}", x, result);
return result;
};
var tasks = new List<Task<double>>();
for(var i = 0; i < IterationCount; i++) {
if(IsDebugEnabled)
log.Debug("@power({0}) called...", i);
// Thread.Sleep(0);
// 함수를 BeginInvoke, EndInvoke로 비동기 실행할 수 있습니다.
//
tasks.Add(DelegateAsync.Run(@power, i));
}
Task.WaitAll(tasks.ToArray());
Assert.IsTrue(tasks.All(task => task.IsCompleted));
tasks.ForEach(task => {
if(IsDebugEnabled)
log.Debug("계산 결과=" + task.Result);
});
}
示例2: LoggingLevelSwitchDynamicallyChangesLevel
public void LoggingLevelSwitchDynamicallyChangesLevel()
{
var events = new List<LogEvent>();
var sink = new DelegatingSink(events.Add);
var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Information);
var log = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Sink(sink)
.CreateLogger()
.ForContext<LoggerTests>();
log.Debug("Suppressed");
log.Information("Emitted");
log.Warning("Emitted");
// Change the level
levelSwitch.MinimumLevel = LogEventLevel.Error;
log.Warning("Suppressed");
log.Error("Emitted");
log.Fatal("Emitted");
Assert.AreEqual(4, events.Count);
Assert.That(events.All(evt => evt.RenderMessage() == "Emitted"));
}
示例3: Assign
public void Assign()
{
var assigner = MockRepository.GenerateMock<IAssign<Rotation>>();
var block = new Block();
var rotations = new List<Rotation>() { new Rotation() };
rotations.ForEach(block.Rotations.Add);
var block2 = new Block();
var rotations2 = new List<Rotation>() { new Rotation(), new Rotation() };
rotations2.ForEach(block2.Rotations.Add);
var residents = new List<Resident> { new Resident() };
var residents2 = new List<Resident> { new Resident(), new Resident() };
var assignmentResult = new AssignmentResult(residents2);
assigner.Stub(a => a.Assign(Arg<IEnumerable<Rotation>>.Matches(l=> rotations.All(l.Contains)), Arg.Is(residents))).Return(assignmentResult);
var residents3 = new List<Resident> { new Resident(), new Resident(), new Resident() };
var assignmentResult2 = new AssignmentResult(residents3);
assigner.Stub(a => a.Assign(Arg<IEnumerable<Rotation>>.Matches(l => rotations2.All(l.Contains)), Arg.Is(residents2))).Return(assignmentResult2);
var result = new BlockAssigner(assigner).Assign(new List<Block> { block, block2 }, residents);
Assert.AreEqual(residents3, result.Residents);
}
示例4: MultiHazardRiskAssessmentHazard
public void Given_the_risk_assessor_is_different_when_Update_RA_summary_then_further_control_measure_completed_email_notification_value_is_updated()
{
//Given
var hazard = new MultiHazardRiskAssessmentHazard();
//create mocked tasks
var furtherControlMeasureTasks = new List<Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>>()
{
new Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>() {CallBase = true},
new Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>() {CallBase = true}
};
//Add mocked tasks to risk assessement
furtherControlMeasureTasks.ForEach(x => hazard.FurtherControlMeasureTasks.Add(x.Object));
var riskAss = GeneralRiskAssessment.Create("", "", 123, new UserForAuditing());
riskAss.Hazards.Add(hazard);
//add a hazard without any tasks
riskAss.Hazards.Add(new MultiHazardRiskAssessmentHazard() {});
riskAss.RiskAssessor = new RiskAssessor() {Id = 1, DoNotSendTaskCompletedNotifications = true};
//when
riskAss.UpdateSummary("new title", "new ref", new DateTime(), new RiskAssessor() {Id = 2}, new Site(), new UserForAuditing());
//then
furtherControlMeasureTasks.ForEach(task => task.VerifySet(x => x.SendTaskCompletedNotification, Times.Once()));
Assert.IsTrue(furtherControlMeasureTasks.All(task => task.Object.SendTaskCompletedNotification.Value));
}
示例5: 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);
}
}
示例6: TriggeredMessageSequence
public void ExecuteNextStep_ExecutingWhileTriggeringNewSequenceOfEventsAsync_CanHandleAsyncExecuteAndAddNewSequences()
{
// Arrange
var sequence = new TriggeredMessageSequence();
var executionContext = new SequenceExecutionContext(new List<IMessageSequence> {sequence}, "whatever", new Mock<IMessagePicker>().Object);
sequence.SetNextStep(new SendMessage(new Mock<ISender>().Object));
// Act
IList<Task> tasks = new List<Task>();
for (int i = 0; i < 1000; i++)
{
var execute = new Task(obj => sequence.ExecuteNextStep(obj as SequenceExecutionContext), executionContext);
var triggerNewSequenceOfEvents = new Task(() => sequence.TriggerNewSequenceOfEvents(new Mock<IMessageInitializerParameterBinder>().Object));
tasks.Add(execute);
tasks.Add(triggerNewSequenceOfEvents);
execute.Start();
triggerNewSequenceOfEvents.Start();
}
foreach (var task in tasks)
{
task.Wait();
}
// Assert
Assert.That(tasks.All(task => task.IsCompleted));
}
示例7: 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);
}
}
示例8: FetchAsync_Pocos_Prepares_Just_Once
public void FetchAsync_Pocos_Prepares_Just_Once()
{
const int times = 100;
var users = TestDataHelper.GetUserList();
var sessionMock = new Mock<ISession>(MockBehavior.Strict);
sessionMock
.Setup(s => s.ExecuteAsync(It.IsAny<BoundStatement>()))
.Returns(() => TaskHelper.ToTask(TestDataHelper.GetUsersRowSet(users)))
.Verifiable();
sessionMock
.Setup(s => s.PrepareAsync(It.IsAny<string>()))
.Returns(TaskHelper.ToTask(GetPrepared()))
.Verifiable();
var mappingClient = GetMappingClient(sessionMock);
var taskList = new List<Task<IEnumerable<PlainUser>>>();
for (var i = 0; i < times; i++)
{
var t = mappingClient.FetchAsync<PlainUser>("SELECT * FROM users");
taskList.Add(t);
}
Task.WaitAll(taskList.Select(t => (Task)t).ToArray(), 5000);
Assert.True(taskList.All(t => t.Result.Count() == 10));
sessionMock.Verify();
//Prepare should be called just once
sessionMock
.Verify(s => s.PrepareAsync(It.IsAny<string>()), Times.Once());
//ExecuteAsync should be called the exact number of times
sessionMock
.Verify(s => s.ExecuteAsync(It.IsAny<BoundStatement>()), Times.Exactly(times));
sessionMock.Verify();
}
示例9: Can_Generate_Doubles_Within_Range
public void Can_Generate_Doubles_Within_Range()
{
var doubles = new List<double>();
for (var i = 0; i < 1000; i++)
{
doubles.Add(Numbers.Double());
}
//Should not have any integers below zero
Assert.IsFalse(doubles.Any(x => x < 0));
//All integers should be greater than or equal to zero
Assert.IsTrue(doubles.All(x => x >= 0));
//All integers should not be the same
Assert.IsFalse(doubles.All(x => Math.Abs(x - doubles[0]) < 0.0d));
}
示例10: Can_Generate_Longs_Within_Range
public void Can_Generate_Longs_Within_Range()
{
var longs = new List<long>();
for (var i = 0; i < 1000; i++)
{
longs.Add(Numbers.Long());
}
//Should not have any integers below zero
Assert.IsFalse(longs.Any(x => x < 0));
//All integers should be greater than or equal to zero
Assert.IsTrue(longs.All(x => x >= 0));
//All integers should not be the same
Assert.IsFalse(longs.All(x => x == longs[0]));
}
示例11: ListExtensions_All_ReturnsTrueIfListIsEmpty
public void ListExtensions_All_ReturnsTrueIfListIsEmpty()
{
var list = new List<Int32>();
var result = list.All(x => x % 2 == 0);
TheResultingValue(result).ShouldBe(true);
}
示例12: ListExtensions_All_ReturnsTrueIfAllItemsMatchPredicate
public void ListExtensions_All_ReturnsTrueIfAllItemsMatchPredicate()
{
var list = new List<Int32>() { 2, 4, 6 };
var result = list.All(x => x % 2 == 0);
TheResultingValue(result).ShouldBe(true);
}
示例13: ListExtensions_All_ReturnsFalseIfOneItemDoesNotMatchPredicate
public void ListExtensions_All_ReturnsFalseIfOneItemDoesNotMatchPredicate()
{
var list = new List<Int32>() { 1, 2, 4, 6 };
var result = list.All(x => x % 2 == 0);
TheResultingValue(result).ShouldBe(false);
}
示例14: GetRandomDate_GivenDateOnlyIsTrue_ShouldReturnDateTimeWithNoTimeComponent
public void GetRandomDate_GivenDateOnlyIsTrue_ShouldReturnDateTimeWithNoTimeComponent(int minYear, int minMonth, int minDay, int maxYear, int maxMonth, int maxDay)
{
//---------------Set up test pack-------------------
var results = new List<DateTime>();
var range = new DateTimeRange(minYear, minMonth, minDay, maxYear, maxMonth, maxDay);
//---------------Assert Precondition----------------
//---------------Execute Test ----------------------
RunCycles(() => results.Add(RandomValueGen.GetRandomDate(range.MinDate, range.MaxDate, dateOnly:true)));
//---------------Test Result -----------------------
Assert.AreEqual(RANDOM_TEST_CYCLES, results.Count);
Assert.IsTrue(results.All(range.InRange), "One or more generated value is out of range");
Assert.IsTrue(results.All(d => d.Hour == 0), "Hours are not all zeroed");
Assert.IsTrue(results.All(d => d.Minute == 0), "Minutes are not all zeroed");
Assert.IsTrue(results.All(d => d.Second == 0), "Seconds are not all zeroed");
Assert.IsTrue(results.All(d => d.Millisecond == 0), "Seconds are not all zeroed");
}
示例15: Can_Create_DateTimeOffsets_Within_Range
public void Can_Create_DateTimeOffsets_Within_Range()
{
var dateTimes = new List<DateTimeOffset>();
for (var i = 0; i < 1000; i++)
{
dateTimes.Add(DateTimes.GetDateTimeOffset(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(1)));
}
//Should not have any dates below the current date
Assert.IsFalse(dateTimes.Any(x => x < DateTimeOffset.Now));
//All dates should be greater than the current date
Assert.IsTrue(dateTimes.All(x => x >= DateTimeOffset.Now));
//All dates should be less than today's date one year from now
Assert.IsTrue(dateTimes.All(x => x <= DateTimeOffset.Now.AddYears(1)));
//All dates should not be the same
Assert.IsFalse(dateTimes.All(x => x == dateTimes[0]));
}