Skip to content

Commit

Permalink
NUnit 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Sep 2, 2024
1 parent 4c53337 commit 85dbc3a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[*.{cs,vb}]

tab_width = 4
indent_size = 4
end_of_line = lf
indent_style = tab
6 changes: 3 additions & 3 deletions Tpk.Tests/CompressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void BrotliCompressionReversesPerfectly()
if (compressedData.Length == 0)
Assert.Fail("Compressed data cannot be empty");
byte[] decompressedData = BrotliHandler.Decompress(compressedData);
Assert.AreEqual(randomData, decompressedData);
Assert.That(decompressedData, Is.EqualTo(randomData));
}

[Test]
Expand All @@ -24,7 +24,7 @@ public void Lz4CompressionReversesPerfectly()
if (compressedData.Length == 0)
Assert.Fail("Compressed data cannot be empty");
byte[] decompressedData = Lz4Handler.Decompress(compressedData, randomData.Length);
Assert.AreEqual(randomData, decompressedData);
Assert.That(decompressedData, Is.EqualTo(randomData));
}

[Test]
Expand All @@ -34,7 +34,7 @@ public void LzmaCompressionReversesPerfectly()
if (compressedData.Length == 0)
Assert.Fail("Compressed data cannot be empty");
byte[] decompressedData = LzmaHandler.Decompress(compressedData, randomData.Length);
Assert.AreEqual(randomData, decompressedData);
Assert.That(decompressedData, Is.EqualTo(randomData));
}
}
}
18 changes: 12 additions & 6 deletions Tpk.Tests/EngineAssetsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public void ReadAndWriteAreTheSame()
originalBlob.Data.Add(new KeyValuePair<UnityVersion, string>(new UnityVersion(4), RandomUtils.RandomString()));
byte[] writtenData = originalBlob.ToBinary();
TpkEngineAssetsBlob readBlob = TpkDataBlob.FromBinary<TpkEngineAssetsBlob>(writtenData);
Assert.AreEqual(originalBlob.CreationTime, readBlob.CreationTime);
Assert.AreEqual(originalBlob.Versions, readBlob.Versions);
Assert.AreEqual(originalBlob.Data, readBlob.Data);
Assert.Multiple(() =>
{
Assert.That(readBlob.CreationTime, Is.EqualTo(originalBlob.CreationTime));
Assert.That(readBlob.Versions, Is.EqualTo(originalBlob.Versions));
Assert.That(readBlob.Data, Is.EqualTo(originalBlob.Data));
});
}

[Test]
Expand All @@ -30,8 +33,11 @@ public void EmptyReadAndWriteAreTheSame()
TpkEngineAssetsBlob originalBlob = new();
byte[] writtenData = originalBlob.ToBinary();
TpkEngineAssetsBlob readBlob = TpkDataBlob.FromBinary<TpkEngineAssetsBlob>(writtenData);
Assert.AreEqual(originalBlob.CreationTime, readBlob.CreationTime);
Assert.AreEqual(originalBlob.Versions, readBlob.Versions);
Assert.AreEqual(originalBlob.Data, readBlob.Data);
Assert.Multiple(() =>
{
Assert.That(readBlob.CreationTime, Is.EqualTo(originalBlob.CreationTime));
Assert.That(readBlob.Versions, Is.EqualTo(originalBlob.Versions));
Assert.That(readBlob.Data, Is.EqualTo(originalBlob.Data));
});
}
}
2 changes: 1 addition & 1 deletion Tpk.Tests/FileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void ReadAndWriteAreTheSame()
TpkFileSystemBlob originalBlob = BlobCreator.MakeRandomFileSystemBlob();
byte[] writtenData = originalBlob.ToBinary();
TpkFileSystemBlob readBlob = TpkDataBlob.FromBinary<TpkFileSystemBlob>(writtenData);
Assert.AreEqual(originalBlob.Files, readBlob.Files);
Assert.That(readBlob.Files, Is.EqualTo(originalBlob.Files));
}
}
}
4 changes: 2 additions & 2 deletions Tpk.Tests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void ReadAndWriteAreTheSame()
originalBlob.Text = RandomUtils.RandomString(557);
byte[] writtenData = originalBlob.ToBinary();
TpkJsonBlob readBlob = TpkDataBlob.FromBinary<TpkJsonBlob>(writtenData);
Assert.AreEqual(originalBlob.Text, readBlob.Text);
Assert.That(readBlob.Text, Is.EqualTo(originalBlob.Text));
}

