using Remiss.Core.Repositories; using Remiss.Core.Security; using Xunit; namespace Remiss.Core.Tests; public sealed class SupportTests { [Fact] public void JsonMottagningRepository_readsSortsAndFiltersRegistry() { var path = Path.Combine(Path.GetTempPath(), "mottagningar-" + Guid.NewGuid().ToString("N") + ".json"); File.WriteAllText(path, """ [ { "namn": "Öron Kungälv", "hsaId": "hsa-3" }, { "namn": "Hud SU", "hsaId": "hsa-1" }, { "namn": "", "hsaId": "hsa-x" }, { "namn": "Ortopedi", "hsaId": "hsa-2" } ] """); try { var repo = new JsonMottagningRepository(path); var all = repo.GetAll(); Assert.Equal(3, all.Count); // tom rad bortfiltrerad Assert.Equal("Hud SU", all[0].Namn); // sorterad på namn Assert.Equal("hsa-2", repo.FindByHsaId("HSA-2")!.HsaId); // skiftlägesokänsligt Assert.Null(repo.FindByHsaId("saknas")); } finally { File.Delete(path); } } [Fact] public void JsonMottagningRepository_throwsWhenFileMissing() { Assert.Throws(() => new JsonMottagningRepository(Path.Combine(Path.GetTempPath(), "does-not-exist.json"))); } [Fact] public void SecureTempStore_shredsAndRemovesEverythingOnDispose() { var baseDir = Path.Combine(Path.GetTempPath(), "remiss-securetmp-" + Guid.NewGuid().ToString("N")); string root; using (var store = new SecureTempStore(baseDir)) { root = store.Root; File.WriteAllText(store.NewFile("patient.pdf"), "känsligt innehåll"); Assert.True(File.Exists(store.NewFile("patient.pdf"))); } Assert.False(Directory.Exists(root)); try { Directory.Delete(baseDir, recursive: true); } catch { /* ignore */ } } }