public async Task GetPlayerUseCaseWhenResultIsNullShouldRaisePlayerNotFoundException() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); mockPlayerRepository.Setup(m => m.GetAsync(It.IsAny <int>())).Returns(Task.FromResult((Player)null)); //Act //Assert IGetPlayerUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); await Assert.ThrowsAsync <PlayerNotFoundException>(() => sut.Handle(new PlayerRequest(It.IsAny <int>()))); }
public async Task DeletePlayerUseCaseWhenResultIsNullShouldRaiseArgumentNullApplicationException() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); mockPlayerRepository.Setup(m => m.GetAsync(It.IsAny <int>())).Returns((Task <Player>)null); //Act //Assert IDeletePlayerUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); await Assert.ThrowsAsync <PlayerNotFoundException>(() => sut.Handle(new DeletePlayerCommand(It.IsAny <int>()))); }
public async Task DeletePlayerUseCaseWithNullDeleteCommandShouldRaiseArgumentNullApplicationException() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); mockPlayerRepository.Setup(m => m.DeleteAsync(It.IsAny <int>())).Verifiable(); //Act //Assert IDeletePlayerUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); await Assert.ThrowsAsync <ArgumentNullApplicationException>(() => sut.Handle(null)); }
public async Task GetPlayerUseCaseWithPlayerRequestNullShouldRaiseArgumentNullApplicationException() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); var player = new Player(2, "name2", "surname2", "M", It.IsAny <Country>(), "", It.IsAny <Data>()); mockPlayerRepository.Setup(m => m.GetAsync(It.IsAny <int>())).Returns(Task.FromResult(player)); //Act //Assert IGetPlayerUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); await Assert.ThrowsAsync <ArgumentNullApplicationException>(() => sut.Handle(null)); }
public async Task DeletePlayerUseCaseShouldCallDeleteOnRepository() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); var player = new Player(2, "name2", "surname2", "M", It.IsAny <Country>(), "", It.IsAny <Data>()); mockPlayerRepository.Setup(m => m.DeleteAsync(It.IsAny <int>())).Verifiable(); //Act IDeletePlayerUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); await sut.Handle(new DeletePlayerCommand(player.Id)); //Assert mockPlayerRepository.Verify(r => r.DeleteAsync(It.IsAny <int>()), Times.Once); }
public async Task GetPlayerUseCaseShouldReturnOnePlayer() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); var player = new Player(2, "name2", "surname2", "M", It.IsAny <Country>(), "", It.IsAny <Data>()); mockPlayerRepository.Setup(m => m.GetAsync(It.IsAny <int>())).Returns(Task.FromResult(player)); //Act IGetPlayerUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); var result = await sut.Handle(new PlayerRequest(player.Id)); //Assert Assert.Equal(player, result); }
public async Task GetPlayersUseCaseShouldReturnListOfPlayersShortedByPlayerId() { //Arrange Mock <IPlayerRepository> mockPlayerRepository = new Mock <IPlayerRepository>(); IEnumerable <Player> players = new List <Player> { new Player(2, "name2", "surname2", "M", It.IsAny <Country>(), "", It.IsAny <Data>()), new Player(1, "name", "surname", "M", It.IsAny <Country>(), "", It.IsAny <Data>()) }; mockPlayerRepository.Setup(m => m.GetAsync()).Returns(Task.FromResult(players)); //Act IGetPlayersUsesCase sut = new PlayerUseCase(mockPlayerRepository.Object); var result = await sut.Handle(); //Assert Assert.Equal(players.OrderBy(p => p.Id), result); }