feat(core): DocumentService — create/open/save/close (API7)

- KompasDocumentType (Part/Assembly/Drawing/Fragment/Specification/Text)
  + маппинг в DocumentTypeEnum и парсинг строк (ru/en)
- DocumentInfo (Name/PathName/Type)
- DocumentService: Create/Open/Save/SaveAs/Close/GetActive через IDocuments
- tests: интеграция документов (create part/fragment, SaveAs .scratch, close) — зелёные

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 23:45:28 +03:00
parent 0038790902
commit f0995a67e6
5 changed files with 203 additions and 0 deletions
@@ -0,0 +1,42 @@
using Kompas.Mcp.Core.Documents;
namespace Kompas.Mcp.Tests.Integration;
/// <summary>Интеграция: жизненный цикл документов.</summary>
[Trait("Category", "Integration")]
[Collection(KompasCollection.Name)]
public sealed class DocumentTests
{
private readonly DocumentService _docs;
public DocumentTests(KompasFixture fx)
=> _docs = new DocumentService(fx.Session, fx.Dispatcher);
[Fact]
public async Task Create_part_saveas_close_roundtrip()
{
var created = await _docs.CreateAsync(KompasDocumentType.Part);
Assert.Equal(KompasDocumentType.Part, created.Type);
var path = TestPaths.NewFile(".m3d");
await _docs.SaveAsAsync(path);
var active = await _docs.GetActiveAsync();
Assert.NotNull(active);
Assert.Equal(path, active!.PathName, ignoreCase: true);
var closed = await _docs.CloseAsync(save: false);
Assert.True(closed);
Assert.True(File.Exists(path));
}
[Fact]
public async Task Create_fragment_reports_type()
{
await _docs.CreateAsync(KompasDocumentType.Fragment);
var active = await _docs.GetActiveAsync();
Assert.NotNull(active);
Assert.Equal(KompasDocumentType.Fragment, active!.Type);
await _docs.CloseAsync(save: false);
}
}
+19
View File
@@ -0,0 +1,19 @@
namespace Kompas.Mcp.Tests;
/// <summary>Пути для тестовых артефактов: корень репозитория и gitignore-папка .scratch.</summary>
internal static class TestPaths
{
public static string RepoRoot()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "KompasMcp.slnx")))
dir = dir.Parent;
return dir?.FullName ?? AppContext.BaseDirectory;
}
public static string Scratch
=> Directory.CreateDirectory(Path.Combine(RepoRoot(), ".scratch")).FullName;
public static string NewFile(string extension)
=> Path.Combine(Scratch, $"test_{DateTime.Now:HHmmss}_{Guid.NewGuid():N}{extension}");
}