本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# List.FindAll方法的具体用法?C# List.FindAll怎么用?C# List.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.FindAll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLists
public void TestLists()
{
List<Person> people = new List<Person> { new Person(), new Person("Ted", "TheDog"), new Person("Fred", "TheDog"), new Person("Joe", "Schmoo") };
Assert.AreEqual("Joe", people[3].FirstName);
Assert.AreEqual("Schmoo", people[3].LastName);
Assert.AreEqual(4, people.Count);
List<Person> theJoes = people.FindAll(p => p.FirstName.Equals("Joe"));
Assert.AreEqual(1, theJoes.Count);
theJoes.Add(new Person("Joe", "Soe"));
Assert.AreEqual(2, theJoes.Count);
Assert.AreEqual(4, people.Count);
var joeschmoo = theJoes.FindAll(p => p.FirstName.Equals("Joe") && p.LastName.Equals("Schmoo"));
Assert.AreEqual(1, joeschmoo.Count);
var sando = theJoes.FindAll(p => p.FirstName.Equals("Joe") && Regex.IsMatch(p.LastName, "S.*o.*"));
Assert.AreEqual(2, sando.Count);
StringBuilder sb = new StringBuilder();
foreach (Person person in people)
{
sb.Append(String.Format("{0}, {1}\n", person.LastName, person.FirstName));
}
string pretty = sb.ToString();
Assert.AreEqual("Doe, John\nTheDog, Ted\nTheDog, Fred\nSchmoo, Joe\n", pretty);
}
示例2: RandomWeightedTest
public void RandomWeightedTest()
{
//Arrange
Random randy = new Random();
List<Move> myMoves = new List<Move>();
int MoveCount = 1000;
int Variance = 40;
double Rweight = 6;
double Pweight = 1;
double Sweight = 1;
double Dweight = 1;
double Wweight = 1;
//computed vars
double TotalWeight = Rweight + Pweight + Sweight + Dweight + Wweight;
double Rexpected = (Rweight / TotalWeight) * MoveCount;
double Pexpected = (Pweight / TotalWeight) * MoveCount;
double Sexpected = (Sweight / TotalWeight) * MoveCount;
double Dexpected = (Dweight / TotalWeight) * MoveCount;
double Wexpected = (Wweight / TotalWeight) * MoveCount;
//Act
for (int i = 0; i < MoveCount; i++)
{
myMoves.Add(Strats.RandomWeighted(randy, Rweight, Pweight, Sweight, Dweight, Wweight));
}
var RockCount = myMoves.FindAll(m => m.Equals(Moves.Rock)).Count;
var PaperCount = myMoves.FindAll(m => m.Equals(Moves.Paper)).Count;
var ScissorsCount = myMoves.FindAll(m => m.Equals(Moves.Scissors)).Count;
var DynamiteCount = myMoves.FindAll(m => m.Equals(Moves.Dynamite)).Count;
var WaterCount = myMoves.FindAll(m => m.Equals(Moves.WaterBalloon)).Count;
Console.WriteLine("Rock: " + RockCount + ", Paper: " + PaperCount + ", Scissors: " + ScissorsCount + ", Dyanimite: " + DynamiteCount + ", Water: " + WaterCount);
//Assert
Assert.IsTrue(Rexpected - Variance < RockCount && RockCount < Rexpected + Variance, "RockCount: " + RockCount + " is outside statistical likelyhood.");
Assert.IsTrue(Pexpected - Variance < PaperCount && PaperCount < Pexpected + Variance, "PaperCount: " + PaperCount + " is outside statistical likelyhood.");
Assert.IsTrue(Sexpected - Variance < ScissorsCount && ScissorsCount < Sexpected + Variance, "ScissorsCount: " + ScissorsCount + " is outside statistical likelyhood.");
Assert.IsTrue(Dexpected - Variance < DynamiteCount && DynamiteCount < Dexpected + Variance, "DynamiteCount: " + DynamiteCount + " is outside statistical likelyhood.");
Assert.IsTrue(Wexpected - Variance < WaterCount && WaterCount < Wexpected + Variance, "DynamiteCount: " + WaterCount + " is outside statistical likelyhood.");
}
示例3: GetSecondHandList
private List<SecondHand> GetSecondHandList(List<CompanyGroup.Domain.MaintainModule.SecondHand> list, string key)
{
List<SecondHand> results = list.FindAll(m => m.ProductId.ToLower() == key.ToLower());
return results != null ? results : new List<SecondHand>();
}
示例4: GetPictures
//private ProductManager GetProductManager(List<CompanyGroup.Domain.MaintainModule.ProductManager> managers, string key)
//{
// ProductManager manager = managers.FirstOrDefault(m => m.EmployeeId.ToLower() == key.ToLower());
// return manager != null ? manager : new ProductManager("", "", "", "", "");
//}
private List<Picture> GetPictures(List<CompanyGroup.Domain.MaintainModule.Picture> pictures, string key)
{
List<Picture> pictureList = pictures.FindAll(m => m.ItemId.ToLower() == key.ToLower());
return pictureList != null ? pictureList : new List<Picture>();
}
示例5: AliveNeighborCount
// this can be refactored later
public int AliveNeighborCount(int x, int y)
{
Cell above, below, right, left;
Cell top_right, top_left, bottom_left, bottom_right;
List<Cell> neighbors = new List<Cell>();
// x, y are in "row, column" order, not Cartesian coordinates!
above = cells[y, x - 1];
below = cells[y, x + 1];
right = cells[y + 1, x];
left = cells[y - 1, x];
top_right = cells[y + 1, x - 1];
top_left = cells[y - 1, x - 1];
bottom_right = cells[y + 1, x + 1];
bottom_left = cells[y - 1, x + 1];
neighbors.Add(above);
neighbors.Add(below);
neighbors.Add(right);
neighbors.Add(left);
neighbors.Add(top_left);
neighbors.Add(top_right);
neighbors.Add(bottom_left);
neighbors.Add(bottom_right);
return neighbors.FindAll(IsCellAlive).Count;
}
示例6: ValidateXAxisDataRange
/// <summary>
/// Validate if the X - Axis range matches with the data from the MarketHistory.xml file
/// </summary>
/// <param name="defaultItems"></param>
/// <returns></returns>
private bool ValidateXAxisDataRange(List<MarketHistoryItem> defaultItems)
{
defaultItems.Sort((a, b) => a.Date.CompareTo(b.Date));
//TODO: find a better mechanism to check the X-Axis data
return defaultItems.FindAll(i => Window.AutomationElement.SearchInRawTreeByName(i.Date.ToString()) != null).Count.Equals(defaultItems.Count);
//TODO: also verify the lower and upper bound of the X-Axis - but how?
}
示例7: testDeleteSkill
public void testDeleteSkill()
{
string[] tablesToFill = { "Volunteer.xlsx", "Group.xlsx", "GroupVol.xlsx", "VolAddress.xlsx",
"VolAddr.xlsx", "Skill.xlsx", "VolSkill.xlsx", "VolState.xlsx",
"VolEmail.xlsx", "VolPhone.xlsx"};
cExcel.RemoveAllData();
cExcel.InsertData(tablesToFill);
string directory = cExcel.GetHelperFilesDir();
string hdir = cExcel.GetHelperFilesDir();
sp_Skill_BLL skillBLL = new sp_Skill_BLL();
string query = "SELECT * FROM [Sheet1$]";
DataTable dt = cExcel.QueryExcelFile(hdir + "Skill.xlsx", query);
List<Tuple<Guid, String, int, Guid?>> rowTree = new List<Tuple<Guid, string, int, Guid?>>();
foreach (DataRow row in dt.Rows)
{
var key = new Guid(row["SkillID"].ToString());
var mstr = row["MstrSkillID"].ToString() == "" ? new Nullable<Guid>() : (Guid?)(new Guid(row["MstrSkillID"].ToString()));
var activeFlag = Convert.ToInt32(row["ActiveFlg"]);
var skillname = row["SkillName"].ToString();
rowTree.Add(Tuple.Create<Guid, string, int, Guid?>(key, skillname, activeFlag, mstr));
}
//this function returns the guid of the parent we deleted
Func<Guid, List<Tuple<Guid, String, int, Guid?>>> deleteReturnParent = (Guid key) =>
{
//Check to make sure this key is still contained in the database based
//on the description of how it should work.
var toDeleteRow = rowTree.Find((x) => {
return x.Item1.Equals(key);
});
rowTree.Remove(toDeleteRow);
//Find all rows that have the key as their mstrskill
var updateRows = rowTree.FindAll((x) =>
{
return x.Item4.Equals(key);
});
//Remove them
rowTree.RemoveAll((x) =>
{
return x.Item4.Equals(key);
});
var returnList = new List<Tuple<Guid, String, int, Guid?>>();
foreach (var row in updateRows){
//Update them so that their master skill ids point at the master skill of the deleted node
var guidTpl = Tuple.Create<Guid, String, int, Guid?>(row.Item1, row.Item2, row.Item3, toDeleteRow.Item4);
rowTree.Add(guidTpl);
returnList.Add(guidTpl);
}
return returnList;
};
foreach (DataRow row in dt.Rows)
{
sp_Skill_DM dmskill = new sp_Skill_DM();
dmskill.ActiveFlg = Convert.ToInt32(row["ActiveFlg"]);
dmskill.MstrSkillID = row["MstrSkillID"].ToString() == "" ? new Nullable<Guid>() : (Guid?)(new Guid(row["MstrSkillID"].ToString()));
dmskill.SkillID = new Guid(row["SkillID"].ToString());
dmskill.SkillName = row["SkillName"].ToString();
//Delete a skill
int before = cExcel.getNumRecordsFromDB("Vol.tblVolSkill");
skillBLL.DeleteSkillContext(dmskill);
var updatedList = deleteReturnParent(dmskill.SkillID);
int after = cExcel.getNumRecordsFromDB("Vol.tblVolSkill");
//Did the skill actually get deleted.
Assert.AreEqual(before - 1, after);
//Did all the values get properly updated
foreach (var updatedRow in updatedList){
sp_Skill_DM updatedSkill = skillBLL.ListSingleSkill(updatedRow.Item1);
Assert.AreEqual(updatedSkill.ActiveFlg, updatedRow.Item3);
Assert.AreEqual(updatedSkill.MstrSkillID, updatedRow.Item4);
Assert.AreEqual(updatedSkill.SkillName, updatedRow.Item2);
}
}
cExcel.RemoveData(tablesToFill);
}
示例8: GetMinTemperatureOfTheMonth
private float GetMinTemperatureOfTheMonth(List<DailyValues> listOfDailyValues, out List<DateTime> dayNumber)
{
float minValue = 50F;
List<DateTime> days = new List<DateTime>();
for (int i = 0; i < listOfDailyValues.Count; i++)
{
if (listOfDailyValues[i].minTemp < minValue)
{
minValue = listOfDailyValues[i].minTemp;
}
}
var daysNo = listOfDailyValues.FindAll(day => day.minTemp == minValue);
dayNumber = ExtractDayFieldFromStructData(daysNo);
return minValue;
}
示例9: GetDifTemperatureOfTheMonth
private float GetDifTemperatureOfTheMonth(List<DailyValues> listOfDailyValues, out List<DateTime> foundDifDay)
{
float maxValue = 0F;
List<DateTime> days = new List<DateTime>();
for (int i = 0; i < listOfDailyValues.Count; i++)
{
if ((listOfDailyValues[i].maxTemp - listOfDailyValues[i].minTemp) > maxValue)
{
maxValue = listOfDailyValues[i].maxTemp - listOfDailyValues[i].minTemp;
}
}
var daysNo = listOfDailyValues.FindAll(day => (day.maxTemp-day.minTemp) == maxValue);
foundDifDay = ExtractDayFieldFromStructData(daysNo);
return maxValue;
}
示例10: creerEdTTest
public void creerEdTTest()
{
Astronaute a = new Astronaute("Bob", "Machin", 20);
int numJour = 20;
a.creerEdT(numJour);
Assert.IsNotNull(a.getJourneesMission(), "L'emploi du temps n'a pas été créé");
List<Journee> journees = new List<Journee>(a.getJourneesMission().Values);
int passees = journees.FindAll(e => (!e.isModifiable())).Count;
int enCours = journees.FindAll(e => (e.isEnCours())).Count;
int resultPassee = 19;
int resultEnCours = 1;
Assert.IsTrue(passees == resultPassee && enCours == resultEnCours, "L'emploi du temps a été créé, mais " +
"les journées n'ont pas le bon état");
}
示例11: When_RandomFactor_Is_10_Percent_Then_About_10_Percent_Of_Users_Will_Have_Feature_Enabled
public void When_RandomFactor_Is_10_Percent_Then_About_10_Percent_Of_Users_Will_Have_Feature_Enabled()
{
// Setup
const string FEATURE_NAME = "Feature1";
const string TEN_PERCENT_RANDOM_FACTOR = "0.1";
FeatureToggle.Initialize(
new FeatureCollection
{
NewFeature(FEATURE_NAME, true, TEN_PERCENT_RANDOM_FACTOR)
},
new UserListReaderMock());
// Execute
const int NR_OF_REQUESTS = 100;
var resultList = new List<bool>();
for (int i = 0; i < NR_OF_REQUESTS; i++)
{
resultList.Add(FeatureToggle.IsEnabled(FEATURE_NAME));
}
int nrIsEnabled = resultList.FindAll(b => b == true).Count;
int nrIsDisabled = resultList.FindAll(b => b == false).Count;
Console.WriteLine(nrIsEnabled + "/" + nrIsDisabled);
// Verify
Assert.IsFalse(nrIsDisabled == 0);
Assert.IsFalse(nrIsDisabled == NR_OF_REQUESTS);
Assert.IsTrue(nrIsDisabled > 80);
Assert.IsFalse(nrIsEnabled == 0);
Assert.IsFalse(nrIsEnabled == NR_OF_REQUESTS);
Assert.IsTrue(nrIsEnabled > 3);
}