DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/DoculinkServiceTest.cs
2023-12-04 15:01:51 -05:00

378 lines
21 KiB
C#

using DamageAssesment.Api.DocuLinks.Controllers;
using DamageAssesment.Api.DocuLinks.Interfaces;
using DamageAssesment.Api.DocuLinks.Models;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
namespace DamageAssesment.Api.DocuLinks.Test
{
public class DocumentServiceTest
{
[Fact(DisplayName = "Get Documents - NoContent Case")]
public async Task GetDocumentsLanguageAsync_ShouldReturnStatusCode204()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getNoContentResponse();
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en",null)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NoContentResult)await DocumentProvider.GetDocumentsAsync("", "", null);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get active Documents - NoContent Case")]
public async Task GetDocumentsLinkTypeAsync_ShouldReturnStatusCode204()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getNoContentResponse();
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NoContentResult)await DocumentProvider.GetDocumentsByActiveAsync("", "");
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Documents - Ok case")]
public async Task GetDocumentsAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponses();
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", null)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.GetDocumentsAsync("forms", "en", null);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get active Documents - Ok case")]
public async Task GetActiveDocumentsAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponses();
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.GetDocumentsByActiveAsync("forms", "en");
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get active Documents by linktypeid - Ok case")]
public async Task GetActiveDocumentsLinkTypeIdAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponses();
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.GetDocumentsByActiveLinkTypeIdAsync(null, "en");
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get active Documents by linktypeid - NoContent Case")]
public async Task GetDocumentsLinkTypeIdAsync_ShouldReturnStatusCode204()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getNoContentResponse();
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NoContentResult)await DocumentProvider.GetDocumentsByActiveLinkTypeIdAsync(null, "");
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Document by Id - Ok case")]
public async Task GetDocumentAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponse(1);
mockDocumentService.Setup(service => service.GetDocumentAsync(1, "forms", "en")).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getNotFoundResponse();
mockDocumentService.Setup(service => service.GetDocumentAsync(99, "forms", "en")).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputDocument = await MockData.getInputDocumentData();
var DocumentResponse = await MockData.GetDocuLinksInfo(0);
mockDocumentService.Setup(service => service.PostDocumentAsync(mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockInputDocument = await MockData.getInputDocumentData();
var mockResponse = await MockData.getBadRequestResponse();
ReqDoculink documentInfo = null;
mockDocumentService.Setup(service => service.PostDocumentAsync(mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputDocument = await MockData.getInputDocumentData();
var DocumentResponse = await MockData.GetDocuLinksInfo(1);
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getBadRequestResponse();
var mockInputDocument = await MockData.getInputDocumentData();
mockDocumentService.Setup(service => service.UpdateDocumentAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponse(1);
mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getNotFoundResponse();
mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NotFoundResult)await DocumentProvider.DeleteDocument(1);
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Update Document IsActive- Ok case")]
public async Task UpdateDocumentAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getOkResponse(1);
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1,true)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.UpdateIsActiveDocument(1,true);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Update Document IsActive - NotFound case")]
public async Task UpdateDocumentAsync_ShouldReturnStatusCode404()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await MockData.getNotFoundResponse();
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1,true)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NotFoundResult)await DocumentProvider.UpdateIsActiveDocument(1,true);
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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getOkResponse();
mockDocumentService.Setup(service => service.GetLinkTypesAsync("en")).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.GetLinkTypesAsync("en");
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Link types - NoContent Case")]
public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode204()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getNoContentResponse();
mockDocumentService.Setup(service => service.GetLinkTypesAsync("en")).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NoContentResult)await DocumentProvider.GetLinkTypesAsync("en");
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Link Type by Id - Ok case")]
public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getOkResponse(1);
mockDocumentService.Setup(service => service.GetLinkTypeAsync(1, "en")).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.GetLinkTypeAsync(1, "en");
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Link Type by Id - NotFound case")]
public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode404()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
mockDocumentService.Setup(service => service.GetLinkTypeAsync(99, "en")).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NotFoundResult)await DocumentProvider.GetLinkTypeAsync(99, "en");
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Post Link Type - Ok case")]
public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getOkResponse(1);
var mockInputDocument = await LinkTypeMockData.getInputLinkData(0);
mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getOkResponse(1);
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (OkObjectResult)await DocumentProvider.UpdateLinkType(1, mockInputDocument);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Put Document - NotFound case")]
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode404()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NotFoundObjectResult)await DocumentProvider.UpdateLinkType(99, mockInputDocument);
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Put Document - BadRequest case")]
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode400()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (BadRequestObjectResult)await DocumentProvider.UpdateLinkType(1, mockInputDocument);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Delete Document - Ok case")]
public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode200()
{
var mockDocumentService = new Mock<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getOkResponse(1);
mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(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<IDoculinkProvider>();
var mockUploadService = new Mock<IUploadService>();
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse);
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
var result = (NotFoundResult)await DocumentProvider.DeleteLinkType(99);
Assert.Equal(404, result.StatusCode);
}
}
}