Update rank service to handle dealing with rank entries that dont make it on the list and adding start of unit tests
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TOOHUCardAPI", "TOOHUCardAPI\TOOHUCardAPI.csproj", "{952B5298-5B24-49AC-89DE-0A46F6B1F071}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TOOHUCardAPITests", "TOOHUCardAPITests\TOOHUCardAPITests.csproj", "{ABB94AE7-209A-4588-A8FB-10AB9782B8DB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -12,5 +14,9 @@ Global
|
||||
{952B5298-5B24-49AC-89DE-0A46F6B1F071}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{952B5298-5B24-49AC-89DE-0A46F6B1F071}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{952B5298-5B24-49AC-89DE-0A46F6B1F071}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ABB94AE7-209A-4588-A8FB-10AB9782B8DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ABB94AE7-209A-4588-A8FB-10AB9782B8DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ABB94AE7-209A-4588-A8FB-10AB9782B8DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ABB94AE7-209A-4588-A8FB-10AB9782B8DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace TOOHUCardAPI.DTO.RankData
|
||||
{
|
||||
public class RankDataResetResponse : OkResponse
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace TOOHUCardAPI.DTO.RankData
|
||||
{
|
||||
public class RankDataUploadRequest : AbstractPlayerTargetedRequest
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace TOOHUCardAPI.DTO.RankData
|
||||
{
|
||||
public class RankDataUploadResponse : OkResponse
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,10 @@ namespace TOOHUCardAPI.Data.Services
|
||||
{
|
||||
int bonus = AppSettings.DefaultRankBonus;
|
||||
int index = allEntries.FindIndex(i => i.Id == entry.Id)+1;
|
||||
if (index <= 0)
|
||||
{
|
||||
index = allEntries.Count + 1;
|
||||
}
|
||||
switch (index)
|
||||
{
|
||||
case <= 4:
|
||||
@@ -77,7 +81,27 @@ namespace TOOHUCardAPI.Data.Services
|
||||
TowersUsed = towersUsed,
|
||||
UpdateTime = DateTime.Now
|
||||
};
|
||||
toUpload = await _rankRepository.InsertRankEntry(toUpload);
|
||||
var previousEntry = await _rankRepository.GetRankEntry(toUpload.User.SteamId, toUpload.RankType);
|
||||
bool shouldPushNew = true;
|
||||
if (previousEntry != null)
|
||||
{
|
||||
if (previousEntry.Wave < toUpload.Wave)
|
||||
{
|
||||
await ResetRank(toUpload.User.SteamId, toUpload.RankType);
|
||||
}
|
||||
else if (previousEntry.Wave == toUpload.Wave && previousEntry.Damage < toUpload.Damage)
|
||||
{
|
||||
await ResetRank(toUpload.User.SteamId, toUpload.RankType);
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldPushNew = false;
|
||||
}
|
||||
}
|
||||
if (shouldPushNew)
|
||||
{
|
||||
toUpload = await _rankRepository.InsertRankEntry(toUpload);
|
||||
}
|
||||
List<RankEntry> allEntries = (await _rankRepository.GetRankEntries(toUpload.RankType)).ToList();
|
||||
await _userService.UpdateUserAccountDetails(entry.SteamId, entry.UserId, entry.Username);
|
||||
await _userService.UpdateUserMaxWave(entry.SteamId, entry.Wave, toUpload.RankType);
|
||||
|
||||
15
TOOHUCardAPITests/TOOHUCardAPITests.csproj
Normal file
15
TOOHUCardAPITests/TOOHUCardAPITests.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.12.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
TOOHUCardAPITests/UnitTest1.cs
Normal file
18
TOOHUCardAPITests/UnitTest1.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace TOOHUCardAPITests
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user