DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Responses.Test/SurveyResponsesServiceTest.cs
2023-11-05 13:58:01 -05:00

238 lines
15 KiB
C#

using DamageAssesment.Api.Responses.Controllers;
using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.Responses.Models;
using DamageAssesment.Api.Responses.Test;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
namespace DamageAssesment.SurveyResponses.Test
{
public class SurveyResponsesServiceTest
{
Mock<ISurveysResponse> mockSurveyResponseService;
Mock<IExcelExportService> mockExcelExportService;
public SurveyResponsesServiceTest()
{
mockSurveyResponseService = new Mock<ISurveysResponse>();
mockExcelExportService = new Mock<IExcelExportService>();
}
[Fact(DisplayName = "Get Responses - Ok case")]
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses - BadRequest case")]
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (BadRequestObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by surveyId - Ok case")]
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1, 1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by surveyId - NoContent case")]
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1, 1);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by surveyId and locationId - Ok case")]
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, 1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by surveyId and locationId - NoContent case")]
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, 1);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by surveyId and QuestionId and Answer - Ok case")]
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes", 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes", 1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by surveyId and QuestionId and Answer - NoContent case")]
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes", 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes", 1);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by region and surveyId - Ok case")]
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByRegionAsync(1, 1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by region and surveyId - NoContent Case")]
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByRegionAsync(1, 1);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - Ok case")]
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1, 1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - No Content Case")]
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1, 1);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get SurveyResponse by responseId- Ok case")]
public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - NoContent Case")]
public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode204()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Post Responses - Ok case")]
public async Task PostSurveyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse);
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Post Responses - BadRequest case")]
public async Task PostSurveyAsync_ShouldReturnStatusCode400()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse);
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (BadRequestObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Put Responses - Ok case")]
public async Task PutSurveyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse);
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Put Responses - BadRequest case")]
public async Task PutSurveyAsync_ShouldReturnStatusCode404()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse); ;
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (BadRequestObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Delete Responses - Ok case")]
public async Task DeleteSurveyAsync_ShouldReturnStatusCode200()
{
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (OkObjectResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Delete Responses - NotFound case")]
public async Task DeleteSurveyAsync_ShouldReturnStatusCode404()
{
var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse); ;
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object, mockExcelExportService.Object);
var result = (NotFoundResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
Assert.Equal(404, result.StatusCode);
}
}
}