Skip to content

Commit

Permalink
Merge pull request #149 from TetsuOtter/148-support-json-without-id
Browse files Browse the repository at this point in the history
IDが含まれないJSONでクラッシュする問題を修正
  • Loading branch information
TetsuOtter authored Aug 19, 2024
2 parents bfe93d6 + 67b6228 commit 90d24ba
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 127 deletions.
184 changes: 85 additions & 99 deletions TRViS.IO.Tests/Loaders/LoaderJson.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,131 +21,117 @@ public void GetWorkGroupListTest()
{
IReadOnlyList<WorkGroup> actual = loader!.GetWorkGroupList();

Assert.That(actual, Is.EquivalentTo(new WorkGroup[]
Assert.That(actual, Has.Count.EqualTo(2));
Assert.Multiple(() =>
{
new WorkGroup()
{
Name = "WorkGroup01",
DBVersion = 1,
Id = 0,
},
new WorkGroup()
{
Name = "WorkGroup02",
DBVersion = null,
Id = 1,
},
}));
Assert.That(Guid.TryParse(actual[0].Id, out _), Is.True);
Assert.That(actual[0].Name, Is.EqualTo("WorkGroup01"));
Assert.That(actual[0].DBVersion, Is.EqualTo(1));

Assert.That(Guid.TryParse(actual[1].Id, out _), Is.True);
Assert.That(actual[1].Name, Is.EqualTo("WorkGroup02"));
Assert.That(actual[1].DBVersion, Is.Null);
});
}

[Test]
public void GetWorkListTest0()
{
IReadOnlyList<Work> actual = loader!.GetWorkList(0);
IReadOnlyList<WorkGroup> workGroupList = loader!.GetWorkGroupList();
string workGroupId = workGroupList[0].Id;
IReadOnlyList<Work> actual = loader!.GetWorkList(workGroupId);

Assert.That(actual, Is.EquivalentTo(new Work[]
Assert.That(actual, Has.Count.EqualTo(2));
Assert.Multiple(() =>
{
new Work()
{
WorkGroupId = 0,
Id = 0,
Name = "WG01-Work01",
AffectDate = "20230318",

AffixContent = null,
AffixContentType = -1,
Remarks = "仕業に対する注意事項を記載する",
HasETrainTimetable = false,
ETrainTimetableContent = null,
ETrainTimetableContentType = -1,
},
new Work()
{
WorkGroupId = 0,
Id = 1,
Name = "WG01-Work02",
},
}));
Assert.That(Guid.TryParse(actual[0].Id, out _), Is.True);
Assert.That(actual[0].WorkGroupId, Is.EqualTo(workGroupId));
Assert.That(actual[0].Name, Is.EqualTo("WG01-Work01"));
Assert.That(actual[0].AffectDate, Is.EqualTo("20230318"));
Assert.That(actual[0].Remarks, Is.EqualTo("仕業に対する注意事項を記載する"));
Assert.That(actual[0].HasETrainTimetable, Is.False);
Assert.That(actual[0].ETrainTimetableContent, Is.Null);
Assert.That(actual[0].ETrainTimetableContentType, Is.EqualTo(-1));

Assert.That(Guid.TryParse(actual[1].Id, out _), Is.True);
Assert.That(actual[1].WorkGroupId, Is.EqualTo(workGroupId));
Assert.That(actual[1].Name, Is.EqualTo("WG01-Work02"));
});
}

[Test]
public void GetWorkListTest1()
{
IReadOnlyList<Work> actual = loader!.GetWorkList(1);
IReadOnlyList<WorkGroup> workGroupList = loader!.GetWorkGroupList();
string workGroupId = workGroupList[1].Id;
IReadOnlyList<Work> actual = loader!.GetWorkList(workGroupId);

Assert.That(actual, Is.EquivalentTo(Array.Empty<Work>()));
}

