using DamageAssesment.Api.Documents.Controllers; using DamageAssesment.Api.Documents.Interfaces; using DamageAssesment.Api.Documents.Models; using Microsoft.AspNetCore.Mvc; using Moq; using Xunit; namespace DamageAssesment.Api.Documents.Test { public class DocumentServiceTest { [Fact(DisplayName = "Get Documents - NoContent Case")] public async Task GetDocumentsLanguageAsync_ShouldReturnStatusCode204() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getNoContentResponse(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en")).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NoContentResult)await DocumentProvider.GetDocumentsAsync("", ""); Assert.Equal(204, result.StatusCode); } [Fact(DisplayName = "Get Documents - NoContent Case")] public async Task GetDocumentsLinkTypeAsync_ShouldReturnStatusCode204() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getNoContentResponse(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en")).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NoContentResult)await DocumentProvider.GetDocumentsAsync("", ""); Assert.Equal(204, result.StatusCode); } [Fact(DisplayName = "Get Documents - Ok case")] public async Task GetDocumentsAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getOkResponse(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en")).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.GetDocumentsAsync("forms","en"); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Get Documents - NoContent Case")] public async Task GetDocumentsAsync_ShouldReturnStatusCode204() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getNoContentResponse(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en")).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NoContentResult)await DocumentProvider.GetDocumentsAsync("forms","en"); Assert.Equal(204, result.StatusCode); } [Fact(DisplayName = "Get Document by Id - Ok case")] public async Task GetDocumentAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getOkResponse(1); mockDocumentService.Setup(service => service.GetDocumentAsync(1,"forms","en")).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.GetDocumentAsync(1, "forms", "en"); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Get Document by Id - NotFound case")] public async Task GetDocumentAsync_ShouldReturnStatusCode404() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getNotFoundResponse(); mockDocumentService.Setup(service => service.GetDocumentAsync(99, "forms", "en")).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NotFoundResult)await DocumentProvider.GetDocumentAsync(99, "forms", "en"); Assert.Equal(404, result.StatusCode); } [Fact(DisplayName = "Post Document - Ok case")] public async Task PostDocumentAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getOkResponse(1); var mockInputDocument = await MockData.getInputDocumentData(); var DocumentResponse = await MockData.GetDocumentsInfo(0); mockDocumentService.Setup(service => service.PostDocumentAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NoContentResult)await DocumentProvider.CreateDocument(DocumentResponse); Assert.Equal(204, result.StatusCode); } [Fact(DisplayName = "Post Document - BadRequest case")] public async Task PostDocumentAsync_ShouldReturnStatusCode400() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockInputDocument = await MockData.getInputDocumentData(); var mockResponse = await MockData.getBadRequestResponse(); DocumentInfo documentInfo = null; mockDocumentService.Setup(service => service.PostDocumentAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (BadRequestObjectResult)await DocumentProvider.CreateDocument(documentInfo); Assert.Equal(400, result.StatusCode); } [Fact(DisplayName = "Put Document - Ok case")] public async Task PutDocumentAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getOkResponse(1); var mockInputDocument = await MockData.getInputDocumentData(); var DocumentResponse = await MockData.GetDocumentsInfo(1); mockDocumentService.Setup(service => service.UpdateDocumentAsync(1,mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NotFoundResult)await DocumentProvider.UpdateDocument(1,DocumentResponse); Assert.Equal(404, result.StatusCode); } [Fact(DisplayName = "Put Document - BadRequest case")] public async Task PutDocumentAsync_ShouldReturnStatusCode400() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getBadRequestResponse(); var mockInputDocument = await MockData.getInputDocumentData(); mockDocumentService.Setup(service => service.UpdateDocumentAsync(99,mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (BadRequestObjectResult)await DocumentProvider.UpdateDocument(99,null); Assert.Equal(400, result.StatusCode); } [Fact(DisplayName = "Delete Document - Ok case")] public async Task DeleteDocumentAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getOkResponse(1); mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.DeleteDocument(1); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Delete Document - NotFound case")] public async Task DeleteDocumentAsync_ShouldReturnStatusCode404() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await MockData.getNotFoundResponse(); mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NotFoundResult)await DocumentProvider.DeleteDocument(1); Assert.Equal(404, result.StatusCode); } // Link Type Test cases [Fact(DisplayName = "Get Link types - Ok case")] public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getOkResponse(); mockDocumentService.Setup(service => service.GetLinkTypesAsync()).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.GetLinkTypesAsync(); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Get Link types - NoContent Case")] public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode204() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getNoContentResponse(); mockDocumentService.Setup(service => service.GetLinkTypesAsync()).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NoContentResult)await DocumentProvider.GetLinkTypesAsync(); Assert.Equal(204, result.StatusCode); } [Fact(DisplayName = "Get Link Type by Id - Ok case")] public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getOkResponse(1); mockDocumentService.Setup(service => service.GetLinkTypeAsync(1)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.GetLinkTypeAsync(1); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Get Link Type by Id - NotFound case")] public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode404() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getNotFoundResponse(); mockDocumentService.Setup(service => service.GetLinkTypeAsync(99)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NotFoundResult)await DocumentProvider.GetLinkTypeAsync(99); Assert.Equal(404, result.StatusCode); } [Fact(DisplayName = "Post Link Type - Ok case")] public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getOkResponse(1); var mockInputDocument = await LinkTypeMockData.getInputLinkData(0); mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.CreateLinkType(mockInputDocument); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Post Link Type - BadRequest case")] public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode400() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockInputDocument = await LinkTypeMockData.getInputLinkData(99); var mockResponse = await LinkTypeMockData.getBadRequestResponse(); mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (BadRequestObjectResult)await DocumentProvider.CreateLinkType(mockInputDocument); Assert.Equal(400, result.StatusCode); } [Fact(DisplayName = "Put Document - Ok case")] public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getOkResponse(1); var mockInputDocument = await LinkTypeMockData.getInputLinkData(1); mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.UpdateLinkType(mockInputDocument); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Put Document - NotFound case")] public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode404() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getNotFoundResponse(); var mockInputDocument = await LinkTypeMockData.getInputLinkData(99); mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NotFoundObjectResult)await DocumentProvider.UpdateLinkType(mockInputDocument); Assert.Equal(404, result.StatusCode); } [Fact(DisplayName = "Put Document - BadRequest case")] public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode400() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getBadRequestResponse(); var mockInputDocument = await LinkTypeMockData.getInputLinkData(1); mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (BadRequestObjectResult)await DocumentProvider.UpdateLinkType(mockInputDocument); Assert.Equal(400, result.StatusCode); } [Fact(DisplayName = "Delete Document - Ok case")] public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode200() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getOkResponse(1); mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (OkObjectResult)await DocumentProvider.DeleteLinkType(1); Assert.Equal(200, result.StatusCode); } [Fact(DisplayName = "Delete Document - NotFound case")] public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode404() { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); var mockResponse = await LinkTypeMockData.getNotFoundResponse(); mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse); var DocumentProvider = new DocumentsController(mockDocumentService.Object, mockUploadService.Object); var result = (NotFoundResult)await DocumentProvider.DeleteLinkType(99); Assert.Equal(404, result.StatusCode); } } }