Select Git revision
ViewModelTestBase.cs
Forked from
VECTO / VECTO Sim
5424 commits behind the upstream repository.

Harald Martini authored
Save file only if its valid in MultistageJobViewModel_v0_1 MultistageAirdragView Added Ignore Attributes to UI Tests that are using WinappDriver desktop session. Added VIF Testclass
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ViewModelTestBase.cs 4.00 KiB
using System;
using System.IO;
using Moq;
using Ninject;
using NUnit.Framework;
using TUGraz.VectoCore;
using TUGraz.VectoCore.InputData.FileIO.XML;
using VECTO3GUI2020.Helper;
using VECTO3GUI2020.Ninject;
using VECTO3GUI2020.Ninject.Vehicle;
using VECTO3GUI2020.ViewModel.MultiStage.Implementation;
using VECTO3GUI2020.ViewModel.MultiStage.Interfaces;
namespace Vecto3GUI2020Test
{
public class ViewModelTestBase
{
protected const string DirPath = @"Testdata\";
protected const string consolidated_multiple_stages = "vecto_multistage_consolidated_multiple_stages.xml";
protected const string consolidated_multiple_stages_airdrag =
"vecto_multistage_consolidated_multiple_stages_airdrag.xml";
protected const string consolidated_one_stage = "vecto_multistage_consolidated_one_stage.xml";
protected const string primary_vehicle_only = "vecto_multistage_primary_vehicle_only.xml";
protected IXMLInputDataReader xmlInputReader;
protected IKernel _kernel;
[SetUp]
public void OneTimeSetUp()
{
_kernel = new StandardKernel(
new VectoNinjectModule(),
new JobEditModule(),
new ComponentModule(),
new DocumentModule(),
new XMLWriterFactoryModule(),
new FactoryModule(),
new MultistageModule()
);
xmlInputReader = _kernel.Get<IXMLInputDataReader>();
}
[TearDown]
public void TearDown()
{
_kernel.Dispose();
_kernel = null;
}
public bool checkFileExists(string fileName)
{
var filePath = Path.GetFullPath(DirPath + fileName);
var exists = File.Exists(filePath);
if (exists)
{
Console.WriteLine(filePath + @" exists");
} else {
Console.WriteLine(filePath + @" not existing");
}
return exists;
}
public void deleteFile(string fileName)
{
var filePath = Path.GetFullPath(DirPath + fileName);
File.Delete(fileName);
}
public NewMultiStageJobViewModel loadFile(string fileName)
{
string filePath = "";
filePath = Path.GetFullPath(DirPath + fileName);
var dialogMock = new Mock<IDialogHelper>();
dialogMock.Setup(dialogHelper => dialogHelper.OpenXMLFileDialog(It.IsAny<string>())).Returns(filePath);
dialogMock.Setup(dialogHelper => dialogHelper.OpenXMLFileDialog()).Returns(filePath);
var newMultistageJobViewModel = new NewMultiStageJobViewModel(dialogMock.Object, xmlInputReader,
_kernel.Get<IMultiStageViewModelFactory>());
newMultistageJobViewModel.AddVifFile.Execute(null);
Assert.NotNull(newMultistageJobViewModel.MultiStageJobViewModel);
var manstageVehicleViewModel = newMultistageJobViewModel.MultiStageJobViewModel.ManufacturingStageViewModel.Vehicle as DeclarationInterimStageBusVehicleViewModel_v2_8;
Assert.NotNull(manstageVehicleViewModel);
var auxiliariesViewModel = manstageVehicleViewModel.MultistageAuxiliariesViewModel;
Assert.NotNull(auxiliariesViewModel);
var airdragViewModel = (manstageVehicleViewModel as DeclarationInterimStageBusVehicleViewModel_v2_8)?.MultistageAirdragViewModel;
Assert.NotNull(airdragViewModel);
Assert.AreEqual(filePath, newMultistageJobViewModel.VifPath);
return newMultistageJobViewModel;
}
protected Mock<IDialogHelper> getMockDialogHelper(string fileToLoad = null, string fileToSave = null)
{
Mock<IDialogHelper> mockDialogHelper = null;
if (fileToLoad != null) {
var filePath = Path.GetFullPath(DirPath + fileToLoad);
Assert.NotNull(filePath);
mockDialogHelper = new Mock<IDialogHelper>();
mockDialogHelper.Setup(dialogHelper => dialogHelper.OpenXMLFileDialog(It.IsAny<string>())).Returns(filePath);
mockDialogHelper.Setup(dialogHelper => dialogHelper.OpenXMLFileDialog()).Returns(filePath);
}
if (fileToSave != null) {
var filePath = Path.GetFullPath(DirPath + fileToSave);
mockDialogHelper = mockDialogHelper ?? new Mock<IDialogHelper>();
mockDialogHelper.Setup(dialogHelper =>
dialogHelper.SaveToXMLDialog(It.IsAny<string>())).Returns(filePath);
mockDialogHelper.Setup(dialogHelper =>
dialogHelper.SaveToXMLDialog(null)).Returns(filePath);
}
return mockDialogHelper;
}
}
}