[Test]
public void GetTrainListTest0()
{
IReadOnlyList<TrainData> actual = loader!.GetTrainDataList(0);

Assert.That(actual, Is.EquivalentTo(new TrainData[]
IReadOnlyList<WorkGroup> workGroupList = loader!.GetWorkGroupList();
string workGroupId = workGroupList[0].Id;
IReadOnlyList<Work> workList = loader!.GetWorkList(workGroupId);
string workId = workList[0].Id;
IReadOnlyList<TrainData> actual = loader!.GetTrainDataList(workId);

Assert.That(actual, Has.Count.EqualTo(2));
Assert.Multiple(() =>
{
new TrainData()
{
AfterArrive = "着後作業",
AfterArrive_OnStationTrackCol = "「着後」のうち、着発番線と同じ行に記載されている内容",
AfterRemarks = "`(乗継)`など 最後の駅の下に記載されている内容",
BeforeDeparture = "発前作業",
BeforeDeparture_OnStationTrackCol = "「発前」のうち、着発番線と同じ行に記載されている内容",
BeginRemarks = "`(乗継)`など 最初の駅の上に記載されている内容",
CarCount = 10,
ColorId = -1, // Not Implemented
DayCount = 0,
Destination = "終着駅",
Direction = 1,
Id = 0,
IsRideOnMoving = false,
MaxSpeed = "最高速度",
NominalTractiveCapacity = "けん引定数",
Remarks = "列車に対する注意事項を記載する",
SpeedType = "速度種別",
TrainInfo = "列車情報 (列車名など)",
TrainNumber = "WG01-W01-Train01",
WorkId = 0,
WorkType = 0,
},

new TrainData()
{
Direction = -1,
Id = 1,
TrainNumber = "WG01-W01-Train02",
WorkId = 0,

ColorId = -1, // Not Implemented
},
}));
Assert.That(Guid.TryParse(actual[0].Id, out _), Is.True);
Assert.That(actual[0].WorkId, Is.EqualTo(workId));
Assert.That(actual[0].TrainNumber, Is.EqualTo("WG01-W01-Train01"));
Assert.That(actual[0].Direction, Is.EqualTo(1));
Assert.That(actual[0].ColorId, Is.EqualTo(-1));
Assert.That(actual[0].TrainInfo, Is.EqualTo("列車情報 (列車名など)"));
Assert.That(actual[0].Destination, Is.EqualTo("終着駅"));
Assert.That(actual[0].CarCount, Is.EqualTo(10));
Assert.That(actual[0].SpeedType, Is.EqualTo("速度種別"));
Assert.That(actual[0].MaxSpeed, Is.EqualTo("最高速度"));
Assert.That(actual[0].NominalTractiveCapacity, Is.EqualTo("けん引定数"));
Assert.That(actual[0].BeforeDeparture, Is.EqualTo("発前作業"));
Assert.That(actual[0].BeforeDeparture_OnStationTrackCol, Is.EqualTo("「発前」のうち、着発番線と同じ行に記載されている内容"));
Assert.That(actual[0].AfterArrive, Is.EqualTo("着後作業"));
Assert.That(actual[0].AfterArrive_OnStationTrackCol, Is.EqualTo("「着後」のうち、着発番線と同じ行に記載されている内容"));
Assert.That(actual[0].BeginRemarks, Is.EqualTo("`(乗継)`など 最初の駅の上に記載されている内容"));
Assert.That(actual[0].AfterRemarks, Is.EqualTo("`(乗継)`など 最後の駅の下に記載されている内容"));
Assert.That(actual[0].Remarks, Is.EqualTo("列車に対する注意事項を記載する"));
Assert.That(actual[0].IsRideOnMoving, Is.False);

Assert.That(Guid.TryParse(actual[1].Id, out _), Is.True);
Assert.That(actual[1].WorkId, Is.EqualTo(workId));
Assert.That(actual[1].TrainNumber, Is.EqualTo("WG01-W01-Train02"));
Assert.That(actual[1].Direction, Is.EqualTo(-1));
Assert.That(actual[1].ColorId, Is.EqualTo(-1));
});
}

[Test]
public void GetTrainListTest1()
{
IReadOnlyList<TrainData> actual = loader!.GetTrainDataList(1);

Assert.That(actual, Is.EquivalentTo(new TrainData[]
IReadOnlyList<WorkGroup> workGroupList = loader!.GetWorkGroupList();
string workGroupId = workGroupList[0].Id;
IReadOnlyList<Work> workList = loader!.GetWorkList(workGroupId);
string workId = workList[1].Id;
IReadOnlyList<TrainData> actual = loader!.GetTrainDataList(workId);

Assert.That(actual, Has.Count.EqualTo(2));
Assert.Multiple(() =>
{
new TrainData()
{
Direction = 1,
Id = 2,
TrainNumber = "WG01-W02-Train01",
WorkId = 1,

ColorId = -1, // Not Implemented
},

new TrainData()
{
Direction = -1,
Id = 3,
TrainNumber = "WG01-W02-Train02",
WorkId = 1,

ColorId = -1, // Not Implemented
},
}));
Assert.That(Guid.TryParse(actual[0].Id, out _), Is.True);
Assert.That(actual[0].WorkId, Is.EqualTo(workId));
Assert.That(actual[0].TrainNumber, Is.EqualTo("WG01-W02-Train01"));
Assert.That(actual[0].Direction, Is.EqualTo(1));
Assert.That(actual[0].ColorId, Is.EqualTo(-1));

Assert.That(Guid.TryParse(actual[1].Id, out _), Is.True);
Assert.That(actual[1].WorkId, Is.EqualTo(workId));
Assert.That(actual[1].TrainNumber, Is.EqualTo("WG01-W02-Train02"));
Assert.That(actual[1].Direction, Is.EqualTo(-1));
Assert.That(actual[1].ColorId, Is.EqualTo(-1));
});
}
}
23 changes: 12 additions & 11 deletions TRViS.IO.Tests/Loaders/LoaderSQL.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ public void GetTrainData()
using LoaderSQL loader = new(DB_FILE_PATH);
TimetableRow[] emptyArr = Array.Empty<TimetableRow>();

var all = loader.GetTrainData(1);
var all = loader.GetTrainData("1");

TrainData? actual = loader.GetTrainData(1);
TrainData? actual = loader.GetTrainData("1");
Assert.That(actual, Is.Not.Null);
Assert.That(actual.Rows, Is.Not.Null);

