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 ApiFileRequestModel(); createModel.SetProperties(1, DateTime.Parse("1/1/1988 12:00:00 AM"), "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 2, 1, "B", "B", "B"); CreateResponse <ApiFileResponseModel> createResult = await client.FileCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiFileResponseModel getResponse = await client.FileGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.FileDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiFileResponseModel verifyResponse = await client.FileGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiFileResponseModel> CreateRecord(ApiClient client) { var model = new ApiFileRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1988 12:00:00 AM"), "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 2, 1, "B", "B", "B"); CreateResponse <ApiFileResponseModel> result = await client.FileCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiFileRequestModel model) { CreateResponse <ApiFileResponseModel> result = await this.FileService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Files/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual async Task <CreateResponse <ApiFileResponseModel> > Create( ApiFileRequestModel model) { CreateResponse <ApiFileResponseModel> response = new CreateResponse <ApiFileResponseModel>(await this.FileModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolFileMapper.MapModelToBO(default(int), model); var record = await this.FileRepository.Create(this.DalFileMapper.MapBOToEF(bo)); response.SetRecord(this.BolFileMapper.MapBOToModel(this.DalFileMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiFileRequestModel> PatchModel(int id, JsonPatchDocument <ApiFileRequestModel> patch) { var record = await this.FileService.Get(id); if (record == null) { return(null); } else { ApiFileRequestModel request = this.FileModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiFileRequestModel model) { this.BucketIdRules(); this.DateCreatedRules(); this.DescriptionRules(); this.ExpirationRules(); this.ExtensionRules(); this.ExternalIdRules(); this.FileSizeInBytesRules(); this.FileTypeIdRules(); this.LocationRules(); this.PrivateKeyRules(); this.PublicKeyRules(); return(await this.ValidateAsync(model, id)); }
public async void Create() { var mock = new ServiceMockFacade <IFileRepository>(); var model = new ApiFileRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <File>())).Returns(Task.FromResult(new File())); var service = new FileService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiFileResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.FileModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFileRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <File>())); }
public async void Delete() { var mock = new ServiceMockFacade <IFileRepository>(); var model = new ApiFileRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new FileService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.FileModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiFileResponseModel> > Update( int id, ApiFileRequestModel model) { var validationResult = await this.FileModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolFileMapper.MapModelToBO(id, model); await this.FileRepository.Update(this.DalFileMapper.MapBOToEF(bo)); var record = await this.FileRepository.Get(id); return(new UpdateResponse <ApiFileResponseModel>(this.BolFileMapper.MapBOToModel(this.DalFileMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiFileResponseModel>(validationResult)); } }
public void MapResponseToRequest() { var mapper = new ApiFileModelMapper(); var model = new ApiFileResponseModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1, "A", "A", "A"); ApiFileRequestModel response = mapper.MapResponseToRequest(model); response.BucketId.Should().Be(1); response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Description.Should().Be("A"); response.Expiration.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Extension.Should().Be("A"); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.FileSizeInByte.Should().Be(1); response.FileTypeId.Should().Be(1); response.Location.Should().Be("A"); response.PrivateKey.Should().Be("A"); response.PublicKey.Should().Be("A"); }
public virtual BOFile MapModelToBO( int id, ApiFileRequestModel model ) { BOFile boFile = new BOFile(); boFile.SetProperties( id, model.BucketId, model.DateCreated, model.Description, model.Expiration, model.Extension, model.ExternalId, model.FileSizeInByte, model.FileTypeId, model.Location, model.PrivateKey, model.PublicKey); return(boFile); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiFileRequestModel model) { ApiFileRequestModel request = await this.PatchModel(id, this.FileModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiFileResponseModel> result = await this.FileService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public void CreatePatch() { var mapper = new ApiFileModelMapper(); var model = new ApiFileRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1m, 1, "A", "A", "A"); JsonPatchDocument <ApiFileRequestModel> patch = mapper.CreatePatch(model); var response = new ApiFileRequestModel(); patch.ApplyTo(response); response.BucketId.Should().Be(1); response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Description.Should().Be("A"); response.Expiration.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Extension.Should().Be("A"); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.FileSizeInBytes.Should().Be(1m); response.FileTypeId.Should().Be(1); response.Location.Should().Be("A"); response.PrivateKey.Should().Be("A"); response.PublicKey.Should().Be("A"); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiFileRequestModel> patch) { ApiFileResponseModel record = await this.FileService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiFileRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiFileResponseModel> result = await this.FileService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiFileResponseModel> > FileUpdateAsync(int id, ApiFileRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Files/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiFileResponseModel> >(httpResponse.Content.ContentToString())); }