Add mock constructors to allow designer to instantiate viewmodels.

This commit is contained in:
2025-07-09 14:07:26 +01:00
parent 5586cc19c4
commit 3b576b0b0e
10 changed files with 89 additions and 4 deletions

View File

@@ -49,6 +49,41 @@ public class EditDatViewModel : ViewModelBase
string _name;
string _version;
// Mock
public EditDatViewModel()
{
var romSet = new RomSetModel
{
Author = "Author",
Comment = "Comment",
Category = "Category",
Date = "Date",
Description = "Description",
Homepage = "http://example.com",
Name = "Name",
Version = "Version",
Filename = "Filename.dat",
Sha384 = "MOCKEDSHA384HASH",
TotalMachines = 100,
CompleteMachines = 80,
IncompleteMachines = 20,
TotalRoms = 1000,
HaveRoms = 800,
MissRoms = 200,
Id = 1
};
_romSet = romSet;
_name = romSet.Name;
_version = romSet.Version;
_author = romSet.Author;
_comment = romSet.Comment;
_category = romSet.Category;
_date = romSet.Date;
_description = romSet.Description;
_homepage = romSet.Homepage;
}
public EditDatViewModel(EditDat view, RomSetModel romSet)
{
_view = view;

View File

@@ -49,6 +49,9 @@ public sealed class ExportDatViewModel : ViewModelBase
bool _progressVisible;
string _statusMessage;
// Mock
public ExportDatViewModel() {}
public ExportDatViewModel(ExportDat view, string datHash, string outPath)
{
_view = view;

View File

@@ -58,6 +58,14 @@ public sealed class ExportRomsViewModel : ViewModelBase
string _status3Message;
string _statusMessage;
// Mock
public ExportRomsViewModel()
{
#pragma warning disable PH2080
FolderPath = "C:\\ExportedRoms";
#pragma warning restore PH2080
}
public ExportRomsViewModel(ExportRoms view, string folderPath, long romSetId)
{
_view = view;

View File

@@ -64,6 +64,14 @@ public sealed class ImportDatFolderViewModel : ViewModelBase
string _status2Message;
string _statusMessage;
// Mock
public ImportDatFolderViewModel()
{
#pragma warning disable PH2080
FolderPath = "C:\\ROMs";
#pragma warning restore PH2080
}
public ImportDatFolderViewModel(ImportDatFolder view, string folderPath)
{
_view = view;

View File

@@ -48,6 +48,9 @@ public sealed class ImportDatViewModel : ViewModelBase
bool _progressVisible;
string _statusMessage;
// Mock
public ImportDatViewModel() {}
public ImportDatViewModel(ImportDat view, string datPath)
{
_view = view;

View File

@@ -61,6 +61,14 @@ public sealed class ImportRomFolderViewModel : ViewModelBase
string _status2Message;
string _statusMessage;
// Mock
public ImportRomFolderViewModel()
{
#pragma warning disable PH2080
FolderPath = "C:\\ROMs";
#pragma warning restore PH2080
}
public ImportRomFolderViewModel(ImportRomFolder view, string folderPath)
{
_view = view;

View File

@@ -52,6 +52,9 @@ public class MainWindowViewModel : ViewModelBase
RomSetModel _selectedRomSet;
Vfs _vfs;
// Mock
public MainWindowViewModel() {}
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
{
_view = view;

View File

@@ -35,9 +35,20 @@ using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels;
public sealed class RemoveDatViewModel(RemoveDat view, long romSetId) : ViewModelBase
public sealed class RemoveDatViewModel : ViewModelBase
{
string _statusMessage;
readonly long _romSetId;
readonly RemoveDat _view;
string _statusMessage;
// Mock
public RemoveDatViewModel() {}
public RemoveDatViewModel(RemoveDat view, long romSetId)
{
_view = view;
_romSetId = romSetId;
}
public string StatusMessage
{
@@ -53,7 +64,7 @@ public sealed class RemoveDatViewModel(RemoveDat view, long romSetId) : ViewMode
Dispatcher.UIThread.Post(() => StatusMessage = Localization.RetrievingRomSetFromDatabase);
RomSet romSet = ctx.RomSets.Find(romSetId);
RomSet romSet = ctx.RomSets.Find(_romSetId);
if(romSet == null) return;
@@ -93,7 +104,7 @@ public sealed class RemoveDatViewModel(RemoveDat view, long romSetId) : ViewMode
if(File.Exists(compressedDatPath)) File.Delete(compressedDatPath);
Dispatcher.UIThread.Post(view.Close);
Dispatcher.UIThread.Post(_view.Close);
});
}
}

View File

@@ -56,6 +56,9 @@ public sealed class SettingsViewModel : ViewModelBase
string _unArPath;
string _unArVersion;
// Mock
public SettingsViewModel() {}
public SettingsViewModel(SettingsDialog view)
{
_view = view;

View File

@@ -51,6 +51,9 @@ public sealed class UpdateStatsViewModel : ViewModelBase
RomSetModel _selectedRomSet;
string _statusMessage;
// Mock
public UpdateStatsViewModel() {}
public UpdateStatsViewModel(UpdateStats view)
{
_view = view;