Skip to content

Commit

Permalink
Add missing async suffix and assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
araszka committed Aug 6, 2024
1 parent 90e3445 commit 1a8061a
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface IGameModeUiModuleService
/// <param name="y"></param>
/// <param name="scale"></param>
/// <returns></returns>
public Task<dynamic> GeneratePropertyObject(string uiModuleName, bool visible, double x, double y, double scale);
public Task<dynamic> GeneratePropertyObjectAsync(string uiModuleName, bool visible, double x, double y, double scale);
}
126 changes: 109 additions & 17 deletions src/Modules/GameModeUiModule/Services/GameModeUiModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
namespace EvoSC.Modules.Official.GameModeUiModule.Services;

[Service(LifeStyle = ServiceLifeStyle.Transient)]
public class GameModeUiModuleService(IServerClient server, IGameModeUiModuleSettings settings) : IGameModeUiModuleService
public class GameModeUiModuleService(IServerClient server, IGameModeUiModuleSettings settings)
: IGameModeUiModuleService
{
public async Task ApplyConfigurationAsync()
{
Expand All @@ -22,26 +23,117 @@ public async Task<string> GetUiModulesPropertiesJsonAsync()
{
uimodules = new List<dynamic>
{
await GeneratePropertyObject("Race_Chrono", settings.ChronoVisible, settings.ChronoX, settings.ChronoY, settings.ChronoScale),
await GeneratePropertyObject("Race_RespawnHelper", settings.RespawnHelperVisible, settings.RespawnHelperX, settings.RespawnHelperY, settings.RespawnHelperScale),
await GeneratePropertyObject("Race_Checkpoint", settings.CheckpointVisible, settings.CheckpointX, settings.CheckpointY, settings.CheckpointScale),
await GeneratePropertyObject("Race_LapsCounter", settings.LapsCounterVisible, settings.LapsCounterX, settings.LapsCounterY, settings.LapsCounterScale),
await GeneratePropertyObject("Race_TimeGap", settings.TimeGapVisible, settings.TimeGapX, settings.TimeGapY, settings.TimeGapScale),
await GeneratePropertyObject("Race_ScoresTable", settings.ScoresTableVisible, settings.ScoresTableX, settings.ScoresTableY, settings.ScoresTableScale),
await GeneratePropertyObject("Race_DisplayMessage", settings.DisplayMessageVisible, settings.DisplayMessageX, settings.DisplayMessageY, settings.DisplayMessageScale),
await GeneratePropertyObject("Race_Countdown", settings.CountdownVisible, settings.CountdownX, settings.CountdownY, settings.CountdownScale),
await GeneratePropertyObject("Race_SpectatorBase_Name", settings.SpectatorBaseNameVisible, settings.SpectatorBaseNameX, settings.SpectatorBaseNameY, settings.SpectatorBaseNameScale),
await GeneratePropertyObject("Race_SpectatorBase_Commands", settings.SpectatorBaseCommandsVisible, settings.SpectatorBaseCommandsX, settings.SpectatorBaseCommandsY, settings.SpectatorBaseCommandsScale),
await GeneratePropertyObject("Race_Record", settings.RecordVisible, settings.RecordX, settings.RecordY, settings.RecordScale),
await GeneratePropertyObject("Race_BigMessage", settings.BigMessageVisible, settings.BigMessageX, settings.BigMessageY, settings.BigMessageScale),
await GeneratePropertyObject("Race_BlockHelper", settings.BlockHelperVisible, settings.BlockHelperX, settings.BlockHelperY, settings.BlockHelperScale),
await GeneratePropertyObject("Race_WarmUp", settings.WarmUpVisible, settings.WarmUpX, settings.WarmUpY, settings.WarmUpScale),
await GeneratePropertyObject("Race_BestRaceViewer", settings.BestRaceViewerVisible, settings.BestRaceViewerX, settings.BestRaceViewerY, settings.BestRaceViewerScale),
await GeneratePropertyObjectAsync(
"Race_Chrono",
settings.ChronoVisible,
settings.ChronoX,
settings.ChronoY,
settings.ChronoScale
),
await GeneratePropertyObjectAsync(
"Race_RespawnHelper",
settings.RespawnHelperVisible,
settings.RespawnHelperX,
settings.RespawnHelperY,
settings.RespawnHelperScale
),
await GeneratePropertyObjectAsync(
"Race_Checkpoint",
settings.CheckpointVisible,
settings.CheckpointX,
settings.CheckpointY,
settings.CheckpointScale
),
await GeneratePropertyObjectAsync(
"Race_LapsCounter",
settings.LapsCounterVisible,
settings.LapsCounterX,
settings.LapsCounterY,
settings.LapsCounterScale
),
await GeneratePropertyObjectAsync(
"Race_TimeGap",
settings.TimeGapVisible,
settings.TimeGapX,
settings.TimeGapY,
settings.TimeGapScale
),
await GeneratePropertyObjectAsync(
"Race_ScoresTable",
settings.ScoresTableVisible,
settings.ScoresTableX,
settings.ScoresTableY,
settings.ScoresTableScale
),
await GeneratePropertyObjectAsync(
"Race_DisplayMessage",
settings.DisplayMessageVisible,
settings.DisplayMessageX,
settings.DisplayMessageY,
settings.DisplayMessageScale
),
await GeneratePropertyObjectAsync(
"Race_Countdown",
settings.CountdownVisible,
settings.CountdownX,
settings.CountdownY,
settings.CountdownScale
),
await GeneratePropertyObjectAsync(
"Race_SpectatorBase_Name",
settings.SpectatorBaseNameVisible,
settings.SpectatorBaseNameX,
settings.SpectatorBaseNameY,
settings.SpectatorBaseNameScale
),
await GeneratePropertyObjectAsync(
"Race_SpectatorBase_Commands",
settings.SpectatorBaseCommandsVisible,
settings.SpectatorBaseCommandsX,
settings.SpectatorBaseCommandsY,
settings.SpectatorBaseCommandsScale
),
await GeneratePropertyObjectAsync(
"Race_Record",
settings.RecordVisible,
settings.RecordX,
settings.RecordY,
settings.RecordScale
),
await GeneratePropertyObjectAsync(
"Race_BigMessage",
settings.BigMessageVisible,
settings.BigMessageX,
settings.BigMessageY,
settings.BigMessageScale
),
await GeneratePropertyObjectAsync(
"Race_BlockHelper",
settings.BlockHelperVisible,
settings.BlockHelperX,
settings.BlockHelperY,
settings.BlockHelperScale
),
await GeneratePropertyObjectAsync(
"Race_WarmUp",
settings.WarmUpVisible,
settings.WarmUpX,
settings.WarmUpY,
settings.WarmUpScale
),
await GeneratePropertyObjectAsync(
"Race_BestRaceViewer",
settings.BestRaceViewerVisible,
settings.BestRaceViewerX,
settings.BestRaceViewerY,
settings.BestRaceViewerScale
),
}
});
}

