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.
171 lines
4.8 KiB
C#
171 lines
4.8 KiB
C#
using JdeScoping.ConfigManager.Core.Constants;
|
|
using JdeScoping.ConfigManager.Ui.ViewModels.Dialogs;
|
|
|
|
namespace JdeScoping.ConfigManager.Ui.Tests.ViewModels.Dialogs;
|
|
|
|
public class UnlockStoreDialogViewModelTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_SetsStorePathFromParameter()
|
|
{
|
|
// Arrange
|
|
var storePath = "/path/to/store.secure";
|
|
|
|
// Act
|
|
var sut = new UnlockStoreDialogViewModel(storePath);
|
|
|
|
// Assert
|
|
sut.StorePath.ShouldBe(storePath);
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_ThrowsOnNullStorePath()
|
|
{
|
|
// Act & Assert
|
|
Should.Throw<ArgumentNullException>(() => new UnlockStoreDialogViewModel(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void StorePath_IsReadOnly()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
|
|
// Assert - StorePath property has no setter, verified by checking it returns what was passed
|
|
sut.StorePath.ShouldBe("/path/to/store.secure");
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenEmpty_IsValidReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = ""
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.IsValid.ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenEmpty_ValidationErrorReturnsKeyFilePathRequired()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = ""
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFilePathRequired);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenWhitespace_IsValidReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = " "
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.IsValid.ShouldBeFalse();
|
|
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFilePathRequired);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenFileDoesNotExist_IsValidReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = "/nonexistent/path/to/key.key"
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.IsValid.ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenFileDoesNotExist_ValidationErrorReturnsKeyFileNotFound()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = "/nonexistent/path/to/key.key"
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFileNotFound);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenChanged_RaisesPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
var propertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.KeyFilePath))
|
|
propertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.KeyFilePath = "/new/key/path";
|
|
|
|
// Assert
|
|
propertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenChanged_RaisesIsValidPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
var isValidPropertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.IsValid))
|
|
isValidPropertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.KeyFilePath = "/new/key/path";
|
|
|
|
// Assert
|
|
isValidPropertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenChanged_RaisesValidationErrorPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
var validationErrorPropertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.ValidationError))
|
|
validationErrorPropertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.KeyFilePath = "/new/key/path";
|
|
|
|
// Assert
|
|
validationErrorPropertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void BrowseKeyFilePathCommand_IsInitialized()
|
|
{
|
|
// Arrange & Act
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
|
|
// Assert
|
|
sut.BrowseKeyFilePathCommand.ShouldNotBeNull();
|
|
}
|
|
}
|