From ea62cd7f5ecc5f9246d95356ccf80b02deda2233 Mon Sep 17 00:00:00 2001 From: "VKMTHD\\haraldmartini" <harald.martini@student.tugraz.at> Date: Fri, 31 Mar 2023 12:23:38 +0200 Subject: [PATCH] added tests for different step input types --- VECTO3GUI2020/MainWindow.xaml | 2 +- .../InterimStageBusVehicleViewModel.cs | 7 +- .../ManufacturingStageViewModel_v0_1.cs | 2 +- .../Implementation/StageInputViewModel.cs | 349 +++++++++--------- .../Implementation/StageViewModelBase.cs | 2 +- .../Interfaces/IMultistageVehicleViewModel.cs | 2 +- .../ViewModelTests/StepViewModelTests.cs | 46 +++ 7 files changed, 228 insertions(+), 182 deletions(-) diff --git a/VECTO3GUI2020/MainWindow.xaml b/VECTO3GUI2020/MainWindow.xaml index 85c6888d21..35e21c197d 100644 --- a/VECTO3GUI2020/MainWindow.xaml +++ b/VECTO3GUI2020/MainWindow.xaml @@ -39,7 +39,7 @@ </MenuItem> <Separator></Separator> <MenuItem Header="{x:Static resx:GUILabels.CreateInterimCompletedInput}" Command="{Binding JobListVm.NewCompletedInputCommand}" /> - <MenuItem Header="{x:Static resx:GUILabels.CreateExemptedInterimCompletedInput}" Command="{Binding JobListVm.NewExemptedCompletedInputCommand}" /> + <!--<MenuItem Header="{x:Static resx:GUILabels.CreateExemptedInterimCompletedInput}" Command="{Binding JobListVm.NewExemptedCompletedInputCommand}" />--> </MenuItem> <MenuItem Header="Load File" Command="{Binding JobListVm.AddJobAsyncCommand}"/> <MenuItem Header="Settings" Command="{Binding OpenSettings}"/> diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel.cs index 9bf584c84d..0a0987c415 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel.cs @@ -278,7 +278,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation CreateParameterViewModels(); ShowConsolidatedData = false; - SetVehicleInputData(vehicleInput); + SetVehicleInputData(vehicleInput, checkExempted:true); } private void CreateParameterViewModels() { @@ -439,9 +439,9 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set { SetProperty(ref _consolidatedVehicleData, value); } } - public void SetVehicleInputData(IVehicleDeclarationInputData vehicleInputData) + public void SetVehicleInputData(IVehicleDeclarationInputData vehicleInputData, bool checkExempted) { - if (vehicleInputData.ExemptedVehicle != ExemptedVehicle) { + if (checkExempted && vehicleInputData.ExemptedVehicle != ExemptedVehicle) { throw new VectoException(ExemptedVehicle ? "Only exempted stage inputs are allowed" : "Exempted Vehicle not allowed"); } @@ -497,7 +497,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation private void SetExemptedVehicleInputData(IVehicleDeclarationInputData vehicleInputData) { - Debug.Assert(vehicleInputData.ExemptedVehicle); Manufacturer = vehicleInputData.Manufacturer; Identifier = vehicleInputData.Identifier; ManufacturerAddress = vehicleInputData.ManufacturerAddress; diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs index 629a89884c..7d5cff1b9b 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs @@ -47,7 +47,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public DigestData Signature => throw new NotImplementedException(); public void SetInputData(IVehicleDeclarationInputData vehicleInputData) { - VehicleViewModel.SetVehicleInputData(vehicleInputData); + VehicleViewModel.SetVehicleInputData(vehicleInputData, true); OnPropertyChanged(nameof(CurrentView)); diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs index 9cd834fa9f..57ffc5248f 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -16,183 +15,185 @@ using VECTO3GUI2020.ViewModel.MultiStage.Interfaces; namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { - public class StageInputViewModel : StageViewModelBase, IDocumentViewModel, IJobEditViewModel - { - public enum CompletedBusArchitecture - { - Conventional, - HEV, - PEV, - IEPC, - Exempted - } - - private bool _canBeEdited; - private DataSource _dataSource; - private readonly XmlDocumentType _documentType; - private string _documentName; - private bool _selected; - private static uint _newDocumentCounter = 0; - - - private CompletedBusArchitecture _architecture; - private ObservableCollection<CompletedBusArchitecture> _architectureItems = - new ObservableCollection<CompletedBusArchitecture>(Enum.GetValues(typeof(CompletedBusArchitecture)).Cast<CompletedBusArchitecture>()); - - public ObservableCollection<CompletedBusArchitecture> ArchitectureItems - { - get => _architectureItems; - set => SetProperty(ref _architectureItems, value); - } - - public CompletedBusArchitecture Architecture - { - get => _architecture; - set - { - if (SetProperty(ref _architecture, value)) { - UpdateVehicleViewModel(); - } - } - } - - private void UpdateVehicleViewModel() - { - if (VehicleViewModel.ShowConsolidatedData) { - throw new VectoException("This is only intended on \"standalone\" step inputs"); - } - var oldVm = _vehicleViewModel; - var newVm = _viewModelFactory.GetInterimStageVehicleViewModel(Architecture); - newVm.SetVehicleInputData(oldVm); - VehicleViewModel = newVm; - } - - - private StageInputViewModel(IMultiStageViewModelFactory multistageViewModelFactory, - IAdditionalJobInfoViewModel additionalJobInfoViewModel) : base(multistageViewModelFactory) - { - _documentType = XmlDocumentType.DeclarationJobData; - _additionalJobInfoViewModel = additionalJobInfoViewModel; - _additionalJobInfoViewModel.SetParent(this); - } - - - public StageInputViewModel(bool exemptedVehicle, IMultiStageViewModelFactory multiStageViewModelFactory, IAdditionalJobInfoViewModel additionalJobInfoViewModel) : this(multiStageViewModelFactory, additionalJobInfoViewModel) - { - Architecture = exemptedVehicle - ? CompletedBusArchitecture.Exempted - : CompletedBusArchitecture.Conventional; - - - _vehicleViewModel = multiStageViewModelFactory.GetInterimStageVehicleViewModel(Architecture); - - - - Title = $"{GUILabels.Edit_step_input} - New file"; - - _documentName = $"New {(exemptedVehicle ? "exempted " : "")}step input {++_newDocumentCounter}"; - - Init(); - return; + public class StageInputViewModel : StageViewModelBase, IDocumentViewModel, IJobEditViewModel + { + public enum CompletedBusArchitecture + { + Conventional, + HEV, + PEV, + IEPC, + Exempted } - public StageInputViewModel(IDeclarationInputDataProvider inputData, IMultiStageViewModelFactory multiStageViewModelFactory, IAdditionalJobInfoViewModel additionalJobInfoViewModel) : this(multiStageViewModelFactory,additionalJobInfoViewModel) - { - _documentName = inputData.JobInputData.JobName; + private bool _canBeEdited; + private DataSource _dataSource; + private readonly XmlDocumentType _documentType; + private string _documentName; + private bool _selected; + private static uint _newDocumentCounter = 0; - //_vehicleViewModel = - // _viewModelFactory.CreateStageInputVehicleViewModel(inputData.JobInputData.Vehicle) as IMultistageVehicleViewModel; - // (_vehicleViewModel as InterimStageBusVehicleViewModel).ShowConsolidatedData = false; - _dataSource = inputData.DataSource; - VehicleInputDataFilePath = _dataSource.SourceFile; + private CompletedBusArchitecture _architecture; + private ObservableCollection<CompletedBusArchitecture> _architectureItems = + new ObservableCollection<CompletedBusArchitecture>(Enum.GetValues(typeof(CompletedBusArchitecture)).Cast<CompletedBusArchitecture>()); - Title = $"{GUILabels.Edit_step_input} - {Path.GetFileName(_dataSource.SourceFile)}"; - Init(); + public ObservableCollection<CompletedBusArchitecture> ArchitectureItems + { + get => _architectureItems; + set => SetProperty(ref _architectureItems, value); + } + + public CompletedBusArchitecture Architecture + { + get => _architecture; + set + { + if (SetProperty(ref _architecture, value)) + { + UpdateVehicleViewModel(); + } + } + } + + private void UpdateVehicleViewModel() + { + if (VehicleViewModel.ShowConsolidatedData) + { + throw new VectoException("This is only intended on \"standalone\" step inputs"); + } + var oldVm = _vehicleViewModel; + var newVm = _viewModelFactory.GetInterimStageVehicleViewModel(Architecture); + newVm.SetVehicleInputData(oldVm,false); + VehicleViewModel = newVm; + } + + + private StageInputViewModel(IMultiStageViewModelFactory multistageViewModelFactory, + IAdditionalJobInfoViewModel additionalJobInfoViewModel) : base(multistageViewModelFactory) + { + _documentType = XmlDocumentType.DeclarationJobData; + _additionalJobInfoViewModel = additionalJobInfoViewModel; + _additionalJobInfoViewModel.SetParent(this); + } + + + public StageInputViewModel(bool exemptedVehicle, IMultiStageViewModelFactory multiStageViewModelFactory, IAdditionalJobInfoViewModel additionalJobInfoViewModel) : this(multiStageViewModelFactory, additionalJobInfoViewModel) + { + Architecture = exemptedVehicle + ? CompletedBusArchitecture.Exempted + : CompletedBusArchitecture.Conventional; + + + _vehicleViewModel = multiStageViewModelFactory.GetInterimStageVehicleViewModel(Architecture); + + + + Title = $"{GUILabels.Edit_step_input} - New file"; + + _documentName = $"New {(exemptedVehicle ? "exempted " : "")}step input {++_newDocumentCounter}"; + + Init(); + return; + } + + public StageInputViewModel(IDeclarationInputDataProvider inputData, IMultiStageViewModelFactory multiStageViewModelFactory, IAdditionalJobInfoViewModel additionalJobInfoViewModel) : this(multiStageViewModelFactory, additionalJobInfoViewModel) + { + _documentName = inputData.JobInputData.JobName; + + //_vehicleViewModel = + // _viewModelFactory.CreateStageInputVehicleViewModel(inputData.JobInputData.Vehicle) as IMultistageVehicleViewModel; + // (_vehicleViewModel as InterimStageBusVehicleViewModel).ShowConsolidatedData = false; + + _dataSource = inputData.DataSource; + VehicleInputDataFilePath = _dataSource.SourceFile; + + Title = $"{GUILabels.Edit_step_input} - {Path.GetFileName(_dataSource.SourceFile)}"; + Init(); return; - } - - #region Overrides of StageViewModelBase - /// <summary> - /// Called in base class after input data is loaded. - /// </summary> - /// <param name="loadedInputData"></param> - protected override void LoadStageInputDataFollowUp(IDeclarationInputDataProvider loadedInputData) - { - DataSource = loadedInputData.DataSource; - VehicleInputDataFilePath = DataSource.SourceFile; - UpdateTitle(); - DocumentName = loadedInputData.JobInputData.JobName; - } - - #endregion - - private void UpdateTitle() - { - Title = GUILabels.Edit_step_input + " - " + ((_dataSource?.SourceFile != null) - ? Path.GetFileName(_dataSource.SourceFile) - : "New file"); - } - - private void Init() - { - UpdateTitle(); - Components["vehicle"] = VehicleViewModel as IViewModelBase; - Components["auxiliaries"] = VehicleViewModel.MultistageAuxiliariesViewModel as IViewModelBase; - Components["airdrag"] = VehicleViewModel.MultistageAirdragViewModel as IViewModelBase; - CurrentView = VehicleViewModel as IViewModelBase; - - ShowSaveAndCloseButtons = true; - } - - #region Implementation of IDocumentViewModel - - public string DocumentName - { - get => _documentName; - set => SetProperty(ref _documentName, value); - } - - public XmlDocumentType? DocumentType => _documentType; - - public string DocumentTypeName => "Step input"; - - public DataSource DataSource - { - get => _dataSource; - set - { - SetProperty(ref _dataSource, value); - UpdateTitle(); - } - } - - public IEditViewModel EditViewModel => this; - - public bool Selected - { - get => _selected && CanBeSimulated; - set => SetProperty(ref _selected, value); - } - - public bool CanBeSimulated - { - get => false; - set => throw new System.NotImplementedException(); - } - private IAdditionalJobInfoViewModel _additionalJobInfoViewModel; - public IAdditionalJobInfoViewModel AdditionalJobInfoVm - { - get => _additionalJobInfoViewModel; - set => SetProperty(ref _additionalJobInfoViewModel, value); - } - - #endregion - - #region Implementation of IEditViewModel - - public string Name => "Edit Stage Input"; - - #endregion - } + } + + #region Overrides of StageViewModelBase + /// <summary> + /// Called in base class after input data is loaded. + /// </summary> + /// <param name="loadedInputData"></param> + protected override void LoadStageInputDataFollowUp(IDeclarationInputDataProvider loadedInputData) + { + DataSource = loadedInputData.DataSource; + VehicleInputDataFilePath = DataSource.SourceFile; + UpdateTitle(); + DocumentName = loadedInputData.JobInputData.JobName; + } + + #endregion + + private void UpdateTitle() + { + Title = GUILabels.Edit_step_input + " - " + ((_dataSource?.SourceFile != null) + ? Path.GetFileName(_dataSource.SourceFile) + : "New file"); + } + + private void Init() + { + UpdateTitle(); + Components["vehicle"] = VehicleViewModel as IViewModelBase; + Components["auxiliaries"] = VehicleViewModel.MultistageAuxiliariesViewModel as IViewModelBase; + Components["airdrag"] = VehicleViewModel.MultistageAirdragViewModel as IViewModelBase; + CurrentView = VehicleViewModel as IViewModelBase; + + ShowSaveAndCloseButtons = true; + } + + #region Implementation of IDocumentViewModel + + public string DocumentName + { + get => _documentName; + set => SetProperty(ref _documentName, value); + } + + public XmlDocumentType? DocumentType => _documentType; + + public string DocumentTypeName => "Step input"; + + public DataSource DataSource + { + get => _dataSource; + set + { + SetProperty(ref _dataSource, value); + UpdateTitle(); + } + } + + public IEditViewModel EditViewModel => this; + + public bool Selected + { + get => _selected && CanBeSimulated; + set => SetProperty(ref _selected, value); + } + + public bool CanBeSimulated + { + get => false; + set => throw new System.NotImplementedException(); + } + private IAdditionalJobInfoViewModel _additionalJobInfoViewModel; + public IAdditionalJobInfoViewModel AdditionalJobInfoVm + { + get => _additionalJobInfoViewModel; + set => SetProperty(ref _additionalJobInfoViewModel, value); + } + + #endregion + + #region Implementation of IEditViewModel + + public string Name => "Edit Stage Input"; + + #endregion + } } \ No newline at end of file diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs index b00c7e3b93..c515e3b7c4 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs @@ -230,7 +230,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { var inputData = (IDeclarationInputDataProvider)_inputDataReader.Create(fileName); var vehicleInputData = inputData.JobInputData.Vehicle; - VehicleViewModel.SetVehicleInputData(vehicleInputData); + VehicleViewModel.SetVehicleInputData(vehicleInputData, true); VehicleInputDataFilePath = inputData.DataSource.SourceFile; LoadStageInputDataFollowUp(inputData); diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageVehicleViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageVehicleViewModel.cs index ffd79d079b..c2349ca4cf 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageVehicleViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageVehicleViewModel.cs @@ -14,7 +14,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Interfaces IMultistageAuxiliariesViewModel MultistageAuxiliariesViewModel { get; set; } bool PrimaryVehicleHybridElectric { get; set; } bool ShowConsolidatedData { get; set; } - void SetVehicleInputData(IVehicleDeclarationInputData vehicleInputData); + void SetVehicleInputData(IVehicleDeclarationInputData vehicleInputData, bool checkExempted); } } diff --git a/Vecto3GUI2020Test/ViewModelTests/StepViewModelTests.cs b/Vecto3GUI2020Test/ViewModelTests/StepViewModelTests.cs index 4a174d4eab..537cd4b8e0 100644 --- a/Vecto3GUI2020Test/ViewModelTests/StepViewModelTests.cs +++ b/Vecto3GUI2020Test/ViewModelTests/StepViewModelTests.cs @@ -24,11 +24,13 @@ namespace Vecto3GUI2020Test.ViewModelTests private IKernel _kernel; private MockWindowHelper _windowHelper; private MockDialogHelper _dialogHelper; + private IMultiStageViewModelFactory _viewModelFactory; [SetUp] public void Setup() { _kernel = TestHelper.GetKernel(out _dialogHelper, out _windowHelper); + _viewModelFactory = _kernel.Get<IMultiStageViewModelFactory>(); } [TestCase(true, TestName="Exempted")] @@ -132,12 +134,56 @@ namespace Vecto3GUI2020Test.ViewModelTests [Test] public void CreateStepInput() + { + var stepInput = _viewModelFactory.GetCreateNewStepInputViewModel(false) as StageInputViewModel; + Assert.NotNull(stepInput.VehicleViewModel); + Assert.NotNull(stepInput.VehicleViewModel.MultistageAirdragViewModel); + Assert.NotNull(stepInput.VehicleViewModel.MultistageAuxiliariesViewModel); + Assert.NotNull(stepInput.Architecture == StageInputViewModel.CompletedBusArchitecture.Conventional); + } + + [Test] + public void CreateStepInputForAllArchitectures([Values] StageInputViewModel.CompletedBusArchitecture arch) { + var stepInput = _viewModelFactory.GetCreateNewStepInputViewModel(false) as StageInputViewModel; + Assert.NotNull(stepInput.VehicleViewModel); + var oldVm = stepInput.VehicleViewModel; + if (arch == stepInput.Architecture) { + Assert.Pass("Nothing to see here ..."); + } + stepInput.Architecture = arch; + Assert.NotNull(stepInput.VehicleViewModel); + Assert.AreNotSame(oldVm, stepInput.VehicleViewModel); } + [Test] + public void SwitchArchitectures([Values] StageInputViewModel.CompletedBusArchitecture from, + [Values] StageInputViewModel.CompletedBusArchitecture to) + { + + if (from == to) { + Assert.Pass("Nothing to see here ..."); + } + var stepInput = _viewModelFactory.GetCreateNewStepInputViewModel(false) as StageInputViewModel; + Assert.NotNull(stepInput.VehicleViewModel); + + + stepInput.Architecture = from; + var oldVm = stepInput.VehicleViewModel; + Assert.NotNull(stepInput.VehicleViewModel); + + + stepInput.Architecture = to; + var newVm = stepInput.VehicleViewModel; + Assert.NotNull(newVm); + Assert.AreNotSame(oldVm, newVm); + + } + + } -- GitLab