Browse Source

neuer test zum ziehen einer Karte

feature/uno
ADato88 2 years ago
parent
commit
e64c103512
  1. 1
      BlazorSolution/MiniGames/Client/Program.cs
  2. 12
      BlazorSolution/MiniGames/Client/ViewModel/IUno.cs
  3. 18
      BlazorSolution/MiniGames/Client/ViewModel/Uno.cs
  4. 16
      BlazorSolution/MiniGames/Shared/Models/HandKartenModel.cs
  5. 15
      BlazorSolution/MiniGames/Shared/Models/KartenModel.cs
  6. 13
      BlazorSolution/MiniGames/Shared/Models/StapelModel.cs
  7. 1
      BlazorSolution/MiniGamesTests/MiniGamesTests.csproj
  8. 74
      BlazorSolution/MiniGamesTests/UnoTest.cs

1
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<ISchereSteinPapierEchseSpock, SchereSteinPapierEchseSpock>();
builder.Services.AddScoped<IUno, Uno>();
await builder.Build().RunAsync();
}

12
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);
}
}

18
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;
}
}
}

16
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<KartenModel> KartenModels { get; set; }
}
}

15
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; }
}
}

13
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<KartenModel> KartenModels { get; set;}
}
}

1
BlazorSolution/MiniGamesTests/MiniGamesTests.csproj

@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

74
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);
}
}
}
Loading…
Cancel
Save