예제 #1
0
        private async Task <ApiAccountResponseModel> CreateRecord()
        {
            var model = new ApiAccountRequestModel();

            model.SetProperties("B", "B", "B", "B", "B", "B");
            CreateResponse <ApiAccountResponseModel> result = await this.Client.AccountCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
예제 #2
0
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiAccountRequestModel model)
 {
     this.AccountTypeRules();
     this.EnvironmentIdsRules();
     this.JSONRules();
     this.NameRules();
     this.TenantIdsRules();
     this.TenantTagsRules();
     return(await this.ValidateAsync(model, id));
 }
        public virtual async Task <IActionResult> Create([FromBody] ApiAccountRequestModel model)
        {
            CreateResponse <ApiAccountResponseModel> result = await this.AccountService.Create(model);

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

            if (response.Success)
            {
                var bo     = this.bolAccountMapper.MapModelToBO(default(string), model);
                var record = await this.accountRepository.Create(this.dalAccountMapper.MapBOToEF(bo));

                response.SetRecord(this.bolAccountMapper.MapBOToModel(this.dalAccountMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiAccountRequestModel> PatchModel(string id, JsonPatchDocument <ApiAccountRequestModel> patch)
        {
            var record = await this.AccountService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiAccountRequestModel request = this.AccountModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
예제 #6
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiAccountModelMapper();
            var model  = new ApiAccountResponseModel();

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

            response.AccountType.Should().Be("A");
            response.EnvironmentIds.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.TenantIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
예제 #7
0
        public void MapModelToBO()
        {
            var mapper = new BOLAccountMapper();
            ApiAccountRequestModel model = new ApiAccountRequestModel();

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

            response.AccountType.Should().Be("A");
            response.EnvironmentIds.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.TenantIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
예제 #8
0
        public virtual BOAccount MapModelToBO(
            string id,
            ApiAccountRequestModel model
            )
        {
            BOAccount boAccount = new BOAccount();

            boAccount.SetProperties(
                id,
                model.AccountType,
                model.EnvironmentIds,
                model.JSON,
                model.Name,
                model.TenantIds,
                model.TenantTags);
            return(boAccount);
        }
예제 #9
0
        public void CreatePatch()
        {
            var mapper = new ApiAccountModelMapper();
            var model  = new ApiAccountRequestModel();

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

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

            patch.ApplyTo(response);
            response.AccountType.Should().Be("A");
            response.EnvironmentIds.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.TenantIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
예제 #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IAccountRepository>();
            var model = new ApiAccountRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Account>())).Returns(Task.FromResult(new Account()));
            var service = new AccountService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.AccountModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLAccountMapperMock,
                                             mock.DALMapperMockFactory.DALAccountMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.AccountModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiAccountRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Account>()));
        }
예제 #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IAccountRepository>();
            var model = new ApiAccountRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new AccountService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.AccountModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLAccountMapperMock,
                                             mock.DALMapperMockFactory.DALAccountMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.bolAccountMapper.MapModelToBO(id, model);
                await this.accountRepository.Update(this.dalAccountMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiAccountResponseModel>(this.bolAccountMapper.MapBOToModel(this.dalAccountMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiAccountResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiAccountRequestModel model)
        {
            ApiAccountRequestModel request = await this.PatchModel(id, this.AccountModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiAccountRequestModel> patch)
        {
            ApiAccountResponseModel record = await this.AccountService.Get(id);

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

                UpdateResponse <ApiAccountResponseModel> result = await this.AccountService.Update(id, model);

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