From f15e077bfb1da29f02032c7fff55b64703e87d77 Mon Sep 17 00:00:00 2001
From: "VKMTHD\\haraldmartini" <harald.martini@student.tugraz.at>
Date: Wed, 3 May 2023 11:25:20 +0200
Subject: [PATCH] added Parse method to AlternatorTypeHelper

---
 .../VectoCommon/Models/AlternatorType.cs      | 14 +++++++
 ...MLDeclarationBusAuxiliariesDataProvider.cs |  6 +--
 VectoCore/VectoCoreTest/XML/XMLSchemaTest.cs  | 38 +++++++++++++++++++
 3 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 VectoCore/VectoCoreTest/XML/XMLSchemaTest.cs

diff --git a/VectoCommon/VectoCommon/Models/AlternatorType.cs b/VectoCommon/VectoCommon/Models/AlternatorType.cs
index 7ed133da17..1df0b8b6a4 100644
--- a/VectoCommon/VectoCommon/Models/AlternatorType.cs
+++ b/VectoCommon/VectoCommon/Models/AlternatorType.cs
@@ -11,6 +11,20 @@ namespace TUGraz.VectoCommon.Models
 
 	public static class AlternatorTypeHelper
 	{
+		public static AlternatorType Parse(string xmlFormat)
+		{
+			switch (xmlFormat) {
+				case "conventional":
+					return AlternatorType.Conventional;
+				case "smart":
+					return AlternatorType.Smart;
+				case "no alternator":
+					return AlternatorType.None;
+				default:
+					throw new ArgumentException();
+			}
+		}
+
 
 		public static string ToXMLFormat(this AlternatorType type)
 		{
diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs
index 32d39c88d2..38fd3b639d 100644
--- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs
@@ -61,9 +61,9 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider
 		{
 			get
 			{
-				return GetString(new[]
-						{ XMLNames.BusAux_ElectricSystem, XMLNames.BusAux_ElectricSystem_AlternatorTechnology })
-					.ParseEnum<AlternatorType>();
+				return AlternatorTypeHelper.Parse(GetString(new[]
+					{ XMLNames.BusAux_ElectricSystem, XMLNames.BusAux_ElectricSystem_AlternatorTechnology }));
+				//.ParseEnum<AlternatorType>();
 			}
 		}
 
diff --git a/VectoCore/VectoCoreTest/XML/XMLSchemaTest.cs b/VectoCore/VectoCoreTest/XML/XMLSchemaTest.cs
new file mode 100644
index 0000000000..e16507b401
--- /dev/null
+++ b/VectoCore/VectoCoreTest/XML/XMLSchemaTest.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Schema;
+using NUnit.Framework;
+using TUGraz.VectoCommon.Models;
+using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Utils;
+
+namespace TUGraz.VectoCore.Tests.XML
+{
+    [TestFixture]
+    internal class XMLSchemaTest
+    {
+		XmlSchemaSet _declJobSchemaSet = XMLValidator.GetXMLSchema(XmlDocumentType.DeclarationJobData);
+
+
+
+
+        [TestCase("conventional", AlternatorType.Conventional)]
+		[TestCase("no alternator", AlternatorType.None)]
+		[TestCase("smart", AlternatorType.Smart)]
+        public void ParseAlternatorEnum(string xmlValue, AlternatorType expected)
+		{
+			var enumResult = AlternatorTypeHelper.Parse(xmlValue);
+            Assert.AreEqual(expected, enumResult);
+		}
+
+       
+
+
+
+
+
+    }
+}
-- 
GitLab