public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiApiKeyRequestModel model)
 {
     this.ApiKeyHashedRules();
     this.CreatedRules();
     this.JSONRules();
     this.UserIdRules();
     return(await this.ValidateAsync(model, id));
 }
예제 #2
0
        private async Task <ApiApiKeyResponseModel> CreateRecord()
        {
            var model = new ApiApiKeyRequestModel();

            model.SetProperties("B", DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), "B", "B");
            CreateResponse <ApiApiKeyResponseModel> result = await this.Client.ApiKeyCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
예제 #3
0
        public void MapModelToBO()
        {
            var mapper = new BOLApiKeyMapper();
            ApiApiKeyRequestModel model = new ApiApiKeyRequestModel();

            model.SetProperties("A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A");
            BOApiKey response = mapper.MapModelToBO("A", model);

            response.ApiKeyHashed.Should().Be("A");
            response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.JSON.Should().Be("A");
            response.UserId.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiApiKeyRequestModel model)
        {
            CreateResponse <ApiApiKeyResponseModel> result = await this.ApiKeyService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ApiKeys/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
예제 #5
0
        public virtual async Task <CreateResponse <ApiApiKeyResponseModel> > Create(
            ApiApiKeyRequestModel model)
        {
            CreateResponse <ApiApiKeyResponseModel> response = new CreateResponse <ApiApiKeyResponseModel>(await this.apiKeyModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolApiKeyMapper.MapModelToBO(default(string), model);
                var record = await this.apiKeyRepository.Create(this.dalApiKeyMapper.MapBOToEF(bo));

                response.SetRecord(this.bolApiKeyMapper.MapBOToModel(this.dalApiKeyMapper.MapEFToBO(record)));
            }

            return(response);
        }
예제 #6
0
        public virtual BOApiKey MapModelToBO(
            string id,
            ApiApiKeyRequestModel model
            )
        {
            BOApiKey boApiKey = new BOApiKey();

            boApiKey.SetProperties(
                id,
                model.ApiKeyHashed,
                model.Created,
                model.JSON,
                model.UserId);
            return(boApiKey);
        }
        private async Task <ApiApiKeyRequestModel> PatchModel(string id, JsonPatchDocument <ApiApiKeyRequestModel> patch)
        {
            var record = await this.ApiKeyService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiApiKeyRequestModel request = this.ApiKeyModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
예제 #8
0
        public void CreatePatch()
        {
            var mapper = new ApiApiKeyModelMapper();
            var model  = new ApiApiKeyRequestModel();

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

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

            patch.ApplyTo(response);
            response.ApiKeyHashed.Should().Be("A");
            response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.JSON.Should().Be("A");
            response.UserId.Should().Be("A");
        }
예제 #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IApiKeyRepository>();
            var model = new ApiApiKeyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ApiKey>())).Returns(Task.FromResult(new ApiKey()));
            var service = new ApiKeyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLApiKeyMapperMock,
                                            mock.DALMapperMockFactory.DALApiKeyMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiApiKeyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ApiKey>()));
        }
예제 #10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IApiKeyRepository>();
            var model = new ApiApiKeyRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ApiKeyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLApiKeyMapperMock,
                                            mock.DALMapperMockFactory.DALApiKeyMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
예제 #11
0
        public virtual async Task <UpdateResponse <ApiApiKeyResponseModel> > Update(
            string id,
            ApiApiKeyRequestModel model)
        {
            var validationResult = await this.apiKeyModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolApiKeyMapper.MapModelToBO(id, model);
                await this.apiKeyRepository.Update(this.dalApiKeyMapper.MapBOToEF(bo));

                var record = await this.apiKeyRepository.Get(id);

                return(new UpdateResponse <ApiApiKeyResponseModel>(this.bolApiKeyMapper.MapBOToModel(this.dalApiKeyMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiApiKeyResponseModel>(validationResult));
            }
        }
예제 #12
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiApiKeyRequestModel model)
        {
            ApiApiKeyRequestModel request = await this.PatchModel(id, this.ApiKeyModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
예제 #13
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiApiKeyRequestModel> patch)
        {
            ApiApiKeyResponseModel record = await this.ApiKeyService.Get(id);

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

                UpdateResponse <ApiApiKeyResponseModel> result = await this.ApiKeyService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }