Something went wrong. Try again.
.NET ATProtocol Library - Built for Source Gen
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246using System;using System.IO;using CarpaNet.BuildTasks;using Xunit;
namespace CarpaNet.UnitTests.BuildTasks;
public class LexiconRefExtractorTests{ [Fact] public void ExtractReferencedNsids_DirectRef_ReturnsNsid() { var json = """ { "lexicon": 1, "id": "app.bsky.feed.post", "defs": { "main": { "type": "record", "record": { "type": "object", "properties": { "author": { "type": "ref", "ref": "app.bsky.actor.defs#profileView" } } } } } } """;
var result = LexiconRefExtractor.ExtractReferencedNsids(json);
Assert.Single(result); Assert.Contains("app.bsky.actor.defs", result); }
[Fact] public void ExtractReferencedNsids_UnionRefs_ReturnsAllNsids() { var json = """ { "lexicon": 1, "id": "app.bsky.feed.defs", "defs": { "feedViewPost": { "type": "object", "properties": { "embed": { "type": "union", "refs": [ "app.bsky.embed.images#view", "app.bsky.embed.external#view", "app.bsky.embed.record#view" ] } } } } } """;
var result = LexiconRefExtractor.ExtractReferencedNsids(json);
Assert.Equal(3, result.Count); Assert.Contains("app.bsky.embed.images", result); Assert.Contains("app.bsky.embed.external", result); Assert.Contains("app.bsky.embed.record", result); }
[Fact] public void ExtractReferencedNsids_LocalRef_ExcludedFromResult() { var json = """ { "lexicon": 1, "id": "app.bsky.feed.defs", "defs": { "main": { "type": "object", "properties": { "item": { "type": "ref", "ref": "#localType" } } }, "localType": { "type": "object" } } } """;
var result = LexiconRefExtractor.ExtractReferencedNsids(json);
Assert.Empty(result); }
[Fact] public void ExtractReferencedNsids_SelfRef_ExcludedFromResult() { var json = """ { "lexicon": 1, "id": "app.bsky.feed.defs", "defs": { "main": { "type": "object", "properties": { "item": { "type": "ref", "ref": "app.bsky.feed.defs#otherType" } } } } } """;
var result = LexiconRefExtractor.ExtractReferencedNsids(json);
Assert.Empty(result); }
[Fact] public void ExtractReferencedNsids_DeeplyNested_FindsRefs() { var json = """ { "lexicon": 1, "id": "app.bsky.feed.post", "defs": { "main": { "type": "record", "record": { "type": "object", "properties": { "facets": { "type": "array", "items": { "type": "ref", "ref": "app.bsky.richtext.facet" } } } } } } } """;
var result = LexiconRefExtractor.ExtractReferencedNsids(json);
Assert.Single(result); Assert.Contains("app.bsky.richtext.facet", result); }
[Fact] public void ExtractReferencedNsids_Deduplication_ReturnsSingleEntry() { var json = """ { "lexicon": 1, "id": "app.bsky.feed.defs", "defs": { "type1": { "type": "object", "properties": { "a": { "type": "ref", "ref": "app.bsky.actor.defs#profileView" } } }, "type2": { "type": "object", "properties": { "b": { "type": "ref", "ref": "app.bsky.actor.defs#profileViewBasic" } } } } } """;
var result = LexiconRefExtractor.ExtractReferencedNsids(json);
Assert.Single(result); Assert.Contains("app.bsky.actor.defs", result); }
[Fact] public void ExtractNsid_ReadsIdField() { var json = """{"lexicon":1,"id":"com.example.myapp.getProfile","defs":{}}""";
var nsid = LexiconRefExtractor.ExtractNsid(json);
Assert.Equal("com.example.myapp.getProfile", nsid); }
[Fact] public void ExtractNsid_MissingId_ReturnsNull() { var json = """{"lexicon":1,"defs":{}}""";
var nsid = LexiconRefExtractor.ExtractNsid(json);
Assert.Null(nsid); }
[Fact] public void ExtractReferencedNsidsFromFile_ReadsFromDisk() { var tempFile = Path.GetTempFileName(); try { File.WriteAllText(tempFile, """ { "lexicon": 1, "id": "app.bsky.feed.post", "defs": { "main": { "type": "object", "properties": { "author": { "type": "ref", "ref": "app.bsky.actor.defs#profileView" } } } } } """);
var result = LexiconRefExtractor.ExtractReferencedNsidsFromFile(tempFile);
Assert.Single(result); Assert.Contains("app.bsky.actor.defs", result); } finally { File.Delete(tempFile); } }}