feat: add models and workspace repository layer
This commit is contained in:
1 parent
c2ee02c209
commit
941e22c7ff
9 files changed
+1143
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using YKanBan.Models;
|
||||
using YKanBan.Storage;
|
||||
using YKanBan.Storage.Workspace;
|
||||
using YKanBan.Tests.TestUtilities;
|
||||
|
||||
namespace YKanBan.Tests.Storage.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the workspace session lifecycle: the exclusive lock is held for
|
||||
/// the whole session and the repository is usable through it.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class WorkspaceSessionTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void OpenHoldsLockUntilDisposed()
|
||||
{
|
||||
using var directory = new TempDirectory();
|
||||
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||
|
||||
using WorkspaceSession session = WorkspaceSession.Open(directory.FullPath);
|
||||
|
||||
// A second open while the session is alive must fail on the lock.
|
||||
Assert.ThrowsExactly<WorkspaceLockException>(() => WorkspaceSession.Open(directory.FullPath));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisposeReleasesLockForReopen()
|
||||
{
|
||||
using var directory = new TempDirectory();
|
||||
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||
|
||||
WorkspaceSession.Open(directory.FullPath).Dispose();
|
||||
|
||||
using WorkspaceSession reopened = WorkspaceSession.Open(directory.FullPath);
|
||||
Assert.AreEqual(directory.FullPath, reopened.FolderPath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenUninitializedFolderThrowsNotInitialized()
|
||||
{
|
||||
using var directory = new TempDirectory();
|
||||
|
||||
Assert.ThrowsExactly<WorkspaceNotInitializedException>(
|
||||
() => WorkspaceSession.Open(directory.FullPath));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RepositoryIsUsableThroughSession()
|
||||
{
|
||||
using var directory = new TempDirectory();
|
||||
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||
|
||||
using WorkspaceSession session = WorkspaceSession.Open(directory.FullPath);
|
||||
TagModel tag = session.Repository.AddTag("bug", RgbColor.Parse("#112233"), "");
|
||||
|
||||
Assert.AreEqual("bug", session.Repository.GetTags().Single().Name);
|
||||
Assert.AreEqual(tag.Id, session.Repository.GetTags().Single().Id);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user