DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Surveys.Test/SurveyServiceTest.cs

209 lines
9.8 KiB
C#
Raw Permalink Normal View History

2023-08-15 22:52:30 -05:00
using DamageAssesment.Api.Survey.Test;
using DamageAssesment.Api.Surveys.Controllers;
using DamageAssesment.Api.Surveys.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
namespace DamageAssesment.Api.Surveys.Test
{
public class SurveyServiceTest
{
[Fact(DisplayName = "Get Surveys - Ok case")]
public async Task GetSurveysAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse();
mockSurveyService.Setup(service => service.GetSurveysAsync(null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult) await surveyProvider.GetSurveysAsync(null);
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Surveys - NoContent Case")]
public async Task GetSurveysAsync_ShouldReturnStatusCode204()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getNoContentResponse();
mockSurveyService.Setup(service => service.GetSurveysAsync(null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (NoContentResult)await surveyProvider.GetSurveysAsync(null);
2023-08-15 22:52:30 -05:00
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get active Surveys - Ok case")]
public async Task GetActiveSurveysAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse();
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(true,null)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult)await surveyProvider.GetActiveSurveysAsync(null);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get active Surveys - NoContent Case")]
public async Task GetActiveSurveysAsync_ShouldReturnStatusCode204()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getNoContentResponse();
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(true,null)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (NoContentResult)await surveyProvider.GetActiveSurveysAsync(null);
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get inactive Surveys - Ok case")]
public async Task GetInActiveSurveysAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse();
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(false, null)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult)await surveyProvider.GetInActiveSurveysAsync(null);
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get in active Surveys - NoContent Case")]
public async Task GetInActiveSurveysAsync_ShouldReturnStatusCode204()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getNoContentResponse();
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(false, null)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (NoContentResult)await surveyProvider.GetInActiveSurveysAsync(null);
Assert.Equal(204, result.StatusCode);
}
2023-08-15 22:52:30 -05:00
[Fact(DisplayName = "Get Survey by Id - Ok case")]
public async Task GetSurveyAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse(1);
mockSurveyService.Setup(service => service.GetSurveysAsync(1,null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult)await surveyProvider.GetSurveysAsync(1,null);
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Survey by Id - NotFound case")]
public async Task GetSurveyAsync_ShouldReturnStatusCode404()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getNotFoundResponse();
mockSurveyService.Setup(service => service.GetSurveysAsync(99,null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (NotFoundResult)await surveyProvider.GetSurveysAsync(99,null);
2023-08-15 22:52:30 -05:00
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Post Survey - Ok case")]
public async Task PostSurveyAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputSurvey = await MockData.getInputSurveyData();
mockSurveyService.Setup(service => service.PostSurveyAsync(mockInputSurvey)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult)await surveyProvider.PostSurveysAsync(mockInputSurvey);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Post Survey - BadRequest case")]
public async Task PostSurveyAsync_ShouldReturnStatusCode400()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockInputSurvey = await MockData.getInputSurveyData();
var mockResponse = await MockData.getBadRequestResponse();
mockSurveyService.Setup(service => service.PostSurveyAsync(mockInputSurvey)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (BadRequestObjectResult)await surveyProvider.PostSurveysAsync(mockInputSurvey);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Put Survey - Ok case")]
public async Task PutSurveyAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputSurvey = await MockData.getInputSurveyData();
mockSurveyService.Setup(service => service.PutSurveyAsync(1,mockInputSurvey)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult)await surveyProvider.PutSurveysAsync(1,mockInputSurvey);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Put Survey - NotFound case")]
public async Task PutSurveyAsync_ShouldReturnStatusCode404()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getNotFoundResponse();
var mockInputSurvey = await MockData.getInputSurveyData();
mockSurveyService.Setup(service => service.PutSurveyAsync(1,mockInputSurvey)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (NotFoundObjectResult)await surveyProvider.PutSurveysAsync(1,mockInputSurvey);
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Put Survey - BadRequest case")]
public async Task PutSurveyAsync_ShouldReturnStatusCode400()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getBadRequestResponse();
var mockInputSurvey = await MockData.getInputSurveyData();
mockSurveyService.Setup(service => service.PutSurveyAsync(1,mockInputSurvey)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (BadRequestObjectResult)await surveyProvider.PutSurveysAsync(1,mockInputSurvey);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Delete Survey - Ok case")]
public async Task DeleteSurveyAsync_ShouldReturnStatusCode200()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getOkResponse(1);
mockSurveyService.Setup(service => service.DeleteSurveyAsync(1)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (OkObjectResult)await surveyProvider.DeleteSurveysAsync(1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Delete Survey - NotFound case")]
public async Task DeleteSurveyAsync_ShouldReturnStatusCode404()
{
var mockSurveyService = new Mock<ISurveyProvider>();
var mockResponse = await MockData.getNotFoundResponse();
mockSurveyService.Setup(service => service.DeleteSurveyAsync(1)).ReturnsAsync(mockResponse);
var surveyProvider = new SurveysController(mockSurveyService.Object);
var result = (NotFoundResult)await surveyProvider.DeleteSurveysAsync(1);
Assert.Equal(404, result.StatusCode);
}
}
}