本文整理汇总了C#中Moq.MockRepository.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.Setup方法的具体用法?C# MockRepository.Setup怎么用?C# MockRepository.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moq.MockRepository
的用法示例。
在下文中一共展示了MockRepository.Setup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected
public async Task All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected()
{
// Assort
var store = new List<ForwardTextCandidate>();
var repository = new MockRepository(MockBehavior.Default).Create<Repository<ForwardTextCandidate>>(new Mock<ISession>().Object);
repository.Setup(x => x.Get()).Returns(store.AsQueryable());
repository.Setup(x => x.Save(It.IsAny<IQueryable<ForwardTextCandidate>>())).Callback<IQueryable<ForwardTextCandidate>>(items => store.AddRange(items));
var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
.Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>, Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
((path, opc, rep, creator, locator, updater) =>
{
var itemsToAdd = new List<ForwardTextCandidate>();
InputTextItems.ToList().ForEach(x => itemsToAdd.Add(new ForwardTextCandidate { Text = x }));
rep.Save(itemsToAdd.AsQueryable());
})
.Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));
// Act
var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);
// Assert
Assert.IsTrue(result.Success);
Assert.AreEqual(InputTextItems.Length, store.Count());
var index = 0;
store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));
}
示例2: CreateFakeRepository
private static Mock<Repository<ForwardTextCandidate>> CreateFakeRepository(List<ForwardTextCandidate> store)
{
var repository = new MockRepository(MockBehavior.Default).Create<Repository<ForwardTextCandidate>>(new Mock<ISession>().Object);
repository.Setup(x => x.Get()).Returns(store.AsQueryable());
repository.Setup(x => x.Create(It.IsAny<ForwardTextCandidate>())).Callback<ForwardTextCandidate>(item => store.Add(item));
repository.Setup(x => x.Delete(It.IsAny<ForwardTextCandidate>())).Callback<ForwardTextCandidate>(item => store.Remove(item));
repository.Setup(x => x.Save(It.IsAny<ForwardTextCandidate>())).Callback<ForwardTextCandidate>(item =>
{
var rep = repository.Object;
rep.Create(new ForwardTextCandidate { Text = item.Text, CreatedOn = DateTime.Now, LastUsedOn = DateTime.Now });
});
return repository;
}