public Task<dynamic> GeneratePropertyObject(string uiModuleName, bool visible, double x, double y, double scale)
public Task<dynamic> GeneratePropertyObjectAsync(string uiModuleName, bool visible, double x, double y,
double scale)
{
return Task.FromResult<dynamic>(new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private IGameModeUiModuleService UiModuleServiceMock()
public async Task Generates_Property_Object(string id, bool visible, double x, double y, double scale)
{
var uiModuleService = UiModuleServiceMock();
var uiModulePropertyObject = await uiModuleService.GeneratePropertyObject(id, visible, x, y, scale);
var uiModulePropertyObject = await uiModuleService.GeneratePropertyObjectAsync(id, visible, x, y, scale);

var idProperty = uiModulePropertyObject.GetType().GetProperty("id");
Assert.Equal(id, idProperty.GetValue(uiModulePropertyObject, null));
Expand Down Expand Up @@ -62,6 +62,7 @@ public async Task Gets_Ui_Module_Properties_As_Json()
var uiModuleService = UiModuleServiceMock();
var uiModuleProperties = await uiModuleService.GetUiModulesPropertiesJsonAsync();

Assert.IsType<string>(uiModuleProperties);
JToken.Parse(uiModuleProperties);
}

Expand Down

0 comments on commit 1a8061a

Please sign in to comment.