Beispiel #1
0
        public void TestGetById_ShouldCallRepositoryGetById(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.GetById(id);

            repository.Verify(x => x.GetById(id), Times.Once);
        }
Beispiel #2
0
        public void TestGetById_ShouldReturnCorrectly(int id)
        {
            var mockedProduct = new Mock <Product>();

            var factory    = new Mock <IProductFactory>();
            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);

            var result = service.GetById(id);

            Assert.AreSame(mockedProduct.Object, result);
        }