Files
OpenNest/OpenNest.Server.Tests/DrawingSetFixtures.cs
T
ajandClaude Opus 5.5 be057bf337 feat(server): store versioned drawing sets
A drawing set is a named list of library drawings with quantities (a kit,
an assembly, a recurring order) that will later be released into one nest
per material. This is the server half: sets get the same revision,
If-Match and archive contract as /api/drawings so the client and tests
follow a known shape.

Schema v7 adds drawing_sets, drawing_set_revisions and
drawing_set_members. Members reference drawings by id and mean each
drawing's current revision, so reads join the current drawing record:
the client can group members by material without one request per drawing,
and the joined record is ignored on save so a read record can be sent
back unchanged. Every change keeps its own member list, and
/api/drawings/{id}/sets answers "used in" from current revisions only.

The drawing query's enum, integer and history-paging parsing is now shared
so both APIs refuse bad input identically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 12:51:56 -04:00

54 lines
2.2 KiB
C#

using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using OpenNest.Data;
using static OpenNest.Server.Tests.DrawingLibraryFixtures;
namespace OpenNest.Server.Tests;
/// <summary>Neutral, code-built drawing set fixtures for the server tests.</summary>
internal static class DrawingSetFixtures
{
public static DrawingSetRecord Set(string name = "Synthetic kit", Guid? id = null, params (Guid Drawing, int Quantity)[] members) => new()
{
Id = id ?? Guid.NewGuid(),
Name = name,
Customer = "Synthetic customer",
Notes = "Synthetic set notes",
SavedBy = "Synthetic operator",
Members = members.Select(m => new DrawingSetMember { DrawingId = m.Drawing, Quantity = m.Quantity }).ToList(),
};
/// <summary>Stores a library drawing directly and returns its id.</summary>
public static Guid AddDrawing(NestDatabase database, string name = "Synthetic bracket")
{
var record = Record(name);
database.InsertDrawing(record.Id, record, Package(name));
return record.Id;
}
public static async Task<Guid> AddDrawing(HttpClient client, string name = "Synthetic bracket", Action<DrawingLibraryRecord>? edit = null)
{
var record = Record(name);
edit?.Invoke(record);
return (await Upload(client, record, Package(name))).Id;
}
public static StringContent Json(string json) => new(json, Encoding.UTF8, "application/json");
public static StringContent Json(DrawingSetRecord record) => Json(JsonSerializer.Serialize(record, Options));
public static async Task<DrawingSetRecord> Create(HttpClient client, DrawingSetRecord record)
{
using var response = await client.PostAsync("/api/sets", Json(record));
response.EnsureSuccessStatusCode();
return (await response.Content.ReadFromJsonAsync<DrawingSetRecord>(Options))!;
}
public static async Task<DrawingSetRecord> Read(HttpResponseMessage response) =>
(await response.Content.ReadFromJsonAsync<DrawingSetRecord>(Options))!;
public static IEnumerable<(Guid, int)> MembersOf(DrawingSetRecord record) =>
record.Members.Select(m => (m.DrawingId, m.Quantity));
}