1fc7792cd1
Rename ConfigManager to ConfigManager.Ui to match the Core/CLI/UI project structure, and split the monolithic test project into Core.Tests, Cli.Tests, and Ui.Tests to align with the source project organization.
109 lines
2.8 KiB
C#
109 lines
2.8 KiB
C#
using JdeScoping.ConfigManager.Core.Models;
|
|
using JdeScoping.ConfigManager.Ui.ViewModels.Forms;
|
|
|
|
namespace JdeScoping.ConfigManager.Ui.Tests.ViewModels.Forms;
|
|
|
|
public class SearchFormViewModelTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_InitializesFromModel()
|
|
{
|
|
// Arrange
|
|
var model = new SearchSection
|
|
{
|
|
MaxResultRows = 50000,
|
|
TimeoutSeconds = 600,
|
|
MaxConcurrentSearches = 10
|
|
};
|
|
|
|
// Act
|
|
var sut = new SearchFormViewModel(model, () => { });
|
|
|
|
// Assert
|
|
sut.MaxResultRows.ShouldBe(50000);
|
|
sut.TimeoutSeconds.ShouldBe(600);
|
|
sut.MaxConcurrentSearches.ShouldBe(10);
|
|
}
|
|
|
|
[Fact]
|
|
public void PropertyChange_UpdatesModel()
|
|
{
|
|
// Arrange
|
|
var model = new SearchSection { MaxResultRows = 100000 };
|
|
var sut = new SearchFormViewModel(model, () => { });
|
|
|
|
// Act
|
|
sut.MaxResultRows = 25000;
|
|
|
|
// Assert
|
|
model.MaxResultRows.ShouldBe(25000);
|
|
}
|
|
|
|
[Fact]
|
|
public void PropertyChange_InvokesOnChanged()
|
|
{
|
|
// Arrange
|
|
var model = new SearchSection();
|
|
var changedInvoked = false;
|
|
var sut = new SearchFormViewModel(model, () => changedInvoked = true);
|
|
|
|
// Act
|
|
sut.TimeoutSeconds = 120;
|
|
|
|
// Assert
|
|
changedInvoked.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void PropertyChange_RaisesPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var model = new SearchSection();
|
|
var sut = new SearchFormViewModel(model, () => { });
|
|
var propertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(SearchFormViewModel.MaxConcurrentSearches))
|
|
propertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.MaxConcurrentSearches = 8;
|
|
|
|
// Assert
|
|
propertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_ThrowsOnNullModel()
|
|
{
|
|
// Act & Assert
|
|
Should.Throw<ArgumentNullException>(() => new SearchFormViewModel(null!, () => { }));
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_ThrowsOnNullCallback()
|
|
{
|
|
// Arrange
|
|
var model = new SearchSection();
|
|
|
|
// Act & Assert
|
|
Should.Throw<ArgumentNullException>(() => new SearchFormViewModel(model, null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void PropertyChange_DoesNotInvokeOnChangedWhenValueUnchanged()
|
|
{
|
|
// Arrange
|
|
var model = new SearchSection { MaxResultRows = 50000 };
|
|
var changedCount = 0;
|
|
var sut = new SearchFormViewModel(model, () => changedCount++);
|
|
|
|
// Act - set to same value
|
|
sut.MaxResultRows = 50000;
|
|
|
|
// Assert
|
|
changedCount.ShouldBe(0);
|
|
}
|
|
}
|