public void TearDown()
 {
     mapper          = null;
     planeRepository = null;
     part            = null;
     partDto         = null;
     userRepository  = null;
     partService     = null;
 }
        public void PlaneService_UpdateEntity_IsInvoked()
        {
            //Arrange
            var planePartRepository = new Mock <IPlanePartRepository>();

            planePartRepository.Setup(a => a.UpdatePlanePart(It.Is <PlanePart>(x => x == part))).Verifiable();
            uow         = new UnitOfWork(planeRepository.Object, userRepository.Object, planePartRepository.Object);
            partService = new PlanePartService(uow, new DtoProfile());
            //Act
            partService.UpdatePlanePart(partDto);
            //Assert
            planePartRepository.Verify(h => h.UpdatePlanePart(It.Is <PlanePart>(r => r != null)));
        }
        public void PlaneService_GetEntity_Null(int id)
        {
            //Arrange
            var planePartRepository = new Mock <IPlanePartRepository>();

            planePartRepository.Setup(a => a.GetPlanePart(It.Is <int>(x => x == id))).Throws(new ArgumentNullException("part", "Null argument was passed as a parameter")).Verifiable();
            uow         = new UnitOfWork(planeRepository.Object, userRepository.Object, planePartRepository.Object);
            partService = new PlanePartService(uow, new DtoProfile());
            //Act
            var getPart = partService.GetPlanePart(id);

            //Assert
            Assert.Null(getPart);
            planePartRepository.Verify(a => a.GetPlanePart(It.Is <int>(r => r == id)), Times.Once());
        }
        public void PlaneService_GetEntity(int id)
        {
            //Arrange
            var planePartRepository = new Mock <IPlanePartRepository>();

            planePartRepository.Setup(a => a.GetPlanePart(It.Is <int>(x => x == id))).Returns(part);
            uow         = new UnitOfWork(planeRepository.Object, userRepository.Object, planePartRepository.Object);
            partService = new PlanePartService(uow, new DtoProfile());
            //Act
            var getPart = partService.GetPlanePart(id);

            //Assert
            Assert.NotNull(getPart);
            Assert.AreEqual(partDto.Name, getPart.Name);
            planePartRepository.Verify(a => a.GetPlanePart(It.Is <int>(r => r == id)), Times.Once());
        }
        public void PlaneService_GetEntities_Exception()
        {
            //Arrange
            var planePartRepository = new Mock <IPlanePartRepository>();

            planePartRepository.Setup(a => a.GetAll()).Throws(new Exception()).Verifiable();
            uow         = new UnitOfWork(planeRepository.Object, userRepository.Object, planePartRepository.Object);
            partService = new PlanePartService(uow, new DtoProfile());
            //Act

            var parts = partService.GetPlaneParts();

            //Assert
            Assert.NotNull(parts);
            Assert.IsEmpty(parts);
        }
        public void PlaneService_DeleteEntity_Exception()
        {
            //Arrange
            var planePartRepository = new Mock <IPlanePartRepository>();

            planePartRepository.Setup(a => a.DeletePlanePart(null)).Throws(new ArgumentNullException("part", "Null argument was passed as a parameter")).Verifiable();
            uow         = new UnitOfWork(planeRepository.Object, userRepository.Object, planePartRepository.Object);
            partService = new PlanePartService(uow, new DtoProfile());
            //Act

            partService.DeletePlanePart(null);

            //Assert

            var ex = Assert.Throws <ArgumentNullException>(() => planePartRepository.Object.DeletePlanePart(null));

            Assert.That(ex.Message, Is.EqualTo("Null argument was passed as a parameter (Parameter 'part')"));
        }
        public void PlaneService_GetAll()
        {
            //Arrange
            var planePartRepository = new Mock <IPlanePartRepository>();

            planePartRepository.Setup(a => a.GetAll()).Returns(new List <PlanePart>()
            {
                part
            });
            uow         = new UnitOfWork(planeRepository.Object, userRepository.Object, planePartRepository.Object);
            partService = new PlanePartService(uow, new DtoProfile());
            //Act
            var parts = partService.GetPlaneParts();

            //Assert
            Assert.NotNull(parts);
            Assert.IsNotEmpty(parts);
            Assert.AreEqual(part.Id, parts.FirstOrDefault().Id);
            planePartRepository.Verify(a => a.GetAll(), Times.Once());
        }