Пример #1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiEventStatusRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiEventStatusResponseModel> createResult = await client.EventStatusCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiEventStatusResponseModel getResponse = await client.EventStatusGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.EventStatusDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiEventStatusResponseModel verifyResponse = await client.EventStatusGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Пример #2
0
        public void MapModelToBO()
        {
            var mapper = new BOLEventStatusMapper();
            ApiEventStatusRequestModel model = new ApiEventStatusRequestModel();

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

            response.Name.Should().Be("A");
        }
Пример #3
0
        private async Task <ApiEventStatusResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiEventStatusRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiEventStatusResponseModel> result = await client.EventStatusCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiEventStatusModelMapper();
            var model  = new ApiEventStatusResponseModel();

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

            response.Name.Should().Be("A");
        }
Пример #5
0
        public virtual BOEventStatus MapModelToBO(
            int id,
            ApiEventStatusRequestModel model
            )
        {
            BOEventStatus boEventStatus = new BOEventStatus();

            boEventStatus.SetProperties(
                id,
                model.Name);
            return(boEventStatus);
        }
Пример #6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiEventStatusRequestModel model)
        {
            CreateResponse <ApiEventStatusResponseModel> result = await this.EventStatusService.Create(model);

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

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
Пример #8
0
        private async Task <ApiEventStatusRequestModel> PatchModel(int id, JsonPatchDocument <ApiEventStatusRequestModel> patch)
        {
            var record = await this.EventStatusService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiEventStatusRequestModel request = this.EventStatusModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Пример #9
0
        public virtual async Task <CreateResponse <ApiEventStatusResponseModel> > Create(
            ApiEventStatusRequestModel model)
        {
            CreateResponse <ApiEventStatusResponseModel> response = new CreateResponse <ApiEventStatusResponseModel>(await this.EventStatusModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolEventStatusMapper.MapModelToBO(default(int), model);
                var record = await this.EventStatusRepository.Create(this.DalEventStatusMapper.MapBOToEF(bo));

                response.SetRecord(this.BolEventStatusMapper.MapBOToModel(this.DalEventStatusMapper.MapEFToBO(record)));
            }

            return(response);
        }
Пример #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IEventStatusRepository>();
            var model = new ApiEventStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <EventStatus>())).Returns(Task.FromResult(new EventStatus()));
            var service = new EventStatusService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLEventStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALEventStatusMapperMock,
                                                 mock.BOLMapperMockFactory.BOLEventMapperMock,
                                                 mock.DALMapperMockFactory.DALEventMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiEventStatusRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <EventStatus>()));
        }
Пример #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IEventStatusRepository>();
            var model = new ApiEventStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new EventStatusService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLEventStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALEventStatusMapperMock,
                                                 mock.BOLMapperMockFactory.BOLEventMapperMock,
                                                 mock.DALMapperMockFactory.DALEventMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Пример #12
0
        public virtual async Task <UpdateResponse <ApiEventStatusResponseModel> > Update(
            int id,
            ApiEventStatusRequestModel model)
        {
            var validationResult = await this.EventStatusModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolEventStatusMapper.MapModelToBO(id, model);
                await this.EventStatusRepository.Update(this.DalEventStatusMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiEventStatusResponseModel>(this.BolEventStatusMapper.MapBOToModel(this.DalEventStatusMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiEventStatusResponseModel>(validationResult));
            }
        }
Пример #13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiEventStatusRequestModel model)
        {
            ApiEventStatusRequestModel request = await this.PatchModel(id, this.EventStatusModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiEventStatusRequestModel> patch)
        {
            ApiEventStatusResponseModel record = await this.EventStatusService.Get(id);

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

                UpdateResponse <ApiEventStatusResponseModel> result = await this.EventStatusService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #15
0
        public virtual async Task <UpdateResponse <ApiEventStatusResponseModel> > EventStatusUpdateAsync(int id, ApiEventStatusRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/EventStatuses/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiEventStatusResponseModel> >(httpResponse.Content.ContentToString()));
        }
Пример #16
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiEventStatusRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }