Skip to content

Commit

Permalink
Merge pull request #8 from GranDen-Corp/dev
Browse files Browse the repository at this point in the history
Bugfix/fix unit tests (#7)
  • Loading branch information
windperson authored Jul 6, 2020
2 parents 42e749a + 8d9a445 commit 4bf02dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
7 changes: 3 additions & 4 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project>
<PropertyGroup>
<Version Condition=" '$(Version)'=='' ">0.0.3</Version>
<PackageReleaseNotes>0.0.3 :
&#xD;&#xA;1. Add bingo game preset data mechanism.
&#xD;&#xA;2. Modifiy existing geo point preset data methods.
<Version Condition=" '$(Version)'=='' ">0.0.4</Version>
<PackageReleaseNotes>0.0.4 :
&#xD;&#xA;Rename Preset seeding extension methods for better naming, and prevent existing BingoGameInfo entities being overwritten.
&#xD;&#xA;
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static IServiceCollection ConfigPresetGeoPointData(this IServiceCollectio
/// <param name="geoPointIds">Additional Preset Data</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static IServiceProvider InitGeoPointData(this IServiceProvider serviceProvider,
public static IServiceProvider InitPresetGeoPointData(this IServiceProvider serviceProvider,
IEnumerable<string> geoPointIds = null)
{
var mappingGeoPointsRepo = serviceProvider.GetService<IMappingGeoPointsRepo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static IServiceCollection ConfigPresetBingoGameData(this IServiceCollecti
/// <param name="serviceProvider"></param>
/// <param name="bingoGameOption"></param>
/// <returns></returns>
public static IServiceProvider InitBingoGameData(this IServiceProvider serviceProvider, BingoGameOption bingoGameOption)
public static IServiceProvider InitPresetBingoGameData(this IServiceProvider serviceProvider, BingoGameOption bingoGameOption)
{
var gameInfoDtos = bingoGameOption.Select(o =>
new BingoGameInfoDto
Expand All @@ -70,7 +70,7 @@ public static IServiceProvider InitBingoGameData(this IServiceProvider servicePr
Enabled = true
}).ToList();

return InitBingoGameData(serviceProvider, gameInfoDtos);
return InitPresetBingoGameData(serviceProvider, gameInfoDtos);
}

/// <summary>
Expand All @@ -80,7 +80,7 @@ public static IServiceProvider InitBingoGameData(this IServiceProvider servicePr
/// <param name="bingoGameInfos">Additional Preset Data</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static IServiceProvider InitBingoGameData(this IServiceProvider serviceProvider, IEnumerable<BingoGameInfoDto> bingoGameInfos = null)
public static IServiceProvider InitPresetBingoGameData(this IServiceProvider serviceProvider, IEnumerable<BingoGameInfoDto> bingoGameInfos = null)
{
var bingoGameInfoRepo = serviceProvider.GetService<IBingoGameInfoRepo>();
var presetBingoGameService = serviceProvider.GetService<IPresetBingoGameService>();
Expand All @@ -91,15 +91,10 @@ public static IServiceProvider InitBingoGameData(this IServiceProvider servicePr
{
if (bingoGameInfoRepo.QueryBingoGames().Any(g => g.GameName == bingoGameInfoDto.GameName))
{
if (!bingoGameInfoRepo.UpdateBingoGame(bingoGameInfoDto))
{
throw new Exception($"Update existing Bingo Game {bingoGameInfoDto.GameName} failed.");
}
}
else
{
bingoGameInfoRepo.CreateBingoGame(bingoGameInfoDto);
continue;
}

bingoGameInfoRepo.CreateBingoGame(bingoGameInfoDto);
}
}

Expand All @@ -112,15 +107,10 @@ public static IServiceProvider InitBingoGameData(this IServiceProvider servicePr
{
if (bingoGameInfoRepo.QueryBingoGames().Any(g => g.GameName == bingoGameInfoDto.GameName))
{
if (!bingoGameInfoRepo.UpdateBingoGame(bingoGameInfoDto))
{
throw new Exception($"Update existing Bingo Game {bingoGameInfoDto.GameName} failed.");
}
}
else
{
bingoGameInfoRepo.CreateBingoGame(bingoGameInfoDto);
continue;;
}

bingoGameInfoRepo.CreateBingoGame(bingoGameInfoDto);
}

return serviceProvider;
Expand Down
11 changes: 7 additions & 4 deletions test/GranDen.Game.ApiLib.Bingo.Test/BingoPlayerApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public void PlayerCanAddBingoPointStatusDuringValidGamePeriod()
Assert.True(marked2);
var bingoPointRepo = _serviceProvider.GetService<IBingoPointRepo>();
var markedPoints = bingoPointRepo.QueryBingoPoints(PresetBingoGameName, testPlayerId)
.Include(m => m.BelongingGame).Include(m => m.BelongingPlayer).Where(p => p.MarkPoint.Marked).ToList();
.Include(m => m.BelongingGame).Include(m => m.BelongingPlayer)
.Where(p => p.MarkPoint.Marked).OrderBy(p => p.MarkPoint.X).ThenBy(p => p.MarkPoint.Y).ToList();

Assert.Equal(3, markedPoints.Count);

Expand Down Expand Up @@ -255,16 +256,18 @@ private void InitServices()

private void PresetData()
{
var dbContext = _serviceProvider.GetService<BingoGameDbContext>();
using var serviceScope = _serviceProvider.CreateScope();
var serviceProvider = serviceScope.ServiceProvider;
var dbContext = serviceProvider.GetService<BingoGameDbContext>();

//NOTE: doesn't know why in-memory SQLite DB cannot just call Migration() to create DB Schema
if (!dbContext.Database.EnsureCreated())
{
dbContext.Database.Migrate();
}

_serviceProvider.InitGeoPointData();
_serviceProvider.InitBingoGameData();
serviceProvider.InitPresetGeoPointData();
serviceProvider.InitPresetBingoGameData();
}

private static DbConnection CreateInMemoryDatabase()
Expand Down

0 comments on commit 4bf02dd

Please sign in to comment.