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(); }
public virtual ApiFileResponseModel MapBOToModel( BOFile boFile) { var model = new ApiFileResponseModel(); model.SetProperties(boFile.Id, boFile.BucketId, boFile.DateCreated, boFile.Description, boFile.Expiration, boFile.Extension, boFile.ExternalId, boFile.FileSizeInByte, boFile.FileTypeId, boFile.Location, boFile.PrivateKey, boFile.PublicKey); return(model); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiFileResponseModel response = await client.FileGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiFileResponseModel response = await this.FileService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IFileRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <File>(null)); var service = new FileService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ApiFileResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiFileResponseModel model = await client.FileGetAsync(1); ApiFileModelMapper mapper = new ApiFileModelMapper(); UpdateResponse <ApiFileResponseModel> updateResponse = await client.FileUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
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 async void Create_Errors() { FileControllerMockFacade mock = new FileControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiFileResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiFileResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFileRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFileResponseModel> >(mockResponse.Object)); FileController controller = new FileController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiFileRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiFileRequestModel>())); }
public void MapBOToModel() { var mapper = new BOLFileMapper(); BOFile bo = new BOFile(); bo.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"), 1m, 1, "A", "A", "A"); ApiFileResponseModel response = mapper.MapBOToModel(bo); 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.Id.Should().Be(1); response.Location.Should().Be("A"); response.PrivateKey.Should().Be("A"); response.PublicKey.Should().Be("A"); }
public async void All_Exists() { FileControllerMockFacade mock = new FileControllerMockFacade(); var record = new ApiFileResponseModel(); var records = new List <ApiFileResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); FileController controller = new FileController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiFileResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
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 async void TestGet() { ApiFileResponseModel response = await this.Client.FileGetAsync(1); response.Should().NotBeNull(); }