Esempio n. 1
0
        private void CategoryBasic()
        {
            Clear();

            ICategoriesProvider pro = Provider.CategoriesProvider;

            for (int i = 0; i < TestCount; i++)
            {
                Category data = new Category
                {
                    Name  = $"item {i}",
                    Color = random.NextString(),
                };
                string username = random.Choice(usernames);
                data.UserId = username;
                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, ""), "get after create failed");

                    Category actual = pro.Get(id, username).Result;
                    Valid(actual);

                    data.Id = id;
                    Assert.AreEqual(data, actual, "get failed");
                    Assert.AreEqual(data.GetHashCode(), actual.GetHashCode(), "get failed");
                }

                {
                    data.Name  = $"item {i} update";
                    data.Color = random.NextString();
                    data.Id    = random.Next();
                    Assert.AreEqual(id, pro.Update(id, data, username).Result, "update failed");

                    IEnumerable <Category> items = pro.Query(id, data.Name, data.Color, null, username).Result;
                    Assert.AreEqual(1, items.Count(), "query failed");
                    Category actual = items.First();
                    Valid(actual);

                    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 <Category> items = pro.GetAll(user).Result;
                foreach (Category v in items)
                {
                    Valid(v);
                }
            }
        }
Esempio n. 2
0
 public async Task <Category> Get(int id)
 {
     return(await provider.Get(id, identityDataGetter.GetClaimId(User)));
 }