本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# List.ElementAt方法的具体用法?C# List.ElementAt怎么用?C# List.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.ElementAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateTotalNumberOfVotes
public List<Candidate> CalculateTotalNumberOfVotes(List<List<Candidate>> listPerSection)
{
List<Candidate> finalList = new List<Candidate>();
bool found = false;
for (int i = 0; i < listPerSection.Count; i++)
{
List<Candidate> currentSection = listPerSection[i];
for (int j = 0; j < currentSection.Count; j++)
{
found = false;
Candidate currentCandidate = currentSection[j];
for (int k = 0; k < finalList.Count; k++)
{
if (finalList.ElementAt(k).name == currentCandidate.name)
{
found = true;
currentCandidate.numberOfVotes += finalList.ElementAt(k).numberOfVotes;
finalList.Remove(finalList.ElementAt(k));
finalList.Add(currentCandidate);
break;
}
}
if (found == false)
{
finalList.Add(currentCandidate);
}
}
}
return finalList;
}
示例2: GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase
public void GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase()
{
// Arrange
var stubContext = new Mock<Context>();
var stubRecipients = new List<Recipient>
{
new Recipient("[email protected]"),
new Recipient("[email protected]"),
new Recipient("[email protected]"),
}.AsQueryable();
stubRecipients.ElementAt(0).MarkAsSent(DateTime.Now);
stubRecipients.ElementAt(1).MarkAsSent(DateTime.Now);
stubRecipients.ElementAt(2).MarkAsFailed("sending failed", DateTime.Now);
var stubDbSet = new Mock<DbSet<Recipient>>();
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Provider).Returns(stubRecipients.Provider);
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Expression).Returns(stubRecipients.Expression);
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.ElementType).Returns(stubRecipients.ElementType);
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.GetEnumerator()).Returns(stubRecipients.GetEnumerator());
stubContext.Setup(c => c.Recipients).Returns(stubDbSet.Object);
// Act
var repository = new Repository(stubContext.Object);
var recipient = repository.GetFirstUnsentAddress();
// Assert
Assert.IsNull(recipient);
}
示例3: VerifyFix
/// <summary>
/// <see cref="CodeFixProvider"/>によるコードの修正を検証します。
/// </summary>
/// <param name="oldSource">修正前のソースコード</param>
/// <param name="newSource">修正後のソースコード</param>
/// <param name="codeFixIndex">修正する箇所か複数ある場合に、それを特定するインデックス</param>
/// <param name="allowNewCompilerDiagnostics">修正後に他の警告がある場合、テストを失敗させる場合は<see langword="true"/></param>
protected void VerifyFix(string oldSource, string newSource, int? codeFixIndex = null, bool allowNewCompilerDiagnostics = false)
{
var analyzer = GetDiagnosticAnalyzer();
var codeFixProvider = GetCodeFixProvider();
var document = CreateProject(new[] { oldSource }).Documents.First();
var analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
var compilerDiagnostics = document.GetCompilerDiagnostics();
var attempts = analyzerDiagnostics.Length;
for (int i = 0; i < attempts; ++i)
{
var actions = new List<CodeAction>();
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
codeFixProvider.RegisterCodeFixesAsync(context).Wait();
if (!actions.Any())
{
break;
}
if (codeFixIndex != null)
{
document = document.ApplyFix(actions.ElementAt((int)codeFixIndex));
break;
}
document = document.ApplyFix(actions.ElementAt(0));
analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
var newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, document.GetCompilerDiagnostics());
//check if applying the code fix introduced any new compiler diagnostics
if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
{
// Format and get the compiler diagnostics again so that the locations make sense in the output
document = document.WithSyntaxRoot(Formatter.Format(document.GetSyntaxRootAsync().Result, Formatter.Annotation, document.Project.Solution.Workspace));
newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, document.GetCompilerDiagnostics());
Assert.IsTrue(false,
string.Format("Fix introduced new compiler diagnostics:\r\n{0}\r\n\r\nNew document:\r\n{1}\r\n",
string.Join("\r\n", newCompilerDiagnostics.Select(d => d.ToString())),
document.GetSyntaxRootAsync().Result.ToFullString()));
}
//check if there are analyzer diagnostics left after the code fix
if (!analyzerDiagnostics.Any())
{
break;
}
}
//after applying all of the code fixes, compare the resulting string to the inputted one
var actual = document.GetStringFromDocument();
Assert.AreEqual(newSource, actual);
}
示例4: CompareList
public void CompareList(List<Employee> result, List<Employee> expectedResult)
{
for (var i = 0; i < result.Count; i++)
{
Assert.AreEqual(result.ElementAt(i).LastName, expectedResult.ElementAt(i).LastName);
Assert.AreEqual(result.ElementAt(i).LastName, expectedResult.ElementAt(i).LastName);
Assert.AreEqual(result.ElementAt(i).Position, expectedResult.ElementAt(i).Position);
Assert.AreEqual(result.ElementAt(i).SeparationDate, expectedResult.ElementAt(i).SeparationDate);
}
}
示例5: TestLogEntries
private void TestLogEntries(List<LogEntry> expectedLogEntries, List<LogEntry> actualLogEntries)
{
Assert.AreEqual(expectedLogEntries.Count(), actualLogEntries.Count(), "Log counts not equal");
for (int i = 0; i < expectedLogEntries.Count(); i++)
{
Assert.AreEqual(expectedLogEntries.ElementAt(i).Message, actualLogEntries.ElementAt(i).Message);
Assert.AreEqual(expectedLogEntries.ElementAt(i).LoggerName, actualLogEntries.ElementAt(i).LoggerName);
Assert.AreEqual(expectedLogEntries.ElementAt(i).Level, actualLogEntries.ElementAt(i).Level);
}
}
示例6: WhenSerialingAnObjectWithAStringProperty_ThenItDeserializesItProperly
public void WhenSerialingAnObjectWithAStringProperty_ThenItDeserializesItProperly()
{
var foos = new List<Foo> { new Foo { Bar = 1, Baz = "Baz1" }, new Foo { Bar = 2, Baz = "Baz2" } };
var ser = BindingSerializer.Serialize(foos);
var dserFoos = BindingSerializer.Deserialize<List<Foo>>(ser);
Assert.Equal(dserFoos.Count, foos.Count);
Assert.Equal(dserFoos.ElementAt(0).Bar, foos.ElementAt(0).Bar);
Assert.Equal(dserFoos.ElementAt(0).Baz, foos.ElementAt(0).Baz);
Assert.Equal(dserFoos.ElementAt(1).Bar, foos.ElementAt(1).Bar);
Assert.Equal(dserFoos.ElementAt(1).Baz, foos.ElementAt(1).Baz);
}
示例7: hasSameNumberOfStations
public void hasSameNumberOfStations()
{
ciudades = new List<string>();
ciudades.Add(final[3]);
for (int i = 3; i < final.Length;i++)
{
bool exists = false;
if ((i + 8) < final.Length)
{
i = i + 7;
}
else
{
continue;
}
for (int j = 0; j < ciudades.Count(); j++)
{
if (final[i].Equals(ciudades.ElementAt(j)))
{
exists = true;
}
}
if (!exists)
{
ciudades.Add(final[i]);
}
i--;
}
Assert.AreEqual(13,ciudades.Count);
}
示例8: hasTheSameOrder
public void hasTheSameOrder()
{
String[] ciudadesAnt = { "AVILA", "ARENAS DE SAN PEDRO","BURGOS","MIRANDA DE EBRO","LEON","PONFERRADA","PALENCIA","SALAMANCA","SEGOVIA","SORIA","VALLADOLID","ZAMORA","BEJAR" };
List<string> oldCities = new List<string>(ciudadesAnt);
for(int i = 0 ; i < ciudades.Count; i++){
Assert.AreEqual(oldCities.ElementAt(i), ciudades.ElementAt(i));
}
}
示例9: CreateMethodTest
public void CreateMethodTest()
{
AssemblyDTO assembly = new AssemblyDTO() { Name = "Nosson.Core.UI.exe" };
var forms = new List<FormDTO>()
{
new FormDTO() { Name = "Nosson.Core.AssemblyForm", Assembly = assembly },
new FormDTO() { Name = "Nosson.Core.FormForm", Assembly = assembly },
new FormDTO() { Name = "Nosson.Core.ButtonForm", Assembly = assembly }
};
assembly.Forms = forms;
var buttons = new List<ButtonDTO>()
{
new ButtonDTO() { Name = "c1Button1", Text = "c1Button1", Form = forms.ElementAt(forms.Count - 1) },
new ButtonDTO() { Name = "c1Button2", Text = "c1Button2", Form = forms.ElementAt(forms.Count - 1) }
};
forms.ElementAt(forms.Count - 1).Buttons = buttons;
response = this.InvokeOperation(targetOperationId, "Create", new object[] { assembly });
}
示例10: AssertMappingsMatch
protected static void AssertMappingsMatch(List<IPropertyMapping> original, List<IPropertyMapping> cached)
{
Assert.AreEqual(original.Count, cached.Count);
for (int i = 0; i < original.Count; i++)
{
var o = original.ElementAt(i);
var c = cached.ElementAt(i);
Assert.AreEqual(o.GetType(), c.GetType());
Assert.AreEqual(o.TargetName, c.TargetName);
}
}
示例11: findMinDouble
public static Double findMinDouble(List<Double> doubleList)
{
Assert.IsNotNull(doubleList);
Assert.IsTrue(doubleList.Count > 0);
Double minDouble = doubleList.ElementAt(0);
foreach (var aDouble in doubleList.GetRange(1, doubleList.Count -1))
{
if (aDouble < minDouble) minDouble = aDouble;
}
return minDouble;
}
示例12: Can_convert_Entity_To_Mvc_Model
public void Can_convert_Entity_To_Mvc_Model()
{
// Arrange
IEnumerable<GuestBookEntry> entities = new List<GuestBookEntry>( new [] {
new GuestBookEntry{GuestName = "John", Comment = "Hi, my name is John."},
new GuestBookEntry{GuestName = "Lisa", Comment = "Hi, my name is Lisa."},
new GuestBookEntry{GuestName = "Felice", Comment = "Hi, my name is Felice."}
});
// Act
IEnumerable<GuestBookEntryModel> mvcModels = entities.ToMvcModels<GuestBookEntry, GuestBookEntryModel>();
// Assert
Assert.IsTrue(mvcModels.Any());
int index = 0;
foreach (GuestBookEntryModel guestBookEntryModel in mvcModels)
{
Assert.AreEqual(guestBookEntryModel.Name, entities.ElementAt(index).GuestName);
Assert.AreEqual(guestBookEntryModel.Comment, entities.ElementAt(index).Comment);
index++;
}
}
示例13: FibonacciTest
public void FibonacciTest()
{
IEnumerable<long> list = new List<long>() {
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
};
IEnumerable<long> output = Utils.Fibonacci();
for (int i = 0; i < list.Count(); i++)
{
Assert.AreEqual(list.ElementAt(i), output.ElementAt(i));
}
}
示例14: TestGetUsersForSiteReturnsLoginNamesOfAllDefinedUsers
public void TestGetUsersForSiteReturnsLoginNamesOfAllDefinedUsers()
{
// Arrange.
using (new SharePointEmulationScope())
{
ShimSPUser user1 = new ShimSPUser() {LoginNameGet = () => @"DOMAIN\user1"};
ShimSPUser user2 = new ShimSPUser() {LoginNameGet = () => @"EXTERNAL\some.user"};
ShimSPUser user3 = new ShimSPUser() {LoginNameGet = () => "[email protected]"};
ShimSPUser user4 = new ShimSPUser() {LoginNameGet = () => "mike.test"};
List<ShimSPUser> masterUsers = new List<ShimSPUser>() { user1, user2, user3, user4 };
ShimSPWeb web = new ShimSPWeb();
ShimSPUserCollection coll = new ShimSPUserCollection();
coll.CountGet = () => masterUsers.Count;
coll.GetByIDInt32 = (id) => masterUsers.ElementAt(id);
coll.ItemGetInt32 = (id) => masterUsers.ElementAt(id);
coll.ItemAtIndexInt32 = (id) => masterUsers.ElementAt(id);
web.UsersGet = () => coll;
ShimSPSite.ConstructorString = (instance, url) =>
{
ShimSPSite site = new ShimSPSite(instance);
site.Dispose = () => { };
site.OpenWeb = () => web;
};
WebSiteManager manager = new WebSiteManager("http://test");
// Act.
IEnumerable<string> users = manager.GetUsersForSite();
// Assert.
Assert.IsTrue(users.Contains(user1.Instance.LoginName));
Assert.IsTrue(users.Contains(user2.Instance.LoginName));
Assert.IsTrue(users.Contains(user3.Instance.LoginName));
Assert.IsTrue(users.Contains(user4.Instance.LoginName));
}
}
示例15: ShouldSolvePuzzle
public void ShouldSolvePuzzle()
{
//arrange
PuzzleName puzzle= new PuzzleName("ABDUL",1);
PuzzleName puzzleScore= new PuzzleName("AGNES", 43);
List<PuzzleName> puzzleNames = new List<PuzzleName> {puzzle, puzzleScore };
int position = 1;
PuzzleName puzzleName = puzzleNames.ElementAt(position);
//act
string puzzleAnswer = PuzzleSolver.Solve();
//assert
Assert.AreEqual(puzzleAnswer, puzzleName.Name + puzzleName.Score);
}