public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiLocationRequestModel model)
 {
     this.GpsLatRules();
     this.GpsLongRules();
     this.LocationNameRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #2
0
 public async Task <ValidationResult> ValidateUpdateAsync(short id, ApiLocationRequestModel model)
 {
     this.AvailabilityRules();
     this.CostRateRules();
     this.ModifiedDateRules();
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #3
0
        private async Task <ApiLocationResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiLocationRequestModel();

            model.SetProperties(2, 2, "B");
            CreateResponse <ApiLocationResponseModel> result = await client.LocationCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #4
0
        private async Task <ApiLocationResponseModel> CreateRecord()
        {
            var model = new ApiLocationRequestModel();

            model.SetProperties(2, 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), "B");
            CreateResponse <ApiLocationResponseModel> result = await this.Client.LocationCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #5
0
        public void MapModelToBO()
        {
            var mapper = new BOLLocationMapper();
            ApiLocationRequestModel model = new ApiLocationRequestModel();

            model.SetProperties(1, 1, "A");
            BOLocation response = mapper.MapModelToBO(1, model);

            response.GpsLat.Should().Be(1);
            response.GpsLong.Should().Be(1);
            response.LocationName.Should().Be("A");
        }
Beispiel #6
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiLocationModelMapper();
            var model  = new ApiLocationResponseModel();

            model.SetProperties(1, 1, 1, "A");
            ApiLocationRequestModel response = mapper.MapResponseToRequest(model);

            response.GpsLat.Should().Be(1);
            response.GpsLong.Should().Be(1);
            response.LocationName.Should().Be("A");
        }
Beispiel #7
0
        public virtual async Task <IActionResult> Create([FromBody] ApiLocationRequestModel model)
        {
            CreateResponse <ApiLocationResponseModel> result = await this.LocationService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Locations/{result.Record.LocationID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Beispiel #8
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiLocationModelMapper();
            var model  = new ApiLocationResponseModel();

            model.SetProperties(1, 1, 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            ApiLocationRequestModel response = mapper.MapResponseToRequest(model);

            response.Availability.Should().Be(1);
            response.CostRate.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
        }
Beispiel #9
0
        public virtual BOLocation MapModelToBO(
            int locationId,
            ApiLocationRequestModel model
            )
        {
            BOLocation boLocation = new BOLocation();

            boLocation.SetProperties(
                locationId,
                model.GpsLat,
                model.GpsLong,
                model.LocationName);
            return(boLocation);
        }
Beispiel #10
0
        private async Task <ApiLocationRequestModel> PatchModel(short id, JsonPatchDocument <ApiLocationRequestModel> patch)
        {
            var record = await this.LocationService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiLocationRequestModel request = this.LocationModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiLocationResponseModel> > Create(
            ApiLocationRequestModel model)
        {
            CreateResponse <ApiLocationResponseModel> response = new CreateResponse <ApiLocationResponseModel>(await this.LocationModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolLocationMapper.MapModelToBO(default(int), model);
                var record = await this.LocationRepository.Create(this.DalLocationMapper.MapBOToEF(bo));

                response.SetRecord(this.BolLocationMapper.MapBOToModel(this.DalLocationMapper.MapEFToBO(record)));
            }

            return(response);
        }
Beispiel #12
0
        public void CreatePatch()
        {
            var mapper = new ApiLocationModelMapper();
            var model  = new ApiLocationRequestModel();

            model.SetProperties(1, 1, "A");

            JsonPatchDocument <ApiLocationRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiLocationRequestModel();

            patch.ApplyTo(response);
            response.GpsLat.Should().Be(1);
            response.GpsLong.Should().Be(1);
            response.LocationName.Should().Be("A");
        }
Beispiel #13
0
        public virtual BOLocation MapModelToBO(
            short locationID,
            ApiLocationRequestModel model
            )
        {
            BOLocation boLocation = new BOLocation();

            boLocation.SetProperties(
                locationID,
                model.Availability,
                model.CostRate,
                model.ModifiedDate,
                model.Name);
            return(boLocation);
        }
Beispiel #14
0
        public void CreatePatch()
        {
            var mapper = new ApiLocationModelMapper();
            var model  = new ApiLocationRequestModel();

            model.SetProperties(1, 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

            JsonPatchDocument <ApiLocationRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiLocationRequestModel();

            patch.ApplyTo(response);
            response.Availability.Should().Be(1);
            response.CostRate.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
        }
        public virtual async Task <UpdateResponse <ApiLocationResponseModel> > Update(
            int locationId,
            ApiLocationRequestModel model)
        {
            var validationResult = await this.LocationModelValidator.ValidateUpdateAsync(locationId, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolLocationMapper.MapModelToBO(locationId, model);
                await this.LocationRepository.Update(this.DalLocationMapper.MapBOToEF(bo));

                var record = await this.LocationRepository.Get(locationId);

                return(new UpdateResponse <ApiLocationResponseModel>(this.BolLocationMapper.MapBOToModel(this.DalLocationMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiLocationResponseModel>(validationResult));
            }
        }
Beispiel #16
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ILocationRepository>();
            var model = new ApiLocationRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLLocationMapperMock,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.BOLMapperMockFactory.BOLTweetMapperMock,
                                              mock.DALMapperMockFactory.DALTweetMapperMock,
                                              mock.BOLMapperMockFactory.BOLUserMapperMock,
                                              mock.DALMapperMockFactory.DALUserMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.LocationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #17
0
        public virtual async Task <IActionResult> Update(short id, [FromBody] ApiLocationRequestModel model)
        {
            ApiLocationRequestModel request = await this.PatchModel(id, this.LocationModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiLocationResponseModel> result = await this.LocationService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #18
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ILocationRepository>();
            var model = new ApiLocationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Location>())).Returns(Task.FromResult(new Location()));
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLLocationMapperMock,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.BOLMapperMockFactory.BOLTweetMapperMock,
                                              mock.DALMapperMockFactory.DALTweetMapperMock,
                                              mock.BOLMapperMockFactory.BOLUserMapperMock,
                                              mock.DALMapperMockFactory.DALUserMapperMock);

            CreateResponse <ApiLocationResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LocationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLocationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Location>()));
        }
        public async void Update()
        {
            var mock  = new ServiceMockFacade <ILocationRepository>();
            var model = new ApiLocationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Location>())).Returns(Task.FromResult(new Location()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <short>())).Returns(Task.FromResult(new Location()));
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLLocationMapperMock,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.BOLMapperMockFactory.BOLProductInventoryMapperMock,
                                              mock.DALMapperMockFactory.DALProductInventoryMapperMock,
                                              mock.BOLMapperMockFactory.BOLWorkOrderRoutingMapperMock,
                                              mock.DALMapperMockFactory.DALWorkOrderRoutingMapperMock);

            UpdateResponse <ApiLocationResponseModel> response = await service.Update(default(short), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LocationModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <short>(), It.IsAny <ApiLocationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Location>()));
        }
Beispiel #20
0
        public virtual async Task <IActionResult> Patch(short id, [FromBody] JsonPatchDocument <ApiLocationRequestModel> patch)
        {
            ApiLocationResponseModel record = await this.LocationService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiLocationRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiLocationResponseModel> result = await this.LocationService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #21
0
        public virtual async Task <UpdateResponse <ApiLocationResponseModel> > LocationUpdateAsync(int id, ApiLocationRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Locations/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiLocationResponseModel> >(httpResponse.Content.ContentToString()));
        }