From 62b4c88f7efc3214699aa6b59eca6282dab3dbdb Mon Sep 17 00:00:00 2001
From: "VKMTHD\\haraldmartini" <harald.martini@student.tugraz.at>
Date: Thu, 1 Jun 2023 15:25:40 +0200
Subject: [PATCH] added completed bus tests

---
 Vecto3GUI2020Test/MockInput/MockDocument.cs   |  2 +-
 Vecto3GUI2020Test/TestHelper.cs               | 18 +++++
 Vecto3GUI2020Test/Utils/MockDialogHelper.cs   | 10 ++-
 Vecto3GUI2020Test/Vecto3GUI2020Test.csproj    |  5 ++
 .../DocumentViewModelFactoryTest.cs           |  4 +-
 .../XML/XMLWritingTest/XMLCompleteBus.cs      | 69 +++++++++++++++++++
 6 files changed, 104 insertions(+), 4 deletions(-)
 create mode 100644 Vecto3GUI2020Test/XML/XMLWritingTest/XMLCompleteBus.cs

diff --git a/Vecto3GUI2020Test/MockInput/MockDocument.cs b/Vecto3GUI2020Test/MockInput/MockDocument.cs
index b21146d679..59b2bd94a2 100644
--- a/Vecto3GUI2020Test/MockInput/MockDocument.cs
+++ b/Vecto3GUI2020Test/MockInput/MockDocument.cs
@@ -118,7 +118,7 @@ public static class MockDocument
 		var mock = new Mock<IMultistageVIFInputData>();
 		mock.SetupGet(m => m.MultistageJobInputData).Returns(GetMultistepInput(vifVersion, vifType, stages));
 		mock.SetupGet(m => m.VehicleInputData).Returns(GetStepInput(stepType, stepVersion).Vehicle);
-
+		mock.SetupGet(m => m.DataSource.SourceFile).Returns("mocked.vecto");
 
 
 		return mock.Object;
diff --git a/Vecto3GUI2020Test/TestHelper.cs b/Vecto3GUI2020Test/TestHelper.cs
index 5ad60cd5de..fa6f2d8639 100644
--- a/Vecto3GUI2020Test/TestHelper.cs
+++ b/Vecto3GUI2020Test/TestHelper.cs
@@ -1,6 +1,7 @@
 using System;
 using System.CodeDom;
 using System.Runtime.CompilerServices;
+using System.Security.RightsManagement;
 using Ninject;
 using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCore;
@@ -60,4 +61,21 @@ namespace Vecto3GUI2020Test
 			return name;
 		}
 	}
+
+	public static class IKernelHelperTest
+	{
+		public static MockDialogHelper GetMockDialogHelper(this IKernel k)
+		{
+			var mockDialogHelper = k.Get<IDialogHelper>() as MockDialogHelper;
+            return mockDialogHelper;
+		}
+
+		public static MockWindowHelper GetMockWindowHelper(this IKernel k)
+		{
+			var mockWindowHelper = k.Get<IWindowHelper>() as MockWindowHelper;
+			return mockWindowHelper;
+			
+		}
+
+	}
 }
\ No newline at end of file
diff --git a/Vecto3GUI2020Test/Utils/MockDialogHelper.cs b/Vecto3GUI2020Test/Utils/MockDialogHelper.cs
index 19ed2220d8..c5f8d93b0a 100644
--- a/Vecto3GUI2020Test/Utils/MockDialogHelper.cs
+++ b/Vecto3GUI2020Test/Utils/MockDialogHelper.cs
@@ -44,7 +44,8 @@ public class MockDialogHelper : IDialogHelper
 	public IReadOnlyList<Dialog> Dialogs => _dialogs.ToList();
 
 	public int NrErrors => _dialogs.Count(d => d.Type == Dialog.DialogType.Error);
-	
+
+	private Stack<string> _fileNames = new Stack<string>();
 	#region Implementation of IDialogHelper
 
 	public string OpenFileDialog(string filter = "All files (*.*)|*.*", string initialDirectory = null)
@@ -89,7 +90,7 @@ public class MockDialogHelper : IDialogHelper
 
 	public string SaveToXMLDialog(string initialDirectory = null)
 	{
-		throw new System.NotImplementedException();
+		return _fileNames.Pop();
 	}
 
 	public string SaveToVectoJobDialog(string initialDirectory = null)
@@ -136,5 +137,10 @@ public class MockDialogHelper : IDialogHelper
 		return ShowErrorMessage(errorMessage, "-");
 	}
 
+	public void PushFileName(string fileName)
+	{
+		_fileNames.Push(fileName);
+	}
+
 	#endregion
 }
