예제 #1
0
        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>())));
        }
예제 #2
0
        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>())));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }