-
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.
- Loading branch information
Showing
9 changed files
with
187 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace PointingParty.Client.Tests; | ||
|
||
public class GameContextTests | ||
{ | ||
[Fact] | ||
public void CreateGame_Returns_GameAggregate() | ||
{ | ||
var sut = new GameContext( | ||
Substitute.For<ILogger<GameContext>>(), | ||
Substitute.For<NavigationManager>() | ||
); | ||
|
||
var agg = sut.CreateGame("Game", "Player"); | ||
|
||
Assert.Equal(sut.Game, agg); | ||
Assert.Equal("Game", agg.State.GameId); | ||
Assert.Equal("Player", sut.PlayerName); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
global using Bunit; | ||
global using NSubstitute; | ||
global using Xunit; |
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,78 @@ | ||
using Bunit.TestDoubles; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PointingParty.Client.Pages; | ||
using PointingParty.Domain; | ||
|
||
namespace PointingParty.Client.Tests.Pages; | ||
|
||
public class GameTests : BunitContext | ||
{ | ||
private readonly IGameContext _gameContext; | ||
|
||
public GameTests() | ||
{ | ||
_gameContext = Substitute.For<IGameContext>(); | ||
Services.AddTransient<IGameContext>(_ => _gameContext); | ||
ComponentFactories.AddStub<GameUi>(); | ||
} | ||
|
||
[Fact] | ||
public void WhenSubmittingForm_CreatesGame() | ||
{ | ||
var cut = Render<Game>(parameters => | ||
parameters.Add(p => p.GameId, "Game")); | ||
|
||
var nameInput = cut.Find("""input[placeholder="Player Name"]"""); | ||
nameInput.Change("Player"); | ||
|
||
cut.Find("button").Click(); | ||
|
||
_gameContext.Received(1).CreateGame("Game", "Player"); | ||
_gameContext.Received(1).Initialize(Arg.Any<Action>()); | ||
} | ||
|
||
[Fact] | ||
public void WithGame_RendersGameUi() | ||
{ | ||
_gameContext.Game.Returns(new GameAggregate()); | ||
|
||
var cut = Render<Game>(parameters => | ||
parameters.Add(p => p.GameId, "Game")); | ||
|
||
Assert.NotNull(cut.FindComponent<Stub<GameUi>>()); | ||
} | ||
|
||
[Fact] | ||
public void WithGame_RendersTitle() | ||
{ | ||
_gameContext.Game.Returns(new GameAggregate()); | ||
|
||
var cut = Render<Game>(parameters => | ||
parameters.Add(p => p.GameId, "Game")); | ||
|
||
var h2 = cut.Find("h2"); | ||
|
||
Assert.Equal("Pointing Party: Game", h2.TextContent); | ||
} | ||
|
||
[Fact] | ||
public void WithPlayerName_CreatesGame_And_UpdatesUrl() | ||
{ | ||
_gameContext.Game.Returns(new GameAggregate()); | ||
var navMan = Services.GetRequiredService<BunitNavigationManager>(); | ||
|
||
navMan.NavigateTo("/Game/Game?PlayerName=Player"); | ||
|
||
Render<Game>(parameters => { parameters.Add(p => p.GameId, "Game"); }); | ||
|
||
Assert.Equal("http://localhost/Game/Game", navMan.Uri); | ||
|
||
_gameContext.Received(1).CreateGame("Game", "Player"); | ||
_gameContext.Received(1).Initialize(Arg.Any<Action>()); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
// Override BunitContext.Dispose to avoid calling sync Dispose on the Services | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.