Skip to content

Commit

Permalink
Fix tests #627
Browse files Browse the repository at this point in the history
  • Loading branch information
sussexrick committed Oct 11, 2024
1 parent 5f7d3ca commit d792163
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
using Stoolball.Web.Navigation;
using Stoolball.Web.Statistics.Models;
using Stoolball.Web.Teams;
using Umbraco.Cms.Core.Security;
using Xunit;

namespace Stoolball.Web.UnitTests.Teams
{
public class LinkedPlayersForIdentityControllerTests : UmbracoBaseTest
{
private readonly Mock<IMemberManager> _memberManager = new();
private readonly Mock<IPlayerDataSource> _playerDataSource = new();
private readonly Mock<ITeamDataSource> _teamDataSource = new();
private readonly Mock<IAuthorizationPolicy<Team>> _authorizationPolicy = new();
private readonly Mock<ITeamBreadcrumbBuilder> _breadcrumbBuilder = new();

Expand All @@ -27,7 +30,9 @@ private LinkedPlayersForIdentityController CreateController()
Mock.Of<ILogger<LinkedPlayersForIdentityController>>(),
CompositeViewEngine.Object,
UmbracoContextAccessor.Object,
_memberManager.Object,
_authorizationPolicy.Object,
_teamDataSource.Object,
_playerDataSource.Object,
_breadcrumbBuilder.Object)
{
Expand All @@ -41,11 +46,12 @@ private PlayerIdentity SetupMocks()
{
PlayerIdentityId = Guid.NewGuid(),
PlayerIdentityName = "John Smith",
Team = new Team(),
Team = new Team { TeamRoute = "/teams/example" },
Player = new Player { PlayerId = Guid.NewGuid(), PlayerRoute = "/players/example-player" }
};
_playerDataSource.Setup(x => x.ReadPlayerIdentityByRoute(Request.Object.Path)).ReturnsAsync(identity);
_playerDataSource.Setup(x => x.ReadPlayerByRoute(identity.Player.PlayerRoute, null)).ReturnsAsync(identity.Player);
_teamDataSource.Setup(x => x.ReadTeamByRoute(identity.Team.TeamRoute, false)).ReturnsAsync(identity.Team);
_authorizationPolicy.Setup(x => x.IsAuthorized(identity.Team)).Returns(Task.FromResult(new Dictionary<AuthorizedAction, bool> { { AuthorizedAction.EditTeam, true } }));
return identity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ private PlayerIdentity SetupMocks()
{
PlayerIdentityId = Guid.NewGuid(),
PlayerIdentityName = "John Smith",
Team = new Team()
Team = new Team(),
Player = new Player { PlayerRoute = "/player/john-smith" }
};
_playerDataSource.Setup(x => x.ReadPlayerIdentityByRoute(Request.Object.Path)).Returns(Task.FromResult<PlayerIdentity?>(identity));
_authorizationPolicy.Setup(x => x.IsAuthorized(identity.Team)).Returns(Task.FromResult(new Dictionary<AuthorizedAction, bool> { { AuthorizedAction.EditTeam, true } }));
_playerDataSource.Setup(x => x.ReadPlayerIdentityByRoute(Request.Object.Path)).ReturnsAsync(identity);
_playerDataSource.Setup(x => x.ReadPlayerByRoute(identity.Player.PlayerRoute, null)).ReturnsAsync(identity.Player);
_authorizationPolicy.Setup(x => x.IsAuthorized(identity.Team)).ReturnsAsync(new Dictionary<AuthorizedAction, bool> { { AuthorizedAction.EditTeam, true } });
return identity;
}

Expand Down
2 changes: 1 addition & 1 deletion Stoolball.Web/Teams/PlayerIdentityActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public PlayerIdentityActionsController(ILogger<PlayerIdentityActionsController>
{
// Query the player to get the other identities linked to this one
model.Player = await _playerDataSource.ReadPlayerByRoute(model.PlayerIdentity.Player!.PlayerRoute!).ConfigureAwait(false);
model.Player.PreferredName = model.PlayerIdentity.PlayerIdentityName;
model.Player!.PreferredName = model.PlayerIdentity.PlayerIdentityName;

model.Authorization.CurrentMemberIsAuthorized = await _authorizationPolicy.IsAuthorized(model.PlayerIdentity.Team);

Expand Down

0 comments on commit d792163

Please sign in to comment.