Ejemplo n.º 1
0
        public void AssignVehicleErrorFlowStepOrderTest()
        {
            FlowStepDTO firstStep  = new FlowStepDTO("Mecanica ligera");
            FlowStepDTO secondStep = new FlowStepDTO("Lavado");

            ZoneDTO firstZone = new ZoneDTO();

            firstZone.Name        = "SubZona 1";
            firstZone.MaxCapacity = 60;
            firstZone.Id          = Guid.NewGuid();
            firstZone.IsSubZone   = true;
            firstZone.FlowStep    = secondStep;

            VehicleDTO vehicle = new VehicleDTO();

            vehicle.Brand  = "Chevrolet";
            vehicle.Model  = "Onyx";
            vehicle.Year   = 2016;
            vehicle.Color  = "Gris";
            vehicle.Type   = "Auto";
            vehicle.Vin    = "TEST1234";
            vehicle.Status = StatusCode.ReadyToBeLocated;
            vehicle.Id     = Guid.NewGuid();

            List <VehicleDTO> vehicles = new List <VehicleDTO>();

            vehicles.Add(vehicle);
            firstZone.Vehicles = vehicles;

            List <FlowItemDTO> flow      = new List <FlowItemDTO>();
            FlowItemDTO        firstItem = new FlowItemDTO();

            firstItem.StepNumber = 1;
            firstItem.FlowStep   = firstStep;
            FlowItemDTO secondItem = new FlowItemDTO();

            secondItem.StepNumber = 2;
            secondItem.FlowStep   = secondStep;
            flow.Add(firstItem);
            flow.Add(secondItem);

            var mockZoneDAO    = new Mock <ZoneDAO>();
            var mockFlowDAO    = new Mock <FlowDAO>();
            var mockVehicleDAO = new Mock <VehicleDAO>();

            mockZoneDAO.Setup(z => z.FindZoneById(firstZone.Id)).Returns(firstZone);
            mockZoneDAO.Setup(z => z.GetVehicleCapacityLeft(firstZone.Id)).Returns(60);
            mockZoneDAO.Setup(z => z.AssignVehicle(firstZone.Id, vehicle.Vin)).Verifiable();
            ZoneDTO mockedZone = null;

            mockZoneDAO.Setup(z => z.GetVehicleZone(vehicle.Vin)).Returns(mockedZone);
            mockFlowDAO.Setup(f => f.GetFlow()).Returns(flow);
            mockVehicleDAO.Setup(v => v.FindVehicleByVin(vehicle.Vin)).Returns(vehicle);

            var zoneService = new ZoneServiceImp(mockZoneDAO.Object, mockFlowDAO.Object, mockVehicleDAO.Object);

            zoneService.AssignVehicle(firstZone.Id, vehicle.Vin);
        }
