本文整理汇总了C#中NUnit.Framework.List.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# List.ForEach方法的具体用法?C# List.ForEach怎么用?C# List.ForEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.ForEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_Return_Highest_AccessLevel_Based_On_Role
public void Should_Return_Highest_AccessLevel_Based_On_Role()
{
RunActionInTransaction(session =>
{
var accessRules = new List<AccessRule>(new[] {
new AccessRule { Identity = "RoleA", AccessLevel = AccessLevel.Deny, IsForRole = true},
new AccessRule { Identity = "Admin", AccessLevel = AccessLevel.ReadWrite, IsForRole = true},
new AccessRule { Identity = "RoleB", AccessLevel = AccessLevel.Read, IsForRole = true}
});
var page = TestDataProvider.CreateNewPage();
accessRules.ForEach(page.AddRule);
session.SaveOrUpdate(page);
session.Flush();
session.Clear();
var service = CreateAccessControlService();
var principal = new GenericPrincipal(new GenericIdentity("John"), new[] { "Admin" });
var accessLevel = service.GetAccessLevel(page, principal);
Assert.AreEqual(AccessLevel.ReadWrite, accessLevel);
});
}
示例2: 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));
}
示例3: Adding_tags_should_add_to_existing_tags
public void Adding_tags_should_add_to_existing_tags()
{
Test test = new Test("test");
List<string> tags = new List<string> { "tagged", "another" };
tags.ForEach(x => test.AddTags(x));
tags.ForEach(tag => test.GetTags().AllTags.Contains(tag));
}
示例4: Should_allow_multiple_connections
public void Should_allow_multiple_connections()
{
var clients = new List<TcpClient>();
int expected = 100;
for (int i = 0; i < expected - 1; i++)
{
var client = new TcpClient();
clients.Add(client);
client.Connect("localhost", 8008);
}
Thread.Sleep(50);
_server.ConnectionCount.ShouldEqual(expected);
clients.ForEach(client =>
{
using (client)
client.Close();
});
clients.Clear();
}
示例5: TestAddTracking
public void TestAddTracking()
{
var filenames = new List<string>()
{
"ReadyRedlineDocumentTrackingTest.doc",
"NoPassword.docx",
"RemovePassword.docx",
"password_removed.docx",
"Sample Original Document _ Office 2010 SP2.docx",
"Sample Original Document _ Office 2013 Format.docx",
"Sample Original Document _ Strict Open XML.docx"
};
filenames.ForEach(delegate(string x)
{
string testfile = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(Path.Combine(_path, x));
string tempfile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetFileName(testfile));
System.IO.File.Copy(testfile, tempfile, true);
var intelligentDocument = new IntelligentDocument();
intelligentDocument.SetFileName(tempfile);
Assert.False(intelligentDocument.IsDocumentBeingTracked());
intelligentDocument.AddDocumentTrackingId();
Assert.True(intelligentDocument.IsDocumentBeingTracked());
});
}
示例6: Type_Templates
public void Type_Templates()
{
var razorFilename = "TypeTemplate.cshtml";
var templateCachedName = "TypeTemplate";
var outputFilename = "TypeTemplate.out";
var outputFileNames = new List<string>()
{
outputFilename,
"Type1.out",
"Type2.out",
"Type3.out"
};
outputFileNames.ForEach(file => TestHelper.DeleteOutputFile(file));
var types = new List<Type>();
types.Add(typeof(string));
types.Add(typeof(List<int>));
types.Add(typeof(Guid));
// Set Razor Template Base
//Razor.SetTemplateBase(typeof(RazorEngine.Templating.DictionaryTemplateBase));
// Read template from File
string razorTemplate = File.ReadAllText(Path.Combine(TestHelper.TemplateFolder, razorFilename));
// Very important - Forces RuntimeBinder to kick in.
// Otherwise, we get an exception during razor's compiling
// Without this, only way to get tests to pass is to breakpoint & use propertygrid to inspect the model, which does the same thing - calls stuff so the RuntimeBinder kicks in
//var modelPrototype = new { };
//string dynamicString = (modelPrototype as dynamic).ToString();
// Compile & Cache
//Razor.Compile(razorTemplate, modelPrototype.GetType(), templateCachedName);
Razor.Compile(razorTemplate, typeof(Type), templateCachedName);
// Write out Files
int resultCount = 0;
foreach (var type in types)
{
// Create Model
//dynamic model = new ExpandoObject();
//model.Type = type;
var model = type;
// Execute Razor
var output = Razor.Run(model, templateCachedName);
// Prep for Output
string childFilename = String.Format("Type{0}.out", resultCount);
string outputFilePath = Path.Combine(TestHelper.OutputFolder, childFilename);
File.WriteAllText(outputFilePath, output);
resultCount++;
}
}
示例7: Multiple
public void Multiple()
{
var queues = new List<IFiber>();
var receiveCount = 0;
var reset = new AutoResetEvent(false);
var channel = new QueueChannel<int>();
var messageCount = 100;
var updateLock = new object();
for (var i = 0; i < 5; i++)
{
Action<int> onReceive = delegate
{
Thread.Sleep(15);
lock (updateLock)
{
receiveCount++;
if (receiveCount == messageCount)
{
reset.Set();
}
}
};
var fiber = new PoolFiber();
fiber.Start();
queues.Add(fiber);
channel.Subscribe(fiber, onReceive);
}
for (var i = 0; i < messageCount; i++)
{
channel.Publish(i);
}
Assert.IsTrue(reset.WaitOne(10000, false));
queues.ForEach(delegate(IFiber q) { q.Dispose(); });
}
示例8: UseAllConnectionsInPool
public void UseAllConnectionsInPool()
{
// As this method uses a lot of connections, clear all connections from all pools before starting.
// This is needed in order to not reach the max connections allowed and start to raise errors.
NpgsqlConnection.ClearAllPools();
try {
var openedConnections = new List<NpgsqlConnection>();
// repeat test to exersize pool
for (var i = 0; i < 10; ++i) {
try {
// 18 since base class opens two and the default pool size is 20
for (var j = 0; j < 18; ++j) {
var connection = new NpgsqlConnection(ConnectionString);
connection.Open();
openedConnections.Add(connection);
}
} finally {
openedConnections.ForEach(delegate(NpgsqlConnection con) { con.Dispose(); });
openedConnections.Clear();
}
}
} finally {
NpgsqlConnection.ClearAllPools();
}
}
示例9: DateEdges_AddMultipleDateIntervals_ReturnSortedDateEdges
public void DateEdges_AddMultipleDateIntervals_ReturnSortedDateEdges()
{
//Arrange
var dateIntervalCollection = new DateIntervalCollection();
dateIntervalCollection.Add(nowAndTenDaysInterval);
dateIntervalCollection.Add(nowAndFiveDaysInterval);
dateIntervalCollection.Add(twoDaysAndFiveDaysInterval);
dateIntervalCollection.Add(threeDaysAgoAndTwelveDaysInterval);
dateIntervalCollection.Add(thirteenDaysAndFourteenDaysInterval);
var dateIntervalList = new List<DateInterval>
{
nowAndTenDaysInterval, nowAndFiveDaysInterval, twoDaysAndFiveDaysInterval, threeDaysAgoAndTwelveDaysInterval, thirteenDaysAndFourteenDaysInterval
};
var correctResult = new List<IEndPoint<DateTime>>();
//Act
var result = dateIntervalCollection.DateEdges;
//Assert
dateIntervalList.ForEach(x => correctResult.AddRange(x.GetEndPoints()));
CollectionAssert.AreEquivalent(correctResult, result);
}
示例10: Loop
public void Loop()
{
var finalVideoGames = new List<FinalGames>();
var gamesWithSpaces = new string[5];
for (var i = 0; i < _currentVideoGames.Length; i++)
{
if (_currentVideoGames[i].Contains(" "))
{
gamesWithSpaces[i] = _currentVideoGames[i];
}
}
Array.Sort(gamesWithSpaces);
foreach (var s in gamesWithSpaces)
{
if (s != null)
finalVideoGames.Add(new FinalGames
{
Name = s,
Lenght = s.Length
});
}
finalVideoGames.ForEach(x => Console.WriteLine("VideoGame: {0} (lenght: {1})", x.Name, x.Lenght));
}
示例11: GetSortedDateTimes_ReturnsCorrectList
public void GetSortedDateTimes_ReturnsCorrectList()
{
DateTime dateNow = DateTime.Now;
var orderedDateIntervals = new List<DateInterval>();
orderedDateIntervals.Add( new DateInterval( dateNow, dateNow.AddMinutes( 100 ))); // +-----------------------------------------------+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(10))); // +
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(10))); // +
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(20))); // +---+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(30))); // +-------+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(20), dateNow.AddMinutes(60))); // +----------------------+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(30), dateNow.AddMinutes(60))); // +------------------+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(40), dateNow.AddMinutes(50))); // +------------+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(42), dateNow.AddMinutes(47))); // +-----+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(45), dateNow.AddMinutes(45))); // +
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(70), dateNow.AddMinutes(75))); // +---+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(90), dateNow.AddMinutes(110))); // +--------------+
orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(120), dateNow.AddMinutes(140))); // +-----------+
var result = orderedDateIntervals.GetSortedDateTimes();
var correctDateTimes = new List<DateTime>();
orderedDateIntervals.ForEach(x => correctDateTimes.AddRange(new List<DateTime> { x.Min.Value, x.Max.Value }));
correctDateTimes.Sort();
Assert.AreEqual( correctDateTimes, result);
}
示例12: can_simulate_session
public void can_simulate_session()
{
var cookies = new List<string>
{
"JSESSIONID=E5930D59BEBA0274876288F5655930A1; Path=/; Secure; HttpOnly",
"urn:novell:nidp:cluster:member:id=~03~05~7Dbc~00~17~16rrs~0F; Path=/nidp",
"UrnNovellNidpClusterMemberId=~03~05~7Dbc~00~17~16rrs~0F; Path=/nidp",
"JSESSIONID=58DA1BDDCA579C0185CC36EC11F2D533; Path=/nidp/; Secure; HttpOnly",
"urn:novell:nidp:cluster:member:id=~03~05~7Dbc~00~17~16rrs~0F; Path=/nidp",
"UrnNovellNidpClusterMemberId=~03~05~7Dbc~00~17~16rrs~0F; Path=/nidp",
"JSESSIONID=58DA1BDDCA579C0185CC36EC11F2D533; Path=/nidp/; Secure; HttpOnly",
"JSESSIONID=58DA1BDDCA579C0185CC36EC11F2D533; Path=/nidp",
"JSESSIONID=B271065C59341DD8712651625794931A; Path=/nidp/; Secure; HttpOnly",
"IPCZQX0389199b41=03000300000000000000000000000000c6763e17; path=/; domain=.wwt.com",
"IPCZQX0389199b41=0100a600ac140054acbaf0605ebde866c6763e17; path=/; domain=.wwt.com",
"urn:novell:nidp:cluster:member:id=~03~05~7Dbc~00~17~16rrs~0C; Path=/nesp",
"UrnNovellNidpClusterMemberId=~03~05~7Dbc~00~17~16rrs~0C; Path=/nesp",
"JSESSIONID=E5D020EE26BE899EAC7F79BF7698F479; Path=/nesp/; Secure; HttpOnly",
"IPCZQX0389199b41=0100a600ac140054acbaf0605ebde866c6763e17; path=/; domain=.wwt.com",
"ZNPCQ003-32333900=05033a23; Path=/; Domain=.wwt.com",
"ObSSOCookie=7wqO%2BJcpZyD80dEmgjlAqmeEyTImDL0XJh1H88H3eUOTZOlKcaTocv0ZPxiJhESUjjDqutPVbdjO9p6uVJJflRswsznCgjf6xBYc58bP%2BDNv13FvURUv12Q7p8mK7UTliEu27m85ewAnIV7E2RCLJSUO6rYrkJ%2FU%2BVSWBrOCjBkx8i8lp3vk7jKqxElO%2F2A4qeNcSoj1XP52xpd1yDO2VvJOu4p0h%2B0MIxPDNnLwT%2FeRVQbHpGlU%2Fa1khjUMF0aX4QMpJg%3D%3D; path=/; domain=.wwt.com;",
"OBBasicAuth=fromCache; path=/;",
"SSO_ID=v1.2~1~A41584841334421C8835A431423A39BEB64A4DB5FFDD54011AC916A3B503CC07F0639C5F018B77659A23E2A7BAA3241328BCA83977AA9F711A04EFC972213AE32AE3F536EE7D435004C6F89A35A1F7DAB95D873BF32A904421836495F126CC722514F58615597288A194C9A961D74F17C564665AC19AE63D325FE0C6EDAD60BA9BC916FD05B21A573476EE9DD17F3031EDCEC99FF8A83E5D226932A64B40FD409BCDAB267699C0005BF2BE4D84F50DD8EF3CFC2B8F6F265B623D60F794A52818A4C99DCA55F8D486144736B95530998B484CB98CBCEBACD8645D52E004560065674F7B962658E0D36E0FB135363F34683396737621D9A10C283875A98AADC68D9E0F1C94E818F47DB0B727D713D45FFC; Path=/; Secure",
"ZNPCQ003-31323200=ea6982a1; Path=/; Domain=.wwt.com",
"IPCZQX0389199b41=0100a600ac140054acbaf0605ebde866c6763e17; path=/; domain=.wwt.com",
"OHS-reports.wwt.com-443=6635778950F4EA350BFD7DD9E6CDA958ACD43042F354927D6326FF6DC7A3AFA87DF8074F7EA4CB7E7F91BCE8FC5F3767866DB532F0B9CF07CBB82177CB9990D587E2ED51C59B8F177BAF7585EF06518189F70F7AD9A3AE71ED1ABA3D9EE1D67ED60E5EDE2288DAF8D4C0FC75B8BA1527226B33C00E9767298747C905AAD6389E8AEBBE0832D49A5FF1F72543FBEA0E627FA6F00F0B68BE863715B3427826414E0C951D48EF74F5C05203DACA934D03D14C1AAB180BEBDBB490D83DEB5B55C8E47EBEF34D8221FAE80A7C8EFCC2771140A5B2D72E051A21265FD15376C2BABE696466A9CFBE7E06FC62B8E0F55A340E6306EBE58C201E69749B2E3491305DC29DAEE2E869A267C2AF06C09EA226A24560E851C6CC29CE45C3; path=/",
"ObSSOCookie=7wqO%2BJcpZyD80dEmgjlAqmeEyTImDL0XJh1H88H3eUOTZOlKcaTocv0ZPxiJhESUjjDqutPVbdjO9p6uVJJflRswsznCgjf6xBYc58bP%2BDNv13FvURUv12Q7p8mK7UTliEu27m85ewAnIV7E2RCLJSUO6rYrkJ%2FU%2BVSWBrOCjBkx8i8lpnvk7jKqxElO%2F2A4qeNcSYj1XP52xpd1yDO2VvJOu4p0h%2B0MIBPDNnLwT%2FeRVQbTZ1XP7rSQlf%2B9zdAp; path=/; domain=.wwt.com;",
};
var container = SessionCookieContainer.Create();
cookies.ForEach(c => container.Add(c));
var lst = container.GetCookieList("/reports/rwservlet?17454_dell_supply_hub_alpha_vendor_schedule&");
lst.ForEach(c => Console.WriteLine(c.Text));
TestExtensions.ShouldEqual(lst.Count(), 4);
}
示例13: SetUp
public void SetUp()
{
_users = new List<User>()
{
new User { Email = "[email protected]", FullName = "aaa ddd", FirstName = "aaa", LastName = "ddd", Live = LiveStatuses.Active, ApproveState = ApproveStates.Approved, Role = Roles.Simple },
new User { Email = "[email protected]", FullName = "aaa bbb", FirstName = "aaa", LastName = "bbb", Live = LiveStatuses.Active, ApproveState = ApproveStates.Approved, Role = Roles.Admin }
};
var mock = new Mock<ControllerContext>();
mock.Setup(p => p.HttpContext.Session).Returns(new Mock<HttpSessionStateBase>().Object);
DiMvc.Register();
Ioc.RegisterType<IUserRepository, UserRepository>();
_repoUnit = new RepoUnit();
var lastRecord = _repoUnit.User.Load();
_lastDbRecordId = !lastRecord.Any() ? 0 : lastRecord.Max(user => user.Id);
_users.ForEach(user => _repoUnit.User.Save(user));
var service = new UserService(_repoUnit, null)
{
//PageSize = lastRecord.Count() + _users.Count //Prevent paging
};
_usersController = new UsersController(service);
_usersController.ControllerContext = mock.Object;
}
示例14: TestForEach
public void TestForEach()
{
var targetIntList = new List<int>();
IntCollection.ForEach(e => targetIntList.Add(e * (-1)));
Assert.AreEqual(4, targetIntList.Count);
Assert.AreEqual(-1, targetIntList[1]);
Assert.AreEqual(-3, targetIntList[3]);
IEnumerable<bool> boolList = new List<bool> { false, false, false };
var targetBoolList = new List<bool>();
boolList.ForEach(e => targetBoolList.Add(!e));
Assert.AreEqual(3, targetBoolList.Count);
foreach(var value in targetBoolList)
Assert.IsTrue(value);
var empty = Enumerable.Empty<string>();
var targetStringList = new List<string>();
empty.ForEach(targetStringList.Add);
Assert.AreEqual(0, targetStringList.Count);
StringCollection.ForEach(e => targetStringList.Add(e.ToUpper()));
Assert.AreEqual(3, targetStringList.Count);
for(var i = 0; i < targetStringList.Count; i++)
Assert.AreEqual(StringCollection.ElementAt(i).ToUpper(), targetStringList[i]);
}
示例15: TestMyNumbers
public void TestMyNumbers()
{
var first = new List<DisjointedInterval>
{
new DisjointedInterval(1, 3),
new DisjointedInterval(7, 12),
new DisjointedInterval(15, 23)
};
var second = new List<DisjointedInterval>
{
new DisjointedInterval(5, 9),
new DisjointedInterval(10, 11),
new DisjointedInterval(14, 21)
};
List<DisjointedInterval> result = MergeDisjointedIntervals.Merge(first, second);
first.ForEach(x => Console.Write("({0}-{1})", x.Left, x.Right));
Console.WriteLine();
second.ForEach(x => Console.Write("({0}-{1})", x.Left, x.Right));
Console.WriteLine();
result.ForEach(x => Console.Write("({0}-{1})", x.Left, x.Right));
Console.WriteLine();
}