コード例 #1
0
        public async Task Test_DeleteBrand_ShouldDeleteSuccessfully()
        {
            //arrange
            var brandForDelete = new BrandForDeleteDto {
                Id = 1
            };
            var resultModel = new BrandDeletedDto {
                IsSuccess = true
            };

            brandRepositoryMock.Setup(p => p.DeleteBrand(brandForDelete)).Returns(Task.FromResult(resultModel));

            //act
            var result = await subject.DeleteBrand(brandForDelete);

            var OkActionResult = result as OkResult;

            //assert
            Assert.IsInstanceOf <OkResult>(OkActionResult);
            brandRepositoryMock.Verify(x => x.DeleteBrand(brandForDelete), Times.Once);
        }
コード例 #2
0
        public async Task ValidateDeleteBrand()
        {
            _dbContext.Brands.Add(new Brand
            {
                Id   = 99,
                Name = "GOG.com"
            });

            var controller = new BrandsController(_dbContext);
            var result     = await controller.DeleteBrand(99);

            var actionResult = Assert.IsType <NoContentResult>(result);

            Assert.NotNull(result);
            Assert.NotNull(actionResult);
        }
コード例 #3
0
        public async Task DeleteCategory_Success()
        {
            _applicationDbContex.Brands.Add(new Brand {
                Name = "Test category"
            });
            await _applicationDbContex.SaveChangesAsync();

            var oldCategory = await _applicationDbContex.Brands.OrderByDescending(x => x.BrandID).FirstAsync();

            var controller = new BrandsController(_applicationDbContex);
            var result     = await controller.DeleteBrand(oldCategory.BrandID);

            var returnValue = await _applicationDbContex.Brands.ToListAsync();

            Assert.Empty(returnValue);
        }
コード例 #4
0
        public async Task DeleteBrand_Success()
        {
            var dbContext = _fixture.Context;

            Brand brand = new Brand {
                Name = "Test brand"
            };
            await dbContext.Brands.AddAsync(brand);

            await dbContext.SaveChangesAsync();

            var brandsController = new BrandsController(dbContext);
            // Act
            var result = await brandsController.DeleteBrand(brand.ID);

            // Assert
            var deleteAtActionResult = Assert.IsType <NoContentResult>(result.Result);

            await Assert.ThrowsAsync <Exception>(async() =>
            {
                await brandsController.GetBrand(brand.ID);
            });
        }