[Test]
Expand All @@ -20,7 +20,7 @@ public void EmptyReadAndWriteAreTheSame()
TpkJsonBlob originalBlob = new TpkJsonBlob();
byte[] writtenData = originalBlob.ToBinary();
TpkJsonBlob readBlob = TpkDataBlob.FromBinary<TpkJsonBlob>(writtenData);
Assert.AreEqual(originalBlob.Text, readBlob.Text);
Assert.That(readBlob.Text, Is.EqualTo(originalBlob.Text));
}
}
}
10 changes: 7 additions & 3 deletions Tpk.Tests/Tpk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
11 changes: 7 additions & 4 deletions Tpk.Tests/TpkFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ public void MagicBytesAreCorrect()
{
TpkFile file = CreateTpkFile();
byte[] data = file.WriteToMemory();
Assert.AreEqual((byte)'T', data[0]);
Assert.AreEqual((byte)'P', data[1]);
Assert.AreEqual((byte)'K', data[2]);
Assert.AreEqual((byte)'*', data[3]);
Assert.Multiple(() =>
{
Assert.That(data[0], Is.EqualTo((byte)'T'));
Assert.That(data[1], Is.EqualTo((byte)'P'));
Assert.That(data[2], Is.EqualTo((byte)'K'));
Assert.That(data[3], Is.EqualTo((byte)'*'));
});
}

private static TpkFile CreateTpkFile()
Expand Down
19 changes: 11 additions & 8 deletions Tpk.Tests/TypeTrees/CommonStringTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AssetRipper.Tpk.TypeTrees;
using AssetRipper.Primitives;
using AssetRipper.Primitives;
using AssetRipper.Tpk.TypeTrees;
using NUnit.Framework;

namespace AssetRipper.Tpk.Tests.TypeTrees
Expand All @@ -16,18 +16,21 @@ internal static class CommonStringTests
public static void CountIsCorrectForEmptyCommonString()
{
TpkCommonString commonString = new();
Assert.AreEqual(0, commonString.GetCount(Unity5));
Assert.That(commonString.GetCount(Unity5), Is.EqualTo(0));
}

[Test]
public static void CountIsCorrectForNormalUse()
{
TpkCommonString commonString = MakeCommonString();
Assert.AreEqual(5, commonString.GetCount(Unity3));
Assert.AreEqual(5, commonString.GetCount(Unity4));
Assert.AreEqual(5, commonString.GetCount(Unity5));
Assert.AreEqual(10, commonString.GetCount(Unity6));
Assert.AreEqual(10, commonString.GetCount(Unity7));
Assert.Multiple(() =>
{
Assert.That(commonString.GetCount(Unity3), Is.EqualTo(5));
Assert.That(commonString.GetCount(Unity4), Is.EqualTo(5));
Assert.That(commonString.GetCount(Unity5), Is.EqualTo(5));
Assert.That(commonString.GetCount(Unity6), Is.EqualTo(10));
Assert.That(commonString.GetCount(Unity7), Is.EqualTo(10));
});
}

private static TpkCommonString MakeCommonString()
Expand Down
12 changes: 8 additions & 4 deletions Tpk.TypeTrees.Json.Tests/Tpk.TypeTrees.Json.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -10,9 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
1 change: 1 addition & 0 deletions Tpk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B80E65C0-145A-4034-9EC8-E2D03ECAE732}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
License.md = License.md
README.md = README.md
Expand Down

0 comments on commit 85dbc3a

Please sign in to comment.