BililiveRecorder/test/BililiveRecorder.Core.UnitTests/Config/ConfigTests.cs

92 lines
4.1 KiB
C#
Raw Normal View History

2021-01-01 14:46:27 +08:00
using System.Collections.Generic;
2022-05-17 00:36:54 +08:00
using System.Threading.Tasks;
2021-01-01 14:46:27 +08:00
using BililiveRecorder.Core.Config;
2022-05-17 00:36:54 +08:00
using BililiveRecorder.Core.Config.V3;
using VerifyXunit;
2021-01-01 14:46:27 +08:00
using Xunit;
2021-02-23 18:03:37 +08:00
namespace BililiveRecorder.Core.UnitTests.Config
2021-01-01 14:46:27 +08:00
{
2022-05-17 00:36:54 +08:00
[UsesVerify]
2021-01-01 14:46:27 +08:00
public class ConfigTests
{
2022-05-17 00:36:54 +08:00
[Fact]
public Task CanSerializeToJsonAsync()
2021-01-01 14:46:27 +08:00
{
2022-05-17 00:36:54 +08:00
var config = new ConfigV3()
2021-01-01 14:46:27 +08:00
{
2022-05-17 00:36:54 +08:00
Rooms = new List<RoomConfig>
{
new RoomConfig { RoomId = 1, AutoRecord = true },
new RoomConfig { RoomId = 2 },
new RoomConfig { RoomId = int.MaxValue, RecordDanmaku = false }
},
Global = new GlobalConfig()
{
FileNameRecordTemplate = "TEST TEMPLATE VALUE",
RecordDanmakuRaw = true,
RecordMode = RecordMode.RawData,
}
2021-01-01 14:46:27 +08:00
};
2022-05-17 00:36:54 +08:00
var json = ConfigParser.SaveJson(config);
2021-01-01 14:46:27 +08:00
2022-05-17 00:36:54 +08:00
return Verifier.Verify(json);
2021-01-01 14:46:27 +08:00
}
2022-05-17 00:36:54 +08:00
[Theory]
[InlineData(@"{""version"":1,""data"":""{\""roomlist\"":[{\""enabled\"":true,\""id\"":1},{\""enabled\"":true,\""id\"":3},{\""enabled\"":true,\""id\"":5},{\""enabled\"":false,\""id\"":999},{\""enabled\"":false,\""id\"":2147483647}],\""record_filename_format\"":\""TEST_FILE_NAME_TEMPLATE!!\""}""}")]
[InlineData(@"{""version"":2,""global"":{""RecordFilenameFormat"":{""HasValue"":true,""Value"":""TEST_FILE_NAME_TEMPLATE!!""}},""rooms"":[{""RoomId"":{""HasValue"":true,""Value"":1},""AutoRecord"":{""HasValue"":true,""Value"":true}},{""RoomId"":{""HasValue"":true,""Value"":3},""AutoRecord"":{""HasValue"":true,""Value"":true}},{""RoomId"":{""HasValue"":true,""Value"":5},""AutoRecord"":{""HasValue"":true,""Value"":true}},{""RoomId"":{""HasValue"":true,""Value"":999},""AutoRecord"":{""HasValue"":true,""Value"":false}},{""RoomId"":{""HasValue"":true,""Value"":2147483647},""AutoRecord"":{""HasValue"":true,""Value"":false}}]}")]
[InlineData(@"{""version"":3,""global"":{""FileNameRecordTemplate"":{""HasValue"":true,""Value"":""TEST_FILE_NAME_TEMPLATE!!""}},""rooms"":[{""RoomId"":{""HasValue"":true,""Value"":1},""AutoRecord"":{""HasValue"":true,""Value"":true}},{""RoomId"":{""HasValue"":true,""Value"":3},""AutoRecord"":{""HasValue"":true,""Value"":true}},{""RoomId"":{""HasValue"":true,""Value"":5},""AutoRecord"":{""HasValue"":true,""Value"":true}},{""RoomId"":{""HasValue"":true,""Value"":999},""AutoRecord"":{""HasValue"":true,""Value"":false}},{""RoomId"":{""HasValue"":true,""Value"":2147483647},""AutoRecord"":{""HasValue"":true,""Value"":false}}]}")]
public void CanLoadEveryVersion(string configString)
2021-01-01 14:46:27 +08:00
{
2022-05-17 00:36:54 +08:00
var config = ConfigParser.LoadJson(configString)!;
2021-01-01 14:46:27 +08:00
2022-05-17 00:36:54 +08:00
Assert.NotNull(config);
2021-01-01 14:46:27 +08:00
2022-05-17 00:36:54 +08:00
Assert.True(config.Global.HasFileNameRecordTemplate);
Assert.Equal("TEST_FILE_NAME_TEMPLATE!!", config.Global.FileNameRecordTemplate);
Assert.False(config.Global.HasRecordMode);
Assert.Collection(config.Rooms,
room =>
2021-01-01 14:46:27 +08:00
{
2022-05-17 00:36:54 +08:00
Assert.True(room.AutoRecord);
Assert.Equal(1, room.RoomId);
Assert.False(room.HasRecordDanmaku);
2021-01-01 14:46:27 +08:00
},
2022-05-17 00:36:54 +08:00
room =>
{
Assert.True(room.AutoRecord);
Assert.Equal(3, room.RoomId);
Assert.False(room.HasRecordDanmaku);
},
room =>
{
Assert.True(room.AutoRecord);
Assert.Equal(5, room.RoomId);
Assert.False(room.HasRecordDanmaku);
},
room =>
{
Assert.False(room.AutoRecord);
Assert.Equal(999, room.RoomId);
Assert.False(room.HasRecordDanmaku);
},
room =>
{
Assert.False(room.AutoRecord);
Assert.Equal(int.MaxValue, room.RoomId);
2021-01-01 14:46:27 +08:00
2022-05-17 00:36:54 +08:00
Assert.False(room.HasRecordDanmaku);
}
);
2021-01-01 14:46:27 +08:00
}
}
}