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 <int?> Delete(int id, string identity) { if (identity == null) { return(null); } Models.Note raw = await context.Notes.FindAsync(id); if (raw == null || raw.UserId != identity) { return(null); } { IRelationsProvider provider = parent.RelationsProvider; await provider.ClearAdjacents(id, identity); } context.Notes.Remove(raw); await context.SaveChangesAsync(); return(id); }
public async Task <int?> ClearAdjacents(int noteId) { return(await provider.ClearAdjacents(noteId, identityDataGetter.GetClaimId(User))); }