Some checks failed
CultMesh QUIC native / Build win32-x64 (pull_request) Has been skipped
CultMesh QUIC native / Build linux-x64 (pull_request) Has been skipped
CultMesh QUIC native / Release native binaries (pull_request) Has been skipped
CultMesh portability and performance / ubuntu-latest one-command multiplayer onboarding (pull_request) Has been cancelled
CultMesh portability and performance / windows-latest one-command multiplayer onboarding (pull_request) Has been cancelled
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
CultMesh portability and performance / windows-latest reactive semantics and leases (pull_request) Has been cancelled
CultNet cross-runtime interop / C# / TypeScript / Rust / Python / Kotlin (pull_request) Has been cancelled
CultMesh QUIC native / Verify committed binaries match SHA256SUMS (pull_request) Has been cancelled
A language x package matrix (each cell a tested snippet or "not yet"), a C# first-call test and a TypeScript first-call test that the docs link, and a pointer from the top of README.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
2 KiB
C#
54 lines
2 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using GameCult.Caching;
|
|
using GameCult.Caching.MessagePack;
|
|
using MessagePack;
|
|
using NUnit.Framework;
|
|
|
|
namespace GameCult.Caching.Tests
|
|
{
|
|
// The C# first-call snippet that docs/start/README.md links: define a typed document, store it in a
|
|
// .cc file, read it back through a second cache. Keep it small; it is the front door.
|
|
public class FirstCallTests
|
|
{
|
|
[CultDocument("gamecult.first_call_item", "gamecult.first_call_item.v1")]
|
|
[MessagePackObject(AllowPrivate = true)]
|
|
internal sealed class Item
|
|
{
|
|
[Key(0)] [CultName] public string Name = string.Empty;
|
|
[Key(1)] [CultIndex] public string Category = string.Empty;
|
|
[Key(2)] public int Value;
|
|
}
|
|
|
|
[Test]
|
|
public async Task DefineStoreAndReadBackATypedDocument()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"first-call-{Guid.NewGuid():N}.cc");
|
|
try
|
|
{
|
|
// Write: a cache with one backing store, one typed document.
|
|
var store = new SingleFileMessagePackBackingStore(path);
|
|
var cache = new CultCache();
|
|
cache.AddBackingStore(store);
|
|
var handle = await cache.AddAsync(new Item { Name = "Potion", Category = "Consumable", Value = 50 });
|
|
store.PushAll();
|
|
|
|
// Read: a fresh cache over the same file.
|
|
var reopened = new CultCache();
|
|
reopened.AddBackingStore(new SingleFileMessagePackBackingStore(path));
|
|
await reopened.PullAllBackingStoresAsync();
|
|
|
|
var byKey = reopened.Get<Item>(handle.Key);
|
|
Assert.That(byKey, Is.Not.Null);
|
|
Assert.That(byKey!.Value, Is.EqualTo(50));
|
|
Assert.That(reopened.GetByName<Item>("Potion")!.Category, Is.EqualTo("Consumable"));
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
}
|
|
}
|