|
8 | 8 | using ArcadeManager.Core.Infrastructure.Interfaces;
|
9 | 9 | using ArcadeManager.Core.Actions;
|
10 | 10 | using ArcadeManager.Core.Models.Zip;
|
| 11 | +using FluentAssertions.Extensions; |
11 | 12 |
|
12 | 13 | namespace ArcadeManager.Core.Tests.Services;
|
13 | 14 |
|
@@ -216,4 +217,68 @@ public void Cleanup_removes_excess_files()
|
216 | 217 |
|
217 | 218 | zipFiles.Should().HaveCount(2);
|
218 | 219 | }
|
| 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 | + } |
219 | 284 | }
|
0 commit comments