public void Remove_Given_game_by_id_fails() { //Arrange var expectedGame = new Game { GameId = 1 }; GameRepositoryMock .Setup(g => g.Remove(expectedGame.GameId)).Throws(new Exception()); UnitofWorkMock .Setup(u => u.Game) .Returns(GameRepositoryMock.Object); //Act var result = _uut.Delete(expectedGame.GameId); //Assert GameRepositoryMock.Verify(); var response = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal(400, response.StatusCode); }
public async void Should_Return_Badrequest_when_no_Games_Exsist() { //Arrange var expectedResult = new List <Game>() { new Game { GameId = 1 }, new Game { GameId = 2 } }; GameRepositoryMock .Setup(x => x.GetAll()) .ReturnsAsync((List <Game>)null).Verifiable(); UnitofWorkMock .Setup(m => m.Game) .Returns(GameRepositoryMock.Object); //Act var result = await _uut.GetAll(); //Assert GameRepositoryMock.Verify(); var ErrorResult = Assert.IsType <NotFoundResult>(result); Assert.Equal(404, ErrorResult.StatusCode); }
public async void Should_return_badrequest_on_getwinnerresult() { //Arrange var expectedGame = new Game { GameId = 1 }; GameRepositoryMock .Setup(g => g.Winner(expectedGame.GameId)) .ReturnsAsync((List <GameWinnerResult>)null); UnitofWorkMock .Setup(u => u.Game) .Returns(GameRepositoryMock.Object); //Act var result = await _uut.Get(expectedGame.GameId); //Assert GameRepositoryMock.Verify(); var ErrorResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal(400, ErrorResult.StatusCode); }
public async void Should_Return_Badrequest_when_wrong_input_is_given() { //Arrange var expectedResult = new Game() { GameId = 1 }; GameRepositoryMock .Setup(x => x.Get(expectedResult.GameId)) .ReturnsAsync((Game)null).Verifiable(); UnitofWorkMock .Setup(m => m.Game) .Returns(GameRepositoryMock.Object); //Act var result = await _uut.Get(expectedResult.GameId); //Assert GameRepositoryMock.Verify(); var ErrorResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal(400, ErrorResult.StatusCode); }
public async Task ShouldBeSuccessWhenCallMethodHandle() { var repository = GameRepositoryMock.GetDefaultInstance(); var command = CreateGameCommandMock.GetDefaultValidInstance(); var handler = GetHandler(repository: repository); var result = await handler.Handle(command, default); await repository.ReceivedWithAnyArgs().InsertOneAsync(default, default);
public void drawCardTest() { var gameRepositoryMock = new GameRepositoryMock(); var playGame = new PlayGame(gameRepositoryMock); var returnObject = playGame.drawCard(0); Assert.AreEqual(null, returnObject);//no deck and card in a new Game }
public async Task ShouldBeSuccessWhenCallMethodHandle() { var repository = GameRepositoryMock.GetDefaultInstance(); var command = DeleteGameCommandMock.GetDefaultValidInstance(); var handler = GetHandler(repository: repository, notificationContext: _notificationContext); await handler.Handle(command, default); await repository.ReceivedWithAnyArgs().DeleteOneAsync(default, default);
public void addPlayerTest() { var gameRepositoryMock = new GameRepositoryMock(); var manageGame = new ManageGame(gameRepositoryMock); var returnObject = manageGame.addPlayer(0, 0); var expected = new ReturnObject(true, "test"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void getDecksForGameTest() { var gameRepositoryMock = new GameRepositoryMock(); var viewGame = new ViewGame(gameRepositoryMock); var returnObject = viewGame.getDecksForGame(0); var expected = new Collection <CarddeckEntity>(); Assert.AreEqual(expected.GetType(), returnObject.GetType()); }
public void getAllGamesTest() { var gameRepositoryMock = new GameRepositoryMock(); var viewGame = new ViewGame(gameRepositoryMock); var returnObject = viewGame.getAllGames(); var expected = new Collection <GameEntity>(); Assert.AreEqual(expected.GetType(), returnObject.GetType()); }
public void getGameByIdTest() { var gameRepositoryMock = new GameRepositoryMock(); var viewGame = new ViewGame(gameRepositoryMock); var returnObject = viewGame.getGameById(2); var expected = new GameEntity(0, "Test"); Assert.AreEqual(expected.GetType(), returnObject.GetType()); }
public void changeGamemodeTest() { var gameRepositoryMock = new GameRepositoryMock(); var manageGame = new ManageGame(gameRepositoryMock); var returnObject = manageGame.changeGamemode(0, new Gamemode(0, "testgamemode")); var expected = new ReturnObject(true, "test"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void removePlayerTest() { var gameRepositoryMock = new GameRepositoryMock(); var manageGame = new ManageGame(gameRepositoryMock); var returnObject = manageGame.removePlayer(0, 0); var expected = new ReturnObject(false, "player does not exist"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void finishGameTest() { var gameRepositoryMock = new GameRepositoryMock(); var playGame = new PlayGame(gameRepositoryMock); var returnObject = playGame.finishGame(new GameEntity(0, "Test")); var expected = new ReturnObject(true, "test"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void closeGameTest() { var gameRepositoryMock = new GameRepositoryMock(); var manageGame = new ManageGame(gameRepositoryMock); var returnObject = manageGame.closeGame(new GameEntity(0, "Test")); var expected = new ReturnObject(true, "test"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void changeActualPlayerTest() { var gameRepositoryMock = new GameRepositoryMock(); var playGame = new PlayGame(gameRepositoryMock); var returnObject = playGame.changeActualPlayer(0, 0); var expected = new ReturnObject(true, "test"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void resetExecutionOfTaskRatingTest() { var gameRepositoryMock = new GameRepositoryMock(); var playGame = new PlayGame(gameRepositoryMock); var returnObject = playGame.resetExecutionOfTaskRating(0); var expected = new ReturnObject(true, "test"); Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess()); }
public void getPunishmentTest() { var gameRepositoryMock = new GameRepositoryMock(); var playGame = new PlayGame(gameRepositoryMock); var returnObject = playGame.getPunishment(0); var expected = "test"; Assert.AreEqual(expected.GetType(), returnObject.GetType()); }
public CreateGameCommandHandler GetHandler( IMapper mapper = null, IBaseRepository <Game> repository = null, ILogger <CreateGameCommandHandler> logger = null ) { mapper ??= AutoMapperMock.GetDefaultInstance(); repository ??= GameRepositoryMock.GetDefaultInstance(); logger ??= Substitute.For <ILogger <CreateGameCommandHandler> >(); return(new CreateGameCommandHandler( mapper, repository, logger)); }
public async void Should_return_CreatedAtActionResult_with_created_Game() { //Arrange //var expectedGame = new Game { GameId = 1 }; UnitofWorkMock .Setup(m => m.Game) .Returns(GameRepositoryMock.Object); //Act var result = await _uut.Post(); //Assert GameRepositoryMock.VerifyAll(); }
public async void Should_Return_OkObjectResult_with_list_of_Games() { //Arrange var expectedResult = new List <Game>() { new Game { GameId = 1 }, new Game { GameId = 2 } }; var finalResult = new List <GameResponse>() { new GameResponse() { GameId = 1 }, new GameResponse() { GameId = 2 } }; GameRepositoryMock .Setup(r => r.GetAll()) .ReturnsAsync(expectedResult).Verifiable(); UnitofWorkMock .Setup(x => x.Game) .Returns(GameRepositoryMock.Object); MapperMock .Setup(m => m.Map <List <GameResponse> >(expectedResult)) .Returns(finalResult).Verifiable(); //Act var result = await _uut.GetAll(); //Assert GameRepositoryMock.Verify(); MapperMock.Verify(); var okResult = Assert.IsType <OkObjectResult>(result); Assert.Same(finalResult, okResult.Value); }
public async void AddUserToGame_returns_badrequest() { //Arrange var expectedgameId = 1; var expectedplayer1Id = 1; var expectedplayer2Id = 2; var expectedgame = new Game { GameId = expectedgameId, Players = new List <Player> { new Player { PlayerId = expectedplayer1Id }, new Player { PlayerId = expectedplayer2Id } } }; GameRepositoryMock .Setup(x => x.AddUserToGame(expectedgameId, expectedplayer1Id, expectedplayer2Id)) .ReturnsAsync((Game)null); UnitofWorkMock .Setup(m => m.Game) .Returns(GameRepositoryMock.Object); //Act var result = await _uut.AddUsersToGame(expectedgameId, expectedplayer1Id, expectedplayer2Id); //Assert GameRepositoryMock.Verify(); var ErrorResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal(400, ErrorResult.StatusCode); }
public async void Should_Get_Game_Result() { //Arrange var expectedGame = new Game { GameId = 1 }; var expectedWinnerResult = new List <GameWinnerResult> { new GameWinnerResult { Playerid = 1, Time = 10 }, new GameWinnerResult { Playerid = 2, Time = 1 } }; GameRepositoryMock .Setup(g => g.Winner(expectedGame.GameId)) .ReturnsAsync(expectedWinnerResult); UnitofWorkMock .Setup(u => u.Game) .Returns(GameRepositoryMock.Object); //Act var result = await _uut.GetResult(expectedGame.GameId); //Assert GameRepositoryMock.Verify(); var response = Assert.IsType <OkObjectResult>(result); Assert.Same(expectedWinnerResult, response.Value); }
public async void Should_Add_user_to_chosen_Game() { //Arrange var expectedgameId = 1; var expectedplayer1Id = 1; var expectedplayer2Id = 2; var expectedgame = new Game { GameId = expectedgameId, Players = new List <Player> { new Player { PlayerId = expectedplayer1Id }, new Player { PlayerId = expectedplayer2Id } } }; var expectedgameresponse = new GameResponse { GameId = expectedgameId, Players = new List <PlayerResponse> { new PlayerResponse { PlayerId = expectedplayer1Id }, new PlayerResponse { PlayerId = expectedplayer2Id } } }; GameRepositoryMock .Setup(x => x.AddUserToGame(expectedgameId, expectedplayer1Id, expectedplayer2Id)) .ReturnsAsync(expectedgame); UnitofWorkMock .Setup(m => m.Game) .Returns(GameRepositoryMock.Object); MapperMock .Setup(s => s.Map <GameResponse>(expectedgame)) .Returns(expectedgameresponse); //Act var result = await _uut.AddUsersToGame(expectedgameId, expectedplayer1Id, expectedplayer2Id); //Assert GameRepositoryMock.Verify(); MapperMock.Verify(); var response = Assert.IsType <OkObjectResult>(result); Assert.Same(expectedgameresponse, response.Value); }