From bb98d9602337e8d33856e06bad071781c3bab8f8 Mon Sep 17 00:00:00 2001
From: Harald Martini <harald.martini@student.tugraz.at>
Date: Mon, 30 May 2022 09:53:29 +0200
Subject: [PATCH] removed mockup property from simulatorfactory, added tests
 for primary and completed bus

---
 .../Impl/SimulatorFactory/SimulatorFactory.cs | 28 +++----
 .../VectoMockupTest/MockUpVectoTest.cs        | 73 +++++++++++++++++--
 2 files changed, 79 insertions(+), 22 deletions(-)

diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory/SimulatorFactory.cs b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory/SimulatorFactory.cs
index bbf9a64fc7..e4b4c16841 100644
--- a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory/SimulatorFactory.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory/SimulatorFactory.cs
@@ -72,11 +72,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
 		protected bool _simulate = true;
 
 		//TODO: set with preprocessor directive remove from interface
-#if MOCKUPDEBUG
-		public static bool MockUpRun { get; set; } = true;
-#else
-		public static bool MockUpRun { get; set; } = false;
-#endif
+//#if MOCKUPDEBUG
+//		public static bool MockUpRun { get; set; } = true;
+//#else
+//		public static bool MockUpRun { get; set; } = false;
+//#endif
 
 		public ISimulatorFactory FollowUpSimulatorFactory
 		{
@@ -175,7 +175,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
 		}
 
 
-		private IVectoRun GetExemptedRun(VectoRunData data)
+		protected virtual IVectoRun GetExemptedRun(VectoRunData data)
 		{
 			if (data.Report != null) {
 				data.Report.PrepareResult(data.Loading, data.Mission, data.EngineData?.FuelMode ?? 0, data);
@@ -187,15 +187,15 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
 			});
 		}
 
