var note = await _dbContext.Notes
.Where(n => n.IntNoteId == ReferenceAsInteger)
.FirstOrDefaultAsync();
如何使用最小起订量设置使其工作?
模拟 _dbContext 并将其注入到您的被测软件中。使模拟返回注释列表,其中之一应该具有与您的参考匹配的
IntNoteId
。
var mock = new Mock<DbContext>();
// Create a list of Notes, one of which has the right reference
mock.SetupGet(m => m.Notes)
.Returns(Task.FromResult(myListOfNotes));
// initialize your software under test, injecting mock.Object
var result = await myClass.GetNote(referenceAsInteger);
// or whatever it is you want to do.