public async Task TestThatMethodStubCanBeOverwritten_Async() { var stub = new StubIPhoneBook(). GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(12345678)); stub.GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(11122233), overwrite: true); IPhoneBook phoneBook = stub; Assert.AreEqual(11122233, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); }
public async Task TestMethod_WithReturnType_WithParameters_Async() { long number = 6041234567; string firstName = null; string lastName = null; var stub = new StubIPhoneBook(); stub.GetContactPhoneNumberAsync(async(fn, ln) => { firstName = fn; lastName = ln; return(await Task.FromResult(number)); }); IPhoneBook phoneBook = stub; long actualNumber = await phoneBook.GetContactPhoneNumberAsync("John", "Smith"); Assert.AreEqual(number, actualNumber); Assert.AreEqual("John", firstName); Assert.AreEqual("Smith", lastName); }