Beispiel #1
0
        public void CreateManufacturer(ManufacturerEntity manufacturerEntity)
        {
            var manufacturerDb = AutoMapper.Mapper.Map <ManufacturerEntity, Manufacturer>(manufacturerEntity);

            _unitOfWork.ManufacturerRepository.Insert(manufacturerDb);
            _unitOfWork.Save();
        }
Beispiel #2
0
        public void UpdateManufacturer_Calls_Update_In_Repository()
        {
            var manufacturer = new ManufacturerEntity();
            var dto          = new ManufacturerDto();

            mockRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(manufacturer);
            manufacturerService.UpdateManufacturer(dto);

            mockRepo.Verify(r => r.Update(It.IsAny <ManufacturerEntity>()), Times.Once);
        }
        public ActionResult Create(ManufacturerEntity manufacturerEntity)
        {
            if (ModelState.IsValid)
            {
                _manufacturerServices.CreateManufacturer(manufacturerEntity);
                return(RedirectToAction("Index", "Home"));
            }

            return(View(manufacturerEntity));
        }
Beispiel #4
0
        public void GetManufacturerById_Returns_Manufacturer()
        {
            var manufacturer = new ManufacturerEntity();
            var dto          = new ManufacturerDto();

            mockRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(manufacturer);
            mockMapper.Setup(m => m.Map <ManufacturerDto>(manufacturer)).Returns(dto);
            var actual = manufacturerService.GetManufacturer(1);

            Assert.AreEqual(dto, actual);
        }
Beispiel #5
0
        public void CreateManufacturer_Returns_Manufacturer()
        {
            var manufacturer = new ManufacturerEntity();
            var dto          = new ManufacturerDto();

            mockRepo.Setup(r => r.Insert(It.IsAny <ManufacturerEntity>()))
            .Returns(manufacturer);
            mockMapper.Setup(m => m.Map <ManufacturerDto>(manufacturer)).Returns(dto);
            var actual = manufacturerService.CreateManufacturer(dto);

            Assert.AreEqual(dto, actual);
        }
Beispiel #6
0
        public void GetManufacturerBySlug_Returns_Manufacturer()
        {
            var slug         = "test";
            var manufacturer = new ManufacturerEntity();
            var dto          = new ManufacturerDto();

            mockRepo.Setup(r => r.GetBySlug(It.IsAny <string>())).Returns(manufacturer);
            mockMapper.Setup(m => m.Map <ManufacturerDto>(manufacturer)).Returns(dto);
            var actual = manufacturerService.GetManufacturerBySlug(slug);

            Assert.AreEqual(dto, actual);
        }
Beispiel #7
0
        public ManufacturerEntity Create(EmployeeEntity EmployeeEntity, ManufacturerEntity ManufacturerEntity)
        {
            if (ManufacturerEntity == null)
            {
                throw new NotFoundException();
            }
            Manufacturer Manufacturer = new Manufacturer(ManufacturerEntity);

            UnitOfWork.ManufacturerRepository.AddOrUpdate(Manufacturer);
            UnitOfWork.Complete();
            return(Get(EmployeeEntity, Manufacturer.Id));
        }
Beispiel #8
0
 public Manufacturer(ManufacturerEntity ManufacturerEntity) : base(ManufacturerEntity)
 {
     if (ManufacturerEntity.ProductEntities != null)
     {
         this.Products = new HashSet <Product>();
         foreach (ProductEntity ProductEntity in ManufacturerEntity.ProductEntities)
         {
             ProductEntity.ManufacturerId = ManufacturerEntity.Id;
             this.Products.Add(new Product(ProductEntity));
         }
     }
 }
Beispiel #9
0
        public void CreateManufacturer_Inserts_Manufacturer()
        {
            var manufacturer = new ManufacturerEntity();
            var dto          = new ManufacturerDto();

            mockRepo.Setup(r => r.Insert(It.IsAny <ManufacturerEntity>()))
            .Returns(manufacturer);

            mockMapper.Setup(m => m.Map <ManufacturerEntity>(dto))
            .Returns(manufacturer);

            var actual = manufacturerService.CreateManufacturer(dto);

            mockRepo.Verify(r => r.Insert(manufacturer), Times.Once);
        }
Beispiel #10
0
        public void UpdateManufacturer_Inserts_Manufacturer()
        {
            var testString   = "test";
            var manufacturer = new ManufacturerEntity();
            var dto          = new ManufacturerDto
            {
                ImageUrl = testString,
                Name     = testString
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(manufacturer);
            manufacturerService.UpdateManufacturer(dto);

            mockRepo.Verify(r => r.Update(It.Is <ManufacturerEntity>(m =>
                                                                     m.ImageUrl == testString &&
                                                                     m.Name == testString)),
                            Times.Once);
        }
Beispiel #11
0
        public List <DatfileEnitty> Load(ManufacturerEntity manufacturer, HardwareEntity hardware, string repositoryPath)
        {
            var path = Path.Combine(repositoryPath, manufacturer.Code, hardware.Code);

            List <DatfileEnitty>?result = new List <DatfileEnitty>();

            if (!Directory.Exists(path))
            {
                return(result);
            }

            foreach (string filename in Directory.GetFiles(path, "*.json"))
            {
                var datfile = JsonSerializer.Deserialize <DatfileEnitty>(File.ReadAllText(filename), _jsonOptions);
                if (datfile is not null)
                {
                    result.Add(datfile);
                }
            }

            return(result);
        }
Beispiel #12
0
 public ManufacturerEntity Update(Guid ManufacturerId, [FromBody] ManufacturerEntity ManufacturerEntity)
 {
     return(ManufacturerService.Update(EmployeeEntity, ManufacturerId, ManufacturerEntity));
 }
Beispiel #13
0
 public ManufacturerEntity Create([FromBody] ManufacturerEntity ManufacturerEntity)
 {
     return(ManufacturerService.Create(EmployeeEntity, ManufacturerEntity));
 }
Beispiel #14
0
        private void UpdateManufacturer(ManufacturerUpdateModel manufacturerUpdateModel, ManufacturerEntity manufacturerEntity)
        {
            var productToRemove = manufacturerEntity.Product.Where(product =>
                                                                   !manufacturerUpdateModel.Product.Any(products => products.Id == product.Id));

            foreach (var product in productToRemove)
            {
                product.ManufacturerId = Guid.Empty;
                product.Manufacturer   = null;
                productRepository.Update(product);
            }

            var productToAdd = manufacturerUpdateModel.Product.Where(
                product => !manufacturerEntity.Product.Any(products => products.Id == product.Id));


            foreach (var product in productToAdd)
            {
                var goodEntity = productRepository.GetById(product.Id);
                goodEntity.ManufacturerId = manufacturerUpdateModel.Id;
                productRepository.Update(goodEntity);
            }
        }
Beispiel #15
0
 public void Update(ManufacturerEntity manufacturer)
 {
     _context.Manufacturers.Update(manufacturer);
     _context.SaveChanges();
 }
Beispiel #16
0
 public ManufacturerEntity Insert(ManufacturerEntity manufacturer)
 {
     _context.Manufacturers.Add(manufacturer);
     _context.SaveChanges();
     return(manufacturer);
 }