chore: deprecate standalone SecureStoreManager utility
Move SecureStoreManager project and tests to Deprecated folder and remove from solution. SecureStore functionality is now integrated into ConfigManager.
This commit is contained in:
@@ -0,0 +1,343 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using JdeScoping.SecureStoreManager.ViewModels;
|
||||
|
||||
namespace JdeScoping.SecureStoreManager.Tests.ViewModels;
|
||||
|
||||
public class NewStoreDialogViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsValid_WhenStorePathEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = string.Empty;
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenKeyFilePathEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WithValidConfiguration_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenStorePathEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Store path is required.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenKeyFilePathEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Key file path is required.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenValid_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
public class OpenStoreDialogViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsValid_WhenStorePathEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenKeyFilePathEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenStorePathEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Store path is required.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenStoreFileDoesNotExist_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = "/nonexistent/path/to/store.json";
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Store file does not exist.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenKeyFilePathEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange - Create temp store file so we get past that validation
|
||||
var tempFile = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = tempFile;
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Key file path is required.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenKeyFileDoesNotExist_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange - Create temp store file so we get past that validation
|
||||
var tempFile = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = tempFile;
|
||||
sut.KeyFilePath = "/nonexistent/key.key";
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Key file does not exist.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SecretEditDialogViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultConstructor_SetsIsNewSecretToTrue()
|
||||
{
|
||||
// Arrange & Act
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
|
||||
// Assert
|
||||
sut.IsNewSecret.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParameterizedConstructor_SetsKey()
|
||||
{
|
||||
// Arrange & Act
|
||||
var sut = new SecretEditDialogViewModel("testKey", "testValue");
|
||||
|
||||
// Assert
|
||||
sut.Key.ShouldBe("testKey");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParameterizedConstructor_SetsValue()
|
||||
{
|
||||
// Arrange & Act
|
||||
var sut = new SecretEditDialogViewModel("testKey", "testValue");
|
||||
|
||||
// Assert
|
||||
sut.Value.ShouldBe("testValue");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParameterizedConstructor_SetsIsNewSecretToFalse()
|
||||
{
|
||||
// Arrange & Act
|
||||
var sut = new SecretEditDialogViewModel("testKey", "testValue");
|
||||
|
||||
// Assert
|
||||
sut.IsNewSecret.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsKeyEditable_WhenIsNewSecret_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
|
||||
// Act & Assert
|
||||
sut.IsKeyEditable.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsKeyEditable_WhenEditingExisting_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel("testKey", "testValue");
|
||||
|
||||
// Act & Assert
|
||||
sut.IsKeyEditable.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DialogTitle_WhenIsNewSecret_ReturnsAddSecret()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
|
||||
// Act & Assert
|
||||
sut.DialogTitle.ShouldBe("Add Secret");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DialogTitle_WhenEditingExisting_ReturnsEditSecret()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel("testKey", "testValue");
|
||||
|
||||
// Act & Assert
|
||||
sut.DialogTitle.ShouldBe("Edit Secret");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenKeyEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
sut.Key = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenKeyWhitespace_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
sut.Key = " ";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenKeyProvided_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
sut.Key = "validKey";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenKeyEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
sut.Key = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Key is required.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenKeyProvided_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
sut.Key = "validKey";
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Key_SetterRaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(sut.Key))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.Key = "newKey";
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Value_SetterRaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new SecretEditDialogViewModel();
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(sut.Value))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.Value = "newValue";
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user