diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc069c9..7eb5766 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,17 +10,21 @@ on: branches: [ "main" ] workflow_dispatch: +permissions: + id-token: write + contents: read + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore Homestead - name: Build @@ -30,7 +34,7 @@ jobs: - name: Publish run: dotnet publish Homestead/Server/Homestead.Server.csproj -c Release -o website - name: Upload a Build Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: website path: website/** @@ -42,14 +46,22 @@ jobs: steps: - name: Download a Build Artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: website path: website + - name: Azure Login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Deploy to Azure - uses: azure/webapps-deploy@v2 + uses: azure/webapps-deploy@v3 with: app-name: HomesteadGame - publish-profile: ${{ secrets.azureWebAppPublishProfile }} package: website + - name: logout + run: | + az logout \ No newline at end of file diff --git a/Homestead/Client/Homestead.Client.csproj b/Homestead/Client/Homestead.Client.csproj index 9f68281..b9cd999 100644 --- a/Homestead/Client/Homestead.Client.csproj +++ b/Homestead/Client/Homestead.Client.csproj @@ -1,7 +1,7 @@  - net6.0 + net10.0 enable enable @@ -11,10 +11,10 @@ - - - - + + + + diff --git a/Homestead/Client/Pages/Index.razor b/Homestead/Client/Pages/Index.razor index 106f7df..c1b396d 100644 --- a/Homestead/Client/Pages/Index.razor +++ b/Homestead/Client/Pages/Index.razor @@ -106,7 +106,7 @@ protected override async Task OnInitializedAsync() { - Lobby.PlayerId = await localStorage.GetItemAsync("PlayerId"); + Lobby.PlayerId = await localStorage.GetItemAsync("PlayerId") ?? string.Empty; if (string.IsNullOrEmpty(Lobby.PlayerId)) { Lobby.PlayerId = Guid.NewGuid().ToString(); diff --git a/Homestead/Homestead.Client.Tests/Homestead.Client.Tests.csproj b/Homestead/Homestead.Client.Tests/Homestead.Client.Tests.csproj index 5cd9c62..c79ff66 100644 --- a/Homestead/Homestead.Client.Tests/Homestead.Client.Tests.csproj +++ b/Homestead/Homestead.Client.Tests/Homestead.Client.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net10.0 enable enable @@ -9,10 +9,10 @@ - - - - + + + + diff --git a/Homestead/Homestead.Client.Tests/Usings.cs b/Homestead/Homestead.Client.Tests/Usings.cs index ab67c7e..0753788 100644 --- a/Homestead/Homestead.Client.Tests/Usings.cs +++ b/Homestead/Homestead.Client.Tests/Usings.cs @@ -1 +1,2 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file +global using Microsoft.VisualStudio.TestTools.UnitTesting; +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] \ No newline at end of file diff --git a/Homestead/Homestead.Shared.Tests/GameEngineTest.cs b/Homestead/Homestead.Shared.Tests/GameEngineTest.cs index 9c35d11..dea1163 100644 --- a/Homestead/Homestead.Shared.Tests/GameEngineTest.cs +++ b/Homestead/Homestead.Shared.Tests/GameEngineTest.cs @@ -1,5 +1,4 @@ -using NuGet.Frameworks; - + namespace Homestead.Shared.Tests { [TestClass] @@ -70,7 +69,7 @@ public void DrawFromDiscardTest() game = engine.ProcessAction(game, action); Assert.IsFalse(game.DiscardPile.Any()); Assert.IsTrue(game.Players[game.ActivePlayer].Hand.Any()); - Assert.IsTrue(game.Players[game.ActivePlayer].Hand[0] is Cards.Well); + Assert.AreEqual(Cards.Well, game.Players[game.ActivePlayer].Hand[0]); Assert.IsFalse(game.AvailableActions.Any(a => a.Type is PlayerAction.ActionType.DrawFromDeck)); Assert.IsFalse(game.AvailableActions.Any(a => a.Type is PlayerAction.ActionType.DrawFromDiscard)); @@ -97,11 +96,11 @@ public void DrawFromDiscardWhenMultipleOfSameTypeExist() game = engine.ProcessAction(game, action); Assert.IsTrue(game.Players[game.ActivePlayer].Hand.Any()); - Assert.IsTrue(game.Players[game.ActivePlayer].Hand[0] is Cards.Well); + Assert.AreEqual(Cards.Well, game.Players[game.ActivePlayer].Hand[0]); Assert.IsTrue(game.DiscardPile.Any()); - Assert.IsTrue(game.DiscardPile.First() is Cards.Well); - Assert.IsTrue(game.DiscardPile.Last() is Cards.Wood); + Assert.AreEqual(Cards.Well, game.DiscardPile.First()); + Assert.AreEqual(Cards.Wood, game.DiscardPile.Last()); } // Draw from discard with no discard @@ -130,7 +129,7 @@ public void PlayCardWithoutCardInHandThrowsKeyNotFound() PlayerAction action = new(PlayerAction.ActionType.Play, game.ActivePlayer); action.PlayerCard = Cards.Well; - Assert.ThrowsException(() => engine.ProcessAction(game, action)); + Assert.Throws(() => engine.ProcessAction(game, action)); } // Active Player reverts to 1 after 4 @@ -152,13 +151,13 @@ public void PlayCardGiveCard() action.TargetCard = Cards.Well; //action.PlayerCard = "Give"; - Assert.AreEqual(2, game.Players[game.ActivePlayer].Hand.Count); - Assert.AreEqual(0, game.Players[2].Hand.Count); + Assert.HasCount(2, game.Players[game.ActivePlayer].Hand); + Assert.IsEmpty(game.Players[2].Hand); game = engine.ProcessAction(game, action); - Assert.AreEqual(0, game.Players[game.ActivePlayer].Hand.Count); - Assert.AreEqual(1, game.Players[2].Hand.Count); + Assert.IsEmpty(game.Players[game.ActivePlayer].Hand); + Assert.HasCount(1, game.Players[2].Hand); } [TestMethod] @@ -173,13 +172,13 @@ public void PlayCardGiveCardWithoutAdditionalCardInHand() PlayerAction action = new(PlayerAction.ActionType.Play, game.ActivePlayer); action.PlayerCard = Cards.GoodNeighbor; - Assert.AreEqual(1, game.Players[game.ActivePlayer].Hand.Count); - Assert.AreEqual(0, game.Players[2].Hand.Count); + Assert.HasCount(1, game.Players[game.ActivePlayer].Hand); + Assert.IsEmpty(game.Players[2].Hand); - Assert.ThrowsException(() => engine.ProcessAction(game, action)); + Assert.Throws(() => engine.ProcessAction(game, action)); - Assert.AreEqual(0, game.Players[game.ActivePlayer].Hand.Count); - Assert.AreEqual(0, game.Players[2].Hand.Count); + Assert.IsEmpty(game.Players[game.ActivePlayer].Hand); + Assert.IsEmpty(game.Players[2].Hand); } [TestMethod] @@ -198,13 +197,13 @@ public void PlayCardStealCard() action.TargetCard = Cards.Well; //action.PlayerCard = "Give"; - Assert.AreEqual(1, game.Players[game.ActivePlayer].Hand.Count); - Assert.AreEqual(1, game.Players[2].Hand.Count); + Assert.HasCount(1, game.Players[game.ActivePlayer].Hand); + Assert.HasCount(1, game.Players[2].Hand); game = engine.ProcessAction(game, action); - Assert.AreEqual(1, game.Players[game.ActivePlayer].Hand.Count); - Assert.AreEqual(0, game.Players[2].Hand.Count); + Assert.HasCount(1, game.Players[game.ActivePlayer].Hand); + Assert.IsEmpty(game.Players[2].Hand); } // Player cannot draw two cards from deck @@ -243,7 +242,7 @@ public void Wolves() PlayerAction action = new(PlayerAction.ActionType.Play, game.ActivePlayer, Cards.WolfAll); game = engine.ProcessAction(game, action); - Assert.AreEqual(4, game.AvailableActions.Count); + Assert.HasCount(4, game.AvailableActions); Assert.IsTrue(game.AvailableActions.All(a => a.Type is PlayerAction.ActionType.Discard)); } diff --git a/Homestead/Homestead.Shared.Tests/GameLookupTest.cs b/Homestead/Homestead.Shared.Tests/GameLookupTest.cs index 9d91b3c..628e2cb 100644 --- a/Homestead/Homestead.Shared.Tests/GameLookupTest.cs +++ b/Homestead/Homestead.Shared.Tests/GameLookupTest.cs @@ -5,12 +5,13 @@ namespace Homestead.Shared.Tests [TestClass] public class GameLookupTest { - GameLookup _lookup { get; set; } - GameLookupTest(GameLookup lookup) + GameLookup _lookup { get; set; } = new GameLookup(); + + [TestInitialize] + public void Initialize() { - _lookup = lookup; + _lookup = new GameLookup(); } - [TestInitialize] [TestMethod] public void addGame() diff --git a/Homestead/Homestead.Shared.Tests/GameTest.cs b/Homestead/Homestead.Shared.Tests/GameTest.cs index 7819cc1..c9dcafd 100644 --- a/Homestead/Homestead.Shared.Tests/GameTest.cs +++ b/Homestead/Homestead.Shared.Tests/GameTest.cs @@ -9,8 +9,8 @@ public void CreateGame() GameEngineWithActions engine = new(); Game game = engine.Start("test"); - Assert.AreEqual(4, game.Players.Count); - Assert.IsTrue(game.Players[3].Name != null); + Assert.HasCount(4, game.Players); + Assert.IsNotNull(game.Players[3].Name); } } } \ No newline at end of file diff --git a/Homestead/Homestead.Shared.Tests/Homestead.Shared.Tests.csproj b/Homestead/Homestead.Shared.Tests/Homestead.Shared.Tests.csproj index c2b9c7b..dd92f05 100644 --- a/Homestead/Homestead.Shared.Tests/Homestead.Shared.Tests.csproj +++ b/Homestead/Homestead.Shared.Tests/Homestead.Shared.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net10.0 enable enable @@ -9,10 +9,10 @@ - - - - + + + + diff --git a/Homestead/Homestead.Shared.Tests/Usings.cs b/Homestead/Homestead.Shared.Tests/Usings.cs index ab67c7e..ed6b537 100644 --- a/Homestead/Homestead.Shared.Tests/Usings.cs +++ b/Homestead/Homestead.Shared.Tests/Usings.cs @@ -1 +1,3 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file +global using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] \ No newline at end of file diff --git a/Homestead/Server/Homestead.Server.csproj b/Homestead/Server/Homestead.Server.csproj index 2010651..dc0c2ed 100644 --- a/Homestead/Server/Homestead.Server.csproj +++ b/Homestead/Server/Homestead.Server.csproj @@ -1,15 +1,15 @@ - net6.0 + net10.0 enable enable - - - + + + diff --git a/Homestead/Shared/Actions/ActionPlayCard.cs b/Homestead/Shared/Actions/ActionPlayCard.cs index c74089b..6a8ff87 100644 --- a/Homestead/Shared/Actions/ActionPlayCard.cs +++ b/Homestead/Shared/Actions/ActionPlayCard.cs @@ -105,7 +105,7 @@ private void DoDisaster(string card, int? targetPlayer) CurrentPlayer.Hand.Remove(card); } - private bool RemoveCardsBasedOnDisaster(int playerNumber, string impactedCard, string preventionCard) + private bool RemoveCardsBasedOnDisaster(int playerNumber, string impactedCard, string? preventionCard) { if (preventionCard==null || !RemoveCardFromPlayersHand(playerNumber, preventionCard)) { diff --git a/Homestead/Shared/Cards.cs b/Homestead/Shared/Cards.cs index f3daaaa..2633090 100644 --- a/Homestead/Shared/Cards.cs +++ b/Homestead/Shared/Cards.cs @@ -41,7 +41,6 @@ public static class Cards static Cards() { int extreme = 20; - int tons = 15; int lots = 10; int some = 2; int few = 1; diff --git a/Homestead/Shared/Homestead.Shared.csproj b/Homestead/Shared/Homestead.Shared.csproj index 0ad93ca..cf91585 100644 --- a/Homestead/Shared/Homestead.Shared.csproj +++ b/Homestead/Shared/Homestead.Shared.csproj @@ -1,13 +1,13 @@  - net6.0 + net10.0 enable enable - +