239 lines
14 KiB
C#
239 lines
14 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 ResponsesServiceTest
|
|
{
|
|
private Mock<ISurveysResponse> mockSurveyResponseService;
|
|
private string token { get; set; }
|
|
public ResponsesServiceTest()
|
|
{
|
|
mockSurveyResponseService = new Mock<ISurveysResponse>();
|
|
token = Guid.NewGuid().ToString();
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses - Ok case")]
|
|
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode200()
|
|
{
|
|
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
var mockResponse = await MockData.getOkResponse(mockRequestObject);
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync()).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync();
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses - BadRequest case")]
|
|
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode204()
|
|
{
|
|
var mockResponse = await MockData.getResponse();
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync()).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (BadRequestObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync();
|
|
Assert.Equal(400, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses by surveyId - NoContent case")]
|
|
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode204()
|
|
{
|
|
var mockResponse = await MockData.getResponse();
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
|
|
Assert.Equal(204, result.StatusCode);
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses by surveyId and locationId - NoContent case")]
|
|
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode204()
|
|
{
|
|
var mockResponse = await MockData.getResponse();
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1);
|
|
Assert.Equal(204, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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")).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes");
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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")).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes");
|
|
Assert.Equal(204, result.StatusCode);
|
|
}
|
|
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByRegionAsync(1);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses by region and surveyId - NoContent Case")]
|
|
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode204()
|
|
{
|
|
var mockResponse = await MockData.getResponse();
|
|
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByRegionAsync(1);
|
|
Assert.Equal(204, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses by maintenanceCenter and surveyId - No Content Case")]
|
|
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode204()
|
|
{
|
|
var mockResponse = await MockData.getResponse();
|
|
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1)).ReturnsAsync(mockResponse);
|
|
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(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);
|
|
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Get SurveyResponses 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);
|
|
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
|
|
Assert.Equal(204, result.StatusCode);
|
|
}
|
|
|
|
|
|
[Fact(DisplayName = "Post SurveyResponses - 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);
|
|
var result = (OkObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Post SurveyResponses - 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);
|
|
var result = (BadRequestObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
|
|
Assert.Equal(400, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Put SurveyResponses - 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);
|
|
var result = (OkObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Put SurveyResponses - 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);
|
|
var result = (BadRequestObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
|
|
Assert.Equal(400, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Delete SurveyResponses - 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);
|
|
var result = (OkObjectResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
|
|
Assert.Equal(200, result.StatusCode);
|
|
}
|
|
|
|
[Fact(DisplayName = "Delete SurveyResponses - 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);
|
|
var result = (NotFoundResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
|
|
Assert.Equal(404, result.StatusCode);
|
|
}
|
|
}
|
|
} |