Skip to content

Commit

Permalink
Merge pull request #15 from tacobell1896/fix/game-put
Browse files Browse the repository at this point in the history
add fix to put method for games
  • Loading branch information
tacobell1896 authored May 19, 2024
2 parents b51926c + c66a6bc commit cd758a4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
27 changes: 17 additions & 10 deletions src/Controllers/SavePointGamesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,29 @@ public async Task<IActionResult> PutSavePointGame(int id, SavePointGameDTO saveP
return BadRequest();
}

_context.Entry(savePointGameDTO).State = EntityState.Modified;
var savePointGame = await _context.SavePointGames.FindAsync(id);
if (savePointGame == null)
{
return NotFound();
}

savePointGame.GameName = savePointGameDTO.GameName;
savePointGame.GameConsole = savePointGameDTO.GameConsole;
savePointGame.GameGenre = savePointGameDTO.GameGenre;
savePointGame.GameDeveloper = savePointGameDTO.GameDeveloper;
savePointGame.GamePublisher = savePointGameDTO.GamePublisher;
savePointGame.GameReleaseDate = savePointGameDTO.GameReleaseDate;
savePointGame.GameDescription = savePointGameDTO.GameDescription;
savePointGame.GameRating = savePointGameDTO.GameRating;
savePointGame.GameImage = savePointGameDTO.GameImage;

try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
catch (DbUpdateConcurrencyException) when (!SavePointGameExists(id))
{
if (!SavePointGameExists(id))
{
return NotFound();
}
else
{
throw;
}
return NotFound();
}

return NoContent();
Expand Down
66 changes: 33 additions & 33 deletions test/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,39 @@ public async void TestGetGameById()
}

// TOOD: Fix this test
// [Fact]
// public async void TestPutGame()
// {
// // Arrange
// var options = new DbContextOptionsBuilder<SavePointContext>()
// .UseInMemoryDatabase(databaseName: "SavePointGames")
// .Options;
// var context = new SavePointContext(options);
// var controller = new SavePointGamesController(context);

// // Mocking the SavePointGameDTO object
// var savePointGameDTO = new SavePointGameDTO
// {
// SavePointGameId = 1,
// GameName = "Test Game",
// GameGenre = "Test Genre",
// GameConsole = "Test Platform"
// };
// await controller.PostSavePointGame(savePointGameDTO);

// savePointGameDTO = new SavePointGameDTO
// {
// SavePointGameId = 1,
// GameName = "Test Game Updated",
// GameGenre = "Test Genre Updated",
// GameConsole = "Test Platform Updated"
// };
// // Act
// var result = await controller.PutSavePointGame(1, savePointGameDTO);

// // Assert
// Assert.IsType<NoContentResult>(result);
// }
[Fact]
public async void TestPutGame()
{
// Arrange
var options = new DbContextOptionsBuilder<SavePointContext>()
.UseInMemoryDatabase(databaseName: "SavePointGames")
.Options;
var context = new SavePointContext(options);
var controller = new SavePointGamesController(context);

// Mocking the SavePointGameDTO object
var savePointGameDTO = new SavePointGameDTO
{
SavePointGameId = 1,
GameName = "Test Game",
GameGenre = "Test Genre",
GameConsole = "Test Platform"
};
await controller.PostSavePointGame(savePointGameDTO);

savePointGameDTO = new SavePointGameDTO
{
SavePointGameId = 1,
GameName = "Test Game Updated",
GameGenre = "Test Genre Updated",
GameConsole = "Test Platform Updated"
};
// Act
var result = await controller.PutSavePointGame(1, savePointGameDTO);

// Assert
Assert.IsType<NoContentResult>(result);
}

[Fact]
public async void TestPostNote()
Expand Down

0 comments on commit cd758a4

Please sign in to comment.