private void RelationBasic() { Clear(); INotesProvider npro = Provider.NotesProvider; IRelationsProvider pro = Provider.RelationsProvider; string[] usernames = new string[] { "user" }; List <int> nodes = new List <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); } for (int i = 0; i < TestCount; i++) { Relation data = new Relation { From = random.Choice(nodes), To = random.Choice(nodes), }; string username = random.Choice(usernames); Assert.AreEqual(data, data.Clone()); int id; { int?tid = pro.Create(data, username).Result; Assert.IsTrue(tid.HasValue, "create failed"); id = tid.Value; Assert.IsNotNull(pro.Get(id, username), "get after create failed"); Relation actual = pro.Get(id, username).Result; Valid(actual, username); data.Id = id; Assert.AreEqual(data, actual, "get failed"); Assert.AreEqual(data.GetHashCode(), actual.GetHashCode(), "get failed"); } { data.From = random.Choice(nodes); data.To = random.Choice(nodes); data.Id = random.Next(); Assert.AreEqual(id, pro.Update(id, data, username).Result, "update failed"); IEnumerable <Relation> items = pro.Query(id, data.From, data.To, username).Result; Assert.AreEqual(1, items.Count(), "query failed"); Relation actual = items.First(); Valid(actual, username); data.Id = id; Assert.AreEqual(data, actual, "query failed"); } if (random.NextDouble() < DeleteRate) { Assert.IsNotNull(pro.Delete(id, username).Result, "delete failed"); Assert.IsNull(pro.Get(id, username).Result, "get after delete failed"); } } foreach (string user in usernames) { IEnumerable <Relation> items = pro.GetAll(user).Result; foreach (Relation v in items) { Valid(v, user); } } }
public async Task <Relation> Get(int id) { return(await provider.Get(id, identityDataGetter.GetClaimId(User))); }