forked from MDCPS/DamageAssessment_Backend
Merged new dev changes
This commit is contained in:
@ -8,42 +8,42 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
public class CategoryMockData
|
||||
{
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.QuestionCategory>, string)> getOkResponse()
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.MultiLanQuestionCategory>, string)> getOkResponse()
|
||||
{
|
||||
IEnumerable<Questions.Models.QuestionCategory> list = new List<Questions.Models.QuestionCategory>();
|
||||
IEnumerable<Questions.Models.MultiLanQuestionCategory> list = new List<Questions.Models.MultiLanQuestionCategory>();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
list.Append(new Questions.Models.QuestionCategory { Id = i, CategoryImage = "img"+i,CategoryName="Category "+i });
|
||||
list.Append(new Questions.Models.MultiLanQuestionCategory { Id = i, IconLibrary = "img"+i,IconName="Category "+i });
|
||||
}
|
||||
return (true, list, null);
|
||||
}
|
||||
|
||||
public static async Task<(bool, Questions.Models.QuestionCategory, string)> getOkResponse(int Id)
|
||||
public static async Task<(bool, Questions.Models.MultiLanQuestionCategory, string)> getOkResponse(int Id)
|
||||
{
|
||||
var Questions = await getOkResponse();
|
||||
var Question = Questions.Item2.FirstOrDefault(s => s.Id == Id);
|
||||
return (true, Question, null);
|
||||
}
|
||||
|
||||
public static async Task<(bool, Questions.Models.QuestionCategory, string)> getBadRequestResponse()
|
||||
public static async Task<(bool, Questions.Models.MultiLanQuestionCategory, string)> getBadRequestResponse()
|
||||
{
|
||||
return (false, null, "Bad Request");
|
||||
}
|
||||
|
||||
public static async Task<(bool, Questions.Models.QuestionCategory, string)> getNotFoundResponse()
|
||||
public static async Task<(bool, Questions.Models.MultiLanQuestionCategory, string)> getNotFoundResponse()
|
||||
{
|
||||
return (false, null, "Not Found");
|
||||
}
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.QuestionCategory>, string)> getNoContentResponse()
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.MultiLanQuestionCategory>, string)> getNoContentResponse()
|
||||
{
|
||||
IEnumerable<Questions.Models.QuestionCategory> list = new List<Questions.Models.QuestionCategory>();
|
||||
IEnumerable<Questions.Models.MultiLanQuestionCategory> list = new List<Questions.Models.MultiLanQuestionCategory>();
|
||||
return (false, list, null);
|
||||
}
|
||||
|
||||
public static async Task<Questions.Models.QuestionCategory> getInputQuestionCategoryData()
|
||||
{
|
||||
return new Questions.Models.QuestionCategory { Id = 1, CategoryName = "Category 1",CategoryImage="img 1" };
|
||||
return new Questions.Models.QuestionCategory { Id = 1, IconName = "Category 1",IconLibrary="img 1" };
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,17 @@
|
||||
using DamageAssesment.Api.Questions.Db;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
|
||||
namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
public class MockData
|
||||
{
|
||||
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.Question>, string)> getOkResponse()
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.MultiLanguage>, string)> getOkResponse()
|
||||
{
|
||||
IEnumerable<Questions.Models.Question> list = new List<Questions.Models.Question>();
|
||||
IEnumerable<Questions.Models.MultiLanguage> list = new List<Questions.Models.MultiLanguage>();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
list.Append(new Questions.Models.Question { Id = i, TypeText = "Text" + i, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, QuestionGroup = "group1",CategoryId=i });
|
||||
list.Append(new Questions.Models.MultiLanguage { Id = i, TypeText = "Text" + i, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId=i });
|
||||
}
|
||||
return (true, list, null);
|
||||
}
|
||||
@ -30,38 +23,38 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
List<Models.Question> question = new List<Models.Question>();
|
||||
question.Add(new Models.Question { Id = i, TypeText = "Text" + i, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, QuestionGroup = "group1", CategoryId = i });
|
||||
List<Models.MultiLanguage> question = new List<Models.MultiLanguage>();
|
||||
question.Add(new Models.MultiLanguage { Id = i, TypeText = "Text" + i, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = i });
|
||||
list.Append(new Questions.Models.SurveyQuestions
|
||||
{
|
||||
CategoryId = i,
|
||||
CategoryImage = "img" + i,
|
||||
CategoryName = "Category " + i,
|
||||
Questions = question
|
||||
IconLibrary = "img" + i,
|
||||
IconName = "Category " + i,
|
||||
QuestionsText = question
|
||||
});
|
||||
}
|
||||
return (true, list, null);
|
||||
}
|
||||
|
||||
public static async Task<(bool, Questions.Models.Question, string)> getOkResponse(int Id)
|
||||
public static async Task<(bool, Questions.Models.MultiLanguage, string)> getOkResponse(int Id)
|
||||
{
|
||||
var Questions = await getOkResponse();
|
||||
var Question = Questions.Item2.FirstOrDefault(s => s.Id == Id);
|
||||
return (true, Question, null);
|
||||
}
|
||||
|
||||
public static async Task<(bool, Questions.Models.Question, string)> getBadRequestResponse()
|
||||
public static async Task<(bool, Questions.Models.MultiLanguage, string)> getBadRequestResponse()
|
||||
{
|
||||
return (false, null, "Bad Request");
|
||||
}
|
||||
|
||||
public static async Task<(bool, Questions.Models.Question, string)> getNotFoundResponse()
|
||||
public static async Task<(bool, Questions.Models.MultiLanguage, string)> getNotFoundResponse()
|
||||
{
|
||||
return (false, null, "Not Found");
|
||||
}
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.Question>, string)> getNoContentResponse()
|
||||
public static async Task<(bool, IEnumerable<Questions.Models.MultiLanguage>, string)> getNoContentResponse()
|
||||
{
|
||||
IEnumerable<Questions.Models.Question> list = new List<Questions.Models.Question>();
|
||||
IEnumerable<Questions.Models.MultiLanguage> list = new List<Questions.Models.MultiLanguage>();
|
||||
return (false, list, null);
|
||||
}
|
||||
public static async Task<(bool, List<Questions.Models.SurveyQuestions>, string)> getNoSurveyContentResponse()
|
||||
@ -79,7 +72,7 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
};
|
||||
List<Models.QuestionsTranslation> QuestionsTranslations = new List<Models.QuestionsTranslation>();
|
||||
QuestionsTranslations.Add(QuestionsTranslation);
|
||||
return new Questions.Models.Question { Id = 1, Questions=QuestionsTranslations, TypeText = "Text 1", SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, QuestionGroup = "group1" ,CategoryId=1};
|
||||
return new Questions.Models.Question { Id = 1, Questions=QuestionsTranslations, TypeText = "Text 1", SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId=1};
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,7 @@
|
||||
|
||||
using AutoMapper;
|
||||
using DamageAssesment.Api.Questions.Controllers;
|
||||
using DamageAssesment.Api.Questions.Db;
|
||||
using DamageAssesment.Api.Questions.Interfaces;
|
||||
using DamageAssesment.Api.Questions.Models;
|
||||
using DamageAssesment.Api.Questions.Profiles;
|
||||
using DamageAssesment.Api.Questions.Providers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace DamageAssesment.Api.Questions.Test
|
||||
@ -22,10 +13,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await MockData.getOkResponse();
|
||||
mockQuestionService.Setup(service => service.GetQuestionsAsync()).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionsAsync(null)).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionsAsync();
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionsAsync(null);
|
||||
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
}
|
||||
@ -35,10 +26,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await MockData.getNoContentResponse();
|
||||
mockQuestionService.Setup(service => service.GetQuestionsAsync()).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionsAsync(null)).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (NoContentResult)await QuestionProvider.GetQuestionsAsync();
|
||||
var result = (NoContentResult)await QuestionProvider.GetQuestionsAsync(null);
|
||||
|
||||
Assert.Equal(204, result.StatusCode);
|
||||
}
|
||||
@ -48,10 +39,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await MockData.getOkResponse(1);
|
||||
mockQuestionService.Setup(service => service.GetQuestionAsync(1)).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionAsync(1,null)).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionAsync(1);
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionByIdAsync(1,null);
|
||||
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
}
|
||||
@ -61,10 +52,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await MockData.getNotFoundResponse();
|
||||
mockQuestionService.Setup(service => service.GetQuestionAsync(99)).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionAsync(99,null)).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (NotFoundResult)await QuestionProvider.GetQuestionAsync(99);
|
||||
var result = (NotFoundResult)await QuestionProvider.GetQuestionByIdAsync(99,null);
|
||||
Assert.Equal(404, result.StatusCode);
|
||||
}
|
||||
|
||||
@ -197,10 +188,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await CategoryMockData.getOkResponse();
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoriesAsync()).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoriesAsync("en")).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionCategoriesAsync();
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionCategoriesAsync("en");
|
||||
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
}
|
||||
@ -210,10 +201,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await CategoryMockData.getNoContentResponse();
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoriesAsync()).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoriesAsync("en")).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (NoContentResult)await QuestionProvider.GetQuestionCategoriesAsync();
|
||||
var result = (NoContentResult)await QuestionProvider.GetQuestionCategoriesAsync("en");
|
||||
|
||||
Assert.Equal(204, result.StatusCode);
|
||||
}
|
||||
@ -223,10 +214,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await CategoryMockData.getOkResponse(1);
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoryAsync(1)).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoryAsync(1, "en")).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionCategoryAsync(1);
|
||||
var result = (OkObjectResult)await QuestionProvider.GetQuestionCategoryAsync(1, "en");
|
||||
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
}
|
||||
@ -236,10 +227,10 @@ namespace DamageAssesment.Api.Questions.Test
|
||||
{
|
||||
var mockQuestionService = new Mock<IQuestionsProvider>();
|
||||
var mockResponse = await CategoryMockData.getNotFoundResponse();
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoryAsync(99)).ReturnsAsync(mockResponse);
|
||||
mockQuestionService.Setup(service => service.GetQuestionCategoryAsync(99, "en")).ReturnsAsync(mockResponse);
|
||||
|
||||
var QuestionProvider = new QuestionsController(mockQuestionService.Object);
|
||||
var result = (NotFoundResult)await QuestionProvider.GetQuestionCategoryAsync(99);
|
||||
var result = (NotFoundResult)await QuestionProvider.GetQuestionCategoryAsync(99, "en");
|
||||
Assert.Equal(404, result.StatusCode);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user