本文整理汇总了C#中NUnit.Framework.List.Find方法的典型用法代码示例。如果您正苦于以下问题:C# List.Find方法的具体用法?C# List.Find怎么用?C# List.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AttributeStatement_Invalid_Attribute_AnyAttrSamlQualified
public void AttributeStatement_Invalid_Attribute_AnyAttrSamlQualified()
{
Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();
List<StatementAbstract> statements = new List<StatementAbstract>(saml20Assertion.Items);
AttributeStatement sas =
(AttributeStatement)statements.Find(delegate(StatementAbstract ssa) { return ssa is AttributeStatement; });
SamlAttribute sab = (SamlAttribute)sas.Items[0];
XmlDocument doc = new XmlDocument();
saml20Assertion.Items = statements.ToArray();
foreach (string samlns in Saml20Constants.SAML_NAMESPACES)
{
sab.AnyAttr = new XmlAttribute[1] { doc.CreateAttribute("someprefix", "SamlQualified", samlns) };
try
{
CreateSaml20Token(saml20Assertion);
Assert.Fail("A SAML-qualified xml attribute extension on Attribute must not be valid");
}
catch (Saml20FormatException sfe)
{
Assert.AreEqual(sfe.Message, "Attribute extension xml attributes MUST NOT use a namespace reserved by SAML");
}
}
}
示例2: SingleContestant
public void SingleContestant()
{
List<Contestant> ContestantList = new List<Contestant>(); //List of contestants
ContestantList.Add(new Contestant("Bill"));
Contestant item = ContestantList.Find(o => o.name == "Will");
Assert.IsNotNull(item);
//Assert.AreSame("Bill", ContestantList.);
}
示例3: NewContestant
public void NewContestant()
{
string null_string = "";
List<Contestant> ContestantList = new List<Contestant>(); //List of contestants
ContestantList.Add(new Contestant(null_string));
Contestant item = ContestantList.Find(o => o.name == "");
Assert.IsNotNull(item);
//Assert.AreSame("Bill", ContestantList.);
}
示例4: AssertContainsProperty
void AssertContainsProperty(string propertyName, IEnumerable items)
{
var itemsList = new List<Property>();
foreach (Property property in items) {
itemsList.Add(property);
}
var matchedProperty = itemsList.Find(p => p.Name == propertyName);
Assert.AreEqual(propertyName, matchedProperty.Name);
}
示例5: DiscardEvent_EventCard_EventHandGetsShorterAndDiscardGetsLonger
public void DiscardEvent_EventCard_EventHandGetsShorterAndDiscardGetsLonger()
{
var cards = new List<EventCard> {new EventCard(Event.DevilishPower, true, EventType.Keep)};
var discard = new List<EventCard>();
dracula.TakeEvent(cards, discard);
var cardCountBefore = dracula.EventHand.Count();
dracula.DiscardEvent(Event.DevilishPower, discard);
Assert.AreEqual(null, dracula.EventHand.Find(card => card.Event == Event.DevilishPower));
Assert.AreNotEqual(null, discard.Find(card => card.Event == Event.DevilishPower));
Assert.AreEqual(cardCountBefore - 1, dracula.EventHand.Count());
}
示例6: BucketRefreshTest
public void BucketRefreshTest()
{
List<Node> nodes = new List<Node>();
for (int i = 0; i < 5; i++)
nodes.Add(new Node(NodeId.Create(), new IPEndPoint(IPAddress.Any, i)));
engine.TimeOut = TimeSpan.FromMilliseconds(25);
engine.BucketRefreshTimeout = TimeSpan.FromMilliseconds(75);
engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e)
{
DhtEngine.MainLoop.Queue(delegate
{
if (!e.TimedOut)
return;
Node current = nodes.Find(delegate(Node n) { return n.EndPoint.Port.Equals(e.EndPoint.Port); });
if (current == null)
return;
if (e.Query is Ping)
{
PingResponse r = new PingResponse(current.Id, e.Query.TransactionId);
listener.RaiseMessageReceived(r, current.EndPoint);
}
else if (e.Query is FindNode)
{
FindNodeResponse response = new FindNodeResponse(current.Id, e.Query.TransactionId);
response.Nodes = "";
listener.RaiseMessageReceived(response, current.EndPoint);
}
});
};
engine.Add(nodes);
engine.Start();
System.Threading.Thread.Sleep(500);
foreach (Bucket b in engine.RoutingTable.Buckets)
{
Assert.IsTrue(b.LastChanged > DateTime.UtcNow.AddSeconds(-2));
Assert.IsTrue(b.Nodes.Exists(delegate(Node n) { return n.LastSeen > DateTime.UtcNow.AddMilliseconds(-900); }));
}
}
示例7: can_get_a_seven_digit_number
public void can_get_a_seven_digit_number()
{
var tehNumbersFromTehCodez = new List<PhoneNumber>();
for (int i = 2; i < 10; i++)
{
List<PhoneNumber> results = numberGenerator.GetNumbersStartingFrom(i);
tehNumbersFromTehCodez.AddRange(results);
}
Console.WriteLine("We found {0} phone numbers", tehNumbersFromTehCodez.Count);
Console.WriteLine("How many are distinct? {0}", tehNumbersFromTehCodez.Distinct().Count());
PhoneNumber containsAFive = tehNumbersFromTehCodez.Find(c => c.ToString().Contains("5"));
Assert.IsNull(containsAFive);
foreach (PhoneNumber phoneNumber in tehNumbersFromTehCodez)
{
Console.WriteLine(phoneNumber);
}
}
示例8: GetAttributeStatement
/// <summary>
/// Convenience method for extracting the list of Attributes from the assertion.
/// </summary>
/// <param name="statements"></param>
/// <returns></returns>
private static AttributeStatement GetAttributeStatement(List<StatementAbstract> statements)
{
return (AttributeStatement) statements.Find(delegate(StatementAbstract ssa) { return ssa is AttributeStatement; });
}
示例9: JobWatcher_YieldsJobsInExpectedSequence
public void JobWatcher_YieldsJobsInExpectedSequence()
{
IJobWatcher watcher = jobStore.CreateJobWatcher(SchedulerGuid);
JobDetails orphaned = CreateOrphanedJob("orphaned", new DateTime(1970, 1, 3));
JobDetails pending = CreatePendingJob("pending", new DateTime(1970, 1, 2));
JobDetails triggered = CreateTriggeredJob("triggered", new DateTime(1970, 1, 6));
JobDetails completed = CreateCompletedJob("completed", new DateTime(1970, 1, 1));
JobDetails scheduled = CreateScheduledJob("scheduled", new DateTime(1970, 1, 4));
// Ensure we tolerate a few odd cases where data may not be available like it should.
JobDetails scheduled2 = CreateScheduledJob("scheduled2", new DateTime(1970, 1, 2));
scheduled2.NextTriggerFireTimeUtc = null;
jobStore.SaveJobDetails(scheduled2);
JobDetails completed2 = CreateCompletedJob("completed2", new DateTime(1970, 1, 1));
completed2.LastJobExecutionDetails = null;
jobStore.SaveJobDetails(completed2);
JobDetails orphaned2 = CreateOrphanedJob("orphaned2", new DateTime(1970, 1, 3));
orphaned2.LastJobExecutionDetails.EndTimeUtc = null;
jobStore.SaveJobDetails(orphaned2);
// Populate a table of expected jobs.
List<JobDetails> expectedJobs = new List<JobDetails>(new JobDetails[]
{
orphaned, pending, triggered, completed, scheduled, scheduled2
, completed2, orphaned2
});
// Add in some extra jobs in other states that will not be returned.
CreateRunningJob("running1");
CreateStoppedJob("stopped1");
CreateScheduledJob("scheduled-in-the-future", DateTime.MaxValue);
// Ensure expected jobs are retrieved.
while (expectedJobs.Count != 0)
{
JobDetails actualJob = watcher.GetNextJobToProcess();
JobDetails expectedJob =
expectedJobs.Find(delegate(JobDetails candidate) { return candidate.JobSpec.Name == actualJob.JobSpec.Name; });
Assert.IsNotNull(expectedJob, "Did expect job {0}", actualJob.JobSpec.Name);
// All expected scheduled jobs will have been triggered.
if (expectedJob.JobState == JobState.Scheduled)
expectedJob.JobState = JobState.Triggered;
JobAssert.AreEqual(expectedJob, actualJob);
if (expectedJobs.Count == 1)
{
// Ensure same job is returned a second time until its status is changed.
// We wait for Count == 1 because that's the easiest case for which to verify
// this behavior.
JobDetails actualJob2 = watcher.GetNextJobToProcess();
JobAssert.AreEqual(expectedJob, actualJob2);
}
// Change the status to progress.
actualJob.JobState = JobState.Stopped;
jobStore.SaveJobDetails(actualJob);
expectedJobs.Remove(expectedJob);
}
// Ensure next request blocks but is released by the call to dispose.
ThreadPool.QueueUserWorkItem(delegate
{
Thread.Sleep(2);
watcher.Dispose();
});
// This call blocks until the dispose runs.
Assert.IsNull(watcher.GetNextJobToProcess());
}
示例10: SetUp
public void SetUp()
{
// will be used in GetById and GetAll mocks
var entities = new List<Product>();
for (int i = 0; i < 100; i++)
entities.Add(new Product { Id = i, Name = "Product" });
// setup a fake repository for productService .. retrieves data from the above list.
var mockProductRepo = new Mock<IRepository<Product>>();
mockProductRepo
.Setup(e => e.Add(It.IsAny<Product>()))
.Callback(() => { productRepoCalls["Add"] += 1; })
.Returns((Product entity) =>
{
entity.Id = 1; // give this an ID so it registers as 'non transient'
return entity;
});
mockProductRepo
.Setup(e => e.Update(It.IsAny<Product>()))
.Callback(() => { productRepoCalls["Update"] += 1; })
.Returns((Product entity) => { return entity; });
mockProductRepo
.Setup(e => e.Delete(It.IsAny<Product>()))
.Callback(() => { productRepoCalls["Delete"] += 1; });
mockProductRepo
.Setup(e => e.GetById(It.IsAny<int>()))
.Callback(() => { productRepoCalls["GetById"] += 1; })
.Returns((int id) =>
{
return entities.Find(e => e.Id == id);
});
mockProductRepo
.Setup(e => e.GetAll())
.Callback(() => { productRepoCalls["GetList"] += 1; })
.Returns(entities);
// we want our service to call all of it's real methods
// they're all marked as virtual so we have to explicitally tell moq to call them.
var mockProductService = new Mock<GenericService<Product>>(mockProductRepo.Object);
mockProductService.Setup(e => e.New()).CallBase();
mockProductService.Setup(e => e.Add(It.IsAny<Product>())).CallBase();
mockProductService.Setup(e => e.Update(It.IsAny<Product>())).CallBase();
// mockProductService.Setup(e => e.Delete(It.IsAny<Product>()));
mockProductService.Setup(e => e.ValidateAdd(It.IsAny<Product>())).CallBase();
mockProductService.Setup(e => e.ValidateUpdate(It.IsAny<Product>())).CallBase();
mockProductService.Setup(e => e.ValidateDelete(It.IsAny<Product>())).CallBase();
mockProductService.Setup(e => e.GetById(It.IsAny<int>())).CallBase();
mockProductService.Setup(e => e.GetList()).CallBase();
mockProductService.Setup(e => e.GetList(It.IsAny<int>(), It.IsAny<int>())).CallBase();
productService = mockProductService.Object;
}
示例11: AttributeStatement_Invalid_EncryptedAttribute_WrongType
public void AttributeStatement_Invalid_EncryptedAttribute_WrongType()
{
Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();
List<StatementAbstract> statements = new List<StatementAbstract>(saml20Assertion.Items);
AttributeStatement sas =
(AttributeStatement)statements.Find(delegate(StatementAbstract ssa) { return ssa is AttributeStatement; });
List<object> attributes = new List<object>(sas.Items);
EncryptedElement ee = new EncryptedElement();
ee.encryptedData = new EncryptedData();
ee.encryptedData.Type = "SomeWrongType";
attributes.Add(ee);
sas.Items = attributes.ToArray();
saml20Assertion.Items = statements.ToArray();
CreateSaml20Token(saml20Assertion);
}
示例12: Init
//.........这里部分代码省略.........
};
var _status = new List<Cats.Models.WorkflowStatus>()
{
new WorkflowStatus()
{
Description = "Draft",
StatusID = 1,
WorkflowID = 1
},
new WorkflowStatus()
{
Description = "Approved",
StatusID = 2,
WorkflowID = 1
},
new WorkflowStatus()
{
Description = "Closed",
StatusID = 3,
WorkflowID = 1
}
};
var commonService = new Mock<ICommonService>();
commonService.Setup(t => t.GetAminUnits(It.IsAny<Expression<Func<AdminUnit, bool>>>(),
It.IsAny<Func<IQueryable<AdminUnit>, IOrderedQueryable<AdminUnit>>>(),
It.IsAny<string>())).Returns(adminUnit);
commonService.Setup(t => t.GetStatus(It.IsAny<WORKFLOW>())).Returns(_status);
commonService.Setup(t => t.GetPlan(plan.First().ProgramID)).Returns(plan);
var mockRegionalRequestService = new Mock<IRegionalRequestService>();
mockRegionalRequestService.Setup(
t => t.GetSubmittedRequest(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())).Returns(
(int region, int month, int status) =>
{
return regionalRequests.FindAll(
t => t.RegionID == region && t.RequistionDate.Month == month && t.Status == status).ToList();
});
mockRegionalRequestService.Setup(
t =>
t.Get(It.IsAny<Expression<Func<RegionalRequest, bool>>>(),
It.IsAny<Func<IQueryable<RegionalRequest>, IOrderedQueryable<RegionalRequest>>>(),
It.IsAny<string>())).Returns(
(Expression<Func<RegionalRequest, bool>> filter,
Func<IQueryable<RegionalRequest>, IOrderedQueryable<RegionalRequest>> sort, string includes)
=>
{
return regionalRequests.AsQueryable().Where(filter);
;
});
mockRegionalRequestService.Setup(t => t.FindById(It.IsAny<int>())).Returns(
(int requestId) => regionalRequests.Find(t => t.RegionalRequestID == requestId));
mockRegionalRequestService.Setup(t => t.ApproveRequest(It.IsAny<int>())).Returns((int reqId) =>
{
regionalRequests.
Find
(t =>
t.
RegionalRequestID
== reqId).
Status
=
(int)
RegionalRequestStatus
.Approved;
return true;
});
mockRegionalRequestService.Setup(t => t.AddRegionalRequest(It.IsAny<RegionalRequest>())).Returns(
示例13: ThrowsExceptionWhenXmlAttributeStatementEncryptedAttributeWrongType
public void ThrowsExceptionWhenXmlAttributeStatementEncryptedAttributeWrongType()
{
// Arrange
var saml20Assertion = AssertionUtil.GetBasicAssertion();
var statements = new List<StatementAbstract>(saml20Assertion.Items);
var attributeStatments = (AttributeStatement)statements.Find(x => x is AttributeStatement);
var attributes = new List<object>(attributeStatments.Items);
var ee = new EncryptedElement
{
EncryptedData = new EncryptedData
{
Type = "SomeWrongType"
}
};
attributes.Add(ee);
attributeStatments.Items = attributes.ToArray();
saml20Assertion.Items = statements.ToArray();
// Act
var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
}
示例14: ThrowsExceptionWhenXmlAttributeStatementAttributeAnyAttrSamlQualified
public void ThrowsExceptionWhenXmlAttributeStatementAttributeAnyAttrSamlQualified()
{
// Arrange
var saml20Assertion = AssertionUtil.GetBasicAssertion();
var statements = new List<StatementAbstract>(saml20Assertion.Items);
var attributeStatments = (AttributeStatement)statements.Find(x => x is AttributeStatement);
var attribute = (SamlAttribute)attributeStatments.Items[0];
var doc = new XmlDocument();
saml20Assertion.Items = statements.ToArray();
foreach (var samlns in Saml20Constants.SamlNamespaces)
{
attribute.AnyAttr = new[] { doc.CreateAttribute("someprefix", "SamlQualified", samlns) };
try
{
// Act
var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
Assert.Fail("A SAML-qualified xml attribute extension on Attribute must not be valid");
}
catch (Saml20FormatException sfe)
{
Assert.AreEqual(sfe.Message, "Attribute extension xml attributes MUST NOT use a namespace reserved by SAML");
}
}
}
示例15: AssertPropertiesContainProperty
void AssertPropertiesContainProperty(string expectedPropertyName)
{
var propertiesList = new List<Property>(properties);
Property property = propertiesList.Find(p => p.Name == expectedPropertyName);
Assert.IsNotNull(property, "Unable to find property: " + expectedPropertyName);
}