private void addBtn_Click(object sender, EventArgs e) { if (txtType.Text != "") { FlowStepDTO flowStep = new FlowStepDTO(txtType.Text); try { this.flowService.CreateStep(flowStep); txtType.Text = ""; this.loadTypes(); } catch (FlowStepAlreadyExistException) { MessageBox.Show( "Ya existe un tipo de zona creado con ese nombre", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show( "No se puede crear un tipo de zona vacio", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void addBtn_Click(object sender, EventArgs e) { if (isCreationValid()) { ZoneDTO newZone = new ZoneDTO(); newZone.Name = txtName.Text; newZone.IsSubZone = isSubZoneChk.Checked; newZone.MaxCapacity = (int)numericCapacity.Value; if (newZone.IsSubZone) { FlowStepDTO flowStep = new FlowStepDTO(this.comboTypes.SelectedItem.ToString()); newZone.FlowStep = flowStep; } this.zoneService.AddZone(newZone); this.subject.Notify(); this.Close(); } else { MessageBox.Show( "Los valores deben estar todos completos, y la capacidad debe ser mayor a 1.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void removeType_Click(object sender, EventArgs e) { if (this.listFlow.SelectedItems.Count > 0) { string removedType = this.listFlow.SelectedItems[0].SubItems[1].Text; this.flow.Remove(this.listFlow.Items.IndexOf(this.listFlow.SelectedItems[0]) + 1); int reindex = 1; Dictionary <int, FlowStepDTO> changedFlow = new Dictionary <int, FlowStepDTO>(); foreach (int key in this.flow.Keys) { FlowStepDTO tempFlow = this.flow[key]; changedFlow[reindex] = tempFlow; reindex++; } this.addSelectedType(removedType); this.flow = changedFlow; this.refreshFlow(); } else { MessageBox.Show( "Seleccione un paso del flujo de la lista.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); }
public FlowStepDTO GetStepByName(string name) { FlowStepDTO flowStep = this.flowDAO.GetStepByName(name); if (flowStep == null) { throw new FlowStepNotFoundException("No se ha encontrado paso de flujo con ese nombre"); } return(flowStep); }
public void GetStepByNameTest() { FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera"); var mockFlowDAO = new Mock <FlowDAO>(); mockFlowDAO.Setup(f => f.GetStepByName(mecanica.Name)).Returns(mecanica); FlowService flowService = new FlowServiceImp(mockFlowDAO.Object); FlowStepDTO result = flowService.GetStepByName(mecanica.Name); Assert.AreEqual(mecanica.Name, result.Name); }
public void CreateStep(FlowStepDTO step) { if (this.flowDAO.IsStepAvailable(step)) { this.flowDAO.CreateStep(step); } else { throw new FlowStepAlreadyExistException("Ya existe un paso de flujo con ese nombre"); } }
public void CreateStepErrorDuplicatedStepTest() { FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera"); var mockFlowDAO = new Mock <FlowDAO>(); mockFlowDAO.Setup(f => f.IsStepAvailable(mecanica)).Returns(false); mockFlowDAO.Setup(f => f.CreateStep(mecanica)).Verifiable(); FlowService flowService = new FlowServiceImp(mockFlowDAO.Object); flowService.CreateStep(mecanica); }
public void CreateStep(FlowStepDTO step) { FlowStep flowStep = new FlowStep(); flowStep.Name = step.Name; flowStep.Id = Guid.NewGuid(); using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { context.FlowSteps.Add(flowStep); context.SaveChanges(); } }
public void GetStepByNameTest() { FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera"); FlowDAO flowDAO = new FlowDAOImp(); if (flowDAO.IsStepAvailable(mecanica)) { flowDAO.CreateStep(mecanica); } FlowStepDTO result = flowDAO.GetStepByName("Mecanica ligera"); Assert.AreEqual(mecanica.Name, result.Name); }
public void GetAllStepsTest() { List <FlowStepDTO> steps = new List <FlowStepDTO>(); FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera"); steps.Add(mecanica); var mockFlowDAO = new Mock <FlowDAO>(); mockFlowDAO.Setup(f => f.GetAllSteps()).Returns(steps); FlowService flowService = new FlowServiceImp(mockFlowDAO.Object); List <FlowStepDTO> result = flowService.GetAllSteps(); Assert.IsNotNull(result); Assert.IsTrue(result.Count > 0); }
public void GetAllStepsTest() { FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera"); FlowDAO flowDAO = new FlowDAOImp(); if (flowDAO.IsStepAvailable(mecanica)) { flowDAO.CreateStep(mecanica); } List <FlowStepDTO> results = flowDAO.GetAllSteps(); Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0); }
public List <FlowStepDTO> GetAllSteps() { List <FlowStepDTO> flowStepsDTO = new List <FlowStepDTO>(); using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { foreach (FlowStep flowStep in context.FlowSteps) { FlowStepDTO flowStepDTO = new FlowStepDTO(flowStep.Name); flowStepDTO.Id = flowStep.Id; flowStepsDTO.Add(flowStepDTO); } } return(flowStepsDTO); }
private void addType_Click(object sender, EventArgs e) { if (this.listTypes.SelectedItems.Count > 0) { FlowStepDTO flowStep = new FlowStepDTO(this.listTypes.SelectedItems[0].Text); this.flow[this.flow.Count + 1] = flowStep; this.removeSelectedType(); this.refreshFlow(); } else { MessageBox.Show( "Seleccione un tipo de la lista.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void DeleteStep(FlowStepDTO step) { FlowStep flowStep = null; using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { var query = from f in context.FlowSteps where f.Name == step.Name select f; flowStep = query.ToList().FirstOrDefault(); if (flowStep != null) { context.FlowSteps.Remove(flowStep); context.SaveChanges(); } } }
public void ErrorCreatingFlowIncorrectStepsTest() { Dictionary <int, FlowStepDTO> request = new Dictionary <int, FlowStepDTO>(); FlowStepDTO mecanica = new FlowStepDTO("Mecanica ligera"); FlowStepDTO pintura = new FlowStepDTO("Pintura"); FlowStepDTO lavado = new FlowStepDTO("Lavado"); request.Add(1, mecanica); request.Add(2, pintura); request.Add(3, pintura); var mockFlowDAO = new Mock <FlowDAO>(); mockFlowDAO.Setup(f => f.CreateFlow(request)).Verifiable(); FlowService flowService = new FlowServiceImp(mockFlowDAO.Object); flowService.CreateFlow(request); }
public bool IsStepAvailable(FlowStepDTO step) { bool stepAvailable = false; FlowStep flowStep = null; using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { var query = from f in context.FlowSteps where f.Name == step.Name select f; flowStep = query.ToList().FirstOrDefault(); if (flowStep == null) { stepAvailable = true; } } return(stepAvailable); }
public FlowStepDTO GetStepByName(string name) { FlowStepDTO flowStepDTO = null; FlowStep flowStep = null; using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { var query = from f in context.FlowSteps where f.Name == name select f; flowStep = query.ToList().FirstOrDefault(); if (flowStep != null) { flowStepDTO = new FlowStepDTO(name); } } return(flowStepDTO); }
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); }
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); }
public void ErrorCreatingSubZoneWithoutFlowStepTest() { ZoneDTO zone = new ZoneDTO(); zone.Name = "Zona 1"; zone.MaxCapacity = 60; zone.IsSubZone = true; zone.Id = Guid.NewGuid(); FlowStepDTO flowStep = new FlowStepDTO("Lavado"); zone.FlowStep = flowStep; var mockZoneDAO = new Mock <ZoneDAO>(); var mockFlowDAO = new Mock <FlowDAO>(); var mockVehicleDAO = new Mock <VehicleDAO>(); mockFlowDAO.Setup(f => f.IsStepAvailable(flowStep)).Returns(true); var zoneService = new ZoneServiceImp(mockZoneDAO.Object, mockFlowDAO.Object, mockVehicleDAO.Object); zoneService.AddZone(zone); }
public void CreateSubZoneSuccessfullyTest() { ZoneDTO zone = new ZoneDTO(); zone.Name = "Zona 1"; zone.MaxCapacity = 60; zone.IsSubZone = true; zone.Id = Guid.NewGuid(); FlowStepDTO flowStep = new FlowStepDTO("Lavado"); zone.FlowStep = flowStep; var mockZoneDAO = new Mock <ZoneDAO>(); ZoneDTO mockZone = new ZoneDTO(); mockZone.Name = "Zona 1"; mockZone.MaxCapacity = 60; mockZone.IsSubZone = true; mockZone.FlowStep = new FlowStepDTO("Lavado"); mockZoneDAO.Setup(z => z.FindZoneById(zone.Id)).Returns(mockZone); var mockFlowDAO = new Mock <FlowDAO>(); var mockVehicleDAO = new Mock <VehicleDAO>(); mockFlowDAO.Setup(f => f.IsStepAvailable(flowStep)).Returns(false); var zoneService = new ZoneServiceImp(mockZoneDAO.Object, mockFlowDAO.Object, mockVehicleDAO.Object); zoneService.AddZone(zone); ZoneDTO resultZone = zoneService.FindZoneById(zone.Id); Assert.AreEqual(zone.Name, resultZone.Name); Assert.AreEqual(zone.MaxCapacity, resultZone.MaxCapacity); Assert.AreEqual(zone.IsSubZone, resultZone.IsSubZone); Assert.AreEqual(zone.FlowStep.Name, resultZone.FlowStep.Name); }