Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement worker #43

Merged
merged 9 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"strawberryshake.tools": {
"version": "14.3.0",
"commands": [
"dotnet-graphql"
],
"rollForward": false
}
}
}
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "NineChronicles.RPC.Shared"]
path = NineChronicles.RPC.Shared
url = [email protected]:planetarium/NineChronicles.RPC.Shared.git
[submodule "Lib9c"]
path = Lib9c
url = [email protected]:planetarium/lib9c.git
28 changes: 27 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
},
{
"name": "Debug ArenaService.Worker",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/ArenaService.Worker/bin/Debug/net8.0/ArenaService.Worker.dll",
"cwd": "${workspaceFolder}/ArenaService.Worker",
"stopAtEntry": false,
"console": "internalConsole",
"preLaunchTask": "build-worker",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
{
"type": "node",
"request": "launch",
"name": "Debug Worker",
"runtimeExecutable": "pnpm",
"runtimeArgs": ["start"],
"skipFiles": ["<node_internals>/**"],
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/Worker/.env",
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/Worker/dist/**/*.js"],
"console": "integratedTerminal"
},
]
}
14 changes: 13 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
},
{
"label": "build-worker",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/ArenaService.Worker/ArenaService.Worker.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
]
}
2 changes: 1 addition & 1 deletion ArenaService.Tests/Auth/JwtCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ArenaService.Tests.Auth;

