public async Task GivenValidRequestWithAcceptTextCsvHeader_ThenReturnsListOfAssetOutputModel() { //arrange var assetOutputModel = new AssetRegisterVersionOutputModel { Id = Faker.GlobalUniqueIndex }; _mockUseCase.Setup(s => s.ExecuteAsync(It.IsAny <GetAssetRegisterVersionsRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAssetRegisterVersionsResponse { AssetRegisterVersions = new List <AssetRegisterVersionOutputModel> { assetOutputModel } }); _classUnderTest.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; _classUnderTest.ControllerContext.HttpContext.Request.Headers.Add( new KeyValuePair <string, StringValues>("accept", "text/csv")); var request = new GetAssetRegisterVersionsRequest(); //act var response = await _classUnderTest.Get(request).ConfigureAwait(false); //assert response.Should().NotBeNull(); var result = response as ObjectResult; result.Should().NotBeNull(); result.Value.Should().BeOfType <List <AssetRegisterVersionOutputModel> >(); }
public async Task <GetAssetRegisterVersionsResponse> ExecuteAsync(GetAssetRegisterVersionsRequest requests, CancellationToken cancellationToken) { var query = new PagedQuery(); if (requests.Page != null) { query.Page = requests.Page; } if (requests.PageSize != null) { query.PageSize = requests.PageSize; } var response = await _assetRegisterVersionSearcher.Search(query, cancellationToken).ConfigureAwait(false) ?? new PagedResults <IAssetRegisterVersion> { Results = new List <IAssetRegisterVersion>(), NumberOfPages = 0, TotalCount = 0 }; var useCaseReponse = new GetAssetRegisterVersionsResponse { AssetRegisterVersions = response.Results.Select(s => new AssetRegisterVersionOutputModel(s)).ToList(), TotalCount = response.TotalCount, Pages = response.NumberOfPages }; return(useCaseReponse); }
public void GivenInvalidRequest_ThenIsValid(int?page, int?pageSize) { var apiRequest = new GetAssetRegisterVersionsRequest { Page = page, PageSize = pageSize, }; apiRequest.IsValid().Should().BeTrue(); }
public async Task <IActionResult> Get([FromQuery] GetAssetRegisterVersionsRequest request) { if (!request.IsValid()) { return(StatusCode(400)); } return(this.StandardiseResponse <GetAssetRegisterVersionsResponse, AssetRegisterVersionOutputModel>( await _getAssetRegisterVersionsUseCase.ExecuteAsync(request, CancellationToken.None) .ConfigureAwait(false))); }
public async Task GivenValidRequest_ThenReturnsGetAssetResponse() { //arrange _mockUseCase.Setup(s => s.ExecuteAsync(It.IsAny <GetAssetRegisterVersionsRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAssetRegisterVersionsResponse()); var request = new GetAssetRegisterVersionsRequest(); //act var response = await _classUnderTest.Get(request); //assert response.Should().NotBeNull(); }
public async Task GivenValidRequest_WhenGatewayReturnsNull_ThenResponseNotNull(int?page, int?pageSize) { //arrange _mockGateway.Setup(s => s.Search(It.IsAny <IPagedQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync((PagedResults <IAssetRegisterVersion>)null); var request = new GetAssetRegisterVersionsRequest { Page = page, PageSize = pageSize }; //act var response = await _classUnderTest.ExecuteAsync(request, CancellationToken.None) .ConfigureAwait(false); //assert response.Should().NotBeNull(); response.AssetRegisterVersions.Count.Should().Be(0); response.TotalCount.Should().Be(0); response.Pages.Should().Be(0); }
public async Task GivenNullParams_WhenWeExecute_ThenWeCallGatewayWithDefaultParams(int?page, int?pageSize) { //arrange _mockGateway.Setup(s => s.Search(It.IsAny <IPagedQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(new PagedResults <IAssetRegisterVersion> { NumberOfPages = 1, Results = new List <IAssetRegisterVersion>(), TotalCount = 1 }); var request = new GetAssetRegisterVersionsRequest { Page = page, PageSize = pageSize }; //act var response = await _classUnderTest.ExecuteAsync(request, CancellationToken.None) .ConfigureAwait(false); //assert response.Should().NotBeNull(); _mockGateway.Verify(v => v.Search(It.Is <IPagedQuery>(i => i.Page == 1 && i.PageSize == 25), It.IsAny <CancellationToken>())); }
public async Task GivenInValidRequest_WhenValidatingRequest_ThenReturnsBadRequest(int?page, int?pageSize) { //arrange var assetOutputModel = new AssetRegisterVersionOutputModel { Id = Faker.GlobalUniqueIndex }; _mockUseCase.Setup(s => s.ExecuteAsync(It.IsAny <GetAssetRegisterVersionsRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAssetRegisterVersionsResponse { AssetRegisterVersions = new List <AssetRegisterVersionOutputModel> { assetOutputModel } }); _classUnderTest.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; var request = new GetAssetRegisterVersionsRequest { Page = page, PageSize = pageSize }; //act var response = await _classUnderTest.Get(request).ConfigureAwait(false); //assert response.Should().NotBeNull(); var result = response as StatusCodeResult; result.Should().NotBeNull(); result.StatusCode.Should().Be(400); }