private void RelationSpecial() { Clear(); INotesProvider npro = Provider.NotesProvider; IRelationsProvider pro = Provider.RelationsProvider; string[] usernames = new string[] { "user" }; List <(int, string)> nodes = new List <(int, string)>(); Dictionary <int, HashSet <int> > adjs = new Dictionary <int, HashSet <int> >(); for (int i = 0; i < TestCount; i++) { Note data = new Note { Title = $"item {i}", Content = $"item content {i}", CategoryId = null, }; string username = random.Choice(usernames); int? tid = npro.Create(data, username).Result; Assert.IsTrue(tid.HasValue, "create failed"); nodes.Add((tid.Value, username)); adjs.Add(tid.Value, new HashSet <int>()); } for (int i = 0; i < TestCount; i++) { Relation data = new Relation { From = random.Choice(nodes).Item1, To = random.Choice(nodes).Item1, }; string username = random.Choice(usernames); { int?tid = pro.Create(data, username).Result; Assert.IsTrue(tid.HasValue, "create failed"); adjs[data.From].Add(data.To); adjs[data.To].Add(data.From); } } foreach ((int id, string user) in nodes) { IEnumerable <Relation> actual = pro.GetAdjacents(id, user).Result; CollectionAssert.AreEquivalent(adjs[id].ToArray(), new HashSet <int>(actual.Select(x => x.From ^ x.To ^ id)).ToArray()); } foreach ((int id, string user) in nodes) { pro.ClearAdjacents(id, user).Wait(); Assert.IsFalse(pro.GetAdjacents(id, user).Result.Any()); } }
public async Task <IEnumerable <Relation> > GetAdjacents(int noteId) { return(await provider.GetAdjacents(noteId, identityDataGetter.GetClaimId(User))); }