feat(configmanager): add DataAccessFormViewModel

This commit is contained in:
Joseph Doherty
2026-01-19 19:42:10 -05:00
parent c416544efe
commit 64518c7000
2 changed files with 180 additions and 0 deletions
@@ -0,0 +1,137 @@
using JdeScoping.ConfigManager.Models;
namespace JdeScoping.ConfigManager.ViewModels.Forms;
/// <summary>
/// ViewModel for editing DataAccess configuration section.
/// </summary>
public class DataAccessFormViewModel : ViewModelBase
{
private readonly DataAccessSection _model;
private readonly Action _onChanged;
public DataAccessFormViewModel(DataAccessSection model, Action onChanged)
{
_model = model ?? throw new ArgumentNullException(nameof(model));
_onChanged = onChanged ?? throw new ArgumentNullException(nameof(onChanged));
}
/// <summary>
/// Gets or sets the default query timeout in seconds.
/// </summary>
public int DefaultTimeoutSeconds
{
get => _model.DefaultTimeoutSeconds;
set
{
if (_model.DefaultTimeoutSeconds != value)
{
_model.DefaultTimeoutSeconds = value;
OnPropertyChanged();
_onChanged();
}
}
}
/// <summary>
/// Gets or sets the lot usage query timeout in seconds.
/// </summary>
public int LotUsageTimeoutSeconds
{
get => _model.LotUsageTimeoutSeconds;
set
{
if (_model.LotUsageTimeoutSeconds != value)
{
_model.LotUsageTimeoutSeconds = value;
OnPropertyChanged();
_onChanged();
}
}
}
/// <summary>
/// Gets or sets the MIS data query timeout in seconds.
/// </summary>
public int MisDataTimeoutSeconds
{
get => _model.MisDataTimeoutSeconds;
set
{
if (_model.MisDataTimeoutSeconds != value)
{
_model.MisDataTimeoutSeconds = value;
OnPropertyChanged();
_onChanged();
}
}
}
/// <summary>
/// Gets or sets the production schema name.
/// </summary>
public string ProductionSchema
{
get => _model.ProductionSchema;
set
{
if (_model.ProductionSchema != value)
{
_model.ProductionSchema = value;
OnPropertyChanged();
_onChanged();
}
}
}
/// <summary>
/// Gets or sets the archive schema name.
/// </summary>
public string ArchiveSchema
{
get => _model.ArchiveSchema;
set
{
if (_model.ArchiveSchema != value)
{
_model.ArchiveSchema = value;
OnPropertyChanged();
_onChanged();
}
}
}
/// <summary>
/// Gets or sets the stage schema name.
/// </summary>
public string StageSchema
{
get => _model.StageSchema;
set
{
if (_model.StageSchema != value)
{
_model.StageSchema = value;
OnPropertyChanged();
_onChanged();
}
}
}
/// <summary>
/// Gets or sets whether detailed logging is enabled.
/// </summary>
public bool EnableDetailedLogging
{
get => _model.EnableDetailedLogging;
set
{
if (_model.EnableDetailedLogging != value)
{
_model.EnableDetailedLogging = value;
OnPropertyChanged();
_onChanged();
}
}
}
}
@@ -0,0 +1,43 @@
using JdeScoping.ConfigManager.Models;
using JdeScoping.ConfigManager.ViewModels.Forms;
namespace JdeScoping.ConfigManager.Tests.ViewModels.Forms;
public class DataAccessFormViewModelTests
{
[Fact]
public void Constructor_InitializesFromModel()
{
// Arrange
var model = new DataAccessSection
{
DefaultTimeoutSeconds = 60,
ProductionSchema = "dbo",
EnableDetailedLogging = true
};
// Act
var sut = new DataAccessFormViewModel(model, () => { });
// Assert
sut.DefaultTimeoutSeconds.ShouldBe(60);
sut.ProductionSchema.ShouldBe("dbo");
sut.EnableDetailedLogging.ShouldBeTrue();
}
[Fact]
public void PropertyChange_UpdatesModelAndInvokesOnChanged()
{
// Arrange
var model = new DataAccessSection();
var changedInvoked = false;
var sut = new DataAccessFormViewModel(model, () => changedInvoked = true);
// Act
sut.ArchiveSchema = "hist";
// Assert
model.ArchiveSchema.ShouldBe("hist");
changedInvoked.ShouldBeTrue();
}
}