Ejemplo n.º 1
0
        public virtual ApiVehicleOfficerServerResponseModel MapEntityToModel(
            VehicleOfficer item)
        {
            var model = new ApiVehicleOfficerServerResponseModel();

            model.SetProperties(item.Id,
                                item.OfficerId,
                                item.VehicleId);
            if (item.OfficerIdNavigation != null)
            {
                var officerIdModel = new ApiOfficerServerResponseModel();
                officerIdModel.SetProperties(
                    item.OfficerIdNavigation.Id,
                    item.OfficerIdNavigation.Badge,
                    item.OfficerIdNavigation.Email,
                    item.OfficerIdNavigation.FirstName,
                    item.OfficerIdNavigation.LastName,
                    item.OfficerIdNavigation.Password);

                model.SetOfficerIdNavigation(officerIdModel);
            }

            if (item.VehicleIdNavigation != null)
            {
                var vehicleIdModel = new ApiVehicleServerResponseModel();
                vehicleIdModel.SetProperties(
                    item.VehicleIdNavigation.Id,
                    item.VehicleIdNavigation.Name);

                model.SetVehicleIdNavigation(vehicleIdModel);
            }

            return(model);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALVehicleOfficerMapper();
            ApiVehicleOfficerServerRequestModel model = new ApiVehicleOfficerServerRequestModel();

            model.SetProperties(1, 1);
            VehicleOfficer response = mapper.MapModelToEntity(1, model);

            response.OfficerId.Should().Be(1);
            response.VehicleId.Should().Be(1);
        }
        public void MapEntityToModel()
        {
            var            mapper = new DALVehicleOfficerMapper();
            VehicleOfficer item   = new VehicleOfficer();

            item.SetProperties(1, 1, 1);
            ApiVehicleOfficerServerResponseModel response = mapper.MapEntityToModel(item);

            response.Id.Should().Be(1);
            response.OfficerId.Should().Be(1);
            response.VehicleId.Should().Be(1);
        }
Ejemplo n.º 4
0
        public virtual async Task <ApiVehicleOfficerServerResponseModel> Get(int id)
        {
            VehicleOfficer record = await this.VehicleOfficerRepository.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.DalVehicleOfficerMapper.MapEntityToModel(record));
            }
        }
Ejemplo n.º 5
0
        public virtual VehicleOfficer MapModelToEntity(
            int id,
            ApiVehicleOfficerServerRequestModel model
            )
        {
            VehicleOfficer item = new VehicleOfficer();

            item.SetProperties(
                id,
                model.OfficerId,
                model.VehicleId);
            return(item);
        }
        public void MapEntityToModelList()
        {
            var            mapper = new DALVehicleOfficerMapper();
            VehicleOfficer item   = new VehicleOfficer();

            item.SetProperties(1, 1, 1);
            List <ApiVehicleOfficerServerResponseModel> response = mapper.MapEntityToModel(new List <VehicleOfficer>()
            {
                { item }
            });

            response.Count.Should().Be(1);
        }
Ejemplo n.º 7
0
        public virtual async Task <CreateResponse <ApiVehicleOfficerServerResponseModel> > Create(
            ApiVehicleOfficerServerRequestModel model)
        {
            CreateResponse <ApiVehicleOfficerServerResponseModel> response = ValidationResponseFactory <ApiVehicleOfficerServerResponseModel> .CreateResponse(await this.VehicleOfficerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                VehicleOfficer record = this.DalVehicleOfficerMapper.MapModelToEntity(default(int), model);
                record = await this.VehicleOfficerRepository.Create(record);

                response.SetRecord(this.DalVehicleOfficerMapper.MapEntityToModel(record));
                await this.mediator.Publish(new VehicleOfficerCreatedNotification(response.Record));
            }

            return(response);
        }
        public async void Get_ShouldReturnRecords()
        {
            var mock   = new ServiceMockFacade <IVehicleOfficerService, IVehicleOfficerRepository>();
            var record = new VehicleOfficer();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new VehicleOfficerService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.VehicleOfficerModelValidatorMock.Object,
                                                    mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

            ApiVehicleOfficerServerResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 9
0
        public virtual async Task <UpdateResponse <ApiVehicleOfficerServerResponseModel> > Update(
            int id,
            ApiVehicleOfficerServerRequestModel model)
        {
            var validationResult = await this.VehicleOfficerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                VehicleOfficer record = this.DalVehicleOfficerMapper.MapModelToEntity(id, model);
                await this.VehicleOfficerRepository.Update(record);

                record = await this.VehicleOfficerRepository.Get(id);

                ApiVehicleOfficerServerResponseModel apiModel = this.DalVehicleOfficerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new VehicleOfficerUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiVehicleOfficerServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiVehicleOfficerServerResponseModel> .UpdateResponse(validationResult));
            }
        }