public void Create_NullParamater_ThrowsException()
        {
            var mockRepo = new Mock <IRepository <Product> >();

            mockRepo.Setup(x => x.Insert(It.IsAny <Product>())).Returns(new Product());
            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(x => x.Commit()).Returns(1);
            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <Product, ProductDetailsOutput>(It.IsAny <Product>())).Returns(new ProductDetailsOutput());

            var productService = new ProductAppService(mockUow.Object, mockRepo.Object, mockMapper.Object);

            productService.Create(null);
        }
        public void Create_ValidParamater_ReturnsNewInstance()
        {
            var mockRepo = new Mock <IRepository <Product> >();

            mockRepo.Setup(x => x.Insert(It.IsAny <Product>())).Returns(new Product());
            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(x => x.Commit()).Returns(1);
            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <Product, ProductDetailsOutput>(It.IsAny <Product>())).Returns(new ProductDetailsOutput());
            var productService = new ProductAppService(mockUow.Object, mockRepo.Object, mockMapper.Object);

            var result = productService.Create(new ProductCreateInput());

            mockRepo.Verify(x => x.Insert(It.IsAny <Product>()));
            mockUow.Verify(x => x.Commit());
            Assert.IsNotNull(result);
        }
示例#3
0
 public async Task <ActionResult> Upload(List <IFormFile> files)
 {
     foreach (var formFile in files)
     {
         if (formFile.Length > 0)
         {
             var          stream = formFile.OpenReadStream();
             StreamReader reader = new StreamReader(stream);
             while (!reader.EndOfStream)
             {
                 var      line    = reader.ReadLine();
                 string[] parts   = line.Split(",");
                 var      product = new Product(int.Parse(parts[0]), parts[1], parts[2], float.Parse(parts[3]), parts[4], uint.Parse(parts[5]));
                 await _productAppService.Create(product);
             }
         }
     }
     return(Redirect("ProductList"));
 }