public async Task TestLinkTutorial_AllUsersAreProcessed() { // Setup var getUsersMock = new Mock <Func <int, Task <User[]> > >(); getUsersMock.Setup(x => x(It.IsAny <int>())).Returns <int>((x) => GetUsersTask(x)); var writeUsersMock = new Mock <Func <User, Task> >(); writeUsersMock.Setup(x => x(It.IsAny <User>())).Returns <User>((x) => WriteUser(x)); // Call await LinkTutorial.RunSampleOne(getUsersMock.Object, writeUsersMock.Object, _pageCount); // Validate "get data" called per page getUsersMock.Verify(x => x(It.IsAny <int>()), Times.Exactly(_pageCount)); // Validate "write data" called per user writeUsersMock.Verify(x => x(It.IsAny <User>()), Times.Exactly(_usersPerPage * _pageCount)); }
public async Task TestLinkTutorial_WriteOnlyCalledOneAtATime() { // Setup var getUsersMock = new Mock <Func <int, Task <User[]> > >(); getUsersMock.Setup(x => x(It.IsAny <int>())).Returns <int>((x) => GetUsersTask(x)); var currentWriteCount = 0; var writeUsersMock = new Mock <Func <User, Task> >(); writeUsersMock .Setup(x => x(It.IsAny <User>())) .Returns <User>(async(x) => { Assert.AreEqual(0, currentWriteCount); Interlocked.Increment(ref currentWriteCount); await WriteUser(x); Interlocked.Decrement(ref currentWriteCount); }); // Call await LinkTutorial.RunSampleOne(getUsersMock.Object, writeUsersMock.Object, _pageCount); }