DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/QuestionsServiceTest.cs

361 lines
18 KiB
C#
Raw Normal View History

2023-08-15 22:52:30 -05:00
using DamageAssesment.Api.Questions.Controllers;
using DamageAssesment.Api.Questions.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
namespace DamageAssesment.Api.Questions.Test
{
public class QuestionServiceTest
{
[Fact(DisplayName = "Get Questions - Ok case")]
public async Task GetQuestionsAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkResponse();
mockQuestionService.Setup(service => service.GetQuestionsAsync(null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.GetQuestionsAsync(null);
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Questions - NoContent Case")]
public async Task GetQuestionsAsync_ShouldReturnStatusCode204()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getNoContentResponse();
mockQuestionService.Setup(service => service.GetQuestionsAsync(null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (NoContentResult)await QuestionProvider.GetQuestionsAsync(null);
2023-08-15 22:52:30 -05:00
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Question by Id - Ok case")]
public async Task GetQuestionAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkResponse(1);
mockQuestionService.Setup(service => service.GetQuestionAsync(1,null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
2023-09-08 14:40:06 -05:00
var result = (OkObjectResult)await QuestionProvider.GetQuestionByIdAsync(1,null);
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Question by Id - NotFound case")]
public async Task GetQuestionAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getNotFoundResponse();
mockQuestionService.Setup(service => service.GetQuestionAsync(99,null)).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
2023-09-08 14:40:06 -05:00
var result = (NotFoundResult)await QuestionProvider.GetQuestionByIdAsync(99,null);
2023-08-15 22:52:30 -05:00
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Get Question by SurveyID - Ok case")]
public async Task GetQuestionBySurveyAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkSurveyResponse();
mockQuestionService.Setup(service => service.GetSurveyQuestionAsync(1,"en")).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.GetSurveyQuestions(1,"en");
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Question by SurveyID - NotFound case")]
public async Task GetQuestionBySurveyAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getNoSurveyContentResponse();
mockQuestionService.Setup(service => service.GetSurveyQuestionAsync(99,"en")).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (NotFoundResult)await QuestionProvider.GetSurveyQuestions(99,"en");
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Post Question - Ok case")]
public async Task PostQuestionAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputQuestion = await MockData.getInputQuestionData();
mockQuestionService.Setup(service => service.PostQuestionAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.CreateQuestion(mockInputQuestion);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Post Question - BadRequest case")]
public async Task PostQuestionAsync_ShouldReturnStatusCode400()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockInputQuestion = await MockData.getInputQuestionData();
var mockResponse = await MockData.getBadRequestResponse();
mockQuestionService.Setup(service => service.UpdateQuestionAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (BadRequestObjectResult)await QuestionProvider.UpdateQuestion(mockInputQuestion);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Post Questions - Ok case")]
public async Task PostQuestionsAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkResponse();
var mockInputQuestion = await MockData.getInputQuestionsData();
mockQuestionService.Setup(service => service.PostQuestionsAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.CreateQuestions(mockInputQuestion);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Post Questions - BadRequest case")]
public async Task PostQuestionsAsync_ShouldReturnStatusCode400()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockInputQuestion = await MockData.getInputQuestionData();
var mockResponse = await MockData.getBadRequestResponse();
mockQuestionService.Setup(service => service.UpdateQuestionAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (BadRequestObjectResult)await QuestionProvider.UpdateQuestion(mockInputQuestion);
Assert.Equal(400, result.StatusCode);
}
2023-08-15 22:52:30 -05:00
[Fact(DisplayName = "Put Question - Ok case")]
public async Task PutQuestionAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputQuestion = await MockData.getInputQuestionData();
mockQuestionService.Setup(service => service.UpdateQuestionAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.UpdateQuestion(mockInputQuestion);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Put Question - NotFound case")]
public async Task PutQuestionAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getNotFoundResponse();
var mockInputQuestion = await MockData.getInputQuestionData();
mockQuestionService.Setup(service => service.UpdateQuestionAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (NotFoundObjectResult)await QuestionProvider.UpdateQuestion(mockInputQuestion);
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Put Question - BadRequest case")]
public async Task PutQuestionAsync_ShouldReturnStatusCode400()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getBadRequestResponse();
var mockInputQuestion = await MockData.getInputQuestionData();
mockQuestionService.Setup(service => service.UpdateQuestionAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (BadRequestObjectResult)await QuestionProvider.UpdateQuestion(mockInputQuestion);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Delete Question - Ok case")]
public async Task DeleteQuestionAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getOkResponse(1);
mockQuestionService.Setup(service => service.DeleteQuestionAsync(1)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.DeleteQuestion(1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Delete Question - NotFound case")]
public async Task DeleteQuestionAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await MockData.getNotFoundResponse();
mockQuestionService.Setup(service => service.DeleteQuestionAsync(1)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (NotFoundResult)await QuestionProvider.DeleteQuestion(1);
Assert.Equal(404, result.StatusCode);
}
// Question Category Test cases
[Fact(DisplayName = "Get Question Categories - Ok case")]
public async Task GetQuestionCategoriesAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getOkResponse();
2023-09-08 14:40:06 -05:00
mockQuestionService.Setup(service => service.GetQuestionCategoriesAsync("en")).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
2023-09-08 14:40:06 -05:00
var result = (OkObjectResult)await QuestionProvider.GetQuestionCategoriesAsync("en");
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Question Categories - NoContent Case")]
public async Task GetQuestionCategoriesAsync_ShouldReturnStatusCode204()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getNoContentResponse();
2023-09-08 14:40:06 -05:00
mockQuestionService.Setup(service => service.GetQuestionCategoriesAsync("en")).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
2023-09-08 14:40:06 -05:00
var result = (NoContentResult)await QuestionProvider.GetQuestionCategoriesAsync("en");
2023-08-15 22:52:30 -05:00
Assert.Equal(204, result.StatusCode);
}
[Fact(DisplayName = "Get Question category by Id - Ok case")]
public async Task GetQuestioncategoryAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getOkResponse(1);
2023-09-08 14:40:06 -05:00
mockQuestionService.Setup(service => service.GetQuestionCategoryAsync(1, "en")).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
2023-09-08 14:40:06 -05:00
var result = (OkObjectResult)await QuestionProvider.GetQuestionCategoryAsync(1, "en");
2023-08-15 22:52:30 -05:00
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Get Question category by Id - NotFound case")]
public async Task GetQuestioncategoryAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getNotFoundResponse();
2023-09-08 14:40:06 -05:00
mockQuestionService.Setup(service => service.GetQuestionCategoryAsync(99, "en")).ReturnsAsync(mockResponse);
2023-08-15 22:52:30 -05:00
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
2023-09-08 14:40:06 -05:00
var result = (NotFoundResult)await QuestionProvider.GetQuestionCategoryAsync(99, "en");
2023-08-15 22:52:30 -05:00
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Post Question category - Ok case")]
public async Task PostQuestioncategoryAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getOkResponse(1);
var mockInputQuestion = await CategoryMockData.getInputQuestionCategoryData();
mockQuestionService.Setup(service => service.PostQuestionCategoryAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.CreateQuestionCategory(mockInputQuestion);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Post Question category - BadRequest case")]
public async Task PostQuestioncategoryAsync_ShouldReturnStatusCode400()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockInputQuestion = await CategoryMockData.getInputQuestionCategoryData();
var mockResponse = await CategoryMockData.getBadRequestResponse();
mockQuestionService.Setup(service => service.PostQuestionCategoryAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (BadRequestObjectResult)await QuestionProvider.CreateQuestionCategory(mockInputQuestion);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Put Question - Ok case")]
public async Task PutQuestioncategoryAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getOkResponse(1);
var mockInputQuestion = await CategoryMockData.getInputQuestionCategoryData();
mockQuestionService.Setup(service => service.UpdateQuestionCategoryAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.UpdateQuestionCategory(mockInputQuestion);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Put Question - NotFound case")]
public async Task PutQuestioncategoryAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getNotFoundResponse();
var mockInputQuestion = await CategoryMockData.getInputQuestionCategoryData();
mockQuestionService.Setup(service => service.UpdateQuestionCategoryAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (NotFoundObjectResult)await QuestionProvider.UpdateQuestionCategory(mockInputQuestion);
Assert.Equal(404, result.StatusCode);
}
[Fact(DisplayName = "Put Question - BadRequest case")]
public async Task PutQuestioncategoryAsync_ShouldReturnStatusCode400()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getBadRequestResponse();
var mockInputQuestion = await CategoryMockData.getInputQuestionCategoryData();
mockQuestionService.Setup(service => service.UpdateQuestionCategoryAsync(mockInputQuestion)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (BadRequestObjectResult)await QuestionProvider.UpdateQuestionCategory(mockInputQuestion);
Assert.Equal(400, result.StatusCode);
}
[Fact(DisplayName = "Delete Question - Ok case")]
public async Task DeleteQuestioncategoryAsync_ShouldReturnStatusCode200()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getOkResponse(1);
mockQuestionService.Setup(service => service.DeleteQuestionCategoryAsync(1)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (OkObjectResult)await QuestionProvider.DeleteQuestionCategory(1);
Assert.Equal(200, result.StatusCode);
}
[Fact(DisplayName = "Delete Question - NotFound case")]
public async Task DeleteQuestioncategoryAsync_ShouldReturnStatusCode404()
{
var mockQuestionService = new Mock<IQuestionsProvider>();
var mockResponse = await CategoryMockData.getNotFoundResponse();
mockQuestionService.Setup(service => service.DeleteQuestionCategoryAsync(1)).ReturnsAsync(mockResponse);
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
var result = (NotFoundResult)await QuestionProvider.DeleteQuestionCategory(1);
Assert.Equal(404, result.StatusCode);
}
}
}