public async Task RetrieveValue_SynchronousSuccess_Adds42() { var service = new Mock <IMyService>(); service.Setup(x => x.GetAsync()).Returns(() => Task.FromResult(5)); // Or: service.Setup(x => x.GetAsync()).ReturnsAsync(5); var system = new SystemUnderTest2(service.Object); var result = await system.RetrieveValueAsync(); Assert.AreEqual(47, result); }
public async Task RetrieveValue_AsynchronousSuccess_Adds42() { var service = new Mock <IMyService>(); service.Setup(x => x.GetAsync()).Returns(async() => { await Task.Yield(); return(5); }); var system = new SystemUnderTest2(service.Object); var result = await system.RetrieveValueAsync(); Assert.AreEqual(47, result); }