0.2.0-dev Download ZIP
53 lines ·2.5 KB Raw
| 1 | using System.Diagnostics; |
| 2 | using System.Reflection; |
| 3 | using EvilEngine.Conversion; |
| 4 | using EvilEngine.Formats; |
| 5 | |
| 6 | namespace EvilEngine.Host.Tests; |
| 7 | |
| 8 | public sealed class MapListTests(ITestOutputHelper output) |
| 9 | { |
| 10 | private static readonly string Installed = typeof(MapListTests).Assembly |
| 11 | .GetCustomAttributes<AssemblyMetadataAttribute>() |
| 12 | .Single(attribute => attribute.Key == "AdapterOutputRoot").Value!; |
| 13 | |
| 14 | [Fact] |
| 15 | public void ListsEveryMapOfGarrysModAndTheBunkerWithoutConvertingOne() |
| 16 | { |
| 17 | var gmod = Environment.GetEnvironmentVariable("EVIL_GMOD"); |
| 18 | var bunker = Environment.GetEnvironmentVariable("EVIL_BUNKER"); |
| 19 | Assert.SkipWhen(gmod is null || bunker is null, "Set EVIL_GMOD and EVIL_BUNKER to list their maps."); |
| 20 | var host = new EngineHost(); |
| 21 | host.Adapters.LoadAll([Installed]); |
| 22 | var mounts = new[] { gmod!, bunker! }.Select(path => |
| 23 | { |
| 24 | var mount = host.Mounts.Open(Assert.Single(host.Mounts.Probe(path))); |
| 25 | host.Conversion.AddNamespace(ContentNamespace.For(mount)); |
| 26 | return mount; |
| 27 | }).ToArray(); |
| 28 | |
| 29 | var clock = Stopwatch.StartNew(); |
| 30 | var registry = LocalRegistry.Build(mounts, host.Conversion); |
| 31 | var took = clock.Elapsed; |
| 32 | |
| 33 | Assert.DoesNotContain(registry.Problems, problem => problem.Subject != "gmod:records/sounds"); |
| 34 | Assert.Equal(["gmod", "amnesia-bunker"], registry.Maps.Select(maps => maps.Mount.Id.Game)); |
| 35 | var construct = registry.Map(ContentId.Parse("gmod:gm_construct"))!; |
| 36 | Assert.Equal(ContentId.Parse("gmod:maps/gm_construct"), construct.Map); |
| 37 | Assert.Equal(ContentId.Parse("gmod:maps/thumb/gm_construct"), construct.Thumbnail); |
| 38 | var bunkerMaps = registry.Maps[1].Maps; |
| 39 | Assert.Equal( |
| 40 | [ |
| 41 | "arena", "arsenal", "main_menu", "maintenance", "no_mans_land", "officer_hub", "prison", |
| 42 | "soldier_quarters", "training_grounds", "trenches", "tunnels" |
| 43 | ], |
| 44 | bunkerMaps.Select(map => map.Id.Name)); |
| 45 | Assert.Equal(ContentId.Parse("amnesia-bunker:maps/officer_hub/officer_hub"), |
| 46 | registry.Map(ContentId.Parse("amnesia-bunker:officer_hub"))!.Map); |
| 47 | Assert.Null(host.Conversion.Cache.Find(ContentKind.Map, construct.Map)); |
| 48 | Assert.Equal(ConversionStatus.Cached, |
| 49 | LocalRegistry.Build(mounts, host.Conversion).Sets.Select(set => set.Status).Distinct().Single()); |
| 50 | output.WriteLine( |
| 51 | $"{registry.Maps[0].Maps.Count} Garry's Mod maps and {bunkerMaps.Count} of the Bunker's in {took.TotalMilliseconds:0} ms"); |
| 52 | } |
| 53 | } |