Skip to content

Commit

Permalink
v3.9.3 (#186)
Browse files Browse the repository at this point in the history
* Refactor - move SimpleEntity into Gameboard.Api.Features.Common.

* Don't bootstrap JobsService in integration test env

* Address an issue where Gameboard was incorrectly evaluating whether a challenge has a deployed gamespace after destroy. Resolves #182.
  • Loading branch information
sei-bstein authored May 18, 2023
1 parent fc69482 commit da39012
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,40 @@ public void MapStringState_WithCompleteData_PopulatesSpotCheckedFields()
mapped.Vms.FirstOrDefault(vm => vm.IsolationId == "vm2").ShouldNotBeNull();
mapped.Challenge.Questions.First().IsCorrect.ShouldBeFalse();
}

[Theory, GameboardAutoData]
public void MapStateToChallenge_WithIsActiveTrueAndNoVms_YieldsHasActiveGamespaceFalse(IFixture fixture)
{
// given
var state = new GameEngineGameState
{
Id = fixture.Create<string>(),
Name = fixture.Create<string>(),
ManagerId = fixture.Create<string>(),
ManagerName = fixture.Create<string>(),
IsActive = true,
Players = new GameEnginePlayer[]
{
new GameEnginePlayer
{
SubjectId = fixture.Create<string>(),
IsManager = true
}
},
WhenCreated = fixture.Create<DateTimeOffset>(),
StartTime = fixture.Create<DateTimeOffset>(),
EndTime = fixture.Create<DateTimeOffset>(),
ExpirationTime = fixture.Create<DateTimeOffset>(),
Vms = new GameEngineVmState[] { }
};

var mapperConfig = new MapperConfiguration(cfg => cfg.AddProfile(new GameEngineMaps()));
var mapper = new Mapper(mapperConfig);

// when
var mapped = mapper.Map<Data.Challenge>(state);

// then
mapped.HasDeployedGamespace.ShouldBeFalse();
}
}
3 changes: 3 additions & 0 deletions src/Gameboard.Api/Extensions/IWebHostEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public static bool IsDev(this IWebHostEnvironment env)
{
return env.EnvironmentName == _envDev;
}

