public virtual ApiUnitOfficerServerResponseModel MapEntityToModel( UnitOfficer item) { var model = new ApiUnitOfficerServerResponseModel(); model.SetProperties(item.Id, item.OfficerId, item.UnitId); 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.UnitIdNavigation != null) { var unitIdModel = new ApiUnitServerResponseModel(); unitIdModel.SetProperties( item.UnitIdNavigation.Id, item.UnitIdNavigation.CallSign); model.SetUnitIdNavigation(unitIdModel); } return(model); }
public void MapModelToEntity() { var mapper = new DALUnitOfficerMapper(); ApiUnitOfficerServerRequestModel model = new ApiUnitOfficerServerRequestModel(); model.SetProperties(1, 1); UnitOfficer response = mapper.MapModelToEntity(1, model); response.OfficerId.Should().Be(1); response.UnitId.Should().Be(1); }
public void MapEntityToModel() { var mapper = new DALUnitOfficerMapper(); UnitOfficer item = new UnitOfficer(); item.SetProperties(1, 1, 1); ApiUnitOfficerServerResponseModel response = mapper.MapEntityToModel(item); response.Id.Should().Be(1); response.OfficerId.Should().Be(1); response.UnitId.Should().Be(1); }
public virtual UnitOfficer MapModelToEntity( int id, ApiUnitOfficerServerRequestModel model ) { UnitOfficer item = new UnitOfficer(); item.SetProperties( id, model.OfficerId, model.UnitId); return(item); }
public virtual async Task <ApiUnitOfficerServerResponseModel> Get(int id) { UnitOfficer record = await this.UnitOfficerRepository.Get(id); if (record == null) { return(null); } else { return(this.DalUnitOfficerMapper.MapEntityToModel(record)); } }
public void MapEntityToModelList() { var mapper = new DALUnitOfficerMapper(); UnitOfficer item = new UnitOfficer(); item.SetProperties(1, 1, 1); List <ApiUnitOfficerServerResponseModel> response = mapper.MapEntityToModel(new List <UnitOfficer>() { { item } }); response.Count.Should().Be(1); }
public virtual async Task <CreateResponse <ApiUnitOfficerServerResponseModel> > Create( ApiUnitOfficerServerRequestModel model) { CreateResponse <ApiUnitOfficerServerResponseModel> response = ValidationResponseFactory <ApiUnitOfficerServerResponseModel> .CreateResponse(await this.UnitOfficerModelValidator.ValidateCreateAsync(model)); if (response.Success) { UnitOfficer record = this.DalUnitOfficerMapper.MapModelToEntity(default(int), model); record = await this.UnitOfficerRepository.Create(record); response.SetRecord(this.DalUnitOfficerMapper.MapEntityToModel(record)); await this.mediator.Publish(new UnitOfficerCreatedNotification(response.Record)); } return(response); }
public async void Get_ShouldReturnRecords() { var mock = new ServiceMockFacade <IUnitOfficerService, IUnitOfficerRepository>(); var record = new UnitOfficer(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new UnitOfficerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.UnitOfficerModelValidatorMock.Object, mock.DALMapperMockFactory.DALUnitOfficerMapperMock); ApiUnitOfficerServerResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiUnitOfficerServerResponseModel> > Update( int id, ApiUnitOfficerServerRequestModel model) { var validationResult = await this.UnitOfficerModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { UnitOfficer record = this.DalUnitOfficerMapper.MapModelToEntity(id, model); await this.UnitOfficerRepository.Update(record); record = await this.UnitOfficerRepository.Get(id); ApiUnitOfficerServerResponseModel apiModel = this.DalUnitOfficerMapper.MapEntityToModel(record); await this.mediator.Publish(new UnitOfficerUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiUnitOfficerServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiUnitOfficerServerResponseModel> .UpdateResponse(validationResult)); } }