.NET Format Style Fixes

This commit is contained in:
refringe
2025-06-18 17:09:20 +00:00
committed by Format Bot
parent ca0a7d6345
commit 6e01428b2b
774 changed files with 23507 additions and 40003 deletions
+5 -4
View File
@@ -21,20 +21,21 @@ public class DI
}
var services = new ServiceCollection();
var jsonUtil = new JsonUtil([ new SptJsonConverterRegistrator() ]);
var jsonUtil = new JsonUtil([new SptJsonConverterRegistrator()]);
var mathUtil = new MathUtil();
services.AddSingleton<JsonUtil>(jsonUtil);
services.AddSingleton<MathUtil>(mathUtil);
services.AddSingleton<ICloner,JsonCloner>();
services.AddSingleton<ISptLogger<RandomUtil>,MockLogger<RandomUtil>>();
services.AddSingleton<ICloner, JsonCloner>();
services.AddSingleton<ISptLogger<RandomUtil>, MockLogger<RandomUtil>>();
services.AddSingleton<RandomUtil>();
services.AddSingleton<HashUtil>();
_serviceProvider = services.BuildServiceProvider();
}
public static T GetService<T>() where T : notnull
public static T GetService<T>()
where T : notnull
{
return _serviceProvider.GetRequiredService<T>();
}
+6 -1
View File
@@ -6,7 +6,12 @@ namespace UnitTests.Mock;
public class MockLogger<T> : ISptLogger<T>
{
public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null, Exception? ex = null)
public void LogWithColor(
string data,
LogTextColor? textColor = null,
LogBackgroundColor? backgroundColor = null,
Exception? ex = null
)
{
throw new NotImplementedException();
}
+5 -2
View File
@@ -13,9 +13,12 @@ public class Test
[TestInitialize]
public async Task Setup()
{
var importer = new ImporterUtil(new MockLogger<ImporterUtil>(), new FileUtil(), DI.GetService<JsonUtil>());
var importer = new ImporterUtil(
new MockLogger<ImporterUtil>(),
new FileUtil(),
DI.GetService<JsonUtil>()
);
_templates = await importer.LoadRecursiveAsync<Templates>("./TestAssets/");
}
[TestMethod]
+24 -25
View File
@@ -27,11 +27,7 @@ public class HashUtilTests
// Invalid mongoId length
var test = _hashUtil.IsValidMongoId(result);
Assert.AreEqual(
true,
test,
$"IsValidMongoId() `{result}` is not a valid MongoId."
);
Assert.AreEqual(true, test, $"IsValidMongoId() `{result}` is not a valid MongoId.");
}
}
@@ -41,7 +37,11 @@ public class HashUtilTests
false,
"677ddb67406e9918a0264bbz contains invalid char `z`, but result was true"
)]
[DataRow("677ddb67406e9918a0264bbcc", false, "677ddb67406e9918a0264bbcc is 25 characters, but result was true")]
[DataRow(
"677ddb67406e9918a0264bbcc",
false,
"677ddb67406e9918a0264bbcc is 25 characters, but result was true"
)]
[DataRow(
"677ddb67406e9918a0264bbc",
true,
@@ -50,24 +50,19 @@ public class HashUtilTests
public void IsValidMongoIdTest(string mongoId, bool passes, string failMessage)
{
var result = _hashUtil.IsValidMongoId(mongoId);
Assert.AreEqual(
passes,
result,
failMessage
);
Assert.AreEqual(passes, result, failMessage);
}
[TestMethod]
[DataRow("123456789", "25F9E794323B453885F5181F1B624D0B", "Not valid output, expected '25F9E794323B453885F5181F1B624D0B'")]
[DataRow(
"123456789",
"25F9E794323B453885F5181F1B624D0B",
"Not valid output, expected '25F9E794323B453885F5181F1B624D0B'"
)]
public void GenerateValidMd5Test(string input, string expectedOutput, string failMessage)
{
var result = _hashUtil.GenerateHashForData(HashingAlgorithm.MD5,input);
Assert.AreEqual(
expectedOutput,
result,
failMessage
);
var result = _hashUtil.GenerateHashForData(HashingAlgorithm.MD5, input);
Assert.AreEqual(expectedOutput, result, failMessage);
}
[TestMethod]
@@ -78,12 +73,16 @@ public class HashUtilTests
var stopwatch = new Stopwatch();
stopwatch.Start();
Parallel.For(0, 1000, i =>
{
Thread.Sleep(random.Next(0, 10));
var mongoId = _hashUtil.Generate();
concurrentBag.Add(mongoId);
});
Parallel.For(
0,
1000,
i =>
{
Thread.Sleep(random.Next(0, 10));
var mongoId = _hashUtil.Generate();
concurrentBag.Add(mongoId);
}
);
stopwatch.Stop();
Console.WriteLine($"Elapsed time: {stopwatch.ElapsedMilliseconds} ms");
+4 -2
View File
@@ -19,9 +19,11 @@ public class JsonUtilTests
{
var value = new Dictionary<QuestStatusEnum, int>
{
{ QuestStatusEnum.AvailableForStart, 1 }
{ QuestStatusEnum.AvailableForStart, 1 },
};
var result = _jsonUtil.Deserialize<Dictionary<QuestStatusEnum, int>>(_jsonUtil.Serialize(value));
var result = _jsonUtil.Deserialize<Dictionary<QuestStatusEnum, int>>(
_jsonUtil.Serialize(value)
);
Assert.AreEqual(value.Count, result?.Count);
Assert.AreEqual(value.First().Key, result?.First().Key);
Assert.AreEqual(value.First().Value, result?.First().Value);
+18 -61
View File
@@ -16,40 +16,19 @@ public class MathUtilTests
[TestMethod]
public void ListSumTest()
{
var test = new List<float>
{
1.1f,
2.1f,
3.3f
};
var test = new List<float> { 1.1f, 2.1f, 3.3f };
const double expected = 6.5f;
var actual = _mathUtil.ListSum(test);
Assert.AreEqual(
expected,
actual,
$"ListSum() Expected: {expected}, Actual: {actual}"
);
Assert.AreEqual(expected, actual, $"ListSum() Expected: {expected}, Actual: {actual}");
}
[TestMethod]
public void ListCumSumTest()
{
var test = new List<double>
{
1f,
2f,
3f,
4f
};
var expected = new List<double>
{
1f,
3f,
6f,
10f
};
var test = new List<double> { 1f, 2f, 3f, 4f };
var expected = new List<double> { 1f, 3f, 6f, 10f };
var actual = _mathUtil.ListCumSum(test);
@@ -57,7 +36,9 @@ public class MathUtilTests
{
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
{
Assert.Fail($"ListCumSum() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
Assert.Fail(
$"ListCumSum() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}"
);
}
}
}
@@ -65,20 +46,8 @@ public class MathUtilTests
[TestMethod]
public void ListProductTest()
{
var test = new List<double>
{
1f,
2f,
3f,
4f
};
var expected = new List<double>
{
2f,
4f,
6f,
8f
};
var test = new List<double> { 1f, 2f, 3f, 4f };
var expected = new List<double> { 2f, 4f, 6f, 8f };
var actual = _mathUtil.ListProduct(test, 2);
@@ -86,7 +55,9 @@ public class MathUtilTests
{
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
{
Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
Assert.Fail(
$"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}"
);
}
}
}
@@ -94,20 +65,8 @@ public class MathUtilTests
[TestMethod]
public void ListAddTest()
{
var test = new List<double>
{
1f,
2f,
3f,
4f
};
var expected = new List<double>
{
3f,
4f,
5f,
6f
};
var test = new List<double> { 1f, 2f, 3f, 4f };
var expected = new List<double> { 3f, 4f, 5f, 6f };
var actual = _mathUtil.ListAdd(test, 2);
@@ -115,7 +74,9 @@ public class MathUtilTests
{
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
{
Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
Assert.Fail(
$"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}"
);
}
}
}
@@ -127,10 +88,6 @@ public class MathUtilTests
var actual = _mathUtil.MapToRange(0.5, 0, 1, 1, 3);
Assert.AreEqual(
expected,
actual,
$"MapToRange() Expected: {expected}, Actual: {actual}"
);
Assert.AreEqual(expected, actual, $"MapToRange() Expected: {expected}, Actual: {actual}");
}
}
+25 -21
View File
@@ -23,7 +23,9 @@ public sealed class RandomUtilTests
if (result < 0 || result > 10)
{
Assert.Fail($"GetInt(0, 10) out of range. Expected range [0, 10] but was {result}.");
Assert.Fail(
$"GetInt(0, 10) out of range. Expected range [0, 10] but was {result}."
);
}
}
}
@@ -53,7 +55,9 @@ public sealed class RandomUtilTests
if (result is < 0d or >= 10d)
{
Assert.Fail($"GetDouble(0d, 10d) out of range. Expected range [0.0d, 9.999d] but was {result}.");
Assert.Fail(
$"GetDouble(0d, 10d) out of range. Expected range [0.0d, 9.999d] but was {result}."
);
}
}
}
@@ -125,7 +129,9 @@ public sealed class RandomUtilTests
if (result < 0 || result > 9)
{
Assert.Fail($"RandInt(0, 10) out of range. Expected range [0, 9] but was {result}.");
Assert.Fail(
$"RandInt(0, 10) out of range. Expected range [0, 9] but was {result}."
);
}
}
@@ -135,7 +141,9 @@ public sealed class RandomUtilTests
if (result < 0 || result > 9)
{
Assert.Fail($"RandInt(10, null) out of range. Expected range [0, 9] but was {result}.");
Assert.Fail(
$"RandInt(10, null) out of range. Expected range [0, 9] but was {result}."
);
}
}
}
@@ -149,12 +157,16 @@ public sealed class RandomUtilTests
if (result < 0 || result >= 10)
{
Assert.Fail($"RandNum(0, 10) out of range. Expected range [0, 9.999d] but was {result}.");
Assert.Fail(
$"RandNum(0, 10) out of range. Expected range [0, 9.999d] but was {result}."
);
}
if (_randomUtil.GetNumberPrecision(result) > RandomUtil.MaxSignificantDigits)
{
Assert.Fail($"RandNum(0, 10) precision of {result} exceeds the allowable precision ({RandomUtil.MaxSignificantDigits}) for the given values.");
Assert.Fail(
$"RandNum(0, 10) precision of {result} exceeds the allowable precision ({RandomUtil.MaxSignificantDigits}) for the given values."
);
}
}
@@ -164,12 +176,16 @@ public sealed class RandomUtilTests
if (result < 0 || result >= 10)
{
Assert.Fail($"RandNum(10) out of range. Expected range [0, 9.999d] but was {result}.");
Assert.Fail(
$"RandNum(10) out of range. Expected range [0, 9.999d] but was {result}."
);
}
if (_randomUtil.GetNumberPrecision(result) > RandomUtil.MaxSignificantDigits)
{
Assert.Fail($"RandNum(10) precision of {result} exceeds the allowable precision ({RandomUtil.MaxSignificantDigits}) for the given values.");
Assert.Fail(
$"RandNum(10) precision of {result} exceeds the allowable precision ({RandomUtil.MaxSignificantDigits}) for the given values."
);
}
}
}
@@ -177,19 +193,7 @@ public sealed class RandomUtilTests
[TestMethod]
public void ShuffleTest()
{
var testList = new List<int>
{
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
};
var testList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var orig = new List<int>(testList);
-8
View File
@@ -1,35 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Build.props" />
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FastCloner" Version="3.3.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="MSTest" Version="3.9.0" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj" />
<ProjectReference Include="..\Libraries\SPTarkov.DI\SPTarkov.DI.csproj" />
<ProjectReference Include="..\Libraries\SPTarkov.Common\SPTarkov.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="TestAssets\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Remove="Tests\Mock\MockSptLogger.cs" />
</ItemGroup>
</Project>