Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    public async Task RetrieveValue_AsynchronousFailure_Throws()
    {
        var service = new Mock <IMyService>();

        service.Setup(x => x.GetAsync()).Returns(async() =>
        {
            await Task.Yield();
            throw new Exception();
        });
        var system = new SystemUnderTest2(service.Object);
        await AssertEx.ThrowsAsync <Exception>(system.RetrieveValueAsync);
    }
Exemplo n.º 3
0
    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);
    }