2023-10-04 17:45:51 -05:00
|
|
|
using DamageAssesment.Api.Responses.Controllers;
|
|
|
|
using DamageAssesment.Api.Responses.Interfaces;
|
|
|
|
using DamageAssesment.Api.Responses.Models;
|
|
|
|
using DamageAssesment.Api.Responses.Test;
|
2023-08-15 22:52:30 -05:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Moq;
|
|
|
|
using Xunit;
|
2023-09-20 23:58:29 -05:00
|
|
|
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
namespace DamageAssesment.SurveyResponses.Test
|
|
|
|
{
|
|
|
|
public class SurveyResponsesServiceTest
|
|
|
|
{
|
|
|
|
Mock<ISurveysResponse> mockSurveyResponseService;
|
|
|
|
public SurveyResponsesServiceTest()
|
|
|
|
{
|
|
|
|
mockSurveyResponseService = new Mock<ISurveysResponse>();
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode200()
|
|
|
|
{
|
|
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
|
|
var mockResponse = await MockData.getOkResponse(mockRequestObject);
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync(1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses - BadRequest case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync(1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (BadRequestObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(400, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by surveyId - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode200()
|
|
|
|
{
|
|
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
|
|
var mockResponse = await MockData.getOkResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1,1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-10-04 10:55:35 -05:00
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1,1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by surveyId - NoContent case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1,1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-10-04 10:55:35 -05:00
|
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1,1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(204, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by surveyId and locationId - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode200()
|
|
|
|
{
|
|
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
|
|
var mockResponse = await MockData.getOkResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1,1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1,1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by surveyId and locationId - NoContent case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, 1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, 1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(204, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by surveyId and QuestionId and Answer - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode200()
|
|
|
|
{
|
|
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
|
|
var mockResponse = await MockData.getOkResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes",1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes",1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by surveyId and QuestionId and Answer - NoContent case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes", 1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes",1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(204, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by region and surveyId - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode200()
|
|
|
|
{
|
|
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
|
|
var mockResponse = await MockData.getOkResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1,1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByRegionAsync(1, 1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by region and surveyId - NoContent Case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1, 1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByRegionAsync(1, 1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(204, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode200()
|
|
|
|
{
|
|
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
|
|
var mockResponse = await MockData.getOkResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1, 1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1, 1);
|
2023-08-15 22:52:30 -05:00
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - No Content Case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
2023-09-20 23:58:29 -05:00
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1, 1)).ReturnsAsync(mockResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
2023-09-20 23:58:29 -05:00
|
|
|
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1, 1);
|
2023-08-15 22:52:30 -05:00
|
|
|
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 SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
|
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - NoContent Case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode204()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
|
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
|
|
|
|
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
|
|
|
|
Assert.Equal(204, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Post Responses - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
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 SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (OkObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
|
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Post Responses - BadRequest case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
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 SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (BadRequestObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
|
|
|
|
Assert.Equal(400, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Put Responses - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
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 SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (OkObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
|
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Put Responses - BadRequest case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
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 SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (BadRequestObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
|
|
|
|
Assert.Equal(400, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Delete Responses - Ok case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
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 SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (OkObjectResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
|
|
|
|
Assert.Equal(200, result.StatusCode);
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
[Fact(DisplayName = "Delete Responses - NotFound case")]
|
2023-08-15 22:52:30 -05:00
|
|
|
public async Task DeleteSurveyAsync_ShouldReturnStatusCode404()
|
|
|
|
{
|
|
|
|
var mockResponse = await MockData.getResponse();
|
|
|
|
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse); ;
|
|
|
|
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object);
|
|
|
|
var result = (NotFoundResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
|
|
|
|
Assert.Equal(404, result.StatusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|