-		private IVectoRun GetNonExemptedRun(VectoRunData data, int current, VectoRunData d, ref bool warning1Hz)
+		protected virtual IVectoRun GetNonExemptedRun(VectoRunData data, int current, VectoRunData d, ref bool warning1Hz)
 		{
 			var addReportResult = PrepareReport(data);
-            if (MockUpRun)
-            {
-                return new MockupRun(new VehicleContainer(ExecutionMode.Declaration,
-                    new ModalDataContainer(data, ReportWriter, addReportResult))
-                { RunData = data });
-            }
+            //if (MockUpRun)
+            //{
+            //    return new MockupRun(new VehicleContainer(ExecutionMode.Declaration,
+            //        new ModalDataContainer(data, ReportWriter, addReportResult))
+            //    { RunData = data });
+            //}
             if (!data.Cycle.CycleType.IsDistanceBased() && ModalResults1Hz && !warning1Hz) {
 				Log.Error("Output filter for 1Hz results is only available for distance-based cycles!");
 				warning1Hz = true;
@@ -295,7 +295,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
 			return run;
 		}
 
-		private static Action<ModalDataContainer> PrepareReport(VectoRunData data)
+		protected static Action<ModalDataContainer> PrepareReport(VectoRunData data)
 		{
 			if (data.Report != null) {
 				data.Report.PrepareResult(data.Loading, data.Mission, data.EngineData?.FuelMode ?? 0, data);
diff --git a/VectoMockup/VectoMockupTest/MockUpVectoTest.cs b/VectoMockup/VectoMockupTest/MockUpVectoTest.cs
index 2e64918786..4abd2c5faa 100644
--- a/VectoMockup/VectoMockupTest/MockUpVectoTest.cs
+++ b/VectoMockup/VectoMockupTest/MockUpVectoTest.cs
@@ -1,10 +1,13 @@
 using System.IO;
+using System.Xml;
 using System.Xml.Linq;
 using Ninject;
 using NUnit.Framework;
+using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCommon.Models;
 using TUGraz.VectoCore;
 using TUGraz.VectoCore.InputData.FileIO.XML;
+using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider;
 using TUGraz.VectoCore.Models.Simulation;
 using TUGraz.VectoCore.Models.Simulation.Impl;
 using TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory;
@@ -75,6 +78,10 @@ namespace VectoMockupTest
 		protected const string PEV_IEPC_PrimaryBus =
 			@"TestData\XML\XMLReaderDeclaration\SchemaVersion2.4\Distributed\PrimaryBus\IEPC_primaryBus.xml";
 
+		protected const string Conventional_InterimBus =
+			@"TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_consolidated_multiple_stages.xml";
+
+
 
 		protected const string Conventional_CompletedBus = @"TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_conventional_final_vif.VIF_Report_1.xml";
 
@@ -97,7 +104,7 @@ namespace VectoMockupTest
 		[SetUp]
 		public void Setup()
 		{
-			SimulatorFactory.MockUpRun = true;
+			//SimulatorFactory.MockUpRun = true;
 
 		}
 
@@ -126,10 +133,10 @@ namespace VectoMockupTest
 		[TestCase(PEV_E4_HeavyLorry, TestName = "PEV_E4_HeavyLorry")]
 		[TestCase(PEV_IEPC_HeavyLorry, TestName = "PEV_IEPC_HeavyLorry")]
 		[TestCase(HEV_IEPC_S_HeavyLorry, TestName = "HEV_IEPC_S_HeavyLorry")]
-		[NonParallelizable]
+		//[NonParallelizable]
 		public void HeavyLorryMockupTest(string fileName, bool mockup = true)
 		{
-			SimulatorFactory.MockUpRun = mockup;
+			
 			var inputProvider = _inputDataReader.Create(fileName);
 			var fileWriter = GetOutputFileWriter(TestContext.CurrentContext.Test.Name, fileName);
 			var sumWriter = new SummaryDataContainer(fileWriter);
@@ -150,7 +157,6 @@ namespace VectoMockupTest
 		[TestCase(Conventional_PrimaryBus, TestName = "ConventionalPrimaryBus")]
 		public void PrimaryBusMockupTest(string fileName, bool mockup = true)
 		{
-			SimulatorFactory.MockUpRun = mockup;
 			var inputProvider = _inputDataReader.Create(fileName);
 			var fileWriter = GetOutputFileWriter(TestContext.CurrentContext.Test.Name, fileName);
 			var sumWriter = new SummaryDataContainer(fileWriter);
@@ -162,21 +168,72 @@ namespace VectoMockupTest
 			jobContainer.AddRuns(_simulatorFactory);
 			jobContainer.Execute(false);
 			jobContainer.WaitFinished();
-			CheckFileExists(fileWriter);
+			CheckFileExists(fileWriter, checkCif:false, checkVif:true);
+		}
+
+		[TestCase(Conventional_InterimBus, TestName = "ConventionalInterimBus")]
+		public void InterimBusMockupTest(string fileName)
+		{
+			//SimulatorFactory.MockUpRun = mockup;
+			var inputProvider = _inputDataReader.Create(fileName);
+			var fileWriter = GetOutputFileWriter(TestContext.CurrentContext.Test.Name, fileName);
+			var sumWriter = new SummaryDataContainer(fileWriter);
+			var jobContainer = new JobContainer(sumWriter);
+
+			_simulatorFactory =
+				_simFactoryFactory.Factory(ExecutionMode.Declaration, inputProvider, fileWriter, null, null, true);
+
+			jobContainer.AddRuns(_simulatorFactory);
+			jobContainer.Execute(false);
+			jobContainer.WaitFinished();
+			CheckFileExists(fileWriter, checkCif: false, checkVif: true);
+
+
 		}
 
 
-		private static void CheckFileExists(FileOutputWriter fileWriter)
+		[TestCase(Conventional_CompletedBus, TestName = "ConventionalCompletedBus")]
+		public void CompletedBusMockupTest(string fileName)
 		{
-			if (!File.Exists(fileWriter.XMLCustomerReportName)) {
+			//SimulatorFactory.MockUpRun = mockup;
+			XMLDeclarationVIFInputData input = null;
+			var fileWriter = new FileOutputWriter(fileName);
+			using (var reader = XmlReader.Create(fileName))
+			{
+				input = new XMLDeclarationVIFInputData(_inputDataReader.Create(fileName) as IMultistageBusInputDataProvider, null);
+				fileWriter = new FileOutputVIFWriter(fileName, input.MultistageJobInputData.JobInputData.ManufacturingStages.Count);
+			}
+			var sumWriter = new SummaryDataContainer(fileWriter);
+			var jobContainer = new JobContainer(sumWriter);
+
+			_simulatorFactory =
+				_simFactoryFactory.Factory(ExecutionMode.Declaration, input, fileWriter, null, null, true);
+
+			jobContainer.AddRuns(_simulatorFactory);
+			jobContainer.Execute(false);
+			jobContainer.WaitFinished();
+			CheckFileExists(fileWriter, checkCif: false, checkVif: true);
+
+
+		}
+
+
+		private static void CheckFileExists(FileOutputWriter fileWriter, bool checkMrf = true, bool checkCif = true, bool checkVif = false)
+		{
+			if (checkCif && !File.Exists(fileWriter.XMLCustomerReportName)) {
 				TestContext.WriteLine(fileWriter.XMLCustomerReportName);
 				Assert.Fail();
 			}
-			if (!File.Exists(fileWriter.XMLFullReportName))
+			if (checkMrf && !File.Exists(fileWriter.XMLFullReportName))
 			{
 				TestContext.WriteLine(fileWriter.XMLFullReportName);
 				Assert.Fail();
 			}
+
+			if (checkVif && !File.Exists(fileWriter.XMLPrimaryVehicleReportName)) {
+				TestContext.WriteLine(fileWriter.XMLPrimaryVehicleReportName);
+				Assert.Fail();
+			}
 		}
 	}
 }
-- 
GitLab