Assert.Multiple(() =>
{
Assert.That(actual, Is.EqualTo(
new TrainData(
"1",
"Work01",
new(2022, 9, 15),
"T9910X",
Expand Down Expand Up @@ -108,8 +109,8 @@ public void GetTrainData()

Assert.That(actual.Rows, Is.EquivalentTo(new TimetableRow[]
{
new(new(1, null, null, null), 12, 34, "Station1", false, false, false, false, null, new(12, 34, 56, null), "1-1", null, null, "abc", false, null, null),
new(new(2, 135.5, 35.5, 200), 12, null, "Station2", false, false, false, true, new(null, null, null, "停車"), null, null, null, null, null, false, null, null)
new("1", new(1, null, null, null), 12, 34, "Station1", false, false, false, false, null, new(12, 34, 56, null), "1-1", null, null, "abc", false, null, null),
new("2", new(2, 135.5, 35.5, 200), 12, null, "Station2", false, false, false, true, new(null, null, null, "停車"), null, null, null, null, null, false, null, null)
}));
});
}
Expand All @@ -123,7 +124,7 @@ public void GetWorkGroupListTest()

Assert.That(actual, Has.Member(new Models.DB.WorkGroup()
{
Id = 1,
Id = "1",
Name = "Group01",
DBVersion = 1,
}));
Expand All @@ -134,14 +135,14 @@ public void GetWorkListTest()
{
using LoaderSQL loader = new(DB_FILE_PATH);

var actual = loader.GetWorkList(1);
var actual = loader.GetWorkList("1");

for (int i = 1; i <= 3; i++)
{
Assert.That(actual, Has.Member(new Models.DB.Work()
{
Id = i,
WorkGroupId = 1,
Id = i.ToString(),
WorkGroupId = "1",
Name = $"Work0{i}",
AffectDate = "2022-09-15",

Expand All @@ -160,12 +161,12 @@ public void GetTrainDataListTest()
{
using LoaderSQL loader = new(DB_FILE_PATH);

var actual = loader.GetTrainDataList(1);
var actual = loader.GetTrainDataList("1");

Assert.That(actual, Has.Member(new Models.DB.TrainData()
{
Id = 1,
WorkId = 1,
Id = "1",
WorkId = "1",
TrainNumber = "T9910X",
MaxSpeed = "95",
SpeedType = "高速特定",
Expand Down
23 changes: 12 additions & 11 deletions TRViS.IO.Tests/Loaders/LoaderSQL.v0.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ public void GetTrainData()
using LoaderSQL loader = new(DB_FILE_PATH);
TimetableRow[] emptyArr = Array.Empty<TimetableRow>();

var all = loader.GetTrainData(1);
var all = loader.GetTrainData("1");

TrainData? actual = loader.GetTrainData(1);
TrainData? actual = loader.GetTrainData("1");
Assert.That(actual, Is.Not.Null);

Assert.That(actual, Is.EqualTo(
new TrainData(
"1",
"Work01",
new(2022, 9, 15),
"T9910X",
Expand All @@ -98,8 +99,8 @@ public void GetTrainData()

Assert.That(actual.Rows, Is.EquivalentTo(new TimetableRow[]
{
new(new(1), 12, 34, "Station1", false, false, false, false, null, new(12, 34, 56, null), "1-1", null, null, "abc"),
new(new(2), 12, null, "Station2", false, false, false, true, new(null, null, null, "停車"), null, null, null, null, null)
new("1", new(1), 12, 34, "Station1", false, false, false, false, null, new(12, 34, 56, null), "1-1", null, null, "abc"),
new("2", new(2), 12, null, "Station2", false, false, false, true, new(null, null, null, "停車"), null, null, null, null, null)
}));
}

Expand All @@ -112,7 +113,7 @@ public void GetWorkGroupListTest()

Assert.That(actual, Has.Member(new Models.DB.WorkGroup()
{
Id = 1,
Id = "1",
Name = "Group01"
}));
}
Expand All @@ -122,14 +123,14 @@ public void GetWorkListTest()
{
using LoaderSQL loader = new(DB_FILE_PATH);

var actual = loader.GetWorkList(1);
var actual = loader.GetWorkList("1");

for (int i = 1; i <= 3; i++)
{
Assert.That(actual, Has.Member(new Models.DB.Work()
{
Id = i,
WorkGroupId = 1,
Id = i.ToString(),
WorkGroupId = "1",
Name = $"Work0{i}",
AffectDate = "2022-09-15"
}));
Expand All @@ -141,12 +142,12 @@ public void GetTrainDataListTest()
{
using LoaderSQL loader = new(DB_FILE_PATH);

var actual = loader.GetTrainDataList(1);
var actual = loader.GetTrainDataList("1");

Assert.That(actual, Has.Member(new Models.DB.TrainData()
{
Id = 1,
WorkId = 1,
Id = "1",
WorkId = "1",
TrainNumber = "T9910X",
MaxSpeed = "95",
SpeedType = "高速特定",
Expand Down
Loading

0 comments on commit 90d24ba

Please sign in to comment.