Ejemplo n.º 2
0
        private void ValidateIsAllowedInFlow(ZoneDTO subZone, string vin)
        {
            VehicleDTO vehicle = this.vehicleDAO.FindVehicleByVin(vin);

            if (vehicle == null)
            {
                throw new VehicleNotFoundException("El vehiculo que se le intenta agregar una subzona no existe");
            }

            List <FlowItemDTO> flow        = this.flowDAO.GetFlow();
            ZoneDTO            vehicleZone = this.zoneDAO.GetVehicleZone(vin);

            if (vehicleZone == null)
            {
                if (vehicle.Status != StatusCode.ReadyToBeLocated)
                {
                    throw new VehicleStatusDoesntAllowToAssignZoneException("El vehiculo no se encuentra en un estado correcto para ser asignado a una subzona");
                }

                FlowItemDTO firstStepOfFlow = flow.Find(f => f.StepNumber == 1);
                if (subZone.FlowStep.Name != firstStepOfFlow.FlowStep.Name)
                {
                    throw new FlowStepOrderException("El vehiculo no puede ser asignado a esa subzona ya que no respeta el orden del flujo");
                }
            }
            else
            {
                if (vehicle.Status != StatusCode.Located)
                {
                    throw new VehicleStatusDoesntAllowToAssignZoneException("El vehiculo no se encuentra en un estado correcto para ser asignado a una subzona");
                }
                FlowItemDTO nextStepOfFlow = flow.Find(f => f.FlowStep.Name == subZone.FlowStep.Name);
                if (nextStepOfFlow == null)
                {
                    throw new SubezoneDoesNotBelongeToZoneException("La subzona a asignar no esta incluida en el flujo");
                }
                else
                {
                    FlowItemDTO currentStepOfFlow = flow.Find(f => f.FlowStep.Name == vehicleZone.FlowStep.Name);
                    if (currentStepOfFlow == null)
                    {
                        throw new SubezoneDoesNotBelongeToZoneException("La zona actual en la que se encuentra el vehiculo no pertenece al flujo");
                    }
                    else
                    {
                        if (nextStepOfFlow.StepNumber != currentStepOfFlow.StepNumber + 1)
                        {
                            throw new FlowStepOrderException("El vehiculo no puede ser asignado a esa subzona ya que no respeta el orden del flujo");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void SetVehicleReadyToBeSoldSuccessfullyTest()
        {
            VehicleDTO vehicle = new VehicleDTO();

            vehicle.Brand  = "Chevrolet";
            vehicle.Model  = "Onyx";
            vehicle.Year   = 2016;
            vehicle.Color  = "Gris";
            vehicle.Type   = "Auto";
            vehicle.Vin    = "SDE1234";
            vehicle.Id     = Guid.NewGuid();
            vehicle.Status = StatusCode.Located;

            List <FlowItemDTO> flow     = new List <FlowItemDTO>();
            FlowItemDTO        flowItem = new FlowItemDTO();

            flowItem.FlowStep   = new FlowStepDTO("Lavado");
            flowItem.StepNumber = 1;
            flow.Add(flowItem);

            ZoneDTO zone = new ZoneDTO();

            zone.IsSubZone   = true;
            zone.MaxCapacity = 20;
            zone.Vehicles    = new List <VehicleDTO>();
            zone.Vehicles.Add(vehicle);
            zone.Name     = "SZ prueba";
            zone.FlowStep = new FlowStepDTO("Lavado");

            var mockFlowDAO = new Mock <FlowDAO>();

            mockFlowDAO.Setup(f => f.GetFlow()).Returns(flow);

            var mockZoneDAO = new Mock <ZoneDAO>();

            mockZoneDAO.Setup(z => z.GetVehicleZone("SDE1234")).Returns(zone);
            mockZoneDAO.Setup(z => z.RemoveVehicle("SDE1234")).Verifiable();

            var mockVehicleDAO = new Mock <VehicleDAO>();

            mockVehicleDAO.Setup(vs => vs.FindVehicleByVin("SDE1234")).Returns(vehicle);
            mockVehicleDAO.Setup(vs => vs.UpdateVehicle(vehicle)).Verifiable();

            var vehicleService = new VehicleServiceImpl(mockVehicleDAO.Object, mockFlowDAO.Object, mockZoneDAO.Object);

            vehicleService.SetVehicleReadyToSell("SDE1234");
        }
Ejemplo n.º 4
0
        public void CreateFlowTest()
        {
            FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera");
            FlowStepDTO pintura  = new FlowStepDTO("Pintura");
            FlowStepDTO lavado   = new FlowStepDTO("Lavado");
            FlowDAO     flowDAO  = new FlowDAOImp();

            if (flowDAO.IsStepAvailable(mecanica))
            {
                flowDAO.CreateStep(mecanica);
            }
            if (flowDAO.IsStepAvailable(pintura))
            {
                flowDAO.CreateStep(pintura);
            }
            if (flowDAO.IsStepAvailable(lavado))
            {
                flowDAO.CreateStep(lavado);
            }

            Dictionary <int, FlowStepDTO> request = new Dictionary <int, FlowStepDTO>();

            request.Add(1, mecanica);
            request.Add(2, pintura);
            request.Add(3, lavado);

            flowDAO.CreateFlow(request);
            List <FlowItemDTO> flowItems = flowDAO.GetFlow();

            Assert.IsNotNull(flowItems);
            Assert.IsTrue(flowItems.Count > 0);
            FlowItemDTO resultMecanica = flowItems.Find(f => f.FlowStep.Name == mecanica.Name);

            Assert.AreEqual(1, resultMecanica.StepNumber);
            FlowItemDTO resultPintura = flowItems.Find(f => f.FlowStep.Name == pintura.Name);

            Assert.AreEqual(2, resultPintura.StepNumber);
            FlowItemDTO resultLavado = flowItems.Find(f => f.FlowStep.Name == lavado.Name);

            Assert.AreEqual(3, resultLavado.StepNumber);
        }
Ejemplo n.º 5
0
        public void GetFlowTest()
        {
            List <FlowItemDTO> flowItems = new List <FlowItemDTO>();
            FlowItemDTO        flowItem  = new FlowItemDTO();

            flowItem.Id         = Guid.NewGuid();
            flowItem.StepNumber = 1;
            FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera");

            flowItem.FlowStep = mecanica;
            flowItems.Add(flowItem);

            var mockFlowDAO = new Mock <FlowDAO>();

            mockFlowDAO.Setup(f => f.GetFlow()).Returns(flowItems);
            FlowService        flowService = new FlowServiceImp(mockFlowDAO.Object);
            List <FlowItemDTO> result      = flowService.GetFlow();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count > 0);
        }
Ejemplo n.º 6
0
        public List <FlowItemDTO> GetFlow()
        {
            List <FlowItemDTO> flow = new List <FlowItemDTO>();

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                List <FlowItem> flowItems = context.FlowItems.Include("FlowStep").OrderBy(x => x.StepNumber).ToList();
                foreach (FlowItem flowItem in flowItems)
                {
                    FlowItemDTO flowItemDTO = new FlowItemDTO();
                    flowItemDTO.Id          = flowItem.Id;
                    flowItemDTO.StepNumber  = flowItem.StepNumber;
                    flowItemDTO.FlowStep    = new FlowStepDTO(flowItem.FlowStep.Name);
                    flowItemDTO.FlowStep.Id = flowItem.FlowStep.Id;

                    flow.Add(flowItemDTO);
                }
            }

            return(flow);
        }