2026-10-19 14:39:12 +02:00
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
using AIStudio.Tools.Rust;
|
|
|
|
|
using AIStudio.Tools.Services;
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Tests.Tools;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks that the app reads every outcome which the runtime sends after a share request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// ShareFileResponse in runtime/src/share_sheet.rs names the outcome in snake case. A name which the
|
|
|
|
|
/// app does not know would not fail anywhere: the enum converter falls back to the first member, and
|
2026-11-03 18:29:50 +01:00
|
|
|
/// a share sheet which did not respond would go unnoticed again. The answers are read with the options
|
|
|
|
|
/// of RustService itself.
|
2026-10-19 14:39:12 +02:00
|
|
|
/// </remarks>
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public sealed class ShareFileResponseTests
|
|
|
|
|
{
|
|
|
|
|
[TestCase("opened", ShareSheetOutcome.OPENED)]
|
|
|
|
|
[TestCase("failed", ShareSheetOutcome.FAILED)]
|
|
|
|
|
[TestCase("unresponsive", ShareSheetOutcome.UNRESPONSIVE)]
|
|
|
|
|
public void TheAppReadsEveryOutcomeOfTheRuntime(string outcome, ShareSheetOutcome expectedOutcome)
|
|
|
|
|
{
|
2026-11-03 18:29:50 +01:00
|
|
|
var response = JsonSerializer.Deserialize<ShareFileResponse>($$"""{"outcome":"{{outcome}}","issue":"The main window is not available."}""", RustService.JSON_OPTIONS);
|
2026-10-19 14:39:12 +02:00
|
|
|
|
|
|
|
|
Assert.That(response, Is.Not.Null);
|
2026-11-01 20:32:16 +01:00
|
|
|
using (Assert.EnterMultipleScope())
|
2026-10-19 14:39:12 +02:00
|
|
|
{
|
|
|
|
|
Assert.That(response!.Outcome, Is.EqualTo(expectedOutcome));
|
|
|
|
|
Assert.That(response.Issue, Is.EqualTo("The main window is not available."));
|
2026-11-01 20:32:16 +01:00
|
|
|
}
|
2026-10-19 14:39:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AnUnknownOutcomeNeverCountsAsAnOpenedShareSheet()
|
|
|
|
|
{
|
2026-11-03 18:29:50 +01:00
|
|
|
var response = JsonSerializer.Deserialize<ShareFileResponse>("""{"outcome":"vanished","issue":""}""", RustService.JSON_OPTIONS);
|
2026-10-19 14:39:12 +02:00
|
|
|
|
|
|
|
|
Assert.That(response?.Outcome, Is.EqualTo(ShareSheetOutcome.UNKNOWN));
|
|
|
|
|
}
|
|
|
|
|
}
|