Exemplo n.º 1
0
        public async Task DeleteShouldReturnDbWithoutThatItem()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);
            var categoryId        = 1;

            // Act
            await categoriesService.Delete(categoryId);

            // Assert
            db
            .Categories
            .Where(c => c.Id == categoryId)
            .FirstOrDefault()
            .Should()
            .Be(null);

            db
            .Categories
            .Count()
            .Should()
            .Be(2);
        }
Exemplo n.º 2
0
        public async Task DeleteCategory()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstCategory = new Category {
                Id = 1, Name = "test1"
            };
            var secondCategory = new Category {
                Id = 2, Name = "test2"
            };
            var thirdCategory = new Category {
                Id = 3, Name = "test3"
            };

            db.AddRange(firstCategory, secondCategory, thirdCategory);

            await db.SaveChangesAsync();

            var adminCategoryService = new AdminCategoryService(db);
            // Act

            await adminCategoryService.Delete(1);

            await db.SaveChangesAsync();

            var result = await adminCategoryService.AllAsync();


            // Assert
            result
            .Should()
            .HaveCount(2);
        }
        public async Task DeleteShouldReturnFalseWithInvalidId()
        {
            // Arrange
            //Tests.Initialize();
            var adminCategoryService = new AdminCategoryService(this.db);

            // Act
            var result = await adminCategoryService.Delete(10);

            // Assert
            result.Should().Be(false);
        }
        public async Task DeleteShouldReturnCorrectResults()
        {
            // Arrange
            //Tests.Initialize();
            var adminCategoryService = new AdminCategoryService(this.db);

            // Act
            var categoriesCountBefore = this.db.Categories.Count();
            var result = await adminCategoryService.Delete(1);
            var categoriesCountAfter = this.db.Categories.Count();

            // Assert
            result.Should().Be(true);
            categoriesCountBefore.Should().Be(1);
            categoriesCountAfter.Should().Be(0);
        }