private async Task <ApiKeyAllocationResponseModel> CreateRecord()
        {
            var model = new ApiKeyAllocationRequestModel();

            model.SetProperties(2);
            CreateResponse <ApiKeyAllocationResponseModel> result = await this.Client.KeyAllocationCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Exemplo n.º 2
0
        public void MapModelToBO()
        {
            var mapper = new BOLKeyAllocationMapper();
            ApiKeyAllocationRequestModel model = new ApiKeyAllocationRequestModel();

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

            response.Allocated.Should().Be(1);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiKeyAllocationModelMapper();
            var model  = new ApiKeyAllocationResponseModel();

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

            response.Allocated.Should().Be(1);
        }
Exemplo n.º 4
0
        public virtual BOKeyAllocation MapModelToBO(
            string collectionName,
            ApiKeyAllocationRequestModel model
            )
        {
            BOKeyAllocation boKeyAllocation = new BOKeyAllocation();

            boKeyAllocation.SetProperties(
                collectionName,
                model.Allocated);
            return(boKeyAllocation);
        }
Exemplo n.º 5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiKeyAllocationRequestModel model)
        {
            CreateResponse <ApiKeyAllocationResponseModel> result = await this.KeyAllocationService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/KeyAllocations/{result.Record.CollectionName}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiKeyAllocationModelMapper();
            var model  = new ApiKeyAllocationRequestModel();

            model.SetProperties(1);

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

            patch.ApplyTo(response);
            response.Allocated.Should().Be(1);
        }
        public virtual async Task <CreateResponse <ApiKeyAllocationResponseModel> > Create(
            ApiKeyAllocationRequestModel model)
        {
            CreateResponse <ApiKeyAllocationResponseModel> response = new CreateResponse <ApiKeyAllocationResponseModel>(await this.keyAllocationModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolKeyAllocationMapper.MapModelToBO(default(string), model);
                var record = await this.keyAllocationRepository.Create(this.dalKeyAllocationMapper.MapBOToEF(bo));

                response.SetRecord(this.bolKeyAllocationMapper.MapBOToModel(this.dalKeyAllocationMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemplo n.º 8
0
        private async Task <ApiKeyAllocationRequestModel> PatchModel(string id, JsonPatchDocument <ApiKeyAllocationRequestModel> patch)
        {
            var record = await this.KeyAllocationService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiKeyAllocationRequestModel request = this.KeyAllocationModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Exemplo n.º 9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IKeyAllocationRepository>();
            var model = new ApiKeyAllocationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <KeyAllocation>())).Returns(Task.FromResult(new KeyAllocation()));
            var service = new KeyAllocationService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.KeyAllocationModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLKeyAllocationMapperMock,
                                                   mock.DALMapperMockFactory.DALKeyAllocationMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.KeyAllocationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiKeyAllocationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <KeyAllocation>()));
        }
Exemplo n.º 10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IKeyAllocationRepository>();
            var model = new ApiKeyAllocationRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new KeyAllocationService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.KeyAllocationModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLKeyAllocationMapperMock,
                                                   mock.DALMapperMockFactory.DALKeyAllocationMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.KeyAllocationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
        public virtual async Task <UpdateResponse <ApiKeyAllocationResponseModel> > Update(
            string collectionName,
            ApiKeyAllocationRequestModel model)
        {
            var validationResult = await this.keyAllocationModelValidator.ValidateUpdateAsync(collectionName, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolKeyAllocationMapper.MapModelToBO(collectionName, model);
                await this.keyAllocationRepository.Update(this.dalKeyAllocationMapper.MapBOToEF(bo));

                var record = await this.keyAllocationRepository.Get(collectionName);

                return(new UpdateResponse <ApiKeyAllocationResponseModel>(this.bolKeyAllocationMapper.MapBOToModel(this.dalKeyAllocationMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiKeyAllocationResponseModel>(validationResult));
            }
        }
Exemplo n.º 12
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiKeyAllocationRequestModel model)
        {
            ApiKeyAllocationRequestModel request = await this.PatchModel(id, this.KeyAllocationModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 13
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiKeyAllocationRequestModel> patch)
        {
            ApiKeyAllocationResponseModel record = await this.KeyAllocationService.Get(id);

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

                UpdateResponse <ApiKeyAllocationResponseModel> result = await this.KeyAllocationService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiKeyAllocationRequestModel model)
 {
     this.AllocatedRules();
     return(await this.ValidateAsync(model, id));
 }
 public async Task <ValidationResult> ValidateCreateAsync(ApiKeyAllocationRequestModel model)
 {
     this.AllocatedRules();
     return(await this.ValidateAsync(model));
 }