public virtual ApiUnitDispositionServerResponseModel MapEntityToModel(
            UnitDisposition item)
        {
            var model = new ApiUnitDispositionServerResponseModel();

            model.SetProperties(item.Id,
                                item.Name);

            return(model);
        }
Пример #2
0
        public void MapModelToEntity()
        {
            var mapper = new DALUnitDispositionMapper();
            ApiUnitDispositionServerRequestModel model = new ApiUnitDispositionServerRequestModel();

            model.SetProperties("A");
            UnitDisposition response = mapper.MapModelToEntity(1, model);

            response.Name.Should().Be("A");
        }
Пример #3
0
        public void MapEntityToModel()
        {
            var             mapper = new DALUnitDispositionMapper();
            UnitDisposition item   = new UnitDisposition();

            item.SetProperties(1, "A");
            ApiUnitDispositionServerResponseModel response = mapper.MapEntityToModel(item);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
        }
        public virtual UnitDisposition MapModelToEntity(
            int id,
            ApiUnitDispositionServerRequestModel model
            )
        {
            UnitDisposition item = new UnitDisposition();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
Пример #5
0
        public void MapEntityToModelList()
        {
            var             mapper = new DALUnitDispositionMapper();
            UnitDisposition item   = new UnitDisposition();

            item.SetProperties(1, "A");
            List <ApiUnitDispositionServerResponseModel> response = mapper.MapEntityToModel(new List <UnitDisposition>()
            {
                { item }
            });

            response.Count.Should().Be(1);
        }
Пример #6
0
        public virtual async Task <ApiUnitDispositionServerResponseModel> Get(int id)
        {
            UnitDisposition record = await this.UnitDispositionRepository.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.DalUnitDispositionMapper.MapEntityToModel(record));
            }
        }
Пример #7
0
        public virtual async Task <CreateResponse <ApiUnitDispositionServerResponseModel> > Create(
            ApiUnitDispositionServerRequestModel model)
        {
            CreateResponse <ApiUnitDispositionServerResponseModel> response = ValidationResponseFactory <ApiUnitDispositionServerResponseModel> .CreateResponse(await this.UnitDispositionModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                UnitDisposition record = this.DalUnitDispositionMapper.MapModelToEntity(default(int), model);
                record = await this.UnitDispositionRepository.Create(record);

                response.SetRecord(this.DalUnitDispositionMapper.MapEntityToModel(record));
                await this.mediator.Publish(new UnitDispositionCreatedNotification(response.Record));
            }

            return(response);
        }
Пример #8
0
        public async void Get_ShouldReturnRecords()
        {
            var mock   = new ServiceMockFacade <IUnitDispositionService, IUnitDispositionRepository>();
            var record = new UnitDisposition();

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

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #9
0
        public virtual async Task <UpdateResponse <ApiUnitDispositionServerResponseModel> > Update(
            int id,
            ApiUnitDispositionServerRequestModel model)
        {
            var validationResult = await this.UnitDispositionModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                UnitDisposition record = this.DalUnitDispositionMapper.MapModelToEntity(id, model);
                await this.UnitDispositionRepository.Update(record);

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

                ApiUnitDispositionServerResponseModel apiModel = this.DalUnitDispositionMapper.MapEntityToModel(record);
                await this.mediator.Publish(new UnitDispositionUpdatedNotification(apiModel));

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