本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# List.ForEach方法的具体用法?C# List.ForEach怎么用?C# List.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.ForEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NHibernateInsereAtravezDeProcs
public void NHibernateInsereAtravezDeProcs()
{
var listaDePessoas = new List<Pessoa>(numeroDeRegistros);
for (int i = 0; i < numeroDeRegistros; i++)
{
listaDePessoas.Add(new Pessoa(){Nome="teste" + i, Idade = i});
}
var watch = new Stopwatch();
var repositorio = new Repositorio<Pessoa>();
using (SessionManager.OpenSession())
{
watch.Start();
listaDePessoas.ForEach(repositorio.Salvar);
SessionManager.CommitTransaction();
watch.Stop();
Console.WriteLine("Tempo de execução para a inserção de registros: " + watch.ElapsedMilliseconds + "ms");
}
listaDePessoas.ForEach(x => Assert.IsTrue(x.Id > 0));
//listaDePessoas.ForEach(x => Console.WriteLine(string.Format("Id: {0} - Nome: {1} - Idade {2}", x.Id, x.Nome, x.Idade)));
}
示例2: Z__EmbedIOCSharedPerThread
public void Z__EmbedIOCSharedPerThread()
{
EmbedIOC.Register<IDbAccess>(() => _threadStatic ?? (_threadStatic = new SqlDb("SqlDb:" + Thread.CurrentThread.Name)));
var threadList = new List<Thread>();
for (int threadCounter = 1; threadCounter <= 10; threadCounter++)
{
var newThread = new Thread(new ThreadStart(EmbedIOCSharedPerThread_Worker))
{
Name= threadCounter.ToString()
};
threadList.Add(newThread);
}
// start threads
threadList.ForEach(t => t.Start());
// wait for all thread completion
threadList.ForEach(t => t.Join());
_threadReferenceList.ForEach(x =>
{
// assert that 10 different instances were created, one for each thread
Assert.AreEqual(1, _threadReferenceList.Count(v => v == x));
});
}
示例3: ModelContextThreadTests
public void ModelContextThreadTests()
{
List<Thread> ts = new List<Thread>();
// update NumDependents to 10, the therads below update the employee NumDependents to 1,2,3,4 but we roll them back
// at the end of the test , after all theads have finished, we make sure that NumDependents is 10 for all emplloyees
DBUtils.Current().executeSQLWithParams("update employee set NumDependents=10");
int employeeCount = EmployeeDataUtils.findList("NumDependents=10").Count();
Assert.AreEqual(4, employeeCount);
ts.Add(new Thread(ModelContextConcurrencyTest));
ts.Add(new Thread(ModelContextConcurrencyTest));
ts.Add(new Thread(ModelContextConcurrencyTest));
ts.Add(new Thread(ModelContextConcurrencyTest));
ts.Add(new Thread(ModelContextConcurrencyTest));
ts.Add(new Thread(ModelContextConcurrencyTest));
ts.Add(new Thread(ModelContextConcurrencyTest));
int i = 0;
ts.ForEach(x => x.Start(i++));
ts.ForEach(x => x.Join());
employeeCount = EmployeeDataUtils.findList("NumDependents=10").Count();
Assert.AreEqual(4, employeeCount);
// at the end of the test , after all theads have finished, we make sure
// that NumDependents is 10 for all emplloyees since we set it at line 33 and all threads
// rollback
// the test below removed. Never suceeeded but connection count is correct if you
// do a select from database. Threading issues?
//Assert.AreEqual(connectionCount, this.getConnectionCount(),
// "Expected connection count to be starting connection");
}
示例4: AddUpdateDelete_CallWithListObject_ReturnExecution
public void AddUpdateDelete_CallWithListObject_ReturnExecution()
{
// arrange
var service = ServiceFactory();
var objects = new List<XObject>();
for (int i = 0; i < 3; i++)
objects.Add(CreateXObject(service));
// act
service.ObjectService.Add(objects);
objects.ForEach(o => o.Fields[0].Value = "update new value");
service.ObjectService.Update(objects);
objects.ForEach(o => service.ObjectService.Delete(typeId, o.Id));
}
示例5: Can_Determine_Visual_Studio_Commercial_Name_By_Their_Version_Number
public void Can_Determine_Visual_Studio_Commercial_Name_By_Their_Version_Number()
{
var userAgents = new List<string>(){
"Team Foundation (devenv.exe, 10.0.30319.1)",
"Team Foundation (devenv.exe, 10.0.40219.1)",
"Team Foundation (devenv.exe, 10.0.40219.383)",
"Team Foundation (devenv.exe, 10.0.40219.445)",
"Team Foundation (devenv.exe, 10.0.40219.457)",
"Team Foundation (devenv.exe, 11.0.50727.1, Premium, SKU:7)",
"Team Foundation (devenv.exe, 11.0.50727.1, Pro, SKU:6)",
"Team Foundation (devenv.exe, 11.0.50727.1, TE, SKU:5)",
"Team Foundation (devenv.exe, 11.0.50727.1, Ultimate, SKU:8)",
"Team Foundation (devenv.exe, 11.0.60610.1, Premium, SKU:7)",
"Team Foundation (devenv.exe, 11.0.60610.1, Pro, SKU:6)",
"Team Foundation (devenv.exe, 11.0.60610.1, Ultimate, SKU:8)",
"Team Foundation (devenv.exe, 11.0.61030.0, Premium, SKU:7)",
"Team Foundation (devenv.exe, 11.0.61030.0, Pro, SKU:6)",
"Team Foundation (devenv.exe, 11.0.61030.0, Ultimate, SKU:8)",
"Team Foundation (devenv.exe, 12.0.21005.1, Premium, SKU:16)",
"Team Foundation (devenv.exe, 12.0.21005.1, Ultimate, SKU:17)",
"Team Foundation (devenv.exe, 9.0.30729.4413)",
"Team Foundation (devenv.exe, 9.0.30729.5820)"
};
var tuplas = new List<Tuple<string, string>>();
foreach (var agent in userAgents)
{
var Software = "";
if (Regex.Match(agent.ToUpper(), @".+DEVENV.EXE, 8\.").Success)
Software = "Visual Studio 2005";
else if (Regex.Match(agent.ToUpper(), @".+DEVENV.EXE, 9\.").Success)
Software = "Visual Studio 2008";
else if (Regex.Match(agent.ToUpper(), @".+DEVENV.EXE, 10\.").Success)
Software = "Visual Studio 2010";
else if (Regex.Match(agent.ToUpper(), @".+DEVENV.EXE, 11\.").Success)
Software = "Visual Studio 2012";
else if (Regex.Match(agent.ToUpper(), @".+DEVENV.EXE, 12\.").Success)
Software = "Visual Studio 2013";
tuplas.Add(new Tuple<string, string>(agent, Software));
}
tuplas.ForEach(x => Console.WriteLine(string.Format("{0} -> {1}", x.Item1, x.Item2)));
tuplas.ForEach(x => Assert.IsFalse(string.IsNullOrEmpty(x.Item2)));
}
示例6: EncodeToMayaCode
public List<string> EncodeToMayaCode(List<int> mayaCodeInt)
{
List<string> retVal = new List<string>();
mayaCodeInt.ForEach(m => retVal.AddRange(_referenceChiffreMaya[m].Lines));
return retVal;
}
示例7: TestMethod1
public void TestMethod1()
{
int result = gittestproject.Calculator.Add(25, 26);
var x = new List<Calculator>(); x.Add(new Calculator()); x.Add(new Calculator());
x.ForEach(y => { y.name = "saurabh"; });
Assert.AreEqual(52, result);
}
示例8: ConstructorShouldGetHeadersFromParameter
public void ConstructorShouldGetHeadersFromParameter()
{
var originalHeaders = new List<KeyValuePair<string, string>> {new KeyValuePair<string, string>("first-header", "first_value"), new KeyValuePair<string, string>("second header", "second value")};
var eventArgs = new ReceivingResponseEventArgs(new ResponseMessageSimulator(originalHeaders), null, false);
eventArgs.ResponseMessage.Headers.Count().Should().Be(originalHeaders.Count);
originalHeaders.ForEach((h) => eventArgs.ResponseMessage.Headers.Should().Contain(h));
}
示例9: Serializer_UserAttrJsonSerlialize
public void Serializer_UserAttrJsonSerlialize()
{
var prgs = new List<ProgramAttr>
{
new ProgramAttr
{
Id = 1,
Name = "P1"
},
new ProgramAttr
{
Id = 2,
Name = "P2"
}
};
var usrs = new List<UserAttr>
{
new UserAttr
{
Id = 1,
Name = "U1"
},
new UserAttr
{
Id = 2,
Name = "U2"
}
};
prgs.ForEach(x => x.UserAttrs = usrs);
usrs.ForEach(x => x.ProgramAttrs = prgs);
string result = JsonConvert.SerializeObject(usrs);
var expected = "[{\"Id\":1,\"Name\":\"U1\",\"ProgramAttrs\":[{\"Id\":1,\"Name\":\"P1\"},{\"Id\":2,\"Name\":\"P2\"}]}," +
"{\"Id\":2,\"Name\":\"U2\",\"ProgramAttrs\":[{\"Id\":1,\"Name\":\"P1\"},{\"Id\":2,\"Name\":\"P2\"}]}]";
Assert.AreEqual<string>(expected, result);
}
示例10: AllRequiredFieldsAreEmpty
public void AllRequiredFieldsAreEmpty()
{
// Arrange
var p = new ContactUsParams()
{
FirstName = String.Empty,
EmailAddress = String.Empty,
Message = String.Empty,
ErrorMessages = new List<string>()
{
"Your form has encountered a problem. Please scroll down to review.",
"Name is required.",
"Email Address is required.",
"Subject is required.",
"Message is required.",
"Your form has encountered a problem. Please scroll up to review."
}
};
// Act
var contactUsPage = homePage
.ClickContactUsButton()
.ClickContactUsButton()
.SetFields(p)
.ClickSubmitButton();
// Assert
var verifiers = new List<IVerify>()
{
new ContactUsVerifier(contactUsPage, p)
};
verifiers.ForEach(v => v.Verify());
}
示例11: DeleteRuleById_DeletesRuleAndUpdatesOrder
public void DeleteRuleById_DeletesRuleAndUpdatesOrder()
{
// arrange
var ruleToDelete = new Rule
{
iRuleID = 1,
iOrder = 1
};
var rules = new List<Rule>
{
new Rule {iRuleID = 2, iOrder = 2},
new Rule {iRuleID = 3, iOrder = 3}
};
MockRepoRule.Setup(x => x.GetById(1)).Returns(ruleToDelete);
MockRepoRule.Setup(x => x.GetRulesAfterOrderNumber(1)).Returns(rules);
// act
RuleService.DeleteRuleById(1);
// assert
Assert.AreEqual(1, rules[0].iOrder);
Assert.AreEqual(2, rules[1].iOrder);
rules.ForEach(rule => MockRepoRule.Verify(x => x.Update(rule)));
MockRepoRule.Verify(x => x.Delete(1));
MockUow.Verify(x => x.Commit());
}
示例12: CreateItems
public void CreateItems()
{
// Arrange
var service = UniContainer.Resolve<IItemRepository>();
// Act
var items = new List<Item>
{
ItemFactory.CreateItem("发动机", "7200", null, "ENGINE - GENERAL", false),
ItemFactory.CreateItem("风扇", "7220", null, "FAN SECTION", false),
ItemFactory.CreateItem("风扇和低压压气机装置", "7221", null, "FAN AND BOOSTER ASSEMBLY", false),
ItemFactory.CreateItem("风扇框架", "7223", null, "FAN FRAME ASSEMBLY", false),
ItemFactory.CreateItem("高压压气机", "7230", null, "HP COMPRESSOR SECTION", false),
ItemFactory.CreateItem("燃烧室", "7240", null, "COMBUSTION SECTION", false),
ItemFactory.CreateItem("涡轮", "7250", null, "TURBINE SECTION", false),
ItemFactory.CreateItem("发动机燃油和控制", "7300", null, "ENGINE FUEL AND CONTROL - GENERAL", false),
ItemFactory.CreateItem("点火系统", "7400", null, "IGNITION - GENERAL", false),
ItemFactory.CreateItem("发动机引气", "7500", null, "AIR - GENERAL", false),
ItemFactory.CreateItem("发动机防冰", "7510", null, "ENGINE ANTI-ICING", false),
ItemFactory.CreateItem("冷却", "7520", null, "COOLING", false),
ItemFactory.CreateItem("发动机控制", "7600", null, "ENGINE CONTROLS - GENERAL", false),
ItemFactory.CreateItem("功率控制", "7610", null, "POWER CONTROL", false),
ItemFactory.CreateItem("油门控制", "7611", null, "THROTTLE CONTROL", false),
ItemFactory.CreateItem("发动机主控制", "7612", null, "ENGINE MASTER CONTROL", false),
ItemFactory.CreateItem("发动机滑油", "7900", null, "OIL - GENERAL", false),
ItemFactory.CreateItem("发动机滑油分配-总体", "7920", null, "DISTRIBUTION", false),
ItemFactory.CreateItem("发动机滑油分配", "7921", null, "DISTRIBUTION", false),
ItemFactory.CreateItem("回油泵", "7922", null, "PUMP - OIL SCAVENGE", false),
ItemFactory.CreateItem("发动机滑油指示", "7930", null, "INDICATING", false),
};
items.ForEach(service.Add);
service.UnitOfWork.Commit();
}
示例13: All_Text_Is_Removed_And_Readded_When_Replace_Option_Selected
public async Task All_Text_Is_Removed_And_Readded_When_Replace_Option_Selected()
{
// Assort
var store = new List<ForwardTextCandidate>(from x in InputTextItems.Take(2) select new ForwardTextCandidate { Text = x });
var repository = CreateFakeRepository(store);
var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Replace, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
.Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>, Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
((path, opc, rep, creator, locator, updater) =>
{
rep.Get().ToList().ForEach(x => rep.Delete(x));
InputTextItems.ToList().ForEach(x => rep.Save(new ForwardTextCandidate { Text = x }));
})
.Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));
// Act
var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Replace, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);
// Assert
Assert.IsTrue(result.Success);
Assert.AreEqual(InputTextItems.Length, store.Count());
var index = 0;
store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));
repository.Verify(x => x.Create(It.IsAny<ForwardTextCandidate>()), Times.Exactly(3));
}
示例14: All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected
public async Task All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected()
{
// Assort
var store = new List<ForwardTextCandidate>();
var repository = new MockRepository(MockBehavior.Default).Create<Repository<ForwardTextCandidate>>(new Mock<ISession>().Object);
repository.Setup(x => x.Get()).Returns(store.AsQueryable());
repository.Setup(x => x.Save(It.IsAny<IQueryable<ForwardTextCandidate>>())).Callback<IQueryable<ForwardTextCandidate>>(items => store.AddRange(items));
var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
.Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>, Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
((path, opc, rep, creator, locator, updater) =>
{
var itemsToAdd = new List<ForwardTextCandidate>();
InputTextItems.ToList().ForEach(x => itemsToAdd.Add(new ForwardTextCandidate { Text = x }));
rep.Save(itemsToAdd.AsQueryable());
})
.Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));
// Act
var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);
// Assert
Assert.IsTrue(result.Success);
Assert.AreEqual(InputTextItems.Length, store.Count());
var index = 0;
store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));
}
示例15: Search_AreaWithOnePoint_ReturnsOnePoint
public void Search_AreaWithOnePoint_ReturnsOnePoint()
{
var center = new Point(0, 0);
var boundary = new Boundary(center, 1, 1);
var quad = new QuadTree<Point>(boundary);
// insert one point in the second quadrant
var point = new Point(-0.75, +0.75);
quad.Insert(point);
// then insert one point in each remaining quadrant
var points = new List<Point>
{
new Point(+0.75, +0.75), // first quadrant
new Point(-0.75, -0.75), // third quadrant
new Point(+0.75, -0.75) // fourth quadrant
};
points.ForEach(p => quad.Insert(p));
// search second quadrant
var searchArea = new Boundary(new Point(-0.5, 0.5), 0.5, 0.5);
var results = quad.Search(searchArea);
Assert.IsTrue(results.Count == 1);
Assert.IsTrue(results.Contains(point));
}