Files
Chronos/tests/Titano.Core.Tests/Foundation/AtomicFileTests.cs
T
Claude 83a54fb57b chore: bootstrap repository foundation
Solution layout, build rules with zero-package guard, in-house test
framework, localization runtime, brand mark rasteriser with ICO/PNG
generation, Core contracts (imaging, video, domain model, TIFF reader),
Titano.Tools (make-icon, i18n, xaml-lint, package-guard) and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 08:59:40 +00:00

34 lines
1.1 KiB
C#

using Titano.Core.IO;
using Titano.Testing;
namespace Titano.Core.Tests.Foundation;
public sealed class AtomicFileTests(TestContext context)
{
[Test]
public void ReplacesContentAndLeavesNoTemporaryFiles()
{
var dir = context.CreateTempDirectory();
var path = Path.Combine(dir, "sequence.json");
AtomicFile.WriteAllText(path, "one");
AtomicFile.WriteAllText(path, "two");
Assert.Equal("two", File.ReadAllText(path));
Assert.Count(1, Directory.GetFiles(dir));
}
[Test]
public async Task FailedWriteKeepsPreviousContent()
{
var dir = context.CreateTempDirectory();
var path = Path.Combine(dir, "project.json");
AtomicFile.WriteAllText(path, "stable");
await Assert.ThrowsAsync<InvalidOperationException>(() => AtomicFile.WriteAsync(path, async (s, ct) =>
{
await s.WriteAsync("partial"u8.ToArray(), ct);
throw new InvalidOperationException("boom");
}));
Assert.Equal("stable", File.ReadAllText(path));
Assert.Count(1, Directory.GetFiles(dir));
}
}