public async Task UpdateScore_When_Payload_Is_Null_Then_Throw_Exception() { var repository = Mock.Of <IScoresRepository>(); var service = new ScoresService(_mapper, repository); Func <Task> act = async() => { await service.UpdateScore("Dave", null); }; await act.Should() .ThrowAsync <Exception>() .WithMessage("Value cannot be null. (Parameter 'payload is required')"); }
public async Task UpdateScore_Does_Not_Throw_Exception() { var player = "Dave"; var score = 100; var repository = Mock.Of <IScoresRepository>( x => x.UpdateScore(It.Is <ScoreModel>(o => o.Player == player && o.Score == score)) == Task.CompletedTask); var service = new ScoresService(_mapper, repository); Func <Task> act = async() => { await service.UpdateScore(player, new ScoresRequest { Score = score }); }; await act.Should() .NotThrowAsync <Exception>(); }
public async Task UpdateScore_Throws_Exception() { var player = "Dave"; var score = 100; var repository = Mock.Of <IScoresRepository>( x => x.UpdateScore(It.Is <ScoreModel>(o => o.Player == player && o.Score == score)) == Task.FromException <IList <ScoreModel> >(new Exception("Custom Test Exception"))); var service = new ScoresService(_mapper, repository); Func <Task> act = async() => { await service.UpdateScore(player, new ScoresRequest { Score = score }); }; await act.Should() .ThrowAsync <Exception>() .WithMessage("Custom Test Exception"); }