Skip to content

Commit bcd08a1

Browse files
committed
Adds unit tests
1 parent a65fb4a commit bcd08a1

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

TODO.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
## DAT check
44

5-
* unit tests for RebuildGame
65
* Have a progress bar for the steps and a progress bar for the items in the step
76

87
## Other

src/ArcadeManager.Core.Tests/Services/DatCheckerTests.cs

+65
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using ArcadeManager.Core.Infrastructure.Interfaces;
99
using ArcadeManager.Core.Actions;
1010
using ArcadeManager.Core.Models.Zip;
11+
using FluentAssertions.Extensions;
1112

1213
namespace ArcadeManager.Core.Tests.Services;
1314

@@ -216,4 +217,68 @@ public void Cleanup_removes_excess_files()
216217

217218
zipFiles.Should().HaveCount(2);
218219
}
220+
221+
[Fact]
222+
public async Task Rom_is_rebuilt_crc()
223+
{
224+
// arrange: arguments
225+
var args = new RomsActionCheckDat { Speed = "fast" };
226+
227+
// arrange: found files matching the game files in the romset
228+
var foundFiles = new ReadOnlyGameRomFileList([
229+
new ReadOnlyGameRomFile("rom1.zip", "romset", "file1.a", "", 123, "abc", ""),
230+
new ReadOnlyGameRomFile("rom1.zip", "romset", "file2.a", "", 123, "def", ""),
231+
new ReadOnlyGameRomFile("rom2.zip", "romset", "file3.a", "", 123, "ghi", "")
232+
]);
233+
234+
// arrange: expected files in the game
235+
var gameFiles = new GameRomFilesList() {
236+
new GameRomFile { Name = "file1.a", Size = 123, Crc = "abc" },
237+
new GameRomFile { Name = "file2.a", Size = 123, Crc = "def" },
238+
new GameRomFile { Name = "file3.a", Size = 123, Crc = "ghi" }
239+
};
240+
241+
// arrange: assume file replace works
242+
A.CallTo(() => fs.ReplaceZipFile(A<ZipFile>._, A<ZipFile>._, A<IGameRomFile>._, A<IGameRomFile>._))
243+
.Returns(true);
244+
245+
// act
246+
await sut.RebuildGame("rom.zip", foundFiles, gameFiles, args);
247+
248+
// assert
249+
A.CallTo(() => fs.ReplaceZipFile(A<ZipFile>._, A<ZipFile>._, A<IGameRomFile>._, A<IGameRomFile>._))
250+
.MustHaveHappened(3, Times.Exactly);
251+
}
252+
253+
[Fact]
254+
public async Task Rom_is_rebuilt_sha1()
255+
{
256+
// arrange
257+
var args = new RomsActionCheckDat { Speed = "slow" };
258+
259+
// arrange: found files in the romset
260+
var foundFiles = new ReadOnlyGameRomFileList([
261+
new ReadOnlyGameRomFile("rom1.zip", "romset", "file1.a", "", 123, "abc", "1"),
262+
new ReadOnlyGameRomFile("rom1.zip", "romset", "file2.a", "", 123, "def", "2"),
263+
new ReadOnlyGameRomFile("rom2.zip", "romset", "file3.a", "", 123, "ghi", "3")
264+
]);
265+
266+
// arrange: expected files in the game
267+
var gameFiles = new GameRomFilesList() {
268+
new GameRomFile { Name = "file1.a", Size = 123, Crc = "abc", Sha1 = "1" },
269+
new GameRomFile { Name = "file2.a", Size = 123, Crc = "def", Sha1 = "2" },
270+
new GameRomFile { Name = "file3.a", Size = 123, Crc = "ghi", Sha1 = "3" }
271+
};
272+
273+
// arrange: assume file replace works
274+
A.CallTo(() => fs.ReplaceZipFile(A<ZipFile>._, A<ZipFile>._, A<IGameRomFile>._, A<IGameRomFile>._))
275+
.Returns(true);
276+
277+
// act
278+
await sut.RebuildGame("rom.zip", foundFiles, gameFiles, args);
279+
280+
// assert
281+
A.CallTo(() => fs.ReplaceZipFile(A<ZipFile>._, A<ZipFile>._, A<IGameRomFile>._, A<IGameRomFile>._))
282+
.MustHaveHappened(3, Times.Exactly);
283+
}
219284
}

src/ArcadeManager.Core/Services/DatChecker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public async Task RebuildGame(string gameFileFixed, ReadOnlyGameRomFileList foun
333333

334334
if (!await fs.ReplaceZipFile(sourceZip, targetZip, sourceFile, romFile))
335335
{
336-
Console.WriteLine($"warning: did not replace {sourceFile.Name} from {sourceZip.FilePath} to {targetZip.FilePath}");
336+
Console.WriteLine($"warning: did not replace {sourceFile.Name} from {sourceZip?.FilePath} to {targetZip?.FilePath}");
337337
}
338338
}
339339
}

0 commit comments

Comments
 (0)