-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an 'edit players for team' page #626
- Loading branch information
1 parent
b56a881
commit cc4d06b
Showing
22 changed files
with
466 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
Stoolball.Web.UnitTests/Teams/EditPlayersForTeamControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using Stoolball.Clubs; | ||
using Stoolball.Data.Abstractions; | ||
using Stoolball.Security; | ||
using Stoolball.Statistics; | ||
using Stoolball.Teams; | ||
using Stoolball.Web.Teams; | ||
using Stoolball.Web.Teams.Models; | ||
using Xunit; | ||
|
||
namespace Stoolball.Web.UnitTests.Teams | ||
{ | ||
public class EditPlayersForTeamControllerTests : UmbracoBaseTest | ||
{ | ||
private readonly Mock<ITeamDataSource> _teamDataSource = new(); | ||
private readonly Mock<IPlayerDataSource> _playerDataSource = new(); | ||
private readonly Mock<IAuthorizationPolicy<Team>> _authorizationPolicy = new(); | ||
|
||
private EditPlayersForTeamController CreateController() | ||
{ | ||
return new EditPlayersForTeamController( | ||
Mock.Of<ILogger<EditPlayersForTeamController>>(), | ||
CompositeViewEngine.Object, | ||
UmbracoContextAccessor.Object, | ||
_teamDataSource.Object, | ||
_authorizationPolicy.Object, | ||
_playerDataSource.Object) | ||
{ | ||
ControllerContext = ControllerContext | ||
}; | ||
} | ||
|
||
private static Team CreateTeam() | ||
{ | ||
return new Team | ||
{ | ||
TeamId = Guid.NewGuid(), | ||
TeamName = "Example team", | ||
TeamRoute = "/teams/example-team" | ||
}; | ||
} | ||
|
||
private void SetupMocks(Team team) | ||
{ | ||
var players = new List<PlayerIdentity> { | ||
new PlayerIdentity | ||
{ | ||
PlayerIdentityId = Guid.NewGuid(), | ||
PlayerIdentityName = "John Smith", | ||
Player = new Player | ||
{ | ||
PlayerId = Guid.NewGuid() | ||
} | ||
} | ||
}; | ||
_teamDataSource.Setup(x => x.ReadTeamByRoute(Request.Object.Path, true)).ReturnsAsync(team); | ||
_playerDataSource.Setup(x => x.ReadPlayerIdentities(It.Is<PlayerFilter>(x => x.TeamIds.Count == 1 && x.TeamIds.Contains(team.TeamId!.Value)))).Returns(Task.FromResult(players)); | ||
_authorizationPolicy.Setup(x => x.IsAuthorized(team)).Returns(Task.FromResult(new Dictionary<AuthorizedAction, bool> { { AuthorizedAction.EditTeam, true } })); | ||
} | ||
|
||
[Fact] | ||
public async Task Route_not_matching_team_returns_404() | ||
{ | ||
_teamDataSource.Setup(x => x.ReadTeamByRoute(Request.Object.Path, true)).Returns(Task.FromResult<Team?>(null)); | ||
|
||
using (var controller = CreateController()) | ||
{ | ||
var result = await controller.Index(); | ||
|
||
Assert.IsType<NotFoundResult>(result); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Route_matching_team_sets_authorization() | ||
{ | ||
var team = CreateTeam(); | ||
SetupMocks(team); | ||
|
||
using (var controller = CreateController()) | ||
{ | ||
var result = await controller.Index(); | ||
|
||
var model = (TeamViewModel)((ViewResult)result).Model; | ||
|
||
Assert.True(model.Authorization.CurrentMemberIsAuthorized[AuthorizedAction.EditTeam]); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Route_matching_team_returns_player_identities() | ||
{ | ||
var team = CreateTeam(); | ||
SetupMocks(team); | ||
|
||
using (var controller = CreateController()) | ||
{ | ||
var result = await controller.Index(); | ||
|
||
var model = (TeamViewModel)((ViewResult)result).Model; | ||
|
||
Assert.Single(model.PlayerIdentities); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Route_matching_team_sets_page_title() | ||
{ | ||
var team = CreateTeam(); | ||
SetupMocks(team); | ||
|
||
using (var controller = CreateController()) | ||
{ | ||
var result = await controller.Index(); | ||
|
||
var model = (TeamViewModel)((ViewResult)result).Model; | ||
|
||
Assert.Equal($"Edit players for {team.TeamName} stoolball team", model.Metadata.PageTitle); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public async Task Route_matching_team_sets_breadcrumbs_including_club(bool hasClub) | ||
{ | ||
var team = CreateTeam(); | ||
|
||
if (hasClub) | ||
{ | ||
team.Club = new Club | ||
{ | ||
ClubId = Guid.NewGuid(), | ||
ClubName = "Example club", | ||
ClubRoute = "/clubs/example-club" | ||
}; | ||
} | ||
SetupMocks(team); | ||
|
||
using (var controller = CreateController()) | ||
{ | ||
var result = await controller.Index(); | ||
|
||
var model = (TeamViewModel)((ViewResult)result).Model; | ||
|
||
Assert.Equal(hasClub ? 5 : 4, model.Breadcrumbs.Count); | ||
Assert.Equal(team.TeamName, model.Breadcrumbs[^1].Name); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.