Example #1
0
        public void MappingProductToProductModelTest()
        {
            DateTime mockCreatedDate = new DateTime(2019, 1, 1);
            DateTime mockUpdateDate  = new DateTime(2020, 1, 1);
            int      mockId          = 12;
            bool     mockIsDeleted   = false;
            string   mockName        = "Trial";
            string   mockNewName     = "Error";

            Product mockProduct = new Product()
            {
                CreatedDate = mockCreatedDate,
                UpdatedDate = mockUpdateDate,
                Id          = mockId,
                IsDeleted   = mockIsDeleted,
                Name        = mockName
            };

            ProductPersistenceModel mockProductModel = new ProductPersistenceModel()
            {
                Name = mockNewName
            };

            mockProduct = _mapper.Map(mockProductModel, mockProduct);

            Assert.AreEqual(mockProduct.Name, mockNewName);

            Assert.AreEqual(mockProduct.CreatedDate, mockCreatedDate);
            Assert.AreEqual(mockProduct.UpdatedDate, mockUpdateDate);
            Assert.AreEqual(mockProduct.Id, mockId);
            Assert.AreEqual(mockProduct.IsDeleted, mockIsDeleted);

            Assert.Pass();
        }
Example #2
0
        public async Task <ActionResult <bool> > Put(int id, [FromBody] ProductPersistenceModel productPersistenceModel)
        {
            Product product = await _productService.GetProductAsync(id);

            product = _mapper.Map(productPersistenceModel, product);

            bool updateResult = await _productService.UpdateAsync(product);

            _memoryCache.Remove(Startup.ProductInMemoryCacheKey);

            return(Ok(updateResult));
        }
Example #3
0
        public async Task <ActionResult <bool> > Post([FromBody] ProductPersistenceModel productPersistenceModel)
        {
            if (productPersistenceModel == null)
            {
                return(BadRequest("Product can not be null."));
            }
            else if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrors()));
            }

            Product product = _mapper.Map <Product>(productPersistenceModel);

            bool insertResult = await _productService.AddAsync(product);

            _memoryCache.Remove(Startup.ProductInMemoryCacheKey);

            return(Ok(insertResult));
        }