public class JwtCreator
{
public static string CreateJwt(PrivateKey privateKey, string role = "user")
public static string CreateJwt(PrivateKey privateKey, string role = "User")
{
var payload = new
{
Expand Down
192 changes: 96 additions & 96 deletions ArenaService.Tests/Controllers/BattleControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
using System.Security.Claims;
using ArenaService.Controllers;
using ArenaService.Models;
using ArenaService.Repositories;
using ArenaService.Tests.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Moq;
// using System.Security.Claims;
// using ArenaService.Controllers;
// using ArenaService.Models;
// using ArenaService.Repositories;
// using ArenaService.Tests.Utils;
// using Microsoft.AspNetCore.Http;
// using Microsoft.AspNetCore.Http.HttpResults;
// using Microsoft.AspNetCore.Mvc;
// using Moq;

namespace ArenaService.Tests.Controllers;
// namespace ArenaService.Tests.Controllers;

public class BattleControllerTests
{
private readonly BattleController _controller;
private Mock<IAvailableOpponentRepository> _availableOpponentRepoMock;
private Mock<IParticipantRepository> _participantRepoMock;
private Mock<IBattleLogRepository> _battleLogRepoMock;
// public class BattleControllerTests
// {
// private readonly BattleController _controller;
// private Mock<IAvailableOpponentRepository> _availableOpponentRepoMock;
// private Mock<IParticipantRepository> _participantRepoMock;
// private Mock<IBattleLogRepository> _battleLogRepoMock;

public BattleControllerTests()
{
var availableOpponentRepoMock = new Mock<IAvailableOpponentRepository>();
_availableOpponentRepoMock = availableOpponentRepoMock;
var participantRepoMock = new Mock<IParticipantRepository>();
_participantRepoMock = participantRepoMock;
var battleLogRepoMock = new Mock<IBattleLogRepository>();
_battleLogRepoMock = battleLogRepoMock;
_controller = new BattleController(
_availableOpponentRepoMock.Object,
_participantRepoMock.Object,
_battleLogRepoMock.Object
);
}
// public BattleControllerTests()
// {
// var availableOpponentRepoMock = new Mock<IAvailableOpponentRepository>();
// _availableOpponentRepoMock = availableOpponentRepoMock;
// var participantRepoMock = new Mock<IParticipantRepository>();
// _participantRepoMock = participantRepoMock;
// var battleLogRepoMock = new Mock<IBattleLogRepository>();
// _battleLogRepoMock = battleLogRepoMock;
// _controller = new BattleController(
// _availableOpponentRepoMock.Object,
// _participantRepoMock.Object,
// _battleLogRepoMock.Object
// );
// }

[Fact]
public async Task GetBattleToken_WithValidHeader_ReturnsOk()
{
var avatarAddress = "DDF1472fD5a79B8F46C28e7643eDEF045e36BD3d";
ControllerTestUtils.ConfigureMockHttpContextWithAuth(_controller, avatarAddress);
// [Fact]
// public async Task GetBattleToken_WithValidHeader_ReturnsOk()
// {
// var avatarAddress = "DDF1472fD5a79B8F46C28e7643eDEF045e36BD3d";
// ControllerTestUtils.ConfigureMockHttpContextWithAuth(_controller, avatarAddress);

_participantRepoMock
.Setup(repo => repo.GetParticipantByAvatarAddressAsync(1, avatarAddress))
.ReturnsAsync(
new Participant
{
Id = 1,
AvatarAddress = avatarAddress,
NameWithHash = "test",
PortraitId = 1
}
);
// _participantRepoMock
// .Setup(repo => repo.GetParticipantByAvatarAddressAsync(1, avatarAddress))
// .ReturnsAsync(
// new Participant
// {
// Id = 1,
// AvatarAddress = avatarAddress,
// NameWithHash = "test",
// PortraitId = 1
// }
// );

_availableOpponentRepoMock
.Setup(repo => repo.GetAvailableOpponents(1))
.ReturnsAsync(
[
new AvailableOpponent
{
Id = 1,
ParticipantId = 1,
OpponentId = 2,
Opponent = new Participant
{
Id = 2,
AvatarAddress = "test",
NameWithHash = "opponent1",
PortraitId = 1
},
RefillBlockIndex = 1
},
new AvailableOpponent
{
Id = 2,
ParticipantId = 1,
OpponentId = 3,
Opponent = new Participant
{
Id = 3,
AvatarAddress = "test",
NameWithHash = "opponent2",
PortraitId = 1
},
RefillBlockIndex = 1
}
]
);
// _availableOpponentRepoMock
// .Setup(repo => repo.GetAvailableOpponents(1))
// .ReturnsAsync(
// [
// new AvailableOpponent
// {
// Id = 1,
// ParticipantId = 1,
// OpponentId = 2,
// Opponent = new Participant
// {
// Id = 2,
// AvatarAddress = "test",
// NameWithHash = "opponent1",
// PortraitId = 1
// },
// RefillBlockIndex = 1
// },
// new AvailableOpponent
// {
// Id = 2,
// ParticipantId = 1,
// OpponentId = 3,
// Opponent = new Participant
// {
// Id = 3,
// AvatarAddress = "test",
// NameWithHash = "opponent2",
// PortraitId = 1
// },
// RefillBlockIndex = 1
// }
// ]
// );

_battleLogRepoMock
.Setup(repo => repo.AddBattleLogAsync(1, 1, 1, "token"))
.ReturnsAsync(
new BattleLog
{
Id = 1,
ParticipantId = 1,
OpponentId = 1,
SeasonId = 1,
Token = "token"
}
);
// _battleLogRepoMock
// .Setup(repo => repo.AddBattleLogAsync(1, 1, 1, "token"))
// .ReturnsAsync(
// new BattleLog
// {
// Id = 1,
// ParticipantId = 1,
// OpponentId = 1,
// SeasonId = 1,
// Token = "token"
// }
// );

var result = await _controller.CreateBattleToken(1, 1);
// var result = await _controller.CreateBattleToken(1, 1);

var okResult = Assert.IsType<Ok<string>>(result.Result);
}
}
// var okResult = Assert.IsType<Ok<string>>(result.Result);
// }
// }
15 changes: 15 additions & 0 deletions ArenaService.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArenaService", "ArenaServic
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArenaService.Tests", "ArenaService.Tests\ArenaService.Tests.csproj", "{C9C1D7B6-AB58-43C4-9043-8D934B21F10F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib9c", "Lib9c", "{0B86B22F-AD27-4FF2-95B8-9FE298CDFF28}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c", "Lib9c\Lib9c\Lib9c.csproj", "{2ABF529F-81E0-4343-BBE1-CC8B4FD84939}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +28,16 @@ Global
{C9C1D7B6-AB58-43C4-9043-8D934B21F10F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9C1D7B6-AB58-43C4-9043-8D934B21F10F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9C1D7B6-AB58-43C4-9043-8D934B21F10F}.Release|Any CPU.Build.0 = Release|Any CPU
{628EBB8C-A264-4491-92E8-D7CE892F9BC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{628EBB8C-A264-4491-92E8-D7CE892F9BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{628EBB8C-A264-4491-92E8-D7CE892F9BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{628EBB8C-A264-4491-92E8-D7CE892F9BC7}.Release|Any CPU.Build.0 = Release|Any CPU
{2ABF529F-81E0-4343-BBE1-CC8B4FD84939}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2ABF529F-81E0-4343-BBE1-CC8B4FD84939}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2ABF529F-81E0-4343-BBE1-CC8B4FD84939}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2ABF529F-81E0-4343-BBE1-CC8B4FD84939}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2ABF529F-81E0-4343-BBE1-CC8B4FD84939} = {0B86B22F-AD27-4FF2-95B8-9FE298CDFF28}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions ArenaService/ArenaService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

<ItemGroup>
<PackageReference Include="EFCore.NamingConventions" Version="8.0.0" />
<PackageReference Include="Hangfire" Version="1.8.17" />
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4" />
<PackageReference Include="Libplanet.Crypto" Version="5.4.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="StrawberryShake.Server" Version="14.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Lib9c\Lib9c\Lib9c.csproj" />
</ItemGroup>
</Project>
Loading
Loading