Exemplo n.º 1
0
        public void TestDeleteProduct_ShouldCallRepositoryGetByIdCorrectly(int id)
        {
            var factory         = new Mock <IProductFactory>();
            var repository      = new Mock <IRepository <Product> >();
            var categoryService = new Mock <ICategoryService>();
            var unitOfWork      = new Mock <IUnitOfWork>();

            var service = new ZobShop.Services.ProductService(factory.Object, repository.Object, categoryService.Object, unitOfWork.Object);

            service.DeleteProduct(id);

            repository.Verify(x => x.GetById(id), Times.Once);
        }
Exemplo n.º 2
0
        public void TestDeleteProduct_NoProductFound_ShouldNotCallUnitOfWorkCommit(int id)
        {
            var factory    = new Mock <IProductFactory>();
            var repository = new Mock <IRepository <Product> >();

            repository.Setup(x => x.GetById(It.IsAny <object>()))
            .Returns((Product)null);

            var categoryService = new Mock <ICategoryService>();
            var unitOfWork      = new Mock <IUnitOfWork>();

            var service = new ZobShop.Services.ProductService(factory.Object, repository.Object, categoryService.Object, unitOfWork.Object);

            service.DeleteProduct(id);

            unitOfWork.Verify(x => x.Commit(), Times.Never);
        }
Exemplo n.º 3
0
        public void TestDeleteProduct_ShouldCallUnitOfWorkCommitCorrectly(int id)
        {
            var factory = new Mock <IProductFactory>();

            var mockedProduct = new Mock <Product>();

            var repository = new Mock <IRepository <Product> >();

            repository.Setup(x => x.GetById(It.IsAny <object>()))
            .Returns(mockedProduct.Object);

            var categoryService = new Mock <ICategoryService>();
            var unitOfWork      = new Mock <IUnitOfWork>();

            var service = new ZobShop.Services.ProductService(factory.Object, repository.Object, categoryService.Object, unitOfWork.Object);

            service.DeleteProduct(id);

            unitOfWork.Verify(x => x.Commit(), Times.Once);
        }