Update test case project for UserAccess and SurveyResponse modules. Renaming of SurveyResponses to Responses.

This commit is contained in:
Reginald CHERENFANT JASMIN 2023-09-26 15:22:26 -05:00
parent f6387fc371
commit 46520c7e62
42 changed files with 187 additions and 195 deletions

View File

@ -1,36 +1,26 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.SurveyResponses.Controllers namespace DamageAssesment.Api.Responses.Controllers
{ {
[ApiController] [ApiController]
public class SurveyResponsesController : ControllerBase public class ResponsesController : ControllerBase
{ {
private readonly ISurveysResponse surveyResponseProvider; private readonly ISurveysResponse surveyResponseProvider;
private string token; public ResponsesController(ISurveysResponse surveyResponseProvider)
private readonly IHttpContextAccessor httpContextAccessor;
public SurveyResponsesController(ISurveysResponse surveyResponseProvider, IHttpContextAccessor httpContextAccessor)
{ {
this.surveyResponseProvider = surveyResponseProvider; this.surveyResponseProvider = surveyResponseProvider;
this.httpContextAccessor = httpContextAccessor;
token = httpContextAccessor.HttpContext.Request.Headers.Authorization;
if (token != null)
{
token = token.Replace("Bearer ", string.Empty);
} else
{
token = "";
}
} }
/// <summary> /// <summary>
/// GET request for retrieving survey responses. /// GET request for retrieving survey responses.
/// </summary> /// </summary>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses")] [HttpGet("Responses")]
public async Task<ActionResult> GetSurveyResponsesAsync() public async Task<ActionResult> GetSurveyResponsesAsync()
{ {
var result = await this.surveyResponseProvider.GetSurveyResponsesAsync(token); var result = await this.surveyResponseProvider.GetSurveyResponsesAsync();
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.surveyResponses); return Ok(result.surveyResponses);
@ -44,11 +34,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// <summary> /// <summary>
/// GET request for retrieving survey responses by survey ID. /// GET request for retrieving survey responses by survey ID.
/// </summary> /// </summary>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses/BySurvey/{surveyid}")] [HttpGet("Responses/BySurvey/{surveyid}")]
public async Task<ActionResult> GetSurveyResponsesAsync(int surveyid) public async Task<ActionResult> GetSurveyResponsesAsync(int surveyid)
{ {
var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAsync(surveyid, token); var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAsync(surveyid);
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.SurveyResponses); return Ok(result.SurveyResponses);
@ -60,11 +50,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// </summary> /// </summary>
/// <param name="surveyid">The ID of the survey for which responses are to be retrieved.</param> /// <param name="surveyid">The ID of the survey for which responses are to be retrieved.</param>
/// <param name="locationid">The ID of the location for which responses are to be retrieved.</param> /// <param name="locationid">The ID of the location for which responses are to be retrieved.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses/{surveyid}/{locationid}")] [HttpGet("Responses/{surveyid}/{locationid}")]
public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyid, int locationid) public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyid, int locationid)
{ {
var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(surveyid, locationid, token); var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(surveyid, locationid);
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.SurveyResponses); return Ok(result.SurveyResponses);
@ -78,11 +68,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param> /// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
/// <param name="questionId">The ID of the question for which responses are to be retrieved.</param> /// <param name="questionId">The ID of the question for which responses are to be retrieved.</param>
/// <param name="answer">The answer for which responses are to be retrieved.</param> /// <param name="answer">The answer for which responses are to be retrieved.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses/ByAnswer/{surveyid}/{questionid}/{answer}")] [HttpGet("Responses/ByAnswer/{surveyid}/{questionid}/{answer}")]
public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyid, int questionid, string answer) public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyid, int questionid, string answer)
{ {
var result = await surveyResponseProvider.GetResponsesByAnswerAsync(surveyid, questionid, answer, token); var result = await surveyResponseProvider.GetResponsesByAnswerAsync(surveyid, questionid, answer);
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.SurveyResponses); return Ok(result.SurveyResponses);
@ -94,11 +84,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// GET request for retrieving answers from survey responses by survey ID and region. /// GET request for retrieving answers from survey responses by survey ID and region.
/// </summary> /// </summary>
/// <param name="surveyId">The ID of the survey for which answers are to be retrieved.</param> /// <param name="surveyId">The ID of the survey for which answers are to be retrieved.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses/ByRegion/{surveyid}")] [HttpGet("Responses/ByRegion/{surveyid}")]
public async Task<ActionResult> GetAnswersByRegionAsync(int surveyid) public async Task<ActionResult> GetAnswersByRegionAsync(int surveyid)
{ {
var result = await this.surveyResponseProvider.GetAnswersByRegionAsync(surveyid, token); var result = await this.surveyResponseProvider.GetAnswersByRegionAsync(surveyid);
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.Answers); return Ok(result.Answers);
@ -109,11 +99,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// GET request for retrieving survey responses by survey ID and maintenance center. /// GET request for retrieving survey responses by survey ID and maintenance center.
/// </summary> /// </summary>
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param> /// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses/ByMaintenanceCenter/{surveyid}")] [HttpGet("Responses/ByMaintenanceCenter/{surveyid}")]
public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyid) public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyid)
{ {
var result = await this.surveyResponseProvider.GetSurveyResponsesByMaintenanceCenterAsync(surveyid, token); var result = await this.surveyResponseProvider.GetSurveyResponsesByMaintenanceCenterAsync(surveyid);
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.SurveyResponses); return Ok(result.SurveyResponses);
@ -124,11 +114,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// GET request for retrieving a survey response by response ID. /// GET request for retrieving a survey response by response ID.
/// </summary> /// </summary>
/// <param name="responseId">The ID of the survey response to be retrieved.</param> /// <param name="responseId">The ID of the survey response to be retrieved.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpGet("Responses/{id}")] [HttpGet("Responses/{id}")]
public async Task<ActionResult> GetSurveyResponseByIdAsync(int id) public async Task<ActionResult> GetSurveyResponseByIdAsync(int id)
{ {
var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(id, token); var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(id);
if (result.IsSuccess) if (result.IsSuccess)
{ {
return Ok(result.SurveyResponse); return Ok(result.SurveyResponse);
@ -140,7 +130,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// POST request for creating a new survey response. /// POST request for creating a new survey response.
/// </summary> /// </summary>
/// <param name="surveyResponse">The survey response object to be created.</param> /// <param name="surveyResponse">The survey response object to be created.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpPost("Responses")] [HttpPost("Responses")]
public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse) public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse)
{ {
@ -156,7 +146,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// </summary> /// </summary>
/// <param name="Id">The ID of the survey response to be updated.</param> /// <param name="Id">The ID of the survey response to be updated.</param>
/// <param name="surveyResponse">The updated survey response object.</param> /// <param name="surveyResponse">The updated survey response object.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpPut("Responses/{id}")] [HttpPut("Responses/{id}")]
public async Task<ActionResult> PutSurveyResponseAsync(int id, Models.SurveyResponse surveyResponse) public async Task<ActionResult> PutSurveyResponseAsync(int id, Models.SurveyResponse surveyResponse)
{ {
@ -173,7 +163,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// <summary> /// <summary>
/// DELETE request for deleting an existing survey response. /// DELETE request for deleting an existing survey response.
/// </summary> /// </summary>
[Authorize(Roles = "admin,survey,user,report")]
[HttpDelete("Responses/{id}")] [HttpDelete("Responses/{id}")]
public async Task<ActionResult> DeleteSurveyResponseAsync(int id) public async Task<ActionResult> DeleteSurveyResponseAsync(int id)
{ {
@ -188,11 +178,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
/// POST request for submitting survey with multiple answers. /// POST request for submitting survey with multiple answers.
/// </summary> /// </summary>
/// <param name="request">The answers to be submitted for the survey.</param> /// <param name="request">The answers to be submitted for the survey.</param>
[Authorize(Roles = "admin,survey,user,report")]
[HttpPost("Responses/Answers")] [HttpPost("Responses/Answers")]
public async Task<ActionResult> PostSurveyAnswersAsync(Request request) public async Task<ActionResult> PostSurveyAnswersAsync(Request request)
{ {
var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request, token); var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request);
if (result.IsSuccess) if (result.IsSuccess)
return Ok(result.SurveyResponse); return Ok(result.SurveyResponse);

View File

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace DamageAssesment.Api.SurveyResponses.Db namespace DamageAssesment.Api.Responses.Db
{ {
public class SurveyResponse public class SurveyResponse
{ {

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace DamageAssesment.Api.SurveyResponses.Db namespace DamageAssesment.Api.Responses.Db
{ {
public class SurveyResponseDbContext:DbContext public class SurveyResponseDbContext:DbContext
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface IAnswerServiceProvider public interface IAnswerServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface IAttachmentServiceProvider public interface IAttachmentServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface IEmployeeServiceProvider public interface IEmployeeServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface IHttpUtil public interface IHttpUtil
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface ILocationServiceProvider public interface ILocationServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface IQuestionServiceProvider public interface IQuestionServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface IRegionServiceProvider public interface IRegionServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface ISurveyServiceProvider public interface ISurveyServiceProvider
{ {

View File

@ -1,23 +1,22 @@
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.SurveyResponses.Interfaces namespace DamageAssesment.Api.Responses.Interfaces
{ {
public interface ISurveysResponse public interface ISurveysResponse
{ {
Task<(bool IsSuccess, dynamic Answers, string ErrorMessage)> GetAnswersByRegionAsync(int surveyId, string token); Task<(bool IsSuccess, dynamic Answers, string ErrorMessage)> GetAnswersByRegionAsync(int surveyId);
Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyResponseAsync(Models.SurveyResponse surveyResponse); Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyResponseAsync(Models.SurveyResponse surveyResponse);
// Task<(bool IsSuccess,dynamic surveyResponses, string ErrorMessage)> GetSurveyResponseAsync(int responseId); // Task<(bool IsSuccess,dynamic surveyResponses, string ErrorMessage)> GetSurveyResponseAsync(int responseId);
Task<(bool IsSuccess, dynamic surveyResponses, string ErrorMessage)> GetSurveyResponsesAsync(string token); Task<(bool IsSuccess, dynamic surveyResponses, string ErrorMessage)> GetSurveyResponsesAsync();
Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse); Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse);
Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> DeleteSurveyResponseAsync(int Id); Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> DeleteSurveyResponseAsync(int Id);
Task<(bool IsSuccess, dynamic SurveyResponse, string ErrorMessage)> GetSurveyResponseByIdAsync(int responseId, string token); Task<(bool IsSuccess, dynamic SurveyResponse, string ErrorMessage)> GetSurveyResponseByIdAsync(int responseId);
Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAsync(int surveyId, string token); Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAsync(int surveyId);
Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, int locationId, string token); Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, int locationId);
Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesByMaintenanceCenterAsync(int surveyId, string token); Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesByMaintenanceCenterAsync(int surveyId);
Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetResponsesByAnswerAsync(int surveyId, int questionId, string answer, string token); Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetResponsesByAnswerAsync(int surveyId, int questionId, string answer);
Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Request request, string token); Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Request request);
} }
} }

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Answer public class Answer
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class AnswerRequest public class AnswerRequest
{ {

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Attachment public class Attachment
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class AttachmentInfo public class AttachmentInfo
{ {

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Employee public class Employee
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Location public class Location
{ {

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Question public class Question
{ {

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Region public class Region
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Request public class Request
{ {

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class Survey public class Survey
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class SurveyQuestions public class SurveyQuestions
{ {

View File

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class SurveyResponse public class SurveyResponse
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Models namespace DamageAssesment.Api.Responses.Models
{ {
public class SurveyTranslation public class SurveyTranslation
{ {

View File

@ -1,4 +1,4 @@
namespace DamageAssesment.Api.SurveyResponses.Profiles namespace DamageAssesment.Api.Responses.Profiles
{ {
public class SurveyResponsesProvider : AutoMapper.Profile public class SurveyResponsesProvider : AutoMapper.Profile
{ {

View File

@ -1,7 +1,7 @@
using DamageAssesment.Api.SurveyResponses.Db; using DamageAssesment.Api.Responses.Db;
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Services; using DamageAssesment.Api.Responses.Services;
using DamageAssesment.Api.SurveyResponses.Providers; using DamageAssesment.Api.Responses.Providers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Polly; using Polly;
using System.Reflection; using System.Reflection;

View File

@ -9,7 +9,7 @@
} }
}, },
"profiles": { "profiles": {
"DamageAssesment.Api.SurveyResponses": { "DamageAssesment.Api.Responses": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

View File

@ -1,10 +1,10 @@
using AutoMapper; using AutoMapper;
using DamageAssesment.Api.SurveyResponses.Db; using DamageAssesment.Api.Responses.Db;
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace DamageAssesment.Api.SurveyResponses.Providers namespace DamageAssesment.Api.Responses.Providers
{ {
public class SurveyResponsesProvider : ISurveysResponse public class SurveyResponsesProvider : ISurveysResponse
{ {
@ -18,8 +18,10 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
private readonly IQuestionServiceProvider questionServiceProvider; private readonly IQuestionServiceProvider questionServiceProvider;
private readonly ISurveyServiceProvider surveyServiceProvider; private readonly ISurveyServiceProvider surveyServiceProvider;
private readonly IMapper mapper; private readonly IMapper mapper;
private readonly IHttpContextAccessor httpContextAccessor;
private string token;
public SurveyResponsesProvider(SurveyResponseDbContext surveyResponseDbContext, ILogger<SurveyResponsesProvider> logger, IAnswerServiceProvider answerServiceProvider, IRegionServiceProvider regionServiceProvider, ILocationServiceProvider locationServiceProvider, IEmployeeServiceProvider employeeServiceProvider, IAttachmentServiceProvider attachmentServiceProvider, IQuestionServiceProvider questionServiceProvider, ISurveyServiceProvider surveyServiceProvider, IMapper mapper) public SurveyResponsesProvider(SurveyResponseDbContext surveyResponseDbContext, ILogger<SurveyResponsesProvider> logger, IAnswerServiceProvider answerServiceProvider, IRegionServiceProvider regionServiceProvider, ILocationServiceProvider locationServiceProvider, IEmployeeServiceProvider employeeServiceProvider, IAttachmentServiceProvider attachmentServiceProvider, IQuestionServiceProvider questionServiceProvider, ISurveyServiceProvider surveyServiceProvider, IMapper mapper, IHttpContextAccessor httpContextAccessor)
{ {
this.surveyResponseDbContext = surveyResponseDbContext; this.surveyResponseDbContext = surveyResponseDbContext;
this.logger = logger; this.logger = logger;
@ -30,8 +32,19 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
this.attachmentServiceProvider = attachmentServiceProvider; this.attachmentServiceProvider = attachmentServiceProvider;
this.questionServiceProvider = questionServiceProvider; this.questionServiceProvider = questionServiceProvider;
this.surveyServiceProvider = surveyServiceProvider; this.surveyServiceProvider = surveyServiceProvider;
this.httpContextAccessor = httpContextAccessor;
this.mapper = mapper; this.mapper = mapper;
// seedData();
token = httpContextAccessor.HttpContext.Request.Headers.Authorization;
if (token != null)
{
token = token.Replace("Bearer ", string.Empty);
}
else
{
token = "";
}
// seedData();
} }
private void seedData() private void seedData()
@ -42,13 +55,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 2, SurveyId = 1, EmployeeId = 2, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 2, SurveyId = 1, EmployeeId = 2, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now });
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 3, SurveyId = 3, EmployeeId = 4, LocationId = 1, ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 3, SurveyId = 3, EmployeeId = 4, LocationId = 1, ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now });
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 4, SurveyId = 4, EmployeeId = 1, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "false", CreatedDate = DateTime.Now }); surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 4, SurveyId = 4, EmployeeId = 1, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "false", CreatedDate = DateTime.Now });
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 6, SurveyId = 1, EmployeeId = 4, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 5, SurveyId = 1, EmployeeId = 4, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now });
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 7, SurveyId = 1, EmployeeId = 4, LocationId = 3, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "false", CreatedDate = DateTime.Now }); surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 6, SurveyId = 1, EmployeeId = 4, LocationId = 3, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "false", CreatedDate = DateTime.Now });
surveyResponseDbContext.SaveChanges(); surveyResponseDbContext.SaveChanges();
} }
} }
public async Task<(bool IsSuccess, dynamic Answers, string ErrorMessage)> GetAnswersByRegionAsync(int surveyId,string token) public async Task<(bool IsSuccess, dynamic Answers, string ErrorMessage)> GetAnswersByRegionAsync(int surveyId)
{ {
try try
{ {
@ -57,7 +70,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (listSurveyResponse.Any()) if (listSurveyResponse.Any())
{ {
var answers = await getAnswersByRegionAndSurveyIdAsync(listSurveyResponse,token); var answers = await getAnswersByRegionAndSurveyIdAsync(listSurveyResponse);
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
} }
else else
@ -72,7 +85,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
} }
public async Task<(bool IsSuccess, dynamic SurveyResponse, string ErrorMessage)> GetSurveyResponseByIdAsync(int responseId, string token) public async Task<(bool IsSuccess, dynamic SurveyResponse, string ErrorMessage)> GetSurveyResponseByIdAsync(int responseId)
{ {
try try
{ {
@ -81,7 +94,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (surveyResponse != null) if (surveyResponse != null)
{ {
var answers = await getSurveyResponseByResponseIdAsync(surveyResponse, token); var answers = await getSurveyResponseByResponseIdAsync(surveyResponse);
if (answers != null) if (answers != null)
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
@ -105,7 +118,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAsync(int surveyId, string token) public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAsync(int surveyId)
{ {
try try
{ {
@ -114,7 +127,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (survey != null) if (survey != null)
{ {
var answers = await getSurveyResponsesBySurveyIdAsync(surveyId, token); var answers = await getSurveyResponsesBySurveyIdAsync(surveyId);
if (answers != null) if (answers != null)
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
@ -136,7 +149,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
} }
public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, int locationId, string token) public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, int locationId)
{ {
try try
{ {
@ -145,7 +158,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (survey != null) if (survey != null)
{ {
var answers = await getSurveyResponsesBySurveyIdLocationIdAsync(surveyId, locationId, token); var answers = await getSurveyResponsesBySurveyIdLocationIdAsync(surveyId, locationId);
if (answers != null) if (answers != null)
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
@ -167,7 +180,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
} }
public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesByMaintenanceCenterAsync(int surveyId, string token) public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesByMaintenanceCenterAsync(int surveyId)
{ {
try try
{ {
@ -176,7 +189,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (survey != null) if (survey != null)
{ {
var answers = await getResultsByMaintenanceCenterAsync(surveyId,token); var answers = await getResultsByMaintenanceCenterAsync(surveyId);
if (answers != null) if (answers != null)
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
@ -198,7 +211,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
} }
public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetResponsesByAnswerAsync(int surveyId, int questionId, string answer, string token) public async Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetResponsesByAnswerAsync(int surveyId, int questionId, string answer)
{ {
try try
{ {
@ -210,7 +223,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (survey != null && question != null && IsCorrectAnswer) if (survey != null && question != null && IsCorrectAnswer)
{ {
var answers = await getSurveyResponsesByAnswerAsync(survey, question, answer, token); var answers = await getSurveyResponsesByAnswerAsync(survey, question, answer);
if (answers != null) if (answers != null)
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
@ -233,11 +246,11 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
public async Task<(bool IsSuccess, dynamic surveyResponses, string ErrorMessage)> GetSurveyResponsesAsync(string token) public async Task<(bool IsSuccess, dynamic surveyResponses, string ErrorMessage)> GetSurveyResponsesAsync()
{ {
try try
{ {
var answers = await getAllSurveyResponsesAsync(token); var answers = await getAllSurveyResponsesAsync();
if (answers != null) if (answers != null)
return (true, answers, "Request Successful."); return (true, answers, "Request Successful.");
@ -341,7 +354,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
//Method to get Answers by region with surveyId as input parameter //Method to get Answers by region with surveyId as input parameter
private async Task<dynamic> getAnswersByRegionAndSurveyIdAsync(IQueryable<Db.SurveyResponse> surveyResponses, string token) private async Task<dynamic> getAnswersByRegionAndSurveyIdAsync(IQueryable<Db.SurveyResponse> surveyResponses)
{ {
try try
{ {
@ -427,7 +440,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
//Method to get Survey Response by ResponseId //Method to get Survey Response by ResponseId
private async Task<dynamic> getSurveyResponseByResponseIdAsync(Db.SurveyResponse surveyResponse, string token) private async Task<dynamic> getSurveyResponseByResponseIdAsync(Db.SurveyResponse surveyResponse)
{ {
try try
{ {
@ -470,7 +483,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
//Method to get Survey Responses by surveyId //Method to get Survey Responses by surveyId
private async Task<dynamic> getSurveyResponsesBySurveyIdAsync(int surveyId, string token) private async Task<dynamic> getSurveyResponsesBySurveyIdAsync(int surveyId)
{ {
try try
{ {
@ -519,7 +532,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
//Method to get All Survey Responses //Method to get All Survey Responses
private async Task<dynamic> getAllSurveyResponsesAsync(string token) private async Task<dynamic> getAllSurveyResponsesAsync()
{ {
try try
{ {
@ -564,7 +577,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
//Method to get Answers By Maintenance Center by surveyId //Method to get Answers By Maintenance Center by surveyId
private async Task<dynamic> getResultsByMaintenanceCenterAsync(int surveyId, string token) private async Task<dynamic> getResultsByMaintenanceCenterAsync(int surveyId)
{ {
try try
{ {
@ -624,7 +637,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
//Method to get Survey Responses by surveyId and LocationId //Method to get Survey Responses by surveyId and LocationId
private async Task<dynamic> getSurveyResponsesBySurveyIdLocationIdAsync(int surveyId, int locationId, string token) private async Task<dynamic> getSurveyResponsesBySurveyIdLocationIdAsync(int surveyId, int locationId)
{ {
try try
{ {
@ -671,7 +684,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
//Method to get Survey Responses by surveyId questionId and answer //Method to get Survey Responses by surveyId questionId and answer
private async Task<dynamic> getSurveyResponsesByAnswerAsync(Survey survey, Question question, string answer, string token) private async Task<dynamic> getSurveyResponsesByAnswerAsync(Survey survey, Question question, string answer)
{ {
try try
{ {
@ -717,7 +730,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
async Task<bool> ProcessAnswers(AnswerRequest answerRequest, int surveyResponseId,string token) async Task<bool> ProcessAnswers(AnswerRequest answerRequest, int surveyResponseId)
{ {
if (answerRequest != null) if (answerRequest != null)
{ {
@ -747,7 +760,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
} }
} }
public async Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Models.Request request, string token) public async Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Models.Request request)
{ {
try try
{ {
@ -757,7 +770,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
if (response.IsSuccess) if (response.IsSuccess)
{ {
var surveyResponse = response.SurveyResponse; var surveyResponse = response.SurveyResponse;
var tasks = request.Answers.Select(x => ProcessAnswers(x, surveyResponse.Id,token)); var tasks = request.Answers.Select(x => ProcessAnswers(x, surveyResponse.Id));
await Task.WhenAll(tasks); await Task.WhenAll(tasks);
return (true, surveyResponse, null); return (true, surveyResponse, null);
} }

View File

@ -1,10 +1,10 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class AnswerServiceProvider : ServiceProviderBase, IAnswerServiceProvider public class AnswerServiceProvider : ServiceProviderBase, IAnswerServiceProvider
{ {

View File

@ -1,8 +1,8 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class AttachmentServiceProvider : ServiceProviderBase, IAttachmentServiceProvider public class AttachmentServiceProvider : ServiceProviderBase, IAttachmentServiceProvider
{ {

View File

@ -1,9 +1,9 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.Routing;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class EmployeeServiceProvider : ServiceProviderBase, IEmployeeServiceProvider public class EmployeeServiceProvider : ServiceProviderBase, IEmployeeServiceProvider
{ {

View File

@ -1,9 +1,9 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text; using System.Text;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class HttpUtil : IHttpUtil public class HttpUtil : IHttpUtil
{ {

View File

@ -1,8 +1,8 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider
{ {

View File

@ -1,8 +1,8 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider
{ {

View File

@ -1,8 +1,8 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider
{ {

View File

@ -1,6 +1,6 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class ServiceProviderBase public class ServiceProviderBase
{ {

View File

@ -1,8 +1,8 @@
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services namespace DamageAssesment.Api.Responses.Services
{ {
public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
{ {

View File

@ -2,8 +2,6 @@
using DamageAssesment.Api.UsersAccess.Models; using DamageAssesment.Api.UsersAccess.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
namespace DamageAssesment.Api.UsersAccess.Controllers namespace DamageAssesment.Api.UsersAccess.Controllers
{ {
@ -20,14 +18,6 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
[HttpPost("token/{employecode}")] [HttpPost("token/{employecode}")]
public async Task<ActionResult> AuthenticateAsync(string employecode) public async Task<ActionResult> AuthenticateAsync(string employecode)
{ {
/* if (Request.Headers.TryGetValue("Authorization", out var headerAuth))
{
var jwtToken = headerAuth.First().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1];
var handler = new JwtSecurityTokenHandler();
var jsonToken = handler.ReadToken(jwtToken) as JwtSecurityToken;
return Ok(jsonToken.Payload.Sub);
} */
var result = await userAccessProvider.AuthenticateAsync(employecode); var result = await userAccessProvider.AuthenticateAsync(employecode);
if (result.IsSuccess) if (result.IsSuccess)
{ {

View File

@ -1,9 +1,9 @@
 
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace DamageAssesment.Api.SurveyResponses.Test namespace DamageAssesment.Api.Responses.Test
{ {
public class MockData public class MockData
{ {

View File

@ -1,20 +1,19 @@
using DamageAssesment.Api.SurveyResponses.Controllers; using DamageAssesment.Api.Responses.Controllers;
using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models; using DamageAssesment.Api.Responses.Models;
using DamageAssesment.Api.SurveyResponses.Test; using DamageAssesment.Api.Responses.Test;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Moq; using Moq;
using Xunit; using Xunit;
using Xunit.Sdk;
namespace DamageAssesment.SurveyResponses.Test namespace DamageAssesment.SurveyResponses.Test
{ {
public class SurveyResponsesServiceTest public class ResponsesServiceTest
{ {
private Mock<ISurveysResponse> mockSurveyResponseService; private Mock<ISurveysResponse> mockSurveyResponseService;
private string token { get; set; } private string token { get; set; }
public SurveyResponsesServiceTest() public ResponsesServiceTest()
{ {
mockSurveyResponseService = new Mock<ISurveysResponse>(); mockSurveyResponseService = new Mock<ISurveysResponse>();
token = Guid.NewGuid().ToString(); token = Guid.NewGuid().ToString();
@ -25,8 +24,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject); var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync(token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync()).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(); var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync();
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -35,8 +34,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync(token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync()).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (BadRequestObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(); var result = (BadRequestObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync();
Assert.Equal(400, result.StatusCode); Assert.Equal(400, result.StatusCode);
} }
@ -46,8 +45,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(); var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1); var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -56,8 +55,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1); var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
Assert.Equal(204, result.StatusCode); Assert.Equal(204, result.StatusCode);
} }
@ -70,8 +69,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(); var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1); var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -80,8 +79,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1); var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1);
Assert.Equal(204, result.StatusCode); Assert.Equal(204, result.StatusCode);
} }
@ -91,8 +90,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(); var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes", token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes")).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes"); var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes");
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -101,8 +100,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes", token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes")).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes"); var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes");
Assert.Equal(204, result.StatusCode); Assert.Equal(204, result.StatusCode);
} }
@ -113,8 +112,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(); var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByRegionAsync(1); var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByRegionAsync(1);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -123,8 +122,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByRegionAsync(1); var result = (NoContentResult)await surveyResponseProvider.GetAnswersByRegionAsync(1);
Assert.Equal(204, result.StatusCode); Assert.Equal(204, result.StatusCode);
} }
@ -134,8 +133,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(); var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1); var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -144,8 +143,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1); var result = (NoContentResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1);
Assert.Equal(204, result.StatusCode); Assert.Equal(204, result.StatusCode);
} }
@ -155,8 +154,8 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(); var mockResponse = await MockData.getOkResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1); var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -165,8 +164,8 @@ namespace DamageAssesment.SurveyResponses.Test
public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode204() public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode204()
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1, token)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1); var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
Assert.Equal(204, result.StatusCode); Assert.Equal(204, result.StatusCode);
} }
@ -178,7 +177,7 @@ namespace DamageAssesment.SurveyResponses.Test
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject); var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse);
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject); var result = (OkObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -189,7 +188,7 @@ namespace DamageAssesment.SurveyResponses.Test
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse);
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
var result = (BadRequestObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject); var result = (BadRequestObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
Assert.Equal(400, result.StatusCode); Assert.Equal(400, result.StatusCode);
} }
@ -200,7 +199,7 @@ namespace DamageAssesment.SurveyResponses.Test
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject); var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse);
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject); var result = (OkObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -211,7 +210,7 @@ namespace DamageAssesment.SurveyResponses.Test
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse); ; mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse); ;
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
var result = (BadRequestObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject); var result = (BadRequestObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
Assert.Equal(400, result.StatusCode); Assert.Equal(400, result.StatusCode);
} }
@ -222,7 +221,7 @@ namespace DamageAssesment.SurveyResponses.Test
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject(); SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
var mockResponse = await MockData.getOkResponse(mockRequestObject); var mockResponse = await MockData.getOkResponse(mockRequestObject);
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse); mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse);
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
var result = (OkObjectResult)await surveyResponseController.DeleteSurveyResponseAsync(1); var result = (OkObjectResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
Assert.Equal(200, result.StatusCode); Assert.Equal(200, result.StatusCode);
} }
@ -232,7 +231,7 @@ namespace DamageAssesment.SurveyResponses.Test
{ {
var mockResponse = await MockData.getResponse(); var mockResponse = await MockData.getResponse();
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse); ; mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse); ;
var surveyResponseController = new SurveyResponsesController(mockSurveyResponseService.Object); var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
var result = (NotFoundResult)await surveyResponseController.DeleteSurveyResponseAsync(1); var result = (NotFoundResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
Assert.Equal(404, result.StatusCode); Assert.Equal(404, result.StatusCode);
} }

View File

@ -80,6 +80,7 @@ Global
{ADFB79E3-83C9-454F-A070-49D167BD28CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {ADFB79E3-83C9-454F-A070-49D167BD28CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADFB79E3-83C9-454F-A070-49D167BD28CC}.Release|Any CPU.Build.0 = Release|Any CPU {ADFB79E3-83C9-454F-A070-49D167BD28CC}.Release|Any CPU.Build.0 = Release|Any CPU
{6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Release|Any CPU.ActiveCfg = Release|Any CPU {6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Release|Any CPU.Build.0 = Release|Any CPU {6F4B9C9D-CE5D-421A-876F-57D0FEDF8049}.Release|Any CPU.Build.0 = Release|Any CPU
{730E5718-FCE1-42C0-AB76-EA020896A788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {730E5718-FCE1-42C0-AB76-EA020896A788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU