コード例 #1
0
        public void CreateZoneTest()
        {
            ZoneDTO zone = new ZoneDTO();

            zone.MaxCapacity = 60;
            zone.Name        = "Zona 1";
            UserDTO user  = createUserDTO();
            Guid    token = Guid.NewGuid();

            var mockUserService = new Mock <UserService>();

            mockUserService.Setup(us => us.GetUserLoggedIn(token)).Returns(user);
            var mockZoneService = new Mock <ZoneService>();

            mockZoneService.Setup(zs => zs.AddZone(zone)).Verifiable();

            ZoneController zoneController = new ZoneController(mockUserService.Object, mockZoneService.Object, null);

            zoneController.Request = createUserControllerRequest();
            addTokenHeaderToRequest(zoneController.Request, token);

            ResponseMessageResult response = (ResponseMessageResult)zoneController.Create(zone);

            Assert.AreEqual(HttpStatusCode.Created, response.Response.StatusCode);
        }
コード例 #2
0
 private void modifyBtn_Click(object sender, EventArgs e)
 {
     if (this.treeZones.SelectedNode != null && ((ZoneDTO)this.treeZones.SelectedNode.Tag) != null)
     {
         ZoneDTO    zoneToModify      = ((ZoneDTO)this.treeZones.SelectedNode.Tag);
         ModifyZone modifyZoneWindows = new ModifyZone(zoneToModify, this, this.zoneService);
         modifyZoneWindows.ShowDialog();
     }
     else
     {
         if (this.listSubZones.SelectedItems.Count > 0)
         {
             ZoneDTO    zoneToModify      = ((ZoneDTO)this.listSubZones.SelectedItems[0].Tag);
             ModifyZone modifyZoneWindows = new ModifyZone(zoneToModify, this, this.zoneService);
             modifyZoneWindows.ShowDialog();
         }
         else
         {
             MessageBox.Show(
                 "Seleccione una zona o subzona.",
                 "Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #3
0
        public void CreateSubZone(Guid id, ZoneDTO zoneDTO)
        {
            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from z in context.Zones
                            where z.Id == id
                            select z;
                Zone mainZone = query.ToList().FirstOrDefault();

                Zone subzone = this.mapper.ToEntity(zoneDTO);
                if (zoneDTO.FlowStep != null)
                {
                    var querySZ = from f in context.FlowSteps
                                  where f.Name == zoneDTO.FlowStep.Name
                                  select f;
                    FlowStep flowStep = querySZ.ToList().FirstOrDefault();
                    subzone.FlowStep = flowStep;
                    context.FlowSteps.Attach(flowStep);
                }

                context.Zones.Add(subzone);
                if (mainZone != null)
                {
                    mainZone.SubZones.Add(subzone);
                    context.SaveChanges();
                }
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public ZoneDTO FindZoneById(Guid id)
        {
            Zone    zone    = null;
            ZoneDTO zoneDTO = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                zone = context.Zones
                       .Include("Vehicles")
                       .Include("SubZones")
                       .Where(z => z.Id == id)
                       .ToList().FirstOrDefault();

                if (zone != null)
                {
                    if (zone.SubZones.Count == 0)
                    {
                        zone.SubZones = null;
                    }
                    if (zone.Vehicles.Count == 0)
                    {
                        zone.Vehicles = null;
                    }
                    zoneDTO = this.mapper.ToDTO(zone);
                }
            }
            return(zoneDTO);
        }
コード例 #6
0
        public void AddSubZone(Guid id, ZoneDTO zone)
        {
            bool isThereNullFields = this.IsThereNullFields(zone);

            if (isThereNullFields)
            {
                throw new ZoneNullAttributesException("Se debe ingresar el nombre de la zona, y la capacidad debe ser superior a 0");
            }

            ZoneDTO mainZone = this.zoneDAO.FindZoneById(id);

            if (mainZone == null)
            {
                throw new ZoneNotFoundException("No se ha encontrado una zona con ese id");
            }

            zone.IsSubZone = true;

            if (!this.flowDAO.IsStepAvailable(zone.FlowStep))
            {
                this.zoneDAO.CreateSubZone(id, zone);
            }
            else
            {
                throw new SubZoneWithoutFlowStepException("No se puede crear una subzona que no tiene un paso de flujo valido");
            }
        }
コード例 #7
0
        public void Update(ZoneDTO zoneDTO)
        {
            Zone zone = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from z in context.Zones
                            where z.Id == zoneDTO.Id
                            select z;
                zone = query.ToList().FirstOrDefault();

                if (zone != null)
                {
                    zone.MaxCapacity = zoneDTO.MaxCapacity;
                    zone.Name        = zoneDTO.Name;

                    context.Zones.Attach(zone);
                    var entry = context.Entry(zone);
                    entry.Property(e => e.MaxCapacity).IsModified = true;
                    entry.Property(e => e.Name).IsModified        = true;

                    context.SaveChanges();
                }
            }
        }
コード例 #8
0
        public void AssignSubZoneToAZoneWithoutCapacityTest()
        {
            ZoneDTO zone = new ZoneDTO();

            zone.Name        = "Zona 1";
            zone.MaxCapacity = 60;
            zone.Id          = Guid.NewGuid();

            ZoneDTO subZone = new ZoneDTO();

            subZone.Name        = "SubZona 1";
            subZone.MaxCapacity = 70;
            subZone.Id          = Guid.NewGuid();

            List <ZoneDTO> subZones = new List <ZoneDTO>();

            subZones.Add(subZone);
            zone.SubZones = subZones;

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

            mockZoneDAO.Setup(z => z.FindZoneById(zone.Id)).Returns(zone);
            mockZoneDAO.Setup(z => z.FindZoneById(subZone.Id)).Returns(subZone);
            mockZoneDAO.Setup(z => z.GetZoneCapacityLeft(zone.Id)).Returns(60);
            mockZoneDAO.Setup(z => z.AssignZone(subZone.Id, zone.Id)).Throws(new ZoneOutOfCapacityException());

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

            zoneService.AssignZone(subZone.Id, zone.Id);
        }
コード例 #9
0
ファイル: DropdownController.cs プロジェクト: 4L4M1N/Courier
        public async Task <IActionResult> CreateZone(ZoneDTO zone)
        {
            //Using System.Text.Json
            //var result = JsonSerializer.Deserialize<ItemAttribute>(itemAttribute);

            if (zone == null)
            {
                return(BadRequest("No value please check"));
            }
            var isZoneExists = await _unitOfWork.DeliveryAddress.FindZoneByNameAsync(zone.ZoneName, zone.DivisionId);

            if (isZoneExists != null)
            {
                return(BadRequest("duplicate zone!"));
            }
            else
            {
                var zoneToADD = new Zone
                {
                    DivisionId = zone.DivisionId,
                    Name       = zone.ZoneName
                };
                await _unitOfWork.DeliveryAddress.AddZoneAsync(zoneToADD);
            }
            var result = await _unitOfWork.CompleteAsync();

            if (result == 0)
            {
                return(BadRequest("dont save"));
            }
            return(Ok());
        }
コード例 #10
0
        public void CreateZoneSuccessfullyTest()
        {
            ZoneDTO zone = new ZoneDTO();

            zone.Name        = "Zona 1";
            zone.MaxCapacity = 60;
            zone.Id          = Guid.NewGuid();

            var     mockZoneDAO = new Mock <ZoneDAO>();
            ZoneDTO mockZone    = new ZoneDTO();

            mockZone.Name        = "Zona 1";
            mockZone.MaxCapacity = 60;

            mockZoneDAO.Setup(z => z.FindZoneById(zone.Id)).Returns(mockZone);

            var mockFlowDAO    = new Mock <FlowDAO>();
            var mockVehicleDAO = new Mock <VehicleDAO>();
            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);
        }
コード例 #11
0
        public void AddZone(ZoneDTO zone)
        {
            bool isThereNullFields = this.IsThereNullFields(zone);

            if (isThereNullFields)
            {
                throw new ZoneNullAttributesException("Se debe ingresar el nombre de la zona, y la capacidad debe ser superior a 0");
            }

            if (zone.IsSubZone)
            {
                if (!this.flowDAO.IsStepAvailable(zone.FlowStep))
                {
                    this.zoneDAO.CreateZone(zone);
                }
                else
                {
                    throw new SubZoneWithoutFlowStepException("No se puede crear una subzona que no tiene un paso de flujo valido");
                }
            }
            else
            {
                this.zoneDAO.CreateZone(zone);
            }
        }
コード例 #12
0
        public void AssignZoneSuccessfullyTest()
        {
            ZoneDTO zone = new ZoneDTO();

            zone.Name        = "Zona 1";
            zone.MaxCapacity = 60;
            zone.Id          = Guid.NewGuid();

            ZoneDTO subZone = new ZoneDTO();

            subZone.Name        = "SubZona 1";
            subZone.MaxCapacity = 60;
            subZone.Id          = Guid.NewGuid();

            List <ZoneDTO> subZones = new List <ZoneDTO>();

            subZones.Add(subZone);
            zone.SubZones = subZones;

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

            mockZoneDAO.Setup(z => z.FindZoneById(zone.Id)).Returns(zone);
            mockZoneDAO.Setup(z => z.FindZoneById(subZone.Id)).Returns(subZone);
            mockZoneDAO.Setup(z => z.GetZoneCapacityLeft(zone.Id)).Returns(60);
            mockZoneDAO.Setup(z => z.AssignZone(subZone.Id, zone.Id)).Verifiable();

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

            zoneService.AssignZone(subZone.Id, zone.Id);
        }
コード例 #13
0
 private void delBtn_Click(object sender, EventArgs e)
 {
     if (this.treeZones.SelectedNode != null && ((ZoneDTO)this.treeZones.SelectedNode.Tag) != null)
     {
         try
         {
             ZoneDTO      zoneToDelete = ((ZoneDTO)this.treeZones.SelectedNode.Tag);
             DialogResult dialogResult = MessageBox.Show(
                 "¿Está seguro que desea eliminar la zona: " + zoneToDelete.Id + " ?",
                 "Cuidado",
                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
             if (dialogResult == DialogResult.Yes)
             {
                 this.zoneService.Delete(zoneToDelete.Id);
                 this.init();
             }
         }
         catch (ZoneCannotBeDeletedException ex)
         {
             MessageBox.Show(
                 ex.Message,
                 "Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         if (this.listSubZones.SelectedItems.Count > 0)
         {
             try
             {
                 ZoneDTO      zoneToDelete = ((ZoneDTO)this.listSubZones.SelectedItems[0].Tag);
                 DialogResult dialogResult = MessageBox.Show(
                     "¿Está seguro que desea eliminar la zona: " + zoneToDelete.Id + " ?",
                     "Cuidado",
                     MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (dialogResult == DialogResult.Yes)
                 {
                     this.zoneService.Delete(zoneToDelete.Id);
                     this.init();
                 }
             }
             catch (ZoneCannotBeDeletedException ex)
             {
                 MessageBox.Show(
                     ex.Message,
                     "Error",
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show(
                 "Seleccione una zona o subzona.",
                 "Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #14
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);
        }
コード例 #15
0
 private void RemoveZones(object sender, EventArgs e)
 {
     if (listBoxZones.SelectedItem != null)
     {
         ZoneDTO zone = (ZoneDTO)listBoxZones.SelectedItem;
         Services.ZoneService.RemoveZone(zone.Id);
         UpdateScreen();
     }
 }
コード例 #16
0
        private bool IsThereNullFields(ZoneDTO zone)
        {
            bool isThereNullFields = true;

            isThereNullFields = isThereNullFields && zone.Name == null;
            isThereNullFields = isThereNullFields && zone.MaxCapacity <= 0;

            return(isThereNullFields);
        }
コード例 #17
0
 private void AddView(object sender, EventArgs e)
 {
     if (listBoxZones.SelectedItem != null)
     {
         ZoneDTO zone = (ZoneDTO)listBoxZones.SelectedItem;
         Services.ViewService.AddView(zone.Id, textBoxNewViewName.Text);
         LoadZone();
     }
 }
コード例 #18
0
        private ZoneDTO createZone(string name)
        {
            ZoneDTO zone = new ZoneDTO();

            zone.Name        = name;
            zone.IsSubZone   = false;
            zone.MaxCapacity = 60;

            return(zone);
        }
コード例 #19
0
        private void ChangeZoneName(object sender, EventArgs e)
        {
            if (listBoxZones.SelectedItem != null)
            {
                ZoneDTO zone = (ZoneDTO)listBoxZones.SelectedItem;

                Services.ViewService.SetNameView(zone.MainView.Id, textBoxNameNode.Text);

                UpdateScreen();
            }
        }
コード例 #20
0
        public ZoneDTO FindZoneById(Guid id)
        {
            ZoneDTO zone = this.zoneDAO.FindZoneById(id);

            if (zone == null)
            {
                throw new ZoneNotFoundException("La zona con id: " + id + " no se encuentra ingresada en el sistema");
            }

            return(zone);
        }
コード例 #21
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");
                        }
                    }
                }
            }
        }
コード例 #22
0
 public AssignSubZone(ZoneDTO subZone, List <ZoneDTO> zones, ZoneService zoneService, WindowsObserver observer)
 {
     this.subject = new WindowsSubject();
     this.subject.Attach(observer);
     this.subZoneToAssign = subZone;
     this.zoneService     = zoneService;
     this.zones           = zones;
     InitializeComponent();
     this.assignBtn.FlatStyle = FlatStyle.Flat;
     this.assignBtn.FlatAppearance.BorderSize = 0;
     this.loadZones();
 }
コード例 #23
0
        public void CreateZoneDTO()
        {
            ZoneDTO zone = new ZoneDTO();

            zone.Name        = "Zona 1";
            zone.IsSubZone   = false;
            zone.MaxCapacity = 60;

            List <ZoneDTO> subZones = new List <ZoneDTO>();
            ZoneDTO        subZone  = new ZoneDTO();

            subZone.Name        = "Subzona 1";
            subZone.IsSubZone   = true;
            subZone.MaxCapacity = 30;
            subZone.FlowStep    = new FlowStepDTO("Lavado");
            subZones.Add(subZone);
            zone.SubZones = subZones;

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

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

            zone.Vehicles = vehicles;

            Assert.AreEqual("Zona 1", zone.Name);
            Assert.IsFalse(zone.IsSubZone);
            Assert.AreEqual(60, zone.MaxCapacity);
            Assert.IsNotNull(zone.SubZones);
            Assert.AreEqual("Subzona 1", zone.SubZones.ElementAt(0).Name);
            Assert.IsTrue(zone.SubZones.ElementAt(0).IsSubZone);
            Assert.AreEqual(30, zone.SubZones.ElementAt(0).MaxCapacity);
            Assert.AreEqual("Lavado", zone.SubZones.ElementAt(0).FlowStep.Name);

            Assert.AreEqual("Chevrolet", zone.Vehicles.ElementAt(0).Brand);
            Assert.AreEqual("Onyx", zone.Vehicles.ElementAt(0).Model);
            Assert.AreEqual(2016, zone.Vehicles.ElementAt(0).Year);
            Assert.AreEqual("Gris", zone.Vehicles.ElementAt(0).Color);
            Assert.AreEqual("Auto", zone.Vehicles.ElementAt(0).Type);
            Assert.AreEqual("TEST1234", zone.Vehicles.ElementAt(0).Vin);
            Assert.AreEqual("Puerto", zone.Vehicles.ElementAt(0).CurrentLocation);
            Assert.AreEqual("En puerto", zone.Vehicles.ElementAt(0).Status);
        }
コード例 #24
0
 public ModifyZone(ZoneDTO zoneToModify, WindowsObserver observer, ZoneService zoneService)
 {
     this.zoneToModify = zoneToModify;
     this.subject      = new WindowsSubject();
     this.subject.Attach(observer);
     this.zoneService = zoneService;
     InitializeComponent();
     this.modifyBtn.FlatStyle = FlatStyle.Flat;
     this.modifyBtn.FlatAppearance.BorderSize = 0;
     this.cancelBtn.FlatStyle = FlatStyle.Flat;
     this.cancelBtn.FlatAppearance.BorderSize = 0;
     this.loadInfo();
 }
コード例 #25
0
        public IHttpActionResult Get(string id)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            Guid guidId;

            try
            {
                guidId = Guid.Parse(id);
            }
            catch (FormatException)
            {
                string message = "El id enviado no tiene un formato valido.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
                return(ResponseMessage(response));
            }

            try
            {
                Guid              token             = this.GetToken();
                UserDTO           user              = this.userService.GetUserLoggedIn(token);
                PermissionHandler permissionHandler = new PermissionHandler();
                if (permissionHandler.IsUserAllowedToListZones(user.Role))
                {
                    ZoneDTO zone = this.zoneService.FindZoneById(guidId);
                    response = this.Request.CreateResponse(HttpStatusCode.OK, zone);
                }
                else
                {
                    response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion");
                }
            }
            catch (UserNotExistException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (InvalidOperationException)
            {
                string message = "No se ha enviado header de autenticación.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }
            catch (FormatException)
            {
                string message = "El token enviado no tiene un formato valido.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }

            return(ResponseMessage(response));
        }
コード例 #26
0
        public void PersistZoneTest()
        {
            ZoneDAO zoneDAO     = new ZoneDAOImp();
            ZoneDTO expectedDto = createZone("Zona 1");
            Guid    id          = zoneDAO.CreateZone(expectedDto);

            ZoneDTO resultZone = zoneDAO.FindZoneById(id);

            Assert.AreEqual(expectedDto.Name, resultZone.Name);
            Assert.AreEqual(expectedDto.IsSubZone, resultZone.IsSubZone);
            Assert.AreEqual(expectedDto.MaxCapacity, resultZone.MaxCapacity);
            Assert.AreEqual(expectedDto.SubZones, resultZone.SubZones);
            Assert.AreEqual(expectedDto.Vehicles, resultZone.Vehicles);
            Assert.IsNull(resultZone.SubZones);
            Assert.IsNull(resultZone.Vehicles);
        }
コード例 #27
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");
        }
コード例 #28
0
        private void LoadZone()
        {
            if (listBoxZones.SelectedItem != null)
            {
                ZoneDTO zone = (ZoneDTO)listBoxZones.SelectedItem;
                textBoxNameNode.Text = zone.Name;

                if (zone.MainView.ImageMap.Length != 0)
                {
                    MemoryStream ms = new MemoryStream(Services.ViewService.GetViewImage(zone.MainView.Id));
                    pictureBox.Image = Image.FromStream(ms);
                }

                listBoxViews.Items.Clear();
                listBoxViews.Items.AddRange(Services.ViewService.GetViews(zone.Id).ToArray());
            }
        }
コード例 #29
0
        public IHttpActionResult CreateSubZone(string id, [FromBody] ZoneDTO zone)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                Guid              token             = this.GetToken();
                Guid              mainZoneId        = Guid.Parse(id);
                UserDTO           userLogged        = this.userService.GetUserLoggedIn(token);
                PermissionHandler permissionHandler = new PermissionHandler();
                if (permissionHandler.IsUserAllowedToCreateZones(userLogged.Role))
                {
                    this.zoneService.AddSubZone(mainZoneId, zone);
                    response = this.Request.CreateResponse(HttpStatusCode.Created);
                }
                else
                {
                    response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion");
                }
            }
            catch (ZoneNullAttributesException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (UserNotExistException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (ZoneOutOfCapacityException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (InvalidOperationException)
            {
                string message = "No se ha enviado header de autenticación.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }
            catch (FormatException)
            {
                string message = "El token enviado no tiene un formato valido.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }

            return(ResponseMessage(response));
        }
コード例 #30
0
        public void FindZoneWrongIdTest()
        {
            ZoneDTO zone = new ZoneDTO();

            zone.Name        = "Zona 1";
            zone.MaxCapacity = 60;

            var  mockZoneDAO    = new Mock <ZoneDAO>();
            var  mockFlowDAO    = new Mock <FlowDAO>();
            var  mockVehicleDAO = new Mock <VehicleDAO>();
            Guid newId          = Guid.NewGuid();

            mockZoneDAO.Setup(z => z.FindZoneById(newId)).Throws(new ZoneNotFoundException());

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

            zoneService.FindZoneById(zone.Id);
        }