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 ApiTicketStatuRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiTicketStatuResponseModel> createResult = await client.TicketStatuCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTicketStatuResponseModel getResponse = await client.TicketStatuGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TicketStatuDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTicketStatuResponseModel verifyResponse = await client.TicketStatuGetAsync(2); verifyResponse.Should().BeNull(); }
public void MapModelToBO() { var mapper = new BOLTicketStatuMapper(); ApiTicketStatuRequestModel model = new ApiTicketStatuRequestModel(); model.SetProperties("A"); BOTicketStatu response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiTicketStatuModelMapper(); var model = new ApiTicketStatuResponseModel(); model.SetProperties(1, "A"); ApiTicketStatuRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
private async Task <ApiTicketStatuResponseModel> CreateRecord(ApiClient client) { var model = new ApiTicketStatuRequestModel(); model.SetProperties("B"); CreateResponse <ApiTicketStatuResponseModel> result = await client.TicketStatuCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual BOTicketStatu MapModelToBO( int id, ApiTicketStatuRequestModel model ) { BOTicketStatu boTicketStatu = new BOTicketStatu(); boTicketStatu.SetProperties( id, model.Name); return(boTicketStatu); }
public void CreatePatch() { var mapper = new ApiTicketStatuModelMapper(); var model = new ApiTicketStatuRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiTicketStatuRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTicketStatuRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiTicketStatuRequestModel model) { CreateResponse <ApiTicketStatuResponseModel> result = await this.TicketStatuService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TicketStatus/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiTicketStatuRequestModel> PatchModel(int id, JsonPatchDocument <ApiTicketStatuRequestModel> patch) { var record = await this.TicketStatuService.Get(id); if (record == null) { return(null); } else { ApiTicketStatuRequestModel request = this.TicketStatuModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiTicketStatuResponseModel> > Create( ApiTicketStatuRequestModel model) { CreateResponse <ApiTicketStatuResponseModel> response = new CreateResponse <ApiTicketStatuResponseModel>(await this.TicketStatuModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolTicketStatuMapper.MapModelToBO(default(int), model); var record = await this.TicketStatuRepository.Create(this.DalTicketStatuMapper.MapBOToEF(bo)); response.SetRecord(this.BolTicketStatuMapper.MapBOToModel(this.DalTicketStatuMapper.MapEFToBO(record))); } return(response); }
public virtual async Task <UpdateResponse <ApiTicketStatuResponseModel> > Update( int id, ApiTicketStatuRequestModel model) { var validationResult = await this.TicketStatuModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolTicketStatuMapper.MapModelToBO(id, model); await this.TicketStatuRepository.Update(this.DalTicketStatuMapper.MapBOToEF(bo)); var record = await this.TicketStatuRepository.Get(id); return(new UpdateResponse <ApiTicketStatuResponseModel>(this.BolTicketStatuMapper.MapBOToModel(this.DalTicketStatuMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTicketStatuResponseModel>(validationResult)); } }
public async void Create() { var mock = new ServiceMockFacade <ITicketStatuRepository>(); var model = new ApiTicketStatuRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TicketStatu>())).Returns(Task.FromResult(new TicketStatu())); var service = new TicketStatuService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TicketStatuModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTicketStatuMapperMock, mock.DALMapperMockFactory.DALTicketStatuMapperMock, mock.BOLMapperMockFactory.BOLTicketMapperMock, mock.DALMapperMockFactory.DALTicketMapperMock); CreateResponse <ApiTicketStatuResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TicketStatuModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTicketStatuRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TicketStatu>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITicketStatuRepository>(); var model = new ApiTicketStatuRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TicketStatuService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TicketStatuModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTicketStatuMapperMock, mock.DALMapperMockFactory.DALTicketStatuMapperMock, mock.BOLMapperMockFactory.BOLTicketMapperMock, mock.DALMapperMockFactory.DALTicketMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TicketStatuModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTicketStatuRequestModel model) { ApiTicketStatuRequestModel request = await this.PatchModel(id, this.TicketStatuModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTicketStatuResponseModel> result = await this.TicketStatuService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTicketStatuRequestModel> patch) { ApiTicketStatuResponseModel record = await this.TicketStatuService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTicketStatuRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTicketStatuResponseModel> result = await this.TicketStatuService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiTicketStatuResponseModel> > TicketStatuUpdateAsync(int id, ApiTicketStatuRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/TicketStatus/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiTicketStatuResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTicketStatuRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model, id)); }