本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# List.OrderBy方法的具体用法?C# List.OrderBy怎么用?C# List.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyAddRemoveCollectionEvents
/// <summary>
/// Verifies that the expected collection events are raised from the <see cref="ValidationResultCollection"/>
/// for validation results with the specified member names.
/// </summary>
/// <param name="validationResultMemberNames">
/// The array of member names to create validation results for that will be
/// added and removed from the collection.
/// </param>
/// <param name="errorsChangedMemberNames">The array of member names to expect errors changed events for.</param>
private static void VerifyAddRemoveCollectionEvents(string[] validationResultMemberNames, string[] errorsChangedMemberNames)
{
int collectionChangedCount = 0;
int hasErrorsChangedCount = 0;
List<string> propertyErrorsChangedList = new List<string>();
Action collectionChanged = () => ++collectionChangedCount;
Action hasErrorsChanged = () => ++hasErrorsChangedCount;
Action<string> propertyErrorsChanged = propertyName => propertyErrorsChangedList.Add(propertyName);
ValidationResultCollection collection = new TestValidationResultCollection(collectionChanged, hasErrorsChanged, propertyErrorsChanged);
ValidationResult vr1 = new ValidationResult("Error 1", validationResultMemberNames);
collection.Add(vr1);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for first add");
Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for first add");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for first add");
collectionChangedCount = 0;
hasErrorsChangedCount = 0;
propertyErrorsChangedList.Clear();
ValidationResult vr2 = new ValidationResult("Error 2", validationResultMemberNames);
collection.Add(vr2);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for second add");
Assert.AreEqual<int>(0, hasErrorsChangedCount, "HasErrorsChanged count for second add");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for second add");
collectionChangedCount = 0;
hasErrorsChangedCount = 0;
propertyErrorsChangedList.Clear();
collection.Remove(vr1);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for first remove");
Assert.AreEqual<int>(0, hasErrorsChangedCount, "HasErrorsChanged count for first remove");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for first remove");
collectionChangedCount = 0;
hasErrorsChangedCount = 0;
propertyErrorsChangedList.Clear();
collection.Remove(vr2);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for second remove");
Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for second remove");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for second remove");
}
示例2: TestBinarySearch
public void TestBinarySearch()
{
List<string> animalsUnordered = new List<string>(
new[] { "Cat", "Dog", "Elephant", "Eagle", "Eel", "Zebra", "Yak", "Monkey", "Meerkat" });
WordList words;
while (animalsUnordered.Count > 0)
{
words = new WordList(animalsUnordered);
Assert.AreEqual(-1, words.BinarySearch("Unicorn", false, false), "Wrong index for: Unicorn");
string[] animalsOrdered = animalsUnordered.OrderBy(a => a).ToArray();
Assert.AreEqual(-1, words.BinarySearch("Dragon", false, false), "Wrong index for: Dragon");
for (int expectedIndex = 0; expectedIndex < animalsOrdered.Length; expectedIndex++)
{
string word = animalsOrdered[expectedIndex];
Assert.AreEqual(expectedIndex, words.BinarySearch(word, false, false), "Wrong index for: " + word);
}
animalsUnordered.RemoveAt(0);
}
words = new WordList(new[] { "Heaven", "Hell", "Hello", "Zebra", "ZOO" });
Assert.AreEqual(0, words.BinarySearch("H", false, true), "Wrong index for: H");
Assert.AreEqual(1, words.BinarySearch("HELL", false, true), "Wrong index for: H");
Assert.AreEqual(3, words.BinarySearch("M", true, false), "Wrong index for: M");
Assert.AreEqual(-1, words.BinarySearch("M", false, false), "Wrong index for: M");
}
示例3: PartitionEvenlyWorks
public void PartitionEvenlyWorks()
{
var list = new List<int> {
1,
2,
3,
4,
5,
6,
7,
8,
13,
14,
15
};
var partitions = list.PartitionEvenly(i => i * 2, 3).ToList();
Assert.AreEqual(3, partitions.Count);
// Partition size are well-defined if the # of elements is not exactly a factor of the partition count.
Assert.AreEqual(4, partitions[0].Count);
Assert.AreEqual(4, partitions[1].Count);
Assert.AreEqual(3, partitions[2].Count);
// We don't care about what particular elements are inside the partitions,
// but we do care that they are all the same weight
Assert.AreEqual(26, partitions[0].Aggregate((x, y) => x + y));
Assert.AreEqual(26, partitions[1].Aggregate((x, y) => x + y));
Assert.AreEqual(26, partitions[2].Aggregate((x, y) => x + y));
// All the elements of the initial list must be present in the union of the partitions.
Assert.IsTrue(list.OrderBy(x => x).SequenceEqual(partitions.SelectMany(x => x).OrderBy(x => x)));
}
示例4: PrintSchedule
private static void PrintSchedule(List<Employee> employees, List<Duty> duties)
{
var maxNameLength = employees.Max(x => x.Name.Length);
duties = duties.OrderBy(x => x.Timeslot).ToList();
Debug.Write(new string(' ', maxNameLength + Padding));
Debug.Write(String.Join(" ", duties.Select(x => x.Timeslot)));
Debug.WriteLine("");
foreach (var employee in employees)
{
Debug.Write(employee.Name.PadRight(maxNameLength + Padding));
foreach (var duty in duties)
{
if (duty.Employee.Equals(employee))
{
Debug.Write("X");
}
else
{
Debug.Write(" ");
}
Debug.Write(" ");
}
Debug.Write(" ");
PrintStatistics(employee, duties.Where(x => Equals(x.Employee, employee)).ToList());
Debug.WriteLine("");
}
}
示例5: GetExecutionPlan_WhereTaskHasDependencyNotSpecifiedForHost_AddsDependencyToPlan
public void GetExecutionPlan_WhereTaskHasDependencyNotSpecifiedForHost_AddsDependencyToPlan()
{
// Arrange
var taskblock = typeof(InheritDependencies);
var host = new Host
{
Hostname = SomeHostname
};
var config = new DeploymentConfig
{
Hosts = new[]
{
host
}
};
var expected = new List<ExecutionPlan>
{
new ExecutionPlan(host, taskblock.GetObjMethods("Task1", "Task2"))
};
// Act
var manager = new DeploymentManager<InheritDependencies>(config);
var actual = manager.GetExecutionPlans();
// Assert
CollectionAssert.AreEqual(
expected.OrderBy(p => p.Host.Hostname).ToList(),
actual.OrderBy(p => p.Host.Hostname).ToList());
}
示例6: FindByTitleAndPriceRange_AddMultipleProducts_ShouldReturnCorrectOnes
public void FindByTitleAndPriceRange_AddMultipleProducts_ShouldReturnCorrectOnes()
{
var products = new ProductsCollection();
var expectedProducts = new List<Product>();
decimal price = 1.0m;
for (int i = 99; i >= 0; i--)
{
string title = string.Empty;
if (i % 5 == 0 && price <= 15)
{
title = "magnit";
var product = new Product(i, title, "Bai Tosho" + i, price);
expectedProducts.Add(product);
products.Add(i, title, "Bai Tosho" + i, price);
price++;
}
else
{
title = "magnit" + i;
products.Add(i, title, "Bai Tosho" + i, 0.5m);
}
}
expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList();
var actualProducts = products
.FindProductsTitleAndPriceRange("magnit", 1.0m, 15.0m)
.ToList();
CollectionAssert.AreEqual(expectedProducts, actualProducts);
}
示例7: GetDiagnostics
protected Diagnostic[] GetDiagnostics(IEnumerable<string> sourceCodes)
{
DiagnosticAnalyzer analyzer = GetDiagnosticAnalyzer();
Project project = CreateProject(sourceCodes);
CompilationWithAnalyzers compilationWithAnalyzers = project.GetCompilationAsync().Result
.WithAnalyzers(ImmutableArray.Create(analyzer));
ImmutableArray<Diagnostic> analyzerDiagnostics = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
List<Diagnostic> diagnostics = new List<Diagnostic>(analyzerDiagnostics.Length);
foreach (Diagnostic diagnostic in analyzerDiagnostics)
{
if (diagnostic.Location == Location.None || diagnostic.Location.IsInMetadata)
diagnostics.Add(diagnostic);
else
{
SyntaxTree tree;
foreach (Document doc in project.Documents)
{
tree = doc.GetSyntaxTreeAsync().Result;
if (tree == diagnostic.Location.SourceTree)
diagnostics.Add(diagnostic);
}
}
}
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
}
示例8: SortDependenciesTest
public void SortDependenciesTest()
{
// Columns indicate direct dependencies
// 0 1 2 3 4
//0 • •
//1 • • • •
//2 • •
//3 • •
//4 •
var schemas = new List<TableSchema>();
schemas.Add(new TableSchema("0"));
schemas.Add(new TableSchema("1"));
schemas.Add(new TableSchema("2"));
schemas.Add(new TableSchema("3"));
schemas.Add(new TableSchema("4"));
schemas[4].Columns.AddForeignKey("4 -> 3", schemas[3], "4 -> 3");
schemas[4].Columns.AddForeignKey("4 -> 1", schemas[1], "4 -> 1");
schemas[3].Columns.AddForeignKey("3 -> 2", schemas[2], "3 -> 2");
schemas[2].Columns.AddForeignKey("2 -> 1", schemas[1], "2 -> 1");
schemas[3].Columns.AddForeignKey("3 -> 1", schemas[1], "3 -> 1");
schemas[1].Columns.AddForeignKey("1 -> 0", schemas[0], "1 -> 0");
var rand = new Random();
for (int i = 0; i < 10; i++) //Test different orderings
Assert.IsTrue(schemas.OrderBy(j => rand.Next()).SortDependencies().ToArray().SequenceEqual(schemas));
}
示例9: GetEnumerator_IfItemsToRemovePresentAtStart_ThenTheyAreNeverYielded
public void GetEnumerator_IfItemsToRemovePresentAtStart_ThenTheyAreNeverYielded()
{
using (var cts = new CancellationTokenSource())
{
var input = new string[] { "a", "bad one", "b" };
var results = new List<string>(new ReadyItemCollection<string>(input, cts.Token, item => { if (item == "bad one") return null; else return true; }, item => DateTime.UtcNow.AddMilliseconds(10)));
Assert.IsTrue(results.OrderBy(i => i).SequenceEqual(new string[] { "a", "b" }));
}
}
示例10: what_is_comparer
public void what_is_comparer()
{
var now = DateTime.Now;
var v1 = new DataHolder(now);
var v2 = new DataHolder(now);
var list = new List<DataHolder>() { v1, v2 };
list.OrderBy(x => x);
//var comparer = Comparer<DataHolder>.Default;
//Assert.IsFalse(comparer.Compare(v1, v2) == 0);
}
示例11: GetFakeHistory
private static IEnumerable<Event> GetFakeHistory(int nrOfVisitors)
{
var history = new List<Event>();
for (var i = 0; i < nrOfVisitors; i++)
{
history.AddRange(GetVisitorEvents(Guid.NewGuid()));
}
return history.OrderBy(e => e.Version);
}
示例12: TestSorting
public void TestSorting()
{
var doc1 = new TestDocument();
var doc2 = new TestDocument();
var docList = new List<TestDocument>() { doc1, doc2 };
var sorting = docList[0].OrderBy();
var result = docList.OrderBy(sorting).ToList();
Assert.IsTrue(result[0] == doc1);
}
示例13: GetEnumerator_IfAvailableItemsExistAtStart_ThenTheyAreAllYieldedQuickly
public void GetEnumerator_IfAvailableItemsExistAtStart_ThenTheyAreAllYieldedQuickly()
{
using (var cts = new CancellationTokenSource())
{
var input = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
var sw = new Stopwatch();
sw.Start();
var results = new List<string>(new ReadyItemCollection<string>(input, cts.Token, item => true, item => DateTime.UtcNow.AddMinutes(1)));
sw.Stop();
Assert.IsTrue(results.OrderBy(f => f).SequenceEqual(input));
Assert.IsTrue(sw.ElapsedMilliseconds < 1000, String.Format("That took too long ({0} milliseconds)!", sw.ElapsedMilliseconds));
}
}
示例14: RegroupWorkersTestHelper
private static void RegroupWorkersTestHelper(List<int> faultDomains, List<int> expectedBuddyGroups)
{
ServerRole_Accessor target = new ServerRole_Accessor();
IEnumerable<Worker> workers = faultDomains.Select(fd => new Worker(Guid.NewGuid().ToString(), null, fd));
int currentBuddyGroup = 1;
List<string> actualBuddyGroups = target.RegroupWorkers(workers, () => currentBuddyGroup++.ToString())
.Select(worker => worker.BuddyGroupID).OrderBy(bg => bg).ToList();
CollectionAssert.AreEqual(
expectedBuddyGroups.OrderBy(bg => bg).Select(buddyGroup => buddyGroup.ToString()).ToList(),
actualBuddyGroups);
}
示例15: GivenFilterLimitsResults_WhenBind_ThenResultTotalDisplayRecordsMatchesFilteredCount
public void GivenFilterLimitsResults_WhenBind_ThenResultTotalDisplayRecordsMatchesFilteredCount()
{
IQueryable<Program> originalItems = new List<Program> { new Program(), new Program(), new Program() }.AsQueryable();
IQueryable<Program> filteredItems = new List<Program> { new Program() }.AsQueryable();
IQueryable<Program> sortedItems = filteredItems.OrderBy(p => p);
DataTable.Expect(m => m.ApplyFilters(originalItems)).Return(filteredItems);
DataTable.Expect(m => m.ApplySort(filteredItems)).Return(sortedItems);
DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Cast<object>().ToList());
DataTableResultModel actual = Target.Bind<Program>(originalItems, DataTable, RequestModel);
Assert.AreEqual(filteredItems.Count(), actual.iTotalDisplayRecords);
}