1e21e33ade
Move SecureStoreManager project and tests to Deprecated folder and remove from solution. SecureStore functionality is now integrated into ConfigManager.
155 lines
4.8 KiB
C#
155 lines
4.8 KiB
C#
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();
|
|
}
|
|
}
|