From de23c1a49b783ae81c96014beaf9761813165252 Mon Sep 17 00:00:00 2001 From: Giang Nguyen Date: Sat, 17 Feb 2024 20:55:32 +0200 Subject: [PATCH] test: Refactored PLC project initialization in `TestTwincatProject` --- .../TestUtils/TestTwincatProject.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/TwinGet.AutomationInterface.Test/TestUtils/TestTwincatProject.cs b/test/TwinGet.AutomationInterface.Test/TestUtils/TestTwincatProject.cs index 877d8fe..d9e3b8a 100644 --- a/test/TwinGet.AutomationInterface.Test/TestUtils/TestTwincatProject.cs +++ b/test/TwinGet.AutomationInterface.Test/TestUtils/TestTwincatProject.cs @@ -24,15 +24,12 @@ public TestTwincatProject(string name, string absolutePath) using (StringReader reader = new(xmlContent)) { - TcSmProjectData tcSmProject = serializer.Deserialize(reader) as TcSmProjectData ?? throw new InvalidProjectFileFormat("The format of TwinCAT project file is invalid.", absolutePath); - - if (tcSmProject.Project.Plc?.Projects is not null) - { - _plcProjects.AddRange(from ProjectElement project in tcSmProject.Project.Plc.Projects - let plcProject = new TestPlcProject(Path.Join(rootDir, project.PrjFilePath)) - where plcProject is not null - select plcProject); - } + TcSmProjectData tcSmProject = serializer.Deserialize(reader) as TcSmProjectData ?? throw new InvalidProjectFileFormat("The format of TwinCAT project file is invalid.", absolutePath); + + var plcProjects = tcSmProject.Project.Plc?.Projects? + .Select(x => new TestPlcProject(Path.Join(rootDir, x.PrjFilePath))); + + _plcProjects = new(plcProjects ?? []); } } }