\ No newline at end of file
diff --git a/Vecto3GUI2020Test/Vecto3GUI2020Test.csproj b/Vecto3GUI2020Test/Vecto3GUI2020Test.csproj
index 5afd548e38..7d82868a83 100644
--- a/Vecto3GUI2020Test/Vecto3GUI2020Test.csproj
+++ b/Vecto3GUI2020Test/Vecto3GUI2020Test.csproj
@@ -46,6 +46,11 @@
 		  <Link>TestData\Integration\Multistage\%(RecursiveDir)%(FileName)%(Extension)</Link>
 		<!--<TargetPath>TestData\Integration\Multistage</TargetPath>-->
 		  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+	</Content>
+	<Content Include="..\VectoCore\VectoCoreTest\TestData\Integration\Buses\FactorMethod\**\*.*">
+		<Link>TestData\Integration\Multistage\FactorMethod\%(RecursiveDir)%(FileName)%(Extension)</Link>
+		<!--<TargetPath>TestData\Integration\Multistage</TargetPath>-->
+		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 	</Content>
 	  <!--<Content Remove="..\VectoCore\VectoCoreTest\TestData\Integration\Multistage\newVifCompletedConventional.vecto" />
 	  <Content Remove="..\VectoCore\VectoCoreTest\TestData\Integration\Multistage\newVifExempted.vecto" />
diff --git a/Vecto3GUI2020Test/ViewModelTests/FactoryTests/DocumentViewModelFactoryTest.cs b/Vecto3GUI2020Test/ViewModelTests/FactoryTests/DocumentViewModelFactoryTest.cs
index 40d370702a..e14d842949 100644
--- a/Vecto3GUI2020Test/ViewModelTests/FactoryTests/DocumentViewModelFactoryTest.cs
+++ b/Vecto3GUI2020Test/ViewModelTests/FactoryTests/DocumentViewModelFactoryTest.cs
@@ -118,7 +118,9 @@ namespace Vecto3GUI2020Test.ViewModelTests.FactoryTests
 
 			IMultistageVIFInputData vifInputData = MockDocument.GetMultistepVIFInputData(vifNs, vifType, stages, stepType, stepNs);
 
-			Assert.Throws<VectoException>(() => _documentViewModelFactory.CreateDocumentViewModel(vifInputData));
+
+			var doc = _documentViewModelFactory.CreateDocumentViewModel(vifInputData);
+			Assert.NotNull(doc);
 		}
 
 		[TestCase(XMLDefinitions.DECLARATION_DEFINITIONS_NAMESPACE_URI_V24, XMLDeclarationConventionalPrimaryBusVehicleDataProviderV24.XSD_TYPE, XMLDefinitions.DECLARATION_DEFINITIONS_NAMESPACE_URI_V24, XMLDeclarationConventionalCompletedBusDataProviderV24.XSD_TYPE)]
diff --git a/Vecto3GUI2020Test/XML/XMLWritingTest/XMLCompleteBus.cs b/Vecto3GUI2020Test/XML/XMLWritingTest/XMLCompleteBus.cs
new file mode 100644
index 0000000000..34fde93608
--- /dev/null
+++ b/Vecto3GUI2020Test/XML/XMLWritingTest/XMLCompleteBus.cs
@@ -0,0 +1,69 @@
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Ninject;
+using NUnit.Framework;
+using TUGraz.VectoCore;
+using TUGraz.VectoCore.InputData.FileIO.XML;
+using VECTO3GUI2020.Ninject;
+using VECTO3GUI2020.Ninject.Factories;
+using VECTO3GUI2020.ViewModel.Interfaces;
+using VECTO3GUI2020.ViewModel.MultiStage.Implementation;
+using Vecto3GUI2020Test.Utils;
+
+namespace Vecto3GUI2020Test.XML.XMLWritingTest;
+
+[TestFixture]
+public class XMLCompleteBus
+{
+	public const string BASEDIR = @"TestData/Integration/Multistage/FactorMethod";
+
+
+	private ThreadLocal<IKernel> _kernel;
+	private IKernel Kernel => _kernel.Value;
+
+
+
+
+	[OneTimeSetUp]
+	public void OneTimeSetup()
+	{
+		_kernel = new ThreadLocal<IKernel>(TestHelper.GetKernel);
+		
+
+
+
+	}
+	
+
+
+
+
+    [TestCase("CompletedBus_41-32b_AT-P.vecto")]
+	[TestCase("CompletedBus_42-33b.vecto")]
+    public async Task LoadCompletedBus(string completedJob)
+	{
+		var filePath = Path.GetFullPath(Path.Combine(BASEDIR, completedJob));
+		Assert.IsTrue(File.Exists(filePath), "missing file " + filePath);
+		var jobList = Kernel.Get<IJobListViewModel>();
+		var doc = await jobList.AddJobAsync(filePath);
+		Assert.NotNull(doc);
+		var editingViewModel = doc.EditViewModel as MultiStageJobViewModel_v0_1;
+
+
+		var md = Kernel.GetMockDialogHelper();
+		md.PushFileName("test.xml");
+		editingViewModel.SaveVIFCommand.Execute(null);
+
+
+		md.AssertNoErrorDialogs();
+
+
+	}
+
+
+
+
+
+}
\ No newline at end of file
-- 
GitLab