private async Task <ApiInvitationResponseModel> CreateRecord() { var model = new ApiInvitationRequestModel(); model.SetProperties("B", "B"); CreateResponse <ApiInvitationResponseModel> result = await this.Client.InvitationCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiInvitationModelMapper(); var model = new ApiInvitationResponseModel(); model.SetProperties("A", "A", "A"); ApiInvitationRequestModel response = mapper.MapResponseToRequest(model); response.InvitationCode.Should().Be("A"); response.JSON.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLInvitationMapper(); ApiInvitationRequestModel model = new ApiInvitationRequestModel(); model.SetProperties("A", "A"); BOInvitation response = mapper.MapModelToBO("A", model); response.InvitationCode.Should().Be("A"); response.JSON.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiInvitationRequestModel model) { CreateResponse <ApiInvitationResponseModel> result = await this.InvitationService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Invitations/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOInvitation MapModelToBO( string id, ApiInvitationRequestModel model ) { BOInvitation boInvitation = new BOInvitation(); boInvitation.SetProperties( id, model.InvitationCode, model.JSON); return(boInvitation); }
public void CreatePatch() { var mapper = new ApiInvitationModelMapper(); var model = new ApiInvitationRequestModel(); model.SetProperties("A", "A"); JsonPatchDocument <ApiInvitationRequestModel> patch = mapper.CreatePatch(model); var response = new ApiInvitationRequestModel(); patch.ApplyTo(response); response.InvitationCode.Should().Be("A"); response.JSON.Should().Be("A"); }
private async Task <ApiInvitationRequestModel> PatchModel(string id, JsonPatchDocument <ApiInvitationRequestModel> patch) { var record = await this.InvitationService.Get(id); if (record == null) { return(null); } else { ApiInvitationRequestModel request = this.InvitationModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiInvitationResponseModel> > Create( ApiInvitationRequestModel model) { CreateResponse <ApiInvitationResponseModel> response = new CreateResponse <ApiInvitationResponseModel>(await this.invitationModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolInvitationMapper.MapModelToBO(default(string), model); var record = await this.invitationRepository.Create(this.dalInvitationMapper.MapBOToEF(bo)); response.SetRecord(this.bolInvitationMapper.MapBOToModel(this.dalInvitationMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <IInvitationRepository>(); var model = new ApiInvitationRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Invitation>())).Returns(Task.FromResult(new Invitation())); var service = new InvitationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.InvitationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLInvitationMapperMock, mock.DALMapperMockFactory.DALInvitationMapperMock); CreateResponse <ApiInvitationResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.InvitationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiInvitationRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Invitation>())); }
public async void Delete() { var mock = new ServiceMockFacade <IInvitationRepository>(); var model = new ApiInvitationRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new InvitationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.InvitationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLInvitationMapperMock, mock.DALMapperMockFactory.DALInvitationMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.InvitationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiInvitationResponseModel> > Update( string id, ApiInvitationRequestModel model) { var validationResult = await this.invitationModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolInvitationMapper.MapModelToBO(id, model); await this.invitationRepository.Update(this.dalInvitationMapper.MapBOToEF(bo)); var record = await this.invitationRepository.Get(id); return(new UpdateResponse <ApiInvitationResponseModel>(this.bolInvitationMapper.MapBOToModel(this.dalInvitationMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiInvitationResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiInvitationRequestModel model) { ApiInvitationRequestModel request = await this.PatchModel(id, this.InvitationModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiInvitationResponseModel> result = await this.InvitationService.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 <ApiInvitationRequestModel> patch) { ApiInvitationResponseModel record = await this.InvitationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiInvitationRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiInvitationResponseModel> result = await this.InvitationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiInvitationRequestModel model) { this.InvitationCodeRules(); this.JSONRules(); return(await this.ValidateAsync(model, id)); }
public async Task <ValidationResult> ValidateCreateAsync(ApiInvitationRequestModel model) { this.InvitationCodeRules(); this.JSONRules(); return(await this.ValidateAsync(model)); }