0.2.0-dev Download ZIP
62 lines ·2.5 KB Raw
| 1 | using EvilEngine.Formats.Records; |
| 2 | |
| 3 | namespace EvilEngine.Formats.Tests; |
| 4 | |
| 5 | public sealed class AlbumRecordTextTests |
| 6 | { |
| 7 | private const string Albums = """ |
| 8 | [album."half-life-2/half-life-2"] |
| 9 | title = "Half-Life 2" |
| 10 | game = "Half-Life 2" |
| 11 | store = "steam:app/220" |
| 12 | tracks = [ |
| 13 | { music = "hl2:sound/music/hl2_song2.mp3", title = "hl2_song2" }, |
| 14 | { music = "hl2:sound/music/HL2_Song10.mp3", title = "hl2_song10" }, |
| 15 | ] |
| 16 | |
| 17 | [album."portal-2/songs"] |
| 18 | title = "Portal 2 Soundtrack [Songs to Test By]" |
| 19 | game = "Portal 2" |
| 20 | cover = "hl2:soundtrack/songs/albumartwork" |
| 21 | tracks = [ |
| 22 | { music = "hl2:soundtrack/songs/01.mp3" }, |
| 23 | ] |
| 24 | """; |
| 25 | |
| 26 | [Fact] |
| 27 | public void ReadsAlbumsWithTheirGameTracksAndCover() |
| 28 | { |
| 29 | var set = RecordText.Read("hl2", Albums, "albums.toml"); |
| 30 | |
| 31 | Assert.Equal(2, set.Albums.Count); |
| 32 | var hl2 = set.Albums[0]; |
| 33 | Assert.Equal(ContentId.Parse("hl2:half-life-2/half-life-2"), hl2.Id); |
| 34 | Assert.Equal(("Half-Life 2", "Half-Life 2"), (hl2.Title, hl2.Game)); |
| 35 | Assert.Null(hl2.Cover); |
| 36 | Assert.Equal("steam:app/220", hl2.Store); |
| 37 | Assert.Equal( |
| 38 | [ |
| 39 | new AlbumTrack(ContentId.Parse("hl2:sound/music/hl2_song2.mp3")) { Title = "hl2_song2" }, |
| 40 | new AlbumTrack(ContentId.Parse("hl2:sound/music/hl2_song10.mp3")) { Title = "hl2_song10" } |
| 41 | ], |
| 42 | hl2.Tracks); |
| 43 | var portal = set.Albums[1]; |
| 44 | Assert.Equal(ContentId.Parse("hl2:soundtrack/songs/albumartwork"), portal.Cover); |
| 45 | Assert.Null(Assert.Single(portal.Tracks).Title); |
| 46 | } |
| 47 | |
| 48 | [Fact] |
| 49 | public void WritesWhatItReads() |
| 50 | { |
| 51 | var set = RecordText.Read("hl2", Albums, "albums.toml"); |
| 52 | |
| 53 | Assert.Equal(set.Albums, RecordText.Read("hl2", RecordText.Write(set), "written").Albums); |
| 54 | } |
| 55 | |
| 56 | [Fact] |
| 57 | public void RefusesAnAlbumWithNoGame() |
| 58 | { |
| 59 | Assert.Throws<RecordFormatException>(() => |
| 60 | RecordText.Read("hl2", "[album.a]\ntitle = \"A\"\n", "albums.toml")); |
| 61 | } |
| 62 | } |