本文整理汇总了C#中System.Collections.Generic.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.OrderBy方法的具体用法?C# System.Collections.Generic.OrderBy怎么用?C# System.Collections.Generic.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MaximumPageNumberIs8_ShouldGenerateCorrectHtml
public void MaximumPageNumberIs8_ShouldGenerateCorrectHtml()
{
_testList.PageSize = 5;
IHtmlString html = _ajaxHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").SetMaximumPageNumber(8)).AjaxOptions(a=>a.SetUpdateTargetId("test"));
string htmlStr = html.ToHtmlString();
const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
var sb = new StringBuilder(TestHelper.CopyrightText);
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#test\"","data-pagecount=\"8\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"","data-urlformat=\"" + BaseLink + "/__id__\""
};
sb.Append("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
sb.Append("FirstPrev1");
for (int i = 2; i <= 8; i++)
{
sb.AppendFormat(linkFormat, i, i);
}
sb.AppendFormat(linkFormat, 2, "Next");
sb.AppendFormat(linkFormat, 8, "Last");
sb.Append("</div>");
sb.Append(TestHelper.CopyrightText);
Assert.AreEqual(htmlStr, sb.ToString());
}
示例2: In_memory_DbSet_can_be_used_for_AddRange
public void In_memory_DbSet_can_be_used_for_AddRange()
{
var set = new InMemoryNonGenericDbSet<Product>();
var products = new[] { new Product { Id = 1 }, new Product { Id = 2 } };
Assert.Same(products, set.AddRange(products));
Assert.Equal(products.OrderBy(p => p.Id), set.ToList<Product>().OrderBy(p => p.Id));
}
示例3: Index
/// <summary>
/// The index.
/// </summary>
/// <returns>
/// The <see cref="ActionResult"/>.
/// </returns>
public ActionResult Index()
{
var data = new Dictionary<string, object>();
var transformationLinks = new[] { Link.Start, Link.End, Link.CycleStart, Link.CycleEnd };
transformationLinks = transformationLinks.OrderBy(n => (int)n).ToArray();
data.Add("transformationLinks", transformationLinks.ToSelectList());
var operations = new List<SelectListItem> { new SelectListItem { Text = "Dissimilar", Value = 1.ToString() }, new SelectListItem { Text = "Higher order", Value = 2.ToString() } };
data.Add("operations", operations);
ViewBag.data = JsonConvert.SerializeObject(data);
return View();
}
开发者ID:intervals-mining-lab,项目名称:libiada-web,代码行数:20,代码来源:CustomSequenceOrderTransformerController.cs
示例4: ShouldDetectAStraight
public void ShouldDetectAStraight()
{
var cards = new[] {
2.Of(Suit.Spades),
3.Of(Suit.Hearts),
4.Of(Suit.Spades),
5.Of(Suit.Spades),
6.Of(Suit.Clubs),
Picture.Ace.Of(Suit.Hearts),
Picture.King.Of(Suit.Clubs)
};
IEnumerable<Card> result = new Straight().Match(cards);
Assert.That( result, Is.EquivalentTo(cards.OrderBy( x=> x.Rank).Take(5)), "Should have matched the consecutive cards.");
}
示例5: AlwaysShowFirstLastPageNumberWithCurrentPageIndexIs12_ShouldGenerateCorrectHtml
public void AlwaysShowFirstLastPageNumberWithCurrentPageIndexIs12_ShouldGenerateCorrectHtml()
{
_testList.PageSize = 2;
_testList.CurrentPageIndex = 12;
IHtmlString html = _ajaxHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").AlwaysShowFirstLastPageNumber()).AjaxOptions(a=>a.SetUpdateTargetId("test"));
string htmlStr = html.ToHtmlString();
const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
var sb = new StringBuilder(TestHelper.CopyrightText);
var attrs = new[]
{
"data-currentpage=\"12\"","data-firstpage=\"" + BaseLink + "\"",
"data-ajax=\"true\"", "data-ajax-update=\"#test\"","data-pagecount=\"44\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"","data-urlformat=\"" + BaseLink + "/__id__\""
};
sb.Append("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
sb.Append("<a data-pageindex=\"1\" href=\"").Append(BaseLink).Append("\">First</a>");
sb.AppendFormat(linkFormat, 11, "Prev");
sb.Append("<a data-pageindex=\"1\" href=\"").Append(BaseLink).Append("\">1</a>");
sb.AppendFormat(linkFormat, 6, "...");
for (int i = 7; i <= 16; i++)
{
if (i == 12)
sb.Append(i);
else
{
sb.AppendFormat(linkFormat, i, i);
}
}
sb.AppendFormat(linkFormat, 17, "...");
sb.AppendFormat(linkFormat, 44, "44");
sb.AppendFormat(linkFormat, 13, "Next");
sb.AppendFormat(linkFormat, 44, "Last");
sb.Append("</div>");
sb.Append(TestHelper.CopyrightText);
Assert.AreEqual(htmlStr, sb.ToString());
}
示例6: CurrentPageNumberFormatString_PagerItemTemplate_ShouldGenerateCorrectHtml
public void CurrentPageNumberFormatString_PagerItemTemplate_ShouldGenerateCorrectHtml()
{
_testList.CurrentPageIndex = 6;
const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
IHtmlString html = _ajaxHelper.Pager(_testList,
new PagerOptions
{
PageIndexParameterName = "id",
CurrentPagerItemTemplate =
"<span class=\"current\">{0}</span>",
CurrentPageNumberFormatString = "-{0}-"
}, new MvcAjaxOptions { UpdateTargetId = "uptarget" });
var sb = new StringBuilder(TestHelper.CopyrightText);
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"","data-currentpage=\"6\"","data-firstpage=\"" + BaseLink + "\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
"data-urlformat=\"" + BaseLink + "/__id__\""
};
sb.Append("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
sb.AppendFormat("<a data-pageindex=\"1\" href=\"{0}\">First</a>", BaseLink);
sb.AppendFormat(linkFormat, 5, "Prev");
sb.AppendFormat("<a data-pageindex=\"1\" href=\"{0}\">1</a>", BaseLink);
for (int i = 2; i <= 10; i++)
{
if (i == 6)
sb.Append("<span class=\"current\">-6-</span>");
else
sb.AppendFormat(linkFormat, i, i);
}
sb.AppendFormat(linkFormat, 11, "...");
sb.AppendFormat(linkFormat, 7, "Next");
sb.AppendFormat(linkFormat, 11, "Last");
sb.Append("</div>").Append(TestHelper.CopyrightText);
Assert.AreEqual(html.ToHtmlString(), sb.ToString());
}
示例7: MvcAjaxOptions_DisallowCache_ShouldGenerateCorrectAttributes
public void MvcAjaxOptions_DisallowCache_ShouldGenerateCorrectAttributes()
{
_testList.CurrentPageIndex = 3;
IHtmlString html = _ajaxHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id" }, new MvcAjaxOptions { UpdateTargetId = "uptarget", AllowCache = false });
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"","data-currentpage=\"3\"","data-firstpage=\""+BaseLink+"\"",
"data-ajax-allowcache=\"false\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
"data-urlformat=\"" + BaseLink + "/__id__\""
};
var sb=new StringBuilder("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
StringAssert.Contains(html.ToHtmlString(), sb.ToString());}
示例8: Should_ReturnCourseAuthors
public void Should_ReturnCourseAuthors()
{
// Arrange
var coAuthors = new[] { "Eric Burke", "Steve Evans", "Rob Windsor" }
.Select(x => new PluralsightAuthor { FullName = x }).ToList();
var author = new PluralsightAuthor { FullName = "John Smith", UrlName = "john-smith"};
var coAuthorNode = Mock.Of<INode>();
var authorNode = Mock.Of<INode>();
var course = new PluralsightCourse();
var fullnamesakesAuthorsContainer = new Dictionary<IAuthorFullNameNaturalKey, PluralsightAuthor>(
FullNameNaturalKeyEqualityComparer<IAuthorFullNameNaturalKey>.Instance);
fullnamesakesAuthorsContainer.Add(coAuthors[1], coAuthors[1]);
var allAuthorsExceptFullnamesakesContainer = new Dictionary<IAuthorFullNameNaturalKey, PluralsightAuthor>(
FullNameNaturalKeyEqualityComparer<IAuthorFullNameNaturalKey>.Instance);
allAuthorsExceptFullnamesakesContainer.Add(coAuthors[0], coAuthors[0]);
allAuthorsExceptFullnamesakesContainer.Add(coAuthors[2], coAuthors[2]);
allAuthorsExceptFullnamesakesContainer.Add(author, author);
var allAuthorsExceptWhoseUrlNullContainer = new Dictionary<IAuthorUrlNameNaturalKey, PluralsightAuthor>(
UrlNameNaturalKeyEqualityComparer<IAuthorUrlNameNaturalKey>.Instance);
allAuthorsExceptWhoseUrlNullContainer.Add(author, author);
var authorsParseResult = new PluralsightCatalogParser.AuthorsParseResult
{
FullnamesakesAuthorsContainer = fullnamesakesAuthorsContainer,
AllAuthorsByFullNameExceptFullnamesakesContainer = allAuthorsExceptFullnamesakesContainer,
AllAuthorsExceptWhoseUrlNullContainer = allAuthorsExceptWhoseUrlNullContainer
};
var nodeSelector = Mock.Of<INodeSelector>();
var nodeParser = Mock.Of<INodeParser>(x =>
x.IsCoAuthorNode(coAuthorNode) == true &&
x.ParseCoAuthors(coAuthorNode) == coAuthors &&
x.IsCoAuthorNode(authorNode) == false &&
x.ParseAuthor(authorNode) == author);
var sut = new PluralsightCatalogParser(nodeSelector, nodeParser);
// Act
var result = sut.GetCourseAuthors(new[] { authorNode, coAuthorNode }, course, authorsParseResult);
// Assert
Assert.NotNull(result);
Assert.Equal(4, result.Count);
foreach (var courseAuthor in result)
{
Assert.Same(course, courseAuthor.Course);
}
Assert.Equal(coAuthors.OrderBy(x => x.FullName),
result.Where(x => x.IsAuthorCoAuthor).Select(x => x.Author).OrderBy(x => x.FullName),
ReferenceEqualityComparer.Instance);
Assert.Same(author, result.Single(x => x.IsAuthorCoAuthor == false).Author);
Assert.Same(coAuthors[1], result.Single(x => x.HasFullnamesake).Author);
}
示例9: should_get_ordered_sequence
public void should_get_ordered_sequence()
{
var sequence = new[] {4, 2, 1, 3, 5};
IOrderedEnumerable<int> orderedResult = sequence.OrderBy(item => item);
// please update variable value to fix the test.
IEnumerable<int> expectedOrderedResult = new[] {4, 2, 1, 3, 5};
Assert.Equal(expectedOrderedResult, orderedResult);
}
示例10: SetAjaxEvents_ShouldGenerateCorrectHtml
public void SetAjaxEvents_ShouldGenerateCorrectHtml()
{
_testList.CurrentPageIndex = 1;
const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
IHtmlString html = _ajaxHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id")).AjaxOptions(a=>a.SetUpdateTargetId("uptarget").SetOnBegin("function(data){alert(data);}").SetOnComplete("alert(\"complete\")").SetOnFailure("failureHandler").SetOnSuccess("showSuccessMsg"));
var sb = new StringBuilder(TestHelper.CopyrightText);
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"",
"data-ajax-begin=\"" + HttpUtility.HtmlEncode("function(data){alert(data);}") + "\"",
"data-ajax-complete=\"" + HttpUtility.HtmlEncode("alert(\"complete\")") + "\"",
"data-ajax-failure=\"failureHandler\"","data-ajax-success=\"showSuccessMsg\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
"data-urlformat=\"" + BaseLink + "/__id__\""
};
sb.Append("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
sb.Append("First").Append("Prev").Append("1");
for (int i = 2; i <= 10; i++)
{
sb.AppendFormat(linkFormat, i, i);
}
sb.AppendFormat(linkFormat, 11, "...");
sb.AppendFormat(linkFormat, 2, "Next");
sb.AppendFormat(linkFormat, 11, "Last");
sb.Append("</div>").Append(TestHelper.CopyrightText);
Assert.AreEqual(html.ToHtmlString(), sb.ToString());
}
示例11: NavigationPagerItemsPositionIsRight_ShouldGenerateCorrectHtml
public void NavigationPagerItemsPositionIsRight_ShouldGenerateCorrectHtml()
{
_testList.CurrentPageIndex = 1;
const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
IHtmlString html = _ajaxHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id", NavigationPagerItemsPosition = PagerItemsPosition.Right }, new MvcAjaxOptions { UpdateTargetId = "uptarget" });
var sb = new StringBuilder(TestHelper.CopyrightText);
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
"data-urlformat=\"" + BaseLink + "/__id__\""
};
sb.Append("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
sb.Append("1");
for (int i = 2; i <= 10; i++)
{
sb.AppendFormat(linkFormat, i, i);
}
sb.AppendFormat(linkFormat, 11, "...").Append("First").Append("Prev");
sb.AppendFormat(linkFormat, 2, "Next");
sb.AppendFormat(linkFormat, 11, "Last");
sb.Append("</div>").Append(TestHelper.CopyrightText);
Assert.AreEqual(html.ToHtmlString(), sb.ToString());
}
示例12: CurrentPageIndexIsLargerThanTotalPageCount_ShouldGenerateCorrectHtml
public void CurrentPageIndexIsLargerThanTotalPageCount_ShouldGenerateCorrectHtml()
{
_testList.CurrentPageIndex = 88;
IHtmlString html = _ajaxHelper.Pager(_testList).AjaxOptions(a=>a.SetUpdateTargetId("uptarget"));
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"","style=\"color:red;font-weight:bold\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pagerid=\"Webdiyer.MvcPager\""
};
var sb=new StringBuilder("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">").Append(TestHelper.PageIndexOutOfRangeErrorMessage).Append("</div>");
Assert.AreEqual(html.ToHtmlString(), TestHelper.CopyrightText + sb + TestHelper.CopyrightText);
}
示例13: MaximumPageIndexItemsIs6_ShouldGenerateCorrectHtml
public void MaximumPageIndexItemsIs6_ShouldGenerateCorrectHtml()
{
_testList.PageSize = 5;
IHtmlString html = _ajaxHelper.Pager(_testList).Options(o => o.SetPageIndexParameterName("id").SetPageIndexBoxId("pib").SetMaximumPageIndexItems(6)).AjaxOptions(a=>a.SetUpdateTargetId("test"));
string htmlStr = html.ToHtmlString();
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#test\"","data-maxitems=\"6\"","data-pageindexbox=\"#pib\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"","data-pagecount=\"18\"","data-urlformat=\"" + BaseLink + "/__id__\""
};
var sb=new StringBuilder("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
StringAssert.Contains(htmlStr, sb.ToString());
}
示例14: NumericPagerItemTemplate_ShouldOverridePagerItemTemplate
public void NumericPagerItemTemplate_ShouldOverridePagerItemTemplate()
{
const string linkFormat = "<span><a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a></span>";
const string numericLinkFormat = "<span class=\"number\"><a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a></span>";
IHtmlString html = _ajaxHelper.Pager(_testList,
new PagerOptions
{
ContainerTagName = "ul",
PageIndexParameterName = "id",
PagerItemTemplate = "<span>{0}</span>",
NumericPagerItemTemplate = "<span class=\"number\">{0}</span>"
}, new MvcAjaxOptions { UpdateTargetId = "uptarget" });
var sb = new StringBuilder(TestHelper.CopyrightText);
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
"data-urlformat=\"" + BaseLink + "/__id__\""
};
sb.Append("<ul");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append(">");
//sb.Append("<ul data-ajax=\"true\" data-ajax-update=\"#uptarget\" data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\" data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\" data-pageparameter=\"id\" data-pagerid=\"Webdiyer.MvcPager\" data-pagecount=\"11\" data-urlformat=\"").Append(BaseLink).Append("/__id__\">");
sb.Append("<span>First</span>")
.Append("<span>Prev</span>")
.Append("<span>1</span>");
for (int i = 2; i <= 10; i++)
{
sb.AppendFormat(numericLinkFormat, i, i);
}
sb.AppendFormat(linkFormat, 11, "...");
sb.AppendFormat(linkFormat, 2, "Next");
sb.AppendFormat(linkFormat, 11, "Last");
sb.Append("</ul>").Append(TestHelper.CopyrightText);
Assert.AreEqual(html.ToHtmlString(), sb.ToString());
}
示例15: HidePagerItemsAndCurrentPageIndexIs6_ShouldGenerateCorrectHtml
public void HidePagerItemsAndCurrentPageIndexIs6_ShouldGenerateCorrectHtml()
{
_testList.CurrentPageIndex = 6;
IHtmlString html = _ajaxHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id", HidePagerItems = true }, new MvcAjaxOptions { UpdateTargetId = "uptarget" });
var attrs = new[]
{
"data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"","data-currentpage=\"6\"","data-firstpage=\"" + BaseLink + "\"",
"data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
"data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
"data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
"data-urlformat=\"" + BaseLink + "/__id__\"","style=\"display:none\""
};
var sb = new StringBuilder("<div");
foreach (var att in attrs.OrderBy(a => a))
{
sb.Append(" ").Append(att);
}
sb.Append("></div>");
Assert.AreEqual(html.ToHtmlString(), TestHelper.CopyrightText + sb + TestHelper.CopyrightText);
}