public static bool IsTest(this IWebHostEnvironment env)
=> env.EnvironmentName == _envTest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ public static void ConfigureServices(this WebApplicationBuilder builder, AppSett
.AddGameboardData(settings.Database.Provider, settings.Database.ConnectionString)
.AddGameboardServices(settings)
.AddConfiguredHttpClients(settings.Core)
.AddHostedService<JobService>()
.AddDefaults(settings.Defaults, builder.Environment.ContentRootPath)
.AddGameboardMediatR();

// don't add the job service during test - we don't want it to interfere with CI
if (!builder.Environment.IsTest())
services.AddHostedService<JobService>();

services.AddSingleton<AutoMapper.IMapper>(
new AutoMapper.MapperConfiguration(cfg =>
{
Expand Down
3 changes: 2 additions & 1 deletion src/Gameboard.Api/Features/Challenge/ChallengeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ public async Task<Challenge> StopGamespace(string id, string actorId)
Type = ChallengeEventType.GamespaceOff
});

await Sync(
await Sync
(
entity,
GameEngine.StopGamespace(entity)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AutoMapper;
using Gameboard.Api.Data;
using Gameboard.Api.Structure;
using Gameboard.Api.Features.Common;

namespace Gameboard.Api.Features.ChallengeBonuses;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Gameboard.Api;
using Gameboard.Api.Structure;
using Gameboard.Api.Features.Common;

public class CreateManualChallengeBonus
{
Expand Down
15 changes: 15 additions & 0 deletions src/Gameboard.Api/Features/Common/CommonModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Gameboard.Api.Features.Common;

public class SimpleEntity
{
public string Id { get; set; }
public string Name { get; set; }
}

public sealed class DateRange
{
public DateTimeOffset Start { get; set; }
public DateTimeOffset End { get; set; }
}
18 changes: 18 additions & 0 deletions src/Gameboard.Api/Features/ExternalGames/ExternalGamesModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Gameboard.Api.Features.Common;

namespace Gameboard.Api.Features.ExternalGames;

// public sealed class ExternalGameMetaData
// {
// public required SimpleEntity Game { get; set; }

// }

// public sealed class ExternalGameMetaDataTeam
// {
// public required string Id { get; set; }
// public required string Name { get; set; }
// public required DateRange Session { get; set; }
// }

// public sealed class
2 changes: 1 addition & 1 deletion src/Gameboard.Api/Features/Game/GameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
using System.Text.Json;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using Gameboard.Api.Features.Common;
using Gameboard.Api.Features.Games;
using Gameboard.Api.Structure;

namespace Gameboard.Api.Services;

Expand Down
2 changes: 1 addition & 1 deletion src/Gameboard.Api/Features/Game/SyncStartModels.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Gameboard.Api.Structure;
using Gameboard.Api.Features.Common;

namespace Gameboard.Api.Features.Games;

Expand Down
14 changes: 7 additions & 7 deletions src/Gameboard.Api/Features/GameEngine/GameEngineMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ public GameEngineMaps()
.ForSourceMember(gep => gep.Permission, o => o.DoNotValidate())
.ForSourceMember(gep => gep.GamespaceId, o => o.DoNotValidate());

CreateMap<GameEngineGameState, Api.Data.Challenge>(MemberList.Destination)
CreateMap<GameEngineGameState, Api.Data.Challenge>()
.ForMember(c => c.EndTime, o => o.MapFrom(s => s.ExpirationTime))
.ForMember(c => c.HasDeployedGamespace, o => o.MapFrom(s => s.HasDeployedGamespace))
.ForMember(c => c.LastScoreTime, o => o.MapFrom(s => s.Challenge.LastScoreTime))
.ForMember(c => c.ExternalId, o => o.MapFrom(s => s.Id))
.ForMember(c => c.PlayerId, o => o.MapFrom(p => p.Players.Where(p => p.IsManager).First().SubjectId))
.ForMember(c => c.HasDeployedGamespace, o => o.MapFrom(s => s.IsActive))
.ForMember(c => c.EndTime, o => o.MapFrom(s => s.ExpirationTime))
.ForMember(c => c.Points, o => o.MapFrom(s => s.Challenge.MaxPoints))
.ForMember(c => c.LastScoreTime, o => o.MapFrom(s => s.Challenge.LastScoreTime))
.ForMember(c => c.Score, o => o.MapFrom(s => s.Challenge.Score))
.ForMember(c => c.State, o => o.MapFrom(s => jsonService.Serialize(s)))
.ForMember(c => c.Events, o => o.Ignore())
.ForMember(c => c.Feedback, o => o.Ignore())
.ForMember(c => c.Game, o => o.Ignore())
// ignore entity properties because we don't want EF to think that we're trying to insert new ones
.ForMember(c => c.Player, o => o.Ignore())
// game engine type will need to be resolved using an aftermap expression during mapping
.ForMember(c => c.GameEngineType, o => o.Ignore())
// similarly, engines don't know about things like games, tickets, and bonuses
.ForMember(c => c.Events, o => o.Ignore())
.ForMember(c => c.Feedback, o => o.Ignore())
.ForMember(c => c.GameId, o => o.Ignore())
.ForMember(c => c.Game, o => o.Ignore())
.ForMember(c => c.GraderKey, o => o.Ignore())
.ForMember(c => c.LastSyncTime, o => o.Ignore())
.ForMember(c => c.SpecId, o => o.Ignore())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Gameboard.Api.Features.GameEngine;

Expand Down Expand Up @@ -33,6 +34,11 @@ public class GameEngineGameState
public DateTimeOffset ExpirationTime { get; set; }
public IEnumerable<GameEngineVmState> Vms { get; set; }
public GameEngineChallengeView Challenge { get; set; }

public bool HasDeployedGamespace
{
get => Vms != null && Vms.Count() > 0;
}
}

public class GameEnginePlayer
Expand Down
2 changes: 1 addition & 1 deletion src/Gameboard.Api/Features/Scores/ScoringModels.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Gameboard.Api.Structure;
using Gameboard.Api.Features.Common;

public class TeamChallengeScoreSummary
{
Expand Down
2 changes: 1 addition & 1 deletion src/Gameboard.Api/Features/Scores/ScoringService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using AutoMapper;
using Gameboard.Api.Data;
using Gameboard.Api.Data.Abstractions;
using Gameboard.Api.Features.Common;
using Gameboard.Api.Features.Teams;
using Gameboard.Api.Structure;
using Microsoft.EntityFrameworkCore;

namespace Gameboard.Api.Features.Scores;
Expand Down
7 changes: 0 additions & 7 deletions src/Gameboard.Api/Structure/Models/SimpleEntity.cs

This file was deleted.

0 comments on commit da39012

Please sign in to comment.