本文整理汇总了C#中Url.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Url.GetEnumerator方法的具体用法?C# Url.GetEnumerator怎么用?C# Url.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Url
的用法示例。
在下文中一共展示了Url.GetEnumerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_know_if_Url_Exist_or_Not
public void Should_know_if_Url_Exist_or_Not()
{
//Cheate an array of our Model class
var arr = new Url[]
{
new Url{ UrlId = 0, UrlCode = "TYUR", OriginalUrl="https://fluentvalidation.com", IpAddress="127.0.0.1", PostedDate = DateTime.Now},
new Url{ UrlId = 1, UrlCode = "TwUR", OriginalUrl="https://www.facebook.com", IpAddress="127.0.0.1", PostedDate = DateTime.Now},
new Url{ UrlId = 2, UrlCode = "TkUR", OriginalUrl="https://www.youtube.com/", IpAddress="127.0.0.1", PostedDate = DateTime.Now}
}.AsQueryable();
//mock and create the fake of our Url
var mockSet = new Mock<IDbSet<Url>>();
mockSet.As<IQueryable<Url>>().Setup(m => m.Provider).Returns(arr.Provider);
mockSet.As<IQueryable<Url>>().Setup(m => m.Expression).Returns(arr.Expression);
mockSet.As<IQueryable<Url>>().Setup(m => m.ElementType).Returns(arr.ElementType);
mockSet.As<IQueryable<Url>>().Setup(m => m.GetEnumerator()).Returns(arr.GetEnumerator());
var fakeContext = new Mock<EFDbContext>();
fakeContext.SetupGet(ctx => ctx.Urls).Returns(mockSet.Object);
var validator = new UrlValidation();
validator.context = (EFDbContext)fakeContext.Object;
//the url below exist in our record above, therefore notExist shall be false.
Assert.IsFalse(validator.notExist("https://www.youtube.com/"));
//the url below does not exist in our record above and hence notExist shall return true
Assert.IsTrue(validator.notExist("https://www.facebooker.com/"));
}