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,154 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.VisualTree;
|
||||
using NSubstitute;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using JdeScoping.SecureStoreManager.Services;
|
||||
using JdeScoping.SecureStoreManager.ViewModels;
|
||||
using JdeScoping.SecureStoreManager.Views;
|
||||
|
||||
namespace JdeScoping.SecureStoreManager.Tests.Views;
|
||||
|
||||
public class MainWindowTests
|
||||
{
|
||||
private static MainWindowViewModel CreateViewModel(ISecureStoreManager? storeManager = null)
|
||||
{
|
||||
var mockStoreManager = storeManager ?? Substitute.For<ISecureStoreManager>();
|
||||
var mockDialogService = Substitute.For<IDialogService>();
|
||||
var mockClipboardService = Substitute.For<IClipboardService>();
|
||||
return new MainWindowViewModel(mockStoreManager, mockDialogService, mockClipboardService);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_ShowsWithCorrectDefaultTitle()
|
||||
{
|
||||
// Arrange
|
||||
var storeManager = Substitute.For<ISecureStoreManager>();
|
||||
storeManager.IsStoreOpen.Returns(false);
|
||||
var viewModel = CreateViewModel(storeManager);
|
||||
var window = new MainWindow { DataContext = viewModel };
|
||||
|
||||
// Act
|
||||
window.Show();
|
||||
|
||||
// Assert - Title is bound to WindowTitle which is "SecureStore Manager" when no store is open
|
||||
window.Title.ShouldBe("SecureStore Manager");
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_HasExpectedWidth()
|
||||
{
|
||||
// Arrange & Act
|
||||
var window = new MainWindow();
|
||||
window.Show();
|
||||
|
||||
// Assert
|
||||
window.Width.ShouldBe(800);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_HasExpectedHeight()
|
||||
{
|
||||
// Arrange & Act
|
||||
var window = new MainWindow();
|
||||
window.Show();
|
||||
|
||||
// Assert
|
||||
window.Height.ShouldBe(500);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_DataContextIsMainWindowViewModel()
|
||||
{
|
||||
// Arrange
|
||||
var viewModel = CreateViewModel();
|
||||
|
||||
// Act
|
||||
var window = new MainWindow { DataContext = viewModel };
|
||||
window.Show();
|
||||
|
||||
// Assert - DataContext is set via DI in production, but must be set manually in tests
|
||||
window.DataContext.ShouldBeOfType<MainWindowViewModel>();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_ContainsSecretsDataGrid()
|
||||
{
|
||||
// Arrange & Act
|
||||
var window = new MainWindow();
|
||||
window.Show();
|
||||
|
||||
// Assert
|
||||
var dataGrid = window.FindDescendantOfType<DataGrid>();
|
||||
dataGrid.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_ContainsMenuBar()
|
||||
{
|
||||
// Arrange & Act
|
||||
var window = new MainWindow();
|
||||
window.Show();
|
||||
|
||||
// Assert
|
||||
var menu = window.FindDescendantOfType<Menu>();
|
||||
menu.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_ContainsToolbarButtons()
|
||||
{
|
||||
// Arrange & Act
|
||||
var window = new MainWindow();
|
||||
window.Show();
|
||||
|
||||
// Assert
|
||||
var buttons = window.GetVisualDescendants().OfType<Button>().ToList();
|
||||
buttons.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
// Verify toolbar buttons exist with expected content
|
||||
buttons.Any(b => b.Content?.ToString() == "New").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Open").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Save").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Add").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Edit").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Delete").ShouldBeTrue();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_NewButtonCommand_IsBoundToViewModel()
|
||||
{
|
||||
// Arrange
|
||||
var storeManager = Substitute.For<ISecureStoreManager>();
|
||||
var viewModel = CreateViewModel(storeManager);
|
||||
var window = new MainWindow { DataContext = viewModel };
|
||||
|
||||
// Act
|
||||
window.Show();
|
||||
|
||||
var buttons = window.GetVisualDescendants().OfType<Button>().ToList();
|
||||
var newButton = buttons.FirstOrDefault(b => b.Content?.ToString() == "New");
|
||||
|
||||
// Assert
|
||||
newButton.ShouldNotBeNull();
|
||||
newButton.Command.ShouldBe(viewModel.NewStoreCommand);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void MainWindow_StatusBar_DisplaysStatusMessage()
|
||||
{
|
||||
// Arrange
|
||||
var storeManager = Substitute.For<ISecureStoreManager>();
|
||||
var viewModel = CreateViewModel(storeManager);
|
||||
var window = new MainWindow { DataContext = viewModel };
|
||||
|
||||
// Act
|
||||
window.Show();
|
||||
|
||||
// Assert - Find status bar text blocks
|
||||
var textBlocks = window.GetVisualDescendants().OfType<TextBlock>().ToList();
|
||||
// Status message should be "Ready" by default
|
||||
textBlocks.Any(tb => tb.Text == viewModel.StatusMessage).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.VisualTree;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using JdeScoping.SecureStoreManager.ViewModels;
|
||||
using JdeScoping.SecureStoreManager.Views;
|
||||
|
||||
namespace JdeScoping.SecureStoreManager.Tests.Views;
|
||||
|
||||
public class NewStoreDialogTests
|
||||
{
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_ShowsWithCorrectTitle()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.Title.ShouldBe("Create New Store");
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_DataContextIsNewStoreDialogViewModel()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.DataContext.ShouldBeOfType<NewStoreDialogViewModel>();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_HasStorePathTextBox()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
var textBoxes = dialog.GetVisualDescendants().OfType<TextBox>().ToList();
|
||||
textBoxes.Count.ShouldBeGreaterThan(0);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_HasKeyFilePathTextBox()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert - Should have at least 2 text boxes: store path and key file path
|
||||
var textBoxes = dialog.GetVisualDescendants().OfType<TextBox>().ToList();
|
||||
textBoxes.Count.ShouldBeGreaterThanOrEqualTo(2);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_HasCreateAndCancelButtons()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
var buttons = dialog.GetVisualDescendants().OfType<Button>().ToList();
|
||||
buttons.Any(b => b.Content?.ToString() == "Create").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Cancel").ShouldBeTrue();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_ViewModelProperty_ReturnsDataContext()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.ViewModel.ShouldBe(dialog.DataContext);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_CannotResize()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.CanResize.ShouldBeFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.VisualTree;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using JdeScoping.SecureStoreManager.ViewModels;
|
||||
using JdeScoping.SecureStoreManager.Views;
|
||||
|
||||
namespace JdeScoping.SecureStoreManager.Tests.Views;
|
||||
|
||||
public class SecretEditDialogTests
|
||||
{
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_DefaultConstructor_ShowsAddSecretTitle()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.Title.ShouldBe("Add Secret");
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_WithKeyValueParams_ShowsEditSecretTitle()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog("existingKey", "existingValue");
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.Title.ShouldBe("Edit Secret");
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_DataContextIsSecretEditDialogViewModel()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.DataContext.ShouldBeOfType<SecretEditDialogViewModel>();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_HasKeyAndValueTextBoxes()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
var textBoxes = dialog.GetVisualDescendants().OfType<TextBox>().ToList();
|
||||
textBoxes.Count.ShouldBeGreaterThanOrEqualTo(2);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_HasSaveAndCancelButtons()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
var buttons = dialog.GetVisualDescendants().OfType<Button>().ToList();
|
||||
buttons.Any(b => b.Content?.ToString() == "Save").ShouldBeTrue();
|
||||
buttons.Any(b => b.Content?.ToString() == "Cancel").ShouldBeTrue();
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_ViewModelProperty_ReturnsDataContext()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.ViewModel.ShouldBe(dialog.DataContext);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_ParameterizedConstructor_SetsViewModelWithKey()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog("testKey", "testValue");
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.ViewModel.Key.ShouldBe("testKey");
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_ParameterizedConstructor_SetsViewModelWithValue()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog("testKey", "testValue");
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.ViewModel.Value.ShouldBe("testValue");
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void SecretEditDialog_CannotResize()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new SecretEditDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
dialog.CanResize.ShouldBeFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user