From e64c103512d5acb1d411dbf2cab6d7b9199ca734 Mon Sep 17 00:00:00 2001 From: ADato88 Date: Mon, 24 Jan 2022 18:03:45 +0100 Subject: [PATCH] neuer test zum ziehen einer Karte --- BlazorSolution/MiniGames/Client/Program.cs | 1 + .../MiniGames/Client/ViewModel/IUno.cs | 12 +++ .../MiniGames/Client/ViewModel/Uno.cs | 18 ++++- .../Shared/Models/HandKartenModel.cs | 16 ++++ .../MiniGames/Shared/Models/KartenModel.cs | 15 ++++ .../MiniGames/Shared/Models/StapelModel.cs | 13 ++++ .../MiniGamesTests/MiniGamesTests.csproj | 1 + BlazorSolution/MiniGamesTests/UnoTest.cs | 74 +++++++++++++++++++ 8 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 BlazorSolution/MiniGames/Client/ViewModel/IUno.cs create mode 100644 BlazorSolution/MiniGames/Shared/Models/HandKartenModel.cs create mode 100644 BlazorSolution/MiniGames/Shared/Models/KartenModel.cs create mode 100644 BlazorSolution/MiniGames/Shared/Models/StapelModel.cs diff --git a/BlazorSolution/MiniGames/Client/Program.cs b/BlazorSolution/MiniGames/Client/Program.cs index d709778..cd924f9 100644 --- a/BlazorSolution/MiniGames/Client/Program.cs +++ b/BlazorSolution/MiniGames/Client/Program.cs @@ -20,6 +20,7 @@ namespace MiniGames.Client builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddScoped(); + builder.Services.AddScoped(); await builder.Build().RunAsync(); } diff --git a/BlazorSolution/MiniGames/Client/ViewModel/IUno.cs b/BlazorSolution/MiniGames/Client/ViewModel/IUno.cs new file mode 100644 index 0000000..031b0d5 --- /dev/null +++ b/BlazorSolution/MiniGames/Client/ViewModel/IUno.cs @@ -0,0 +1,12 @@ +using MiniGames.Shared.Models; + +namespace MiniGames.Client.ViewModel +{ + public interface IUno + { + StapelModel AblageStabel { get; set; } + + bool IstAblageStabelFarbeGleichHand(string ablegeStapelKarte, string neueKarte); + HandKartenModel ZiehEineKarte(HandKartenModel handStapel, StapelModel stapelModel); + } +} \ No newline at end of file diff --git a/BlazorSolution/MiniGames/Client/ViewModel/Uno.cs b/BlazorSolution/MiniGames/Client/ViewModel/Uno.cs index 697d850..f45e058 100644 --- a/BlazorSolution/MiniGames/Client/ViewModel/Uno.cs +++ b/BlazorSolution/MiniGames/Client/ViewModel/Uno.cs @@ -1,19 +1,33 @@ using MiniGames.Shared.Models; using System; +using System.Linq; namespace MiniGames.Client.ViewModel { - public class Uno + public class Uno : IUno { + public StapelModel AblageStabel { get; set; } + public bool IstAblageStabelFarbeGleichHand(string ablegeStapelKarte, string neueKarte) { if (ablegeStapelKarte.Equals(neueKarte)) { return true; - } else + } + else { return false; } } + + public HandKartenModel ZiehEineKarte(HandKartenModel handStapel, StapelModel stapelModel) + { + HandKartenModel _handStapel = handStapel; + StapelModel _stapelModel = stapelModel; + + _handStapel.KartenModels.Add(_stapelModel.KartenModels.FirstOrDefault()); + + return _handStapel; + } } } diff --git a/BlazorSolution/MiniGames/Shared/Models/HandKartenModel.cs b/BlazorSolution/MiniGames/Shared/Models/HandKartenModel.cs new file mode 100644 index 0000000..96cd1c2 --- /dev/null +++ b/BlazorSolution/MiniGames/Shared/Models/HandKartenModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MiniGames.Shared.Models +{ + public class HandKartenModel + { + public int Id { get; set; } + public string Name { get; set; } + + public List KartenModels { get; set; } + } +} diff --git a/BlazorSolution/MiniGames/Shared/Models/KartenModel.cs b/BlazorSolution/MiniGames/Shared/Models/KartenModel.cs new file mode 100644 index 0000000..8b6d8cf --- /dev/null +++ b/BlazorSolution/MiniGames/Shared/Models/KartenModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MiniGames.Shared.Models +{ + public class KartenModel + { + public string Name { get; set; } + public string Farbe { get; set; } + public bool Spezial { get; set; } + } +} diff --git a/BlazorSolution/MiniGames/Shared/Models/StapelModel.cs b/BlazorSolution/MiniGames/Shared/Models/StapelModel.cs new file mode 100644 index 0000000..b700c1e --- /dev/null +++ b/BlazorSolution/MiniGames/Shared/Models/StapelModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MiniGames.Shared.Models +{ + public class StapelModel + { + public List KartenModels { get; set;} + } +} diff --git a/BlazorSolution/MiniGamesTests/MiniGamesTests.csproj b/BlazorSolution/MiniGamesTests/MiniGamesTests.csproj index 19e109c..15520d8 100644 --- a/BlazorSolution/MiniGamesTests/MiniGamesTests.csproj +++ b/BlazorSolution/MiniGamesTests/MiniGamesTests.csproj @@ -8,6 +8,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BlazorSolution/MiniGamesTests/UnoTest.cs b/BlazorSolution/MiniGamesTests/UnoTest.cs index 8f7ef96..8101a58 100644 --- a/BlazorSolution/MiniGamesTests/UnoTest.cs +++ b/BlazorSolution/MiniGamesTests/UnoTest.cs @@ -1,4 +1,6 @@ using MiniGames.Client.ViewModel; +using MiniGames.Shared.Models; +using Moq; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +14,60 @@ namespace MiniGamesTests { public Uno UnoRegeln = new(); + private HandKartenModel BeispielHand() + { + HandKartenModel HandStapel = new() + { + Id = 1, + Name = "Andrej", + KartenModels = new() + { + new KartenModel + { + Name = "2 Ziehen", + Farbe = "Gelb", + Spezial = true + } + } + }; + + return HandStapel; + } + + private StapelModel BeispielZiehKarten() + { + StapelModel TestStapel = new(); + TestStapel.KartenModels = new() + { + new KartenModel + { + Name = "Retoure", + Farbe = "Blau", + Spezial = true + }, + new KartenModel + { + Name = "Retoure", + Farbe = "Rot", + Spezial = true + }, + new KartenModel + { + Name = "Retoure", + Farbe = "Gruen", + Spezial = true + }, + new KartenModel + { + Name = "Retoure", + Farbe = "Gelb", + Spezial = true + }, + }; + return TestStapel; + } + + [Theory] [InlineData("rot", "rot", true)] [InlineData("blau", "rot", false)] @@ -32,5 +88,23 @@ namespace MiniGamesTests //assert Assert.Equal(_erwartet, erhalten); } + + [Fact] + private void ZiehEineKarteTest() + { + //arrange + StapelModel zuFüllend = new(); + var beispielStapel = BeispielZiehKarten(); + var beispielHand = BeispielHand(); + + //act + zuFüllend.KartenModels = UnoRegeln.ZiehEineKarte(beispielHand, beispielStapel).KartenModels; + + var erwartet = beispielStapel.KartenModels.FirstOrDefault(); + var erhalten = beispielHand.KartenModels.LastOrDefault(); + + //assert + Assert.Equal(erwartet, erhalten); + } } }