本文整理汇总了C#中NUnit.Framework.List.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# List.ElementAt方法的具体用法?C# List.ElementAt怎么用?C# List.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.ElementAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: D_visit_complete_tree_depthFirst_on_VisitDescendants
public void D_visit_complete_tree_depthFirst_on_VisitDescendants()
{
// ACT
var result = new List<Tuple<List<string>, string>>();
"rootNode".VisitDescendants(this.GetChildNodes, (b, n) => result.Add(Tuple.Create(b.ToList(), n)), depthFirst: true);
// ASSERT
Assert.AreEqual(5, result.Count());
CollectionAssert.AreEqual(new[] {
"leftNode",
"leftLeaf",
"rightNode",
"leftRightLeaf",
"rightRightLeaf"
}, result.Select(i => i.Item2));
CollectionAssert.AreEqual(new[] { "leftNode", "leftLeaf", "rightNode", "leftRightLeaf", "rightRightLeaf" }, result.Select(i => i.Item2));
CollectionAssert.AreEqual(new[] { "rootNode" }, result.ElementAt(0).Item1);
CollectionAssert.AreEqual(new[] { "rootNode", "leftNode" }, result.ElementAt(1).Item1);
CollectionAssert.AreEqual(new[] { "rootNode" }, result.ElementAt(2).Item1);
CollectionAssert.AreEqual(new[] { "rootNode", "rightNode" }, result.ElementAt(3).Item1);
CollectionAssert.AreEqual(new[] { "rootNode", "rightNode" }, result.ElementAt(4).Item1);
}
示例2: Given_selected_responsibilities_When_GetViewModel_Then_those_responsibilities_are_marked_as_selected
public void Given_selected_responsibilities_When_GetViewModel_Then_those_responsibilities_are_marked_as_selected()
{
// Given
const int companyId = 12345;
var templates = new List<StatutoryResponsibilityTemplateDto>
{
new StatutoryResponsibilityTemplateDto() { Id = 123L, Description = "description", ResponsibilityCategory = new ResponsibilityCategoryDto() { Category = "category"}, ResponsibilityReason = new ResponsibilityReasonDto() { Reason = "reason"}},
new StatutoryResponsibilityTemplateDto() { Id = 456L, Description = "description", ResponsibilityCategory = new ResponsibilityCategoryDto() { Category = "category"}, ResponsibilityReason = new ResponsibilityReasonDto() { Reason = "reason"} },
new StatutoryResponsibilityTemplateDto() { Id = 789L, Description = "description", ResponsibilityCategory = new ResponsibilityCategoryDto() { Category = "category"}, ResponsibilityReason = new ResponsibilityReasonDto() { Reason = "reason"} }
};
_statutoryResponsibilityTemplateService
.Setup(x => x.GetStatutoryResponsibilityTemplates())
.Returns(templates);
// When
var result = GetTarget()
.WithCompanyId(companyId)
.WithSelectedResponsibilityTemplates(new [] { templates.First().Id })
.GetViewModel();
// Then
Assert.IsTrue(result.Responsibilities.Single(x => x.Id == templates.First().Id ).IsSelected);
Assert.IsFalse(result.Responsibilities.Single(x => x.Id == templates.ElementAt(1).Id ).IsSelected);
Assert.IsFalse(result.Responsibilities.Single(x => x.Id == templates.ElementAt(2).Id).IsSelected);
}
示例3: ForEachGroupWithActionTest
public void ForEachGroupWithActionTest()
{
var numbers = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
var executedGroups = new List<IEnumerable<int>>();
numbers.ForEachGroup(9, executedGroups.Add);
Assert.AreEqual(2, executedGroups.Count);
Assert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, executedGroups.ElementAt(0));
Assert.AreEqual(new[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 }, executedGroups.ElementAt(1));
}
示例4: TestFibSeq
public void TestFibSeq(int value)
{
var result = utility.getFibonacciSequence(5);
List<int> numbers = new List<int>();
int a = 0;
int b = 1;
if (value > 0)
{
int c = a;
for (int i = 0; c <= value; i++)
{
c = a;
a = b;
b = b + c;
if (c <= value)
numbers.Add(c);
}
}
else
{
numbers.Add(value);
}
if (numbers.ElementAt(numbers.Count - 1) != value)
numbers.Add(value);
Assert.That(result, Is.EqualTo(numbers));
}
示例5: HandleMatchesForPlayerQuery_ShouldReturnMatchesPlayerWasMemberOf
public void HandleMatchesForPlayerQuery_ShouldReturnMatchesPlayerWasMemberOf()
{
// Arrange
var random = new Random();
var nzl = setUpHelper.SetUpCountry("New Zealand");
var aus = setUpHelper.SetUpCountry("Australia");
setUpHelper.PopulateCountryPlayerPool(nzl.Name);
setUpHelper.PopulateCountryPlayerPool(aus.Name);
var matches = new List<Match>();
for (var i = 0; i < 5 +random.Next(4); i++)
{
var matchID = setUpHelper.SetUpMatch(nzl, aus);
var match = Resolve<IRepository<Match>>().GetById(matchID);
matches.Add(match);
}
var randomMatch = matches.ElementAt(random.Next(matches.Count - 1));
var selectedPlayerIndex = random.Next(randomMatch.Team1.Members.Count() - 1);
var selectedPlayer = randomMatch.Team1.Members.ElementAt(selectedPlayerIndex);
var expectedResult = matches.Where(m => m.Teams.Any(t => t.Members.Contains(selectedPlayer))).ToArray();
// Act
var result = queryHandler.Handle(new MatchesForPlayerQuery(selectedPlayer.Id));
// Assert
result.Should().BeEquivalentTo(expectedResult);
result.First().Team1.Members.Should().BeEquivalentTo(expectedResult.First().Team1.Members);
}
示例6: OriginalThing_DoesThing
public void OriginalThing_DoesThing()
{
var strings = new List<string>();
new OriginalThing().DoesThing(strings);
strings.Should().NotBeEmpty();
strings.Should().HaveCount(1);
strings.ElementAt(0).Should().Contain("Original");
}
示例7: PruebaDListaCargos
public void PruebaDListaCargos()
{
List<Cargo> listaCargo = new List<Cargo>();
Core.LogicaNegocio.Comandos.ComandoCargo.ConsultarTabla comandoConsultar =
FabricaComandoCargo.CrearComandoConsultarTabla();
listaCargo = comandoConsultar.Ejecutar();
Assert.AreEqual(listaCargo.ElementAt(listaCargo.Count - 1).Nombre, "Probador BD");
}
示例8: ProvidedOriginalThing_DoesThing
public void ProvidedOriginalThing_DoesThing()
{
var strings = new List<string>();
var thingServer = new Mock<IThingFactory>();
thingServer.Setup(ts => ts.GetThing()).Returns(new OriginalThing());
thingServer.Object.GetThing().DoesThing(strings);
strings.Should().NotBeEmpty();
strings.Should().HaveCount(1);
strings.ElementAt(0).Should().Contain("Original");
}
示例9: Test_RemapRange
public static void Test_RemapRange()
{
List<double> input = new List<double> { 0, 1, 2, 3, 4 };
List<double> expectedResults = new List<double> { -10, -2.5, 5, 12.5, 20 };
List<double> results = (List<double>)DSCore.Math.RemapRange(input, -10, 20);
for(int i = 0; i < expectedResults.Count; i++)
{
Assert.AreEqual(expectedResults.ElementAt(i), results.ElementAt(i));
}
}
示例10: AddImageWithRealContextTest
public async void AddImageWithRealContextTest()
{
var count = 5;
var contexts = new List<ShopContext>();
for (int i = 0; i < count; i++)
{
contexts.Add(new ShopContext());
}
var uof = new List<UnitOfWorkStore>();
for (int i = 0; i < count; i++)
{
uof.Add(new UnitOfWorkStore(contexts.ElementAt(i)));
}
var repo = new List<ImageRepository>();
for (int i = 0; i < count; i++)
{
repo.Add(new ImageRepository(contexts.ElementAt(i)));
}
var imgSvc = new List<ImageService>();
for (int i = 0; i < count; i++)
{
imgSvc.Add(new ImageService(uof.ElementAt(i), repo.ElementAt(i)));
}
var ctrls = new List<PhotoController>();
for (int i = 0; i < count; i++)
{
ctrls.Add(new PhotoController(uof.ElementAt(i), imgSvc.ElementAt(i), _log.Object)
{
Request = new HttpRequestMessage()
});
}
for (int i = 0; i < count; i++)
{
await ctrls.ElementAt(i).AddPhoto(521,new FileData()
{
FileName = "test"+i,
});
}
}
示例11: SimpleExample
public void SimpleExample()
{
// This is the result we want to return when execute reader is executed
var fakeDataReader = new FakeDataReader(0,"UserId","Name");
fakeDataReader.AddRow(1, "Smith");
fakeDataReader.AddRow(2, "John");
var result = new List<User>();
using (var connection = new FakeDbConnection("ConnectionString", dbCommand => fakeDataReader))
{
connection.Open();
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM Users";
IDbDataParameter dbDataParameter = command.CreateParameter();
dbDataParameter.ParameterName = "ParameterName";
dbDataParameter.DbType = DbType.Int32;
dbDataParameter.Value = 0;
command.Parameters.Add(dbDataParameter);
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Add(new User { UserId = reader.GetInt32(0), Name = reader.GetString(1)});
}
}
}
}
Assert.That(result.Count, Is.EqualTo(2));
Assert.That(result.ElementAt(0).UserId, Is.EqualTo(1));
Assert.That(result.ElementAt(0).Name, Is.EqualTo("Smith"));
Assert.That(result.ElementAt(1).UserId, Is.EqualTo(2));
Assert.That(result.ElementAt(1).Name, Is.EqualTo("John"));
}
示例12: ProvidedOriginalThing_DoesThing
public void ProvidedOriginalThing_DoesThing()
{
var strings = new List<string>();
var factory = new OriginalThingFactory();
var originalThing = factory.GetThing();
originalThing.Should().BeOfType<OriginalThing>();
originalThing.DoesThing(strings);
strings.Should().NotBeEmpty();
strings.Should().HaveCount(1);
strings.ElementAt(0).Should().Contain("Original");
}
示例13: should_be_sortable
public void should_be_sortable()
{
const string kingsCross = "Kings Cross";
const string bank = "Bank";
const string princeRegent = "Prince Regent";
const short fare = 10;
var accountId = Guid.NewGuid();
var jny1 = new Journey(accountId, kingsCross, bank);
var jny2 = new Journey(accountId, bank, princeRegent);
var jny3 = new Journey(accountId, princeRegent, bank);
jny1.AssignFare((o, d) => fare);
jny2.AssignFare((o, d) => fare);
jny3.AssignFare((o, d) => fare);
var jourenys = new List<Journey>(new[] {jny2, jny3, jny1});
jourenys.Sort();
Assert.That(jourenys.First().Export().Origin, Is.EqualTo(kingsCross));
Assert.That(jourenys.First().Export().Destination, Is.EqualTo(bank));
Assert.That(jourenys.First().Export().Fare, Is.EqualTo(10));
Assert.That(jourenys.First().Export().AccountId, Is.EqualTo(accountId));
Assert.That(jourenys.First().Export().JourneyId, Is.Not.EqualTo(Guid.Empty));
Assert.That(jourenys.ElementAt(1).Export().Origin, Is.EqualTo(bank));
Assert.That(jourenys.ElementAt(1).Export().Destination, Is.EqualTo(princeRegent));
Assert.That(jourenys.ElementAt(1).Export().Fare, Is.EqualTo(10));
Assert.That(jourenys.ElementAt(1).Export().AccountId, Is.EqualTo(accountId));
Assert.That(jourenys.ElementAt(1).Export().JourneyId, Is.Not.EqualTo(Guid.Empty));
Assert.That(jourenys.Last().Export().Origin, Is.EqualTo(princeRegent));
Assert.That(jourenys.Last().Export().Destination, Is.EqualTo(bank));
Assert.That(jourenys.Last().Export().Fare, Is.EqualTo(10));
Assert.That(jourenys.Last().Export().AccountId, Is.EqualTo(accountId));
Assert.That(jourenys.Last().Export().JourneyId, Is.Not.EqualTo(Guid.Empty));
}
示例14: ProvidedFakeThing_DoesThing
public void ProvidedFakeThing_DoesThing()
{
var strings = new List<string>();
var factory = new FakeThingFactory();
var fakeThing = factory.GetThing();
fakeThing.Should().BeOfType<FakeThing>();
fakeThing.DoesThing(strings);
strings.Should().NotBeEmpty();
strings.Should().HaveCount(1);
strings.ElementAt(0).Should().Contain("Fake");
}
示例15: CompositeIndicator
public void CompositeIndicator()
{
var ciResults = new List<DataPoint<decimal>>();
var maResults = new List<DataPoint<decimal>>();
var ci = new CountIndicator(TimeSpan.FromSeconds(1));
var ma = new MovingAverageIndicator(2);
// composite indicator
ci.Subscribe(ma);
ci.Subscribe(ciResults.Add);
ma.Subscribe(maResults.Add);
// 2 second test
// produce 10 in the second #1
for (int i = 0; i < 10; i++)
{
ci.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
Thread.Sleep(99);
}
Thread.Sleep(50);
// produce 20 in the second #2
for (int i = 0; i < 20; i++)
{
ci.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
Thread.Sleep(48);
}
Thread.Sleep(50);
Assert.That(ciResults.ElementAt(0).Value, Is.EqualTo(10));
Assert.That(ciResults.ElementAt(1).Value, Is.EqualTo(20));
Assert.That(maResults.ElementAt(0).Value, Is.EqualTo(15));
}