Esempio n. 1
0
        public async Task Delete_CategoryWithProducts_ShouldDeleteCategory()
        {
            // .Arrange
            Category category = new Category()
            {
                CategoryName = Guid.NewGuid().ToString()
            };

            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                await context.AddAsync(category);

                await context.SaveChangesAsync();

                await context.AddAsync(new Product()
                {
                    CategoryId = category.Id, Title = Guid.NewGuid().ToString()
                });

                await context.SaveChangesAsync();
            }

            // .Act
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                var sut = new GenericRepository <Category>(context);
                await sut.DeleteAsync(category.Id);
            }
            // .Assert
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                Assert.IsNull(context.Find <Category>(category.Id));
            }
        }
Esempio n. 2
0
        public async Task Create_DuplicatedCategory_ShouldThrowException()
        {
            // .Arrange
            Category category = new Category()
            {
                CategoryName = "DUPLICATED"
            };

            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                await context.AddAsync(category);

                await context.SaveChangesAsync();
            }
            var duplicatedCatgory = new Category()
            {
                CategoryName = category.CategoryName
            };

            // .Assert
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                var sut = new GenericRepository <Category>(context);
                Assert.That(async() =>
                            // .Act
                            await sut.CreateAsync(duplicatedCatgory), Throws.Exception);
            }
        }
Esempio n. 3
0
 public async Task Delete_NotExistingCategory_ShouldThrowException()
 {
     // .Assert
     using (var context = CategoriesContext.GetLinnworksIntegrationContext())
     {
         var sut = new GenericRepository <Category>(context);
         Assert.That(async() =>
                     // .Act
                     await sut.DeleteAsync(Guid.NewGuid()), Throws.Exception);
     }
 }
Esempio n. 4
0
 public void Update_ExistingCategory_ShouldNotThrowException()
 {
     // .Assert
     using (var context = CategoriesContext.GetLinnworksIntegrationContext())
     {
         var sut = new GenericRepository <Category>(context);
         Assert.That(async() =>
                     // .Act
                     await sut.UpdateAsync(Guid.NewGuid(), new Category()
         {
             CategoryName = Guid.NewGuid().ToString()
         }), Throws.Nothing);
     }
 }
Esempio n. 5
0
        public async Task GetAll_Categories_Returns_True()
        {
            object AllCategories;

            // .Arrange
            // .Act
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                var sut = new GenericRepository <Category>(context);
                AllCategories = await sut.GetAllAsync();
            }

            // .Assert
            Assert.NotNull(AllCategories);
        }