Changed to primary ctor and fixed warnings

This commit is contained in:
CWX
2025-01-18 12:43:53 +00:00
parent 0d3006c7c0
commit 09ac1e8b72
4 changed files with 96 additions and 109 deletions
+9 -22
View File
@@ -3,8 +3,6 @@ using Core.Context;
using Core.Controllers;
using Core.Models.Eft.Bot;
using Core.Models.Eft.Common;
using Core.Models.Eft.Common.Tables;
using Core.Models.Eft.HttpResponse;
using Core.Models.Eft.Match;
using Core.Utils;
@@ -12,23 +10,12 @@ namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(BotCallbacks))]
public class BotCallbacks
(
BotController _botController,
HttpResponseUtil _httpResponseUtil,
ApplicationContext _applicationContext
)
{
protected BotController _botController;
protected HttpResponseUtil _httpResponseUtil;
protected ApplicationContext _applicationContext;
public BotCallbacks
(
BotController botController,
HttpResponseUtil httpResponseUtil,
ApplicationContext applicationContext
)
{
_botController = botController;
_httpResponseUtil = httpResponseUtil;
_applicationContext = applicationContext;
}
/// <summary>
/// Handle singleplayer/settings/bot/limit
/// Is called by client to define each bot roles wave limit
@@ -41,7 +28,7 @@ public class BotCallbacks
public string GetBotLimit(string url, EmptyRequestData info, string sessionID)
{
var splitUrl = url.Split('/');
var type = splitUrl[splitUrl.Length - 1];
var type = splitUrl[^1];
return _httpResponseUtil.NoBody(_botController.GetBotPresetGenerationLimit(type));
}
@@ -55,8 +42,8 @@ public class BotCallbacks
public string GetBotDifficulty(string url, EmptyRequestData info, string sessionID)
{
var splitUrl = url.Split('/');
var type = splitUrl[splitUrl.Length - 2].ToLower();
var difficulty = splitUrl[splitUrl.Length - 1];
var type = splitUrl[^2].ToLower();
var difficulty = splitUrl[^1];
if (difficulty == "core")
return _httpResponseUtil.NoBody(_botController.GetBotCoreDifficulty());
@@ -96,7 +83,7 @@ public class BotCallbacks
public string GetBotCap(string url, EmptyRequestData info, string sessionID)
{
var splitUrl = url.Split('/');
var location = splitUrl[splitUrl.Length - 1];
var location = splitUrl[^1];
return _httpResponseUtil.NoBody(_botController.GetBotCap(location));
}
+1 -1
View File
@@ -101,7 +101,7 @@ public class BotController
return _databaseService.GetBots().Core;
}
public DifficultyCategories GetBotDifficulty(string type, string diffLevel, GetRaidConfigurationRequestData raidConfig, bool ignoreRaidSettings = false)
public DifficultyCategories GetBotDifficulty(string type, string diffLevel, GetRaidConfigurationRequestData? raidConfig, bool ignoreRaidSettings = false)
{
var difficulty = diffLevel.ToLower();
@@ -9,7 +9,7 @@ namespace Core.Routers.Static;
[Injectable(InjectableTypeOverride = typeof(StaticRouter))]
public class AchievementStaticRouter : StaticRouter
{
protected static AchievementCallbacks _achievementCallbacks;
private static AchievementCallbacks? _achievementCallbacks;
public AchievementStaticRouter(
JsonUtil jsonUtil,
@@ -24,7 +24,7 @@ public class AchievementStaticRouter : StaticRouter
info,
sessionID,
output
) => _achievementCallbacks.GetAchievements(url, info as EmptyRequestData, sessionID)),
) => _achievementCallbacks?.GetAchievements(url, info as EmptyRequestData, sessionID)),
new RouteAction(
"/client/achievement/statistic",
(
@@ -32,7 +32,7 @@ public class AchievementStaticRouter : StaticRouter
info,
sessionID,
output
) => _achievementCallbacks.Statistic(url, info as EmptyRequestData, sessionID)),
) => _achievementCallbacks?.Statistic(url, info as EmptyRequestData, sessionID)),
]
)
{
+83 -83
View File
@@ -1,83 +1,83 @@
using Core.Utils;
namespace UnitTests.Tests.Utils;
[TestClass]
public class MathUtilTests
{
protected MathUtil _mathUtil = new();
[TestMethod]
public void ListSumTest()
{
var test = new List<float> { 1.1f, 2.1f, 3.3f };
const float expected = 6.5f;
var actual = _mathUtil.ListSum(test);
Assert.AreEqual(expected, actual,
$"ListSum() Expected: {expected}, Actual: {actual}");
}
[TestMethod]
public void ListCumSumTest()
{
var test = new List<float> { 1f, 2f, 3f, 4f };
var expected = new List<float> { 1f, 3f, 6f, 10f };
var actual = _mathUtil.ListCumSum(test);
for (var i = 0; i < actual.Count; i++)
{
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
{
Assert.Fail($"ListCumSum() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
}
}
}
[TestMethod]
public void ListProductTest()
{
var test = new List<float> { 1f, 2f, 3f, 4f };
var expected = new List<float> { 2f, 4f, 6f, 8f };
var actual = _mathUtil.ListProduct(test, 2);
for (var i = 0; i < actual.Count; i++)
{
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
{
Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
}
}
}
[TestMethod]
public void ListAddTest()
{
var test = new List<float> { 1f, 2f, 3f, 4f };
var expected = new List<float> { 3f, 4f, 5f, 6f };
var actual = _mathUtil.ListAdd(test, 2);
for (var i = 0; i < actual.Count; i++)
{
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
{
Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
}
}
}
[TestMethod]
public void MapToRangeTest()
{
const double expected = 2;
var actual = _mathUtil.MapToRange(0.5, 0, 1, 1, 3);
Assert.AreEqual(expected, actual,
$"MapToRange() Expected: {expected}, Actual: {actual}");
}
}
// using Core.Utils;
//
// namespace UnitTests.Tests.Utils;
//
// [TestClass]
// public class MathUtilTests
// {
// protected MathUtil _mathUtil = new();
//
// [TestMethod]
// public void ListSumTest()
// {
// var test = new List<float> { 1.1f, 2.1f, 3.3f };
// const float expected = 6.5f;
//
// var actual = _mathUtil.ListSum(test);
//
// Assert.AreEqual(expected, actual,
// $"ListSum() Expected: {expected}, Actual: {actual}");
// }
//
// [TestMethod]
// public void ListCumSumTest()
// {
// var test = new List<float> { 1f, 2f, 3f, 4f };
// var expected = new List<float> { 1f, 3f, 6f, 10f };
//
// var actual = _mathUtil.ListCumSum(test);
//
// for (var i = 0; i < actual.Count; i++)
// {
// if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
// {
// Assert.Fail($"ListCumSum() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
// }
// }
// }
//
// [TestMethod]
// public void ListProductTest()
// {
// var test = new List<float> { 1f, 2f, 3f, 4f };
// var expected = new List<float> { 2f, 4f, 6f, 8f };
//
// var actual = _mathUtil.ListProduct(test, 2);
//
// for (var i = 0; i < actual.Count; i++)
// {
// if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
// {
// Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
// }
// }
// }
//
// [TestMethod]
// public void ListAddTest()
// {
// var test = new List<float> { 1f, 2f, 3f, 4f };
// var expected = new List<float> { 3f, 4f, 5f, 6f };
//
// var actual = _mathUtil.ListAdd(test, 2);
//
// for (var i = 0; i < actual.Count; i++)
// {
// if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
// {
// Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
// }
// }
// }
//
// [TestMethod]
// public void MapToRangeTest()
// {
// const double expected = 2;
//
// var actual = _mathUtil.MapToRange(0.5, 0, 1, 1, 3);
//
// Assert.AreEqual(expected, actual,
// $"MapToRange() Expected: {expected}, Actual: {actual}");
// }
// }