41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using Server.Controllers;
|
|
using Server.Models;
|
|
using Server.Repository;
|
|
|
|
|
|
namespace TestServer
|
|
{
|
|
[TestClass]
|
|
public class UnitTestGetAll
|
|
{
|
|
private readonly Mock<IGameRepository> _mockRepository;
|
|
private readonly GameController _controller;
|
|
private List<Game> _games;
|
|
|
|
public UnitTestGetAll()
|
|
{
|
|
_mockRepository = new Mock<IGameRepository>();
|
|
_controller = new GameController(_mockRepository.Object);
|
|
|
|
_games = new List<Game>
|
|
{
|
|
new Game { Id = 1, Titel = "Game1", Zustand = Zustand.Neu, Kommentar = "Das ist Game1"},
|
|
new Game { Id = 2, Titel = "Game2", Zustand = Zustand.Gebraucht, Kommentar = "Das ist Game2"}
|
|
};
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ShouldReturnAllGames()
|
|
{
|
|
_mockRepository.Setup(repo => repo.GetAllGames()).Returns(_games);
|
|
|
|
var result = _controller.Get();
|
|
|
|
Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));
|
|
Assert.IsInstanceOfType(result.Result, typeof(List<Game>));
|
|
Assert.AreEqual(2, result.Value.Count);
|
|
}
|
|
}
|
|
} |