public void AddGameWithDatabaseExceptionTest() { var game = RepositoryTestService.GetGame(Guid.NewGuid()); var gameToCreate = this.autoMapper.Map <GameToCreateDTO>(game); this.moqGamesRepository.Setup(m => m.AddGame(It.IsAny <Game>())).Throws(new Exception()); GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper); gameController = RepositoryTestService.AssignMockProblemDetailsFactoryToController <GamesController>(gameController); var result = gameController.AddGame(gameToCreate); Assert.IsNotNull(result); Assert.That(result.Result, Is.InstanceOf(typeof(ObjectResult))); ObjectResult problemResult = result.Result as ObjectResult; Assert.That(problemResult.Value, Is.InstanceOf(typeof(ProblemDetails))); }
public void AddGameTest() { var game = RepositoryTestService.GetGame(Guid.NewGuid()); var gameToCreate = this.autoMapper.Map <GameToCreateDTO>(game); this.moqGamesRepository.Setup(m => m.AddGame(It.IsAny <Game>())).Returns(game); this.moqGamesRepository.Setup(m => m.Save()).Returns(1); GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper); var result = gameController.AddGame(gameToCreate); Assert.IsNotNull(result); Assert.That(result.Result, Is.InstanceOf(typeof(CreatedAtRouteResult))); CreatedAtRouteResult createdAtRouteResult = result.Result as CreatedAtRouteResult; Assert.AreEqual(createdAtRouteResult.RouteName, "GetGame"); Assert.AreEqual(createdAtRouteResult.StatusCode, 201); Assert.That((createdAtRouteResult.Value as GameDTO).Id, Is.InstanceOf(typeof(Guid))); }