Ejemplo n.º 1
0
        public async Task GetAll_Success()
        {
            // Arrange
            var loggerController = Loggers.CategoryController();
            var blobService      = BlobService.BlobServiceUpload();

            var mapper = Mapper.Get();

            var dbContext = _fixture.Context;

            var category1 = NewDatas.NewCategory();
            var category2 = NewDatas.NewCategory();
            var category3 = NewDatas.NewCategory();

            await dbContext.AddRangeAsync(category1, category2, category3);

            await dbContext.SaveChangesAsync();

            var categoryRepository  = new CategoryRepository(mapper, blobService, dbContext);
            var catgoriesController = new CategoriesController(loggerController, categoryRepository);

            // Act
            var result = await catgoriesController.GetAll();

            // Assert
            var getCategoriesResultType = Assert.IsType <ActionResult <IEnumerable <CategoryRespone> > >(result);
            var getCategoriesResult     = Assert.IsType <OkObjectResult>(result.Result);

            Assert.NotEmpty(getCategoriesResult.Value as IEnumerable <CategoryRespone>);
        }
Ejemplo n.º 2
0
        public async Task Delete_Success()
        {
            // Arrange
            var loggerController = Loggers.CategoryController();
            var blobService      = BlobService.BlobServiceUpload();

            var mapper = Mapper.Get();

            var dbContext = _fixture.Context;

            var category = NewDatas.NewCategory();

            await dbContext.AddRangeAsync(category);

            await dbContext.SaveChangesAsync();

            var categoryRepository  = new CategoryRepository(mapper, blobService, dbContext);
            var catgoriesController = new CategoriesController(loggerController, categoryRepository);

            // Act
            var result = await catgoriesController.Delete(category.CategoryId);

            // Assert
            var createdCategoryResult = Assert.IsType <OkObjectResult>(result.Result);
            var resultValue           = Assert.IsType <CategoryRespone>(createdCategoryResult.Value);

            Assert.Equal(category.Name, resultValue.Name);
            Assert.Equal(category.Description, resultValue.Description);
            Assert.Equal(category.Image, resultValue.Image);

            await Assert.ThrowsAsync <NotFoundException>(async() =>
            {
                await catgoriesController.GetById(resultValue.CategoryId);
            });
        }
Ejemplo n.º 3
0
        public async Task Update_Success()
        {
            // Arrange
            var loggerController = Loggers.CategoryController();
            var blobService      = BlobService.BlobServiceUpload();

            var mapper = Mapper.Get();

            var dbContext = _fixture.Context;

            var oldCategory = NewDatas.NewCategory();
            await dbContext.AddAsync(oldCategory);

            await dbContext.SaveChangesAsync();

            var newCategoryRequest = NewDatas.NewCategoryRequest();

            var categoryRepository  = new CategoryRepository(mapper, blobService, dbContext);
            var catgoriesController = new CategoriesController(loggerController, categoryRepository);

            // Act
            var result = await catgoriesController.Update(oldCategory.CategoryId, newCategoryRequest);

            // Assert
            var createdCategoryResult = Assert.IsType <OkObjectResult>(result.Result);
            var resultValue           = Assert.IsType <CategoryRespone>(createdCategoryResult.Value);

            Assert.Equal(oldCategory.Name, resultValue.Name);
            Assert.Equal(oldCategory.Description, resultValue.Description);
            Assert.Equal(oldCategory.Image, resultValue.Image);

            Assert.Equal(oldCategory.Name, newCategoryRequest.Name);
            Assert.Equal(oldCategory.Description, newCategoryRequest.Description);
            Assert.Equal(oldCategory.Image, newCategoryRequest.Image);
        }
Ejemplo n.º 4
0
        public async Task UpdateProduct_Success()
        {
            // Arrange
            var loggerController = Loggers.ProductControllerLogger();
            var loggerRepository = Loggers.ProductRepositoryLogger();
            var blobService      = BlobService.BlobServiceUpload();

            var mapper = Mapper.Get();

            var dbContext = _fixture.Context;

            var oldCategory = NewDatas.NewCategory();
            var newCategory = NewDatas.NewCategory();
            await dbContext.Categories.AddRangeAsync(oldCategory, newCategory);

            await dbContext.SaveChangesAsync();

            var product = NewDatas.NewProduct();

            product.CategoryId = oldCategory.CategoryId;
            await dbContext.Products.AddAsync(product);

            await dbContext.SaveChangesAsync();

            var productRepository = new ProductRepository(loggerRepository, mapper, blobService, dbContext);

            var productRequest = NewDatas.NewProductRequest();

            productRequest.CategoryId = newCategory.CategoryId;

            // Act
            var productController = new ProductsController(loggerController, productRepository);
            var result            = await productController.UpdateProduct(product.ProductId, productRequest);

            // Assert
            var updatedResult = Assert.IsType <OkObjectResult>(result.Result);
            var updatedValue  = Assert.IsType <ProductRespone>(updatedResult.Value);

            Assert.Equal(product.Name, updatedValue.Name);
            Assert.Equal(product.Price, updatedValue.Price);
            Assert.Equal(product.Description, updatedValue.Description);
            Assert.Equal(product.Image, updatedValue.Image);
            Assert.Equal(product.Rated, updatedValue.Rated);

            Assert.Equal(newCategory.CategoryId, updatedValue.CategoryId);
            Assert.Equal(newCategory.Name, updatedValue.CategoryName);
        }
Ejemplo n.º 5
0
        public async Task Delete_Success()
        {
            // Arrange
            var loggerController = Loggers.ProductControllerLogger();
            var loggerRepository = Loggers.ProductRepositoryLogger();
            var blobService      = BlobService.BlobServiceUpload();

            var mapper = Mapper.Get();

            var dbContext = _fixture.Context;

            var category = NewDatas.NewCategory();
            await dbContext.Categories.AddRangeAsync(category);

            await dbContext.SaveChangesAsync();

            var product = NewDatas.NewProduct();

            product.CategoryId = category.CategoryId;
            await dbContext.Products.AddAsync(product);

            await dbContext.SaveChangesAsync();

            var productRepository = new ProductRepository(loggerRepository, mapper, blobService, dbContext);
            var productController = new ProductsController(loggerController, productRepository);

            // Act
            var result = await productController.RemoveProduct(product.ProductId);

            // Assert
            var deletedResult      = Assert.IsType <OkObjectResult>(result.Result);
            var deletedResultValue = Assert.IsType <ProductRespone>(deletedResult.Value);

            Assert.Equal(product.Name, deletedResultValue.Name);
            Assert.Equal(product.Price, deletedResultValue.Price);
            Assert.Equal(product.Description, deletedResultValue.Description);
            Assert.Equal(product.Image, deletedResultValue.Image);
            Assert.Equal(product.Rated, deletedResultValue.Rated);
            Assert.Equal(category.CategoryId, deletedResultValue.CategoryId);
            Assert.Equal(category.Name, deletedResultValue.CategoryName);

            await Assert.ThrowsAsync <NotFoundException>(async() =>
            {
                await productController.GetProduct(deletedResultValue.ProductId);
            });
        }