Ejemplo n.º 1
0
        public async Task CategoryCRUDTest()
        {
            await categories.DeleteAllAsync();

            var cat1 = new Category()
            {
                Name = "Category 1"
            };
            var cat2 = new Category()
            {
                Name = "Category 2"
            };

            await categories.InsertAsync(cat1, cat2);

            var cats = await categories.GetAllAsync();

            Assert.AreEqual(2, cats.Count);

            var category1Id = cats.Where(x => x.Name == "Category 1").Single().Id;
            var category2Id = cats.Where(x => x.Name == "Category 2").Single().Id;

            var filter = new CategoryFilter()
            {
                Name = "Category 1"
            };

            Assert.AreEqual("Category 1", (await categories.GetAsync(filter)).Single().Name);
            Assert.AreEqual("Category 1", (await categories.GetAsync(category1Id)).Name);

            filter.Name = "Category 2";
            Assert.AreEqual("Category 2", (await categories.GetAsync(filter)).Single().Name);
            Assert.AreEqual("Category 2", (await categories.GetAsync(category2Id)).Name);

            filter.Name = "Category";
            Assert.AreEqual(2, (await categories.GetAsync(filter)).Count);

            await categories.UpdateAsync(new Category()
            {
                Id = category1Id, Name = "Updated Category"
            });

            Assert.AreEqual(2, (await categories.GetAllAsync()).Count);

            filter.Name = "Category 1";
            Assert.AreEqual(0, (await categories.GetAsync(filter)).Count);
            Assert.AreEqual("Updated Category", (await categories.GetAsync(category1Id)).Name);

            await categories.DeleteAsync(category2Id);

            Assert.AreEqual(1, (await categories.GetAllAsync()).Count);

            await categories.DeleteAllAsync();

            Assert.AreEqual(0, (await categories.GetAllAsync()).Count);
        }