Files
OwnCord/Client/OwnCord.Client.Tests/Services/ProfileServiceTests.cs
T
jevb 9707c4d4af feat: scaffold Phase 3 WPF client shell with MVVM and TDD structure
- WPF (.NET 8) project targeting net8.0-windows
- Models: ServerProfile (record), Channel, Message, User, Role
- ViewModels: ViewModelBase (INotifyPropertyChanged), RelayCommand<T>,
  ConnectViewModel (profiles, login/register toggle, connect command),
  MainViewModel (channels, messages, typing indicator, send command),
  SettingsViewModel (dark theme, notifications, PTT key)
- Services: IProfileService + ProfileService (AppData JSON, immutable ops),
  ICredentialService + CredentialService (DPAPI via ProtectedData),
  IWebSocketService + WebSocketService (ClientWebSocket stub)
- Views: ConnectPage (server address, login/register, profile selector),
  MainPage (3-column: channel list, message area, member list),
  App.xaml wires converters and startup
- Converters: BoolToVisibilityConverter, IntToVisibilityConverter
- Tests: ConnectViewModelTests (11 cases), MainViewModelTests (11 cases),
  ProfileServiceTests (6 cases) — ready to run once NuGet accessible
  (run: dotnet restore && dotnet test OwnCord.Client.Tests/)

Build: dotnet build OwnCord.Client/ succeeds with 0 warnings
2026-03-14 21:07:07 +01:00

79 lines
2.2 KiB
C#

using System.IO;
using OwnCord.Client.Models;
using OwnCord.Client.Services;
namespace OwnCord.Client.Tests.Services;
public sealed class ProfileServiceTests : IDisposable
{
private readonly string _tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
private ProfileService Svc => new(_tempDir);
[Fact]
public void LoadProfiles_ReturnsEmpty_WhenNoFile()
{
var profiles = Svc.LoadProfiles();
Assert.Empty(profiles);
}
[Fact]
public void SaveAndLoad_RoundTrips()
{
var svc = Svc;
var profile = ServerProfile.Create("Home", "192.168.1.10:8443", "alice");
svc.SaveProfiles([profile]);
var loaded = svc.LoadProfiles();
Assert.Single(loaded);
Assert.Equal(profile.Name, loaded[0].Name);
Assert.Equal(profile.Host, loaded[0].Host);
}
[Fact]
public void AddProfile_DoesNotMutateOriginal()
{
var svc = Svc;
IReadOnlyList<ServerProfile> original = [];
var profile = ServerProfile.Create("Home", "localhost:8443");
var updated = svc.AddProfile(original, profile);
Assert.Empty(original);
Assert.Single(updated);
}
[Fact]
public void RemoveProfile_RemovesById()
{
var svc = Svc;
var p1 = ServerProfile.Create("A", "a:8443");
var p2 = ServerProfile.Create("B", "b:8443");
var list = svc.AddProfile(svc.AddProfile([], p1), p2);
var result = svc.RemoveProfile(list, p1.Id);
Assert.Single(result);
Assert.Equal(p2.Id, result[0].Id);
}
[Fact]
public void UpdateProfile_ReplacesMatchingId()
{
var svc = Svc;
var p = ServerProfile.Create("Old", "old:8443");
var list = svc.AddProfile([], p);
var updated = p with { Name = "New" };
var result = svc.UpdateProfile(list, updated);
Assert.Equal("New", result[0].Name);
}
[Fact]
public void SaveProfiles_CreatesDirectory()
{
Assert.False(Directory.Exists(_tempDir));
Svc.SaveProfiles([]);
Assert.True(Directory.Exists(_tempDir));
}
public void Dispose()
{
if (Directory.Exists(_tempDir))
Directory.Delete(_tempDir, recursive: true);
}
}