本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# List.Exists方法的具体用法?C# List.Exists怎么用?C# List.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBuildThreeValidatorsWithThreeValidationAttributes
public void ShouldBuildThreeValidatorsWithThreeValidationAttributes()
{
ParameterInfo paramToValidate = GetParameterInfo("MethodWithMultipleValidators", "id");
Validator v = ParameterValidatorFactory.CreateValidator(paramToValidate);
Assert.IsNotNull(v);
Assert.IsTrue(v is AndCompositeValidator);
List<Validator> validators = new List<Validator>(((AndCompositeValidator)v).Validators);
Assert.AreEqual(3, validators.Count);
Assert.IsTrue(
validators.Exists(
delegate(Validator v1)
{
return v1 is NotNullValidator;
}));
Assert.IsTrue(
validators.Exists(
delegate(Validator v1)
{
return v1 is StringLengthValidator;
}));
Assert.IsTrue(
validators.Exists(
delegate(Validator v1)
{
return v1 is RegexValidator;
}));
}
示例2: ShouldReturnDescriptorsWhenUpdatedWithParameterInfo
public void ShouldReturnDescriptorsWhenUpdatedWithParameterInfo()
{
MetadataValidatedParameterElement validatedElement = new MetadataValidatedParameterElement();
validatedElement.UpdateFlyweight(GetMethod1NameParameterInfo());
Assert.IsNull(validatedElement.MemberInfo);
Assert.IsNull(validatedElement.TargetType);
Assert.AreEqual(CompositionType.And, validatedElement.CompositionType);
Assert.IsFalse(validatedElement.IgnoreNulls);
List<IValidatorDescriptor> descriptors =
new List<IValidatorDescriptor>(validatedElement.GetValidatorDescriptors());
Assert.AreEqual(3, descriptors.Count);
// reflection doesn't preserve ordering of attributes. Therefore,
// it doesn't preserve ordering of validators. Is this an issue?
Assert.IsTrue(descriptors.Exists(delegate(IValidatorDescriptor d)
{
return d is NotNullValidatorAttribute;
}));
Assert.IsTrue(descriptors.Exists(delegate(IValidatorDescriptor d)
{
return d is StringLengthValidatorAttribute;
}));
Assert.IsTrue(descriptors.Exists(delegate(IValidatorDescriptor d)
{
return d is RegexValidatorAttribute;
}));
}
示例3: Gera_Relation_Criar_Cartao
public void Gera_Relation_Criar_Cartao()
{
var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url);
var list = new List<LinkRelation>(assembledUsuario.Links);
Assert.IsTrue(list.Exists(x => x.Rel == "/rels/usuarios/adicionar-cartao"), "'/rels/usuarios/adicionar-cartao' relation is missing");
}
示例4: Gera_Self_Relation
public void Gera_Self_Relation()
{
var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url);
var list = new List<LinkRelation>(assembledUsuario.Links);
Assert.IsTrue(list.Exists(x => x.Rel == "self"),"self relation is missing");
}
示例5: Gera_Validacao_Usuario_Quando_Usuario_Nao_Foi_Validado
public void Gera_Validacao_Usuario_Quando_Usuario_Nao_Foi_Validado()
{
_usuario.StatusValidacao = 0;
var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url);
var list = new List<LinkRelation>(assembledUsuario.Links);
Assert.IsTrue(list.Exists(x => x.Rel == "/rels/usuarios/validacao"), "'/rels/usuarios/validar' relation is missing");
}
示例6: Gera_Validacao_Telefone_Relation
public void Gera_Validacao_Telefone_Relation()
{
var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url);
var list = new List<LinkRelation>(assembledUsuario.Links);
Assert.IsTrue(list.Exists(x => x.Rel == "/rels/usuarios/registrar-numero-telefone"), "'/rels/usuarios/registrar-numero-telefone' relation is missing");
}
示例7: AttackCleanUp_RemoveLowHealth
public void AttackCleanUp_RemoveLowHealth()
{
// arrange
List<Combatant> combatants = new List<Combatant>();
Combatant combatant1Copy = CopyCombatant(combatant1);
combatant1Copy.Health = 0;
Combatant combatant2Copy = CopyCombatant(combatant2);
combatant2Copy.Health = 0;
combatants.Add(combatant1Copy);
combatants.Add(combatant2Copy);
Battle battleClass = new Battle();
// act
battleClass.AttackCleanUp(ref combatant1Copy, ref combatant2Copy, ref combatants);
// assert
if (combatants.Exists(x => x.CombatantID == combatant1Copy.CombatantID))
{
Assert.Fail("AttackCleanUp failed to remove the attacker with low stanima");
return;
}
if (combatants.Exists(x => x.CombatantID == combatant2Copy.CombatantID))
{
Assert.Fail("AttackCleanUp failed to remvoe the defender with low stanima");
return;
}
Assert.IsTrue(true);
}
示例8: AttackCleanUp_NoRemoval
public void AttackCleanUp_NoRemoval()
{
// arrange
List<Combatant> combatants = new List<Combatant>();
Combatant combatant1Copy = CopyCombatant(combatant1);
Combatant combatant2Copy = CopyCombatant(combatant2);
combatants.Add(combatant1Copy);
combatants.Add(combatant2Copy);
Battle battleClass = new Battle();
// act
battleClass.AttackCleanUp(ref combatant1Copy, ref combatant2Copy, ref combatants);
// assert
if(combatant1Copy.Stanima == combatant1Copy.MaxStanima - 1 &&
combatant2Copy.Stanima == combatant2Copy.MaxStanima - 1 &&
combatants.Exists(x => x.CombatantID == combatant1Copy.CombatantID) &&
combatants.Exists(x => x.CombatantID == combatant2Copy.CombatantID))
{
Assert.IsTrue(true);
}
else
{
Assert.Fail("AttackCleanUp removes combatants it's not supposed to remove");
}
}
示例9: TestRemoveNameSpaceForSite
public void TestRemoveNameSpaceForSite()
{
// Create a new NameSpace object and create a new name space for a test site
IInputContext context = DnaMockery.CreateDatabaseInputContext();
// Create the namespace object and call the add namespace method
NameSpaces testNameSpace = new NameSpaces(context);
NameSpaceItem newName = AddNameSpaceToSite(1, "category");
Assert.IsTrue(newName.ID > 0, "NameSpaceId is zero! Failed to create new name space. namespace being added = category");
// Now add some phrases to the namespace by adding some phrases to an article
List<string> phrases = new List<string>();
phrases.Add("funny");
phrases.Add("sad");
phrases.Add("random");
phrases.Add("practical");
using (IDnaDataReader reader = context.CreateDnaDataReader("addkeyphrasestoarticle"))
{
// Add the phrases
string keyPhrases = "";
foreach (string phrase in phrases)
{
keyPhrases += phrase + "|";
}
keyPhrases = keyPhrases.TrimEnd('|');
reader.AddParameter("h2g2id", 5176);
reader.AddParameter("keywords", keyPhrases);
reader.AddParameter("namespaces", "category|category|category|category");
reader.Execute();
}
// Now get all the phrases for a given namespace
List<string> namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace);
Assert.IsTrue(namespacePhrases.Count == 4, "Get phrases for namespace failed to find all phrases");
// now compare the phrases with the known values.
for (int i = 0; i < namespacePhrases.Count; i++)
{
// Check to make sure that we have all the same items in both lists
Assert.IsTrue(phrases.Exists(delegate(string match) { return match == namespacePhrases[i]; }), "Failed to find known phrase in the found phrases. Phrase = " + namespacePhrases[i]);
}
// now remove the namespace and check to make sure that the phrases are removed form the article
using (IDnaDataReader reader3 = context.CreateDnaDataReader("deletenamespaceandassociatedlinks"))
{
testNameSpace.RemoveNameSpaceForSite(1, newName.ID);
// Now get all the phrases for the namespace we removed.
NameSpaces testNameSpace2 = new NameSpaces(context);
namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace2);
Assert.IsTrue(namespacePhrases.Count == 0, "The number of phrases returned from a remove namespace should be zero!");
}
}
示例10: TestGetPhrasesforNameSpace
public void TestGetPhrasesforNameSpace()
{
// Create a new NameSpace object and create a new name space for a test site
IInputContext context = DnaMockery.CreateDatabaseInputContext();
// Create the namespace object and call the add namespace method
NameSpaces testNameSpace = new NameSpaces(context);
NameSpaceItem newName = AddNameSpaceToSite(1, "category");
Assert.IsTrue(newName.ID > 0, "NameSpaceId is zero! Failed to create new name space. namespace being added = category");
// Now add some phrases to the namespace by adding some phrases to an article
List<string> phrases = new List<string>();
phrases.Add("funny");
phrases.Add("sad");
phrases.Add("random");
phrases.Add("practical");
using (IDnaDataReader reader = context.CreateDnaDataReader("addkeyphrasestoarticle"))
{
// Add the phrases
string keyPhrases = "";
foreach (string phrase in phrases)
{
keyPhrases += phrase + "|";
}
keyPhrases = keyPhrases.TrimEnd('|');
reader.AddParameter("h2g2id", 5176);
reader.AddParameter("keywords",keyPhrases);
reader.AddParameter("namespaces", "category|category|category|category");
reader.Execute();
}
List<string> namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace);
Assert.IsTrue(namespacePhrases.Count == 4, "Get phrases for namespace failed to find all phrases");
// now compare the phrases with the known values.
for (int i = 0; i < namespacePhrases.Count; i++)
{
Assert.IsTrue(phrases.Exists(delegate(string match) { return match == namespacePhrases[i]; }), "Failed to find known phrase in the found phrases. Phrase = " + namespacePhrases[i]);
}
}
示例11: AttachNaClGDBTest
public void AttachNaClGDBTest()
{
PluginDebuggerGDB_Accessor target = new PluginDebuggerGDB_Accessor(dte_, properties_);
string existingGDB = "AttachNaClGDBTest_existingGDB";
try
{
target.gdbProcess_ = TestUtilities.StartProcessForKilling(existingGDB, 20);
string existingInitFileName = Path.GetTempFileName();
target.gdbInitFileName_ = existingInitFileName;
// Visual studio won't allow adding a breakpoint unless it is associated with
// an existing file and valid line number, so use BlankValidSolution.
dte_.Solution.Open(naclSolution);
string fileName = "main.cpp";
string functionName = "NaClProjectInstance::HandleMessage";
int lineNumber = 39;
dte_.Debugger.Breakpoints.Add(Function: functionName);
dte_.Debugger.Breakpoints.Add(Line: lineNumber, File: fileName);
target.Attach(null, new PluginDebuggerBase.PluginFoundEventArgs(0));
Assert.IsTrue(File.Exists(target.gdbInitFileName_), "Init file not written");
var gdbCommands = new List<string>(File.ReadAllLines(target.gdbInitFileName_));
// Validate that the commands contain what we specified.
// The syntax itself is not validated since this add-in is not responsible for
// the syntax and it could change.
Assert.IsTrue(
gdbCommands.Exists(s => s.Contains(fileName) && s.Contains(lineNumber.ToString())),
"Line breakpoint not properly set");
Assert.IsTrue(
gdbCommands.Exists(s => s.Contains(functionName)),
"Function breakpoint not properly set");
// Note fake assembly string should be double escaped when passed to gdb.
Assert.IsTrue(
gdbCommands.Exists(s => s.Contains(functionName)),
@"fake\\Assembly\\String");
// Check that the pre-existing gdb process was killed and its init file cleaned up.
Assert.IsFalse(
TestUtilities.DoesProcessExist("python.exe", existingGDB),
"Failed to kill existing GDB process");
Assert.IsFalse(
File.Exists(existingInitFileName),
"Failed to delete existing temp gdb init file");
}
finally
{
if (dte_.Debugger.Breakpoints != null)
{
// Remove all breakpoints.
foreach (EnvDTE.Breakpoint bp in dte_.Debugger.Breakpoints)
{
bp.Delete();
}
}
// Clean up file if not erased.
if (!string.IsNullOrEmpty(target.gdbInitFileName_) && File.Exists(target.gdbInitFileName_))
{
File.Delete(target.gdbInitFileName_);
}
// Kill the gdb process if not killed.
if (target.gdbProcess_ != null && !target.gdbProcess_.HasExited)
{
target.gdbProcess_.Kill();
target.gdbProcess_.Dispose();
}
}
}
示例12: SearchOrderRetrievesOrderFromStartOrderIndex
public void SearchOrderRetrievesOrderFromStartOrderIndex()
{
OrdersManagementDataSet ds = InitOrdersManagementDataSet();
OrdersService ordersService = new OrdersService(ds, new FakeProductService());
int ordersTotalCount;
ICollection<Order> foundOrders = ordersService.SearchOrders("Order", 2, int.MaxValue, out ordersTotalCount);
Assert.AreEqual(3, ordersTotalCount);
Assert.AreEqual(1, foundOrders.Count);
List<Order> searchableList = new List<Order>(foundOrders);
Assert.IsFalse(searchableList.Exists(delegate(Order order) { return order.OrderId == 1; }));
Assert.IsFalse(searchableList.Exists(delegate(Order order) { return order.OrderId == 2; }));
Assert.IsTrue(searchableList.Exists(delegate(Order order) { return order.OrderId == 3; }));
}
示例13: MasterVoteTest
public void MasterVoteTest()
{
TaskNode node1 = new TaskNode();
TaskNode node2 = new TaskNode();
TaskNode node3 = new TaskNode();
TaskNode node4 = new TaskNode(); try
{
List<TaskNode> nodeList = new List<TaskNode>()
{
node2,
node3,
node4,
};
Thread.Sleep(3000);
Assert.AreEqual(Role.Master.ToString(), node1.NodeRole);
node1.Shutdown();
Thread.Sleep(50000);
Assert.IsTrue(nodeList.Exists(u => u.NodeRole == Role.Master.ToString()));
}
finally
{
node1.Shutdown();
node2.Shutdown();
node4.Shutdown();
node3.Shutdown();
}
}
示例14: WhenInitialize_ThenExpectedPropertiesAreProtected
public void WhenInitialize_ThenExpectedPropertiesAreProtected()
{
var expected = new List<Property>
{
new Property { EntityName = "SSD.Domain.Student", Name = "StudentKey" },
new Property { EntityName = "SSD.Domain.Student", Name = "ServiceRequests" },
new Property { EntityName = "SSD.Domain.Student", Name = "StudentAssignedOfferings" },
new Property { EntityName = "SSD.Domain.ServiceOffering", Name = "StudentAssignedOfferings" }
};
ResetDatabase();
Target.Dispose();
Target = new EducationDataContext();
var actual = Target.Properties.Where(p => p.IsProtected).ToList();
Assert.IsTrue(expected.All(p => actual.Exists(a => a.Name == p.Name && a.EntityName == p.EntityName)));
Assert.IsFalse(actual.Any(a => !expected.Exists(p => p.Name == a.Name && p.EntityName == a.EntityName)));
}
示例15: TestTupleVertexIndexes
public void TestTupleVertexIndexes()
{
VoronoiWrapper vw = new VoronoiWrapper();
vw.AddSegment(0, 0, 0, 10);
vw.AddSegment(0, 10, 10, 10);
vw.AddSegment(10, 10, 10, 0);
vw.AddSegment(10, 0, 0, 0);
vw.AddSegment(0, 0, 5, 5);
vw.AddSegment(5, 5, 10, 10);
vw.ConstructVoronoi();
List<Tuple<double, double>> vertices = vw.GetVertices();
List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();
List<int> vertexIndexes = new List<int>();
foreach (var e in edges)
{
if(!vertexIndexes.Exists(v=> v==e.Item2))
vertexIndexes.Add(e.Item2);
if (!vertexIndexes.Exists(v => v == e.Item3))
vertexIndexes.Add(e.Item3);
}
vertexIndexes.Remove(-1);
vertexIndexes.Sort();
int minIndex = vertexIndexes.Min();
int maxIndex = vertexIndexes.Max();
Assert.AreEqual(0, minIndex);
Assert.AreEqual(vertices.Count - 1, maxIndex);
}