Skip to content

Commit

Permalink
fix issues on api testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowindebondt committed Jun 6, 2024
1 parent cdc5b62 commit 83271aa
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ public void GetList_ReturnsOkWithFilledList_ServiceGetAllCalledOnce()

[Fact]
[Trait(TraitCategories.TestLevel, TestLevels.UnitTest)]
public void GetList_ReturnsNotFound_ServiceGetAllCalledOnce()
public void GetList_ReturnsOkWithEmptyList_ServiceGetAllCalledOnce()
{
// arrange
_mockService.Setup(service => service.GetAll(It.IsAny<int>())).Returns((IEnumerable<Game>)null);
OkObjectResult okResult = null;

// act
var result = _controller.GetList(-1);

// assert
Assert.Multiple(
() => _mockService.Verify(service => service.GetAll(It.IsAny<int>()), Times.Once),
() => Assert.IsType<NotFoundResult>(result)
() => okResult = Assert.IsType<OkObjectResult>(result),
() => Assert.Null(okResult.Value)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public void GetList_ReturnsOkWithFilledList_ServiceGetAllCalledOnce()

[Fact]
[Trait(TraitCategories.TestLevel, TestLevels.UnitTest)]
public void GetList_ReturnsNotFound_ServiceGetAllCalledOnce()
public void GetList_ReturnsOkWithEmptyList_ServiceGetAllCalledOnce()
{
// arrange
_mockService.Setup(service => service.GetAll(It.IsAny<int>())).Returns((IEnumerable<Domain.Match>)null);
OkObjectResult okResult = null;

// act
var result = _controller.GetList(-1);

// assert
Assert.Multiple(
() => _mockService.Verify(service => service.GetAll(It.IsAny<int>()), Times.Once),
() => Assert.IsType<NotFoundResult>(result)
() => okResult = Assert.IsType<OkObjectResult>(result),
() => Assert.Null(okResult.Value)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ public void GetList_ReturnsOkWithFilledList_ServiceGetAllCalledOnce()

[Fact]
[Trait(TraitCategories.TestLevel, TestLevels.UnitTest)]
public void GetList_ReturnsNotFound_ServiceGetAllCalledOnce()
public void GetList_ReturnsOkWithEmptyList_ServiceGetAllCalledOnce()
{
// arrange
_mockService.Setup(service => service.GetAll(It.IsAny<int>())).Returns((IEnumerable<Member>)null);
OkObjectResult okResult = null;

// act
var result = _controller.GetList(-1);

// assert
Assert.Multiple(
() => _mockService.Verify(service => service.GetAll(It.IsAny<int>()), Times.Once),
() => Assert.IsType<NotFoundResult>(result)
() => okResult = Assert.IsType<OkObjectResult>(result),
() => Assert.Null(okResult.Value)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ public void GetList_ReturnsOkWithFilledList_ServiceGetAllCalledOnce()

[Fact]
[Trait(TraitCategories.TestLevel, TestLevels.UnitTest)]
public void GetList_ReturnsNotFound_ServiceGetAllCalledOnce()
public void GetList_ReturnsOkWithEmptyList_ServiceGetAllCalledOnce()
{
// arrange
_mockService.Setup(service => service.GetAll(It.IsAny<int>())).Returns((IEnumerable<Poule>)null);
OkObjectResult okResult = null;

// act
var result = _controller.GetList(-1);

// assert
Assert.Multiple(
() => _mockService.Verify(service => service.GetAll(It.IsAny<int>()), Times.Once),
() => Assert.IsType<NotFoundResult>(result)
() => okResult = Assert.IsType<OkObjectResult>(result),
() => Assert.Null(okResult.Value)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ public void GetList_ReturnsOkWithFilledList_ServiceGetAllCalledOnce()

[Fact]
[Trait(TraitCategories.TestLevel, TestLevels.UnitTest)]
public void GetList_ReturnsNotFound_ServiceGetAllCalledOnce()
public void GetList_ReturnsOkWithEmptyList_ServiceGetAllCalledOnce()
{
// arrange
_mockService.Setup(service => service.GetAll(It.IsAny<int>())).Returns((IEnumerable<Round>)null);
OkObjectResult okResult = null;

// act
var result = _controller.GetList(-1);

// assert
Assert.Multiple(
() => _mockService.Verify(service => service.GetAll(It.IsAny<int>()), Times.Once),
() => Assert.IsType<NotFoundResult>(result)
() => okResult = Assert.IsType<OkObjectResult>(result),
() => Assert.Null(okResult.Value)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void GetList_ReturnsOkWithEmptyList_ServiceGetAllCalledOnce()
_mockService.Setup(service => service.GetAll()).Returns((IEnumerable<Tournament>)null);
var controller = new TournamentController(_mockService.Object);
OkObjectResult okResult = null;
IEnumerable<Tournament> content = null;

// act
var result = controller.GetList();
Expand Down
3 changes: 0 additions & 3 deletions Server/TournamentManager.Api/Controllers/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public GameController(IGameService gameService)
public IActionResult GetList([FromRoute]int matchId)
{
var list = _gameService.GetAll(matchId);
if (list == null) {
return NotFound();
}
return Ok(list);
}

Expand Down
3 changes: 0 additions & 3 deletions Server/TournamentManager.Api/Controllers/MatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public MatchController(IMatchService matchService)
public IActionResult GetList([FromRoute]int pouleId)
{
var list = _matchService.GetAll(pouleId);
if (list == null) {
return NotFound();
}
return Ok(list);
}

Expand Down
3 changes: 0 additions & 3 deletions Server/TournamentManager.Api/Controllers/MemberController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public MemberController(IMemberService memberService)
public IActionResult GetList([FromRoute]int tournamentId)
{
var list = _memberService.GetAll(tournamentId);
if (list == null) {
return NotFound();
}
return Ok(list);
}

Expand Down
3 changes: 0 additions & 3 deletions Server/TournamentManager.Api/Controllers/PouleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public PouleController(IPouleService pouleService)
public IActionResult GetList([FromRoute]int roundId)
{
var list = _pouleService.GetAll(roundId);
if (list == null) {
return NotFound();
}
return Ok(list);
}

Expand Down
3 changes: 0 additions & 3 deletions Server/TournamentManager.Api/Controllers/RoundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public RoundController(IRoundService roundService)
public IActionResult GetList([FromRoute]int tournamentId)
{
var list = _roundService.GetAll(tournamentId);
if (list == null) {
return NotFound();
}
return Ok(list);
}

Expand Down
4 changes: 4 additions & 0 deletions Server/TournamentManager.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
builder.Services.AddScoped<ITournamentService, TournamentService>();
builder.Services.AddScoped<IRoundService, RoundService>();
builder.Services.AddScoped<IPouleService, PouleService>();
builder.Services.AddScoped<IMemberService, MemberService>();
builder.Services.AddScoped<IMatchService, MatchService>();
builder.Services.AddScoped<IGameService, GameService>();
builder.Services.AddScoped<IPlayerService, PlayerService>();
#endregion

var app = builder.Build();
Expand Down
4 changes: 2 additions & 2 deletions Server/TournamentManager.Domain/Entities/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class Member : BaseEntity
/// <summary>
/// Reference to the related <see cref="Tournament"/>
/// </summary>
public virtual Tournament Tournament { get; set; } = null!;
public virtual Tournament? Tournament { get; set; } = null!;
/// <summary>
/// Reference to the <see cref="Player"/>
/// </summary>
public virtual Player Player { get; set; } = null!;
public virtual Player? Player { get; set; } = null!;
}
2 changes: 1 addition & 1 deletion Server/TournamentManager.Domain/Entities/Poule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Poule : BaseEntity
/// <summary>
/// Reference to the related <see cref="Round"/>
/// </summary>
public virtual Round Round { get; set; } = null!;
public virtual Round? Round { get; set; } = null!;

/// <summary>
/// Collection of <see cref="Match"/>es that are part of this poule
Expand Down
4 changes: 2 additions & 2 deletions Server/TournamentManager.Domain/Entities/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class Round : BaseEntity
/// <summary>
/// Reference to the related <see cref="Tournament"/>
/// </summary>
public virtual Tournament Tournament { get; set; } = null!;
public virtual Tournament? Tournament { get; set; } = null!;

/// <summary>
/// Reference of the <see cref="RoundSettings"/> that are applied to the round
/// </summary>
public virtual RoundSettings Settings { get; set; } = null!;
public virtual RoundSettings? Settings { get; set; } = null!;
/// <summary>
/// Collection of <see cref="Poule"/>s that are part of this round.
/// </summary>
Expand Down

0 comments on commit 83271aa

Please sign in to comment.