本文整理汇总了C#中Data.List.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# List.AsQueryable方法的具体用法?C# List.AsQueryable怎么用?C# List.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data.List
的用法示例。
在下文中一共展示了List.AsQueryable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static IRepository<Book> Create()
{
var listOfBooks = new List<Book>();
for (int i = 0; i < 20; i++)
{
listOfBooks.Add(new Book
{
Id = i,
Title = "Book " + i,
Description = "Description" + i,
Author = new Author
{
FirstName = "FirstName " + i,
LastName = "LastName " + i
}
});
}
var repository = new Mock<IRepository<Book>>();
repository.Setup(r => r.All()).Returns(listOfBooks.AsQueryable());
repository.Setup(r => r.Add(It.IsAny<Book>())).Callback<Book>(b =>
{
b.Id = 1;
});
repository.Setup(r => r.SaveChanges()).Verifiable();
return repository.Object;
}
示例2: DummyContractsRepository
internal static IRepository<Contract> DummyContractsRepository()
{
var repo = new Mock<IRepository<Contract>>();
var contracts = new List<Contract>();
for (int i = 0; i < NumberOfTestObjects; i++)
{
contracts.Add(new Contract
{
ClientId = (i % 2 == 0 ? i : 3).ToString(),
HitmanId = (i % 2 == 0 ? i : 3).ToString() + "hitman",
Deadline = DateTime.Now,
Status = ConnectionStatus.Pending,
Id = i
});
}
repo.Setup(r => r.GetById(It.Is<int>(x => x == 4))).Returns(() =>
{
return contracts.Where(c => c.Id == 4).FirstOrDefault();
});
repo.Setup(r => r.All()).Returns(() =>
{
return contracts.AsQueryable();
});
return repo.Object;
}
示例3: Create
public static IRepository<Author> Create()
{
var listOfAuthors = new List<Author>
{
new Author
{
UserName = "Valid"
}
};
var repository = new Mock<IRepository<Author>>();
repository.Setup(r => r.All()).Returns(listOfAuthors.AsQueryable());
return repository.Object;
}
示例4: DummyCountriesRepository
internal static IRepository<Country> DummyCountriesRepository()
{
var repo = new Mock<IRepository<Country>>();
repo.Setup(r => r.All()).Returns(() =>
{
var countries = new List<Country>();
for (int i = 0; i < NumberOfTestObjects; i++)
{
countries.Add(new Country
{
Id = i,
Name = "TestCountry" + i
});
}
return countries.AsQueryable();
});
return repo.Object;
}
示例5: DummyHitmenRepository
internal static IRepository<User> DummyHitmenRepository()
{
var repo = new Mock<IRepository<User>>();
var users = new List<User>();
for (int i = 0; i < NumberOfTestObjects; i++)
{
users.Add(new User
{
Id = i.ToString(),
RegistrationDate = DateTime.Now,
AboutMe = "Test About Me" + i,
DateOfBirth = DateTime.Now.AddYears(i),
Gender = true,
IsWorking = i % 2 == 0
});
}
repo.Setup(r => r.All()).Returns(() =>
{
return users.AsQueryable();
});
return repo.Object;
}
示例6: DummyUserRatingsRepository
internal static IRepository<UserRating> DummyUserRatingsRepository()
{
var repo = new Mock<IRepository<UserRating>>();
var ratings = new List<UserRating>();
for (int i = 0; i < NumberOfTestObjects; i++)
{
ratings.Add(new UserRating
{
Id = i,
ClientId = "TestId" + i,
HitmanId = "TestId" + (i % 2 == 0 ? i : 3),
Rating = i % 6
});
}
repo.Setup(r => r.All()).Returns(() =>
{
return ratings.AsQueryable();
});
repo.Setup(r => r.SaveChanges()).Returns(ratings.Last().Id);
repo.Setup(r => r.Add(It.IsAny<UserRating>())).Callback<UserRating>(ur =>
{
ur.Id = ratings.LastOrDefault().Id + 1;
ratings.Add(ur);
});
return repo.Object;
}
示例7: DummyImagesRepository
internal static IRepository<Image> DummyImagesRepository()
{
var repository = new Mock<IRepository<Image>>();
var images = new List<Image>();
for (int i = 0; i < NumberOfTestObjects; i++)
{
var user = DummyHitmenRepository()
.All()
.FirstOrDefault(u => u.Id == i.ToString());
images.Add(new Image()
{
Id = i,
Name = "Image #" + i,
Extension = ".png",
UserId = user.Id,
User = user
});
}
repository.Setup(r => r.All()).Returns(() =>
{
return images.AsQueryable();
});
repository
.Setup(r => r.Add(It.IsAny<Image>()))
.Callback<Image>(i =>
{
i.Id = images.LastOrDefault().Id + 1;
images.Add(i);
});
repository.Setup(r => r.SaveChanges()).Returns(images.Last().Id);
repository
.Setup(r => r.Delete(It.IsAny<Image>()))
.Callback<Image>(i =>
{
images.RemoveAt(i.Id);
});
return repository.Object;
}