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 ApiTicketRequestModel(); createModel.SetProperties("B", 1); CreateResponse <ApiTicketResponseModel> createResult = await client.TicketCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTicketResponseModel getResponse = await client.TicketGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TicketDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTicketResponseModel verifyResponse = await client.TicketGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiTicketResponseModel> CreateRecord() { var model = new ApiTicketRequestModel(); model.SetProperties("B", 1); CreateResponse <ApiTicketResponseModel> result = await this.Client.TicketCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLTicketMapper(); ApiTicketRequestModel model = new ApiTicketRequestModel(); model.SetProperties("A", 1); BOTicket response = mapper.MapModelToBO(1, model); response.PublicId.Should().Be("A"); response.TicketStatusId.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiTicketModelMapper(); var model = new ApiTicketResponseModel(); model.SetProperties(1, "A", 1); ApiTicketRequestModel response = mapper.MapResponseToRequest(model); response.PublicId.Should().Be("A"); response.TicketStatusId.Should().Be(1); }
public virtual BOTicket MapModelToBO( int id, ApiTicketRequestModel model ) { BOTicket boTicket = new BOTicket(); boTicket.SetProperties( id, model.PublicId, model.TicketStatusId); return(boTicket); }
public virtual async Task <IActionResult> Create([FromBody] ApiTicketRequestModel model) { CreateResponse <ApiTicketResponseModel> result = await this.TicketService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Tickets/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiTicketModelMapper(); var model = new ApiTicketRequestModel(); model.SetProperties("A", 1); JsonPatchDocument <ApiTicketRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTicketRequestModel(); patch.ApplyTo(response); response.PublicId.Should().Be("A"); response.TicketStatusId.Should().Be(1); }
private async Task <ApiTicketRequestModel> PatchModel(int id, JsonPatchDocument <ApiTicketRequestModel> patch) { var record = await this.TicketService.Get(id); if (record == null) { return(null); } else { ApiTicketRequestModel request = this.TicketModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiTicketResponseModel> > Create( ApiTicketRequestModel model) { CreateResponse <ApiTicketResponseModel> response = new CreateResponse <ApiTicketResponseModel>(await this.ticketModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolTicketMapper.MapModelToBO(default(int), model); var record = await this.ticketRepository.Create(this.dalTicketMapper.MapBOToEF(bo)); response.SetRecord(this.bolTicketMapper.MapBOToModel(this.dalTicketMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <ITicketRepository>(); var model = new ApiTicketRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Ticket>())).Returns(Task.FromResult(new Ticket())); var service = new TicketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TicketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTicketMapperMock, mock.DALMapperMockFactory.DALTicketMapperMock); CreateResponse <ApiTicketResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TicketModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTicketRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Ticket>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITicketRepository>(); var model = new ApiTicketRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TicketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TicketModelValidatorMock.Object, 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.TicketModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiTicketResponseModel> > Update( int id, ApiTicketRequestModel model) { var validationResult = await this.ticketModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolTicketMapper.MapModelToBO(id, model); await this.ticketRepository.Update(this.dalTicketMapper.MapBOToEF(bo)); var record = await this.ticketRepository.Get(id); return(new UpdateResponse <ApiTicketResponseModel>(this.bolTicketMapper.MapBOToModel(this.dalTicketMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTicketResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTicketRequestModel model) { ApiTicketRequestModel request = await this.PatchModel(id, this.TicketModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTicketResponseModel> result = await this.TicketService.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 <ApiTicketRequestModel> patch) { ApiTicketResponseModel record = await this.TicketService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTicketRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTicketResponseModel> result = await this.TicketService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiTicketResponseModel> > TicketUpdateAsync(int id, ApiTicketRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Tickets/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiTicketResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTicketRequestModel model) { this.PublicIdRules(); this.TicketStatusIdRules(); return(await this.ValidateAsync(model, id)); }