Beispiel #1
0
        public async Task Create_Success()
        {
            // Arrange
            var loggerController = Loggers.CategoryController();

            var mapper = Mapper.Get();

            var dbContext = _fixture.Context;

            var categoryRequest = NewDatas.NewCategoryRequest();

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

            // Act
            var result = await catgoriesController.Create(categoryRequest);

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

            Assert.Equal(categoryRequest.Name, resultValue.Name);
            Assert.Equal(categoryRequest.Description, resultValue.Description);
            Assert.Equal(categoryRequest.Image, resultValue.Image);
        }
Beispiel #2
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);
        }