Merge resolved
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
3ba6b0c521
@ -0,0 +1,42 @@
|
|||||||
|
using Asp.Versioning;
|
||||||
|
using Dto;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
public class InquiryTableController : Controller
|
||||||
|
{
|
||||||
|
private readonly IInquiryTableService<InquiryTableDto> _inquiryTableService;
|
||||||
|
|
||||||
|
private readonly ILogger<InquiryTableController> _logger;
|
||||||
|
|
||||||
|
public InquiryTableController(IInquiryTableService<InquiryTableDto> inquiryTableService, ILogger<InquiryTableController> logger)
|
||||||
|
{
|
||||||
|
_inquiryTableService = inquiryTableService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("database/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(string), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult GetDatabaseNameByInquiryById(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("[INFORMATION] La base de données pour l'enquête avec l'id {id} a été trouvé.", id);
|
||||||
|
return Ok(new KeyValuePair<string,string>("database", _inquiryTableService.GetDatabaseNameByInquiryId(id)));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError("[ERREUR] Aucune base de données trouvée pour l'enquête avec l'id {id}.", id);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
using Asp.Versioning;
|
||||||
|
using Dto;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
public class NotepadController : Controller
|
||||||
|
{
|
||||||
|
private readonly INotepadService<NotepadDto> _notepadDataService;
|
||||||
|
|
||||||
|
private readonly ILogger<NotepadController> _logger;
|
||||||
|
|
||||||
|
public NotepadController(INotepadService<NotepadDto> notepadService, ILogger<NotepadController> logger)
|
||||||
|
{
|
||||||
|
_notepadDataService = notepadService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("notepad/{userId:int}/{inquiryId:int}")]
|
||||||
|
[ProducesResponseType(typeof(NotepadDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(void), 404)]
|
||||||
|
public IActionResult GetNotepadByUserAndInquiryById(int userId, int inquiryId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été trouvé.",
|
||||||
|
userId, inquiryId);
|
||||||
|
return Ok(_notepadDataService.GetNotepadFromUserAndInquiryId(userId,inquiryId));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"[ERREUR] Aucun bloc-notes trouvé pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||||
|
userId, inquiryId);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("notepad")]
|
||||||
|
[ProducesResponseType(typeof(void), 200)]
|
||||||
|
[ProducesResponseType(typeof(void), 404)]
|
||||||
|
public IActionResult SetNotepadByUserAndInquiryById([FromBody] NotepadDto notepad)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (notepad.InquiryId < 0 || notepad.UserId < 0 || notepad.Notes == null)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
_notepadDataService.SetNotepadFromUserAndInquiryId(notepad.UserId, notepad.InquiryId, notepad.Notes);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été créé.",
|
||||||
|
notepad.UserId, notepad.InquiryId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"[ERREUR] Aucun bloc-notes n'a pu être créé pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||||
|
notepad.UserId, notepad.InquiryId);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("notepad")]
|
||||||
|
[ProducesResponseType(typeof(void), 203)]
|
||||||
|
[ProducesResponseType(typeof(void), 404)]
|
||||||
|
public IActionResult UpdateNotepadByUserAndInquiryById([FromBody] NotepadDto notepad)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (notepad.InquiryId < 0 || notepad.UserId < 0 || notepad.Notes == null)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
_notepadDataService.UpdateNotepadFromUserAndInquiryId(notepad.UserId, notepad.InquiryId, notepad.Notes);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été mis à jour.",
|
||||||
|
notepad.UserId, notepad.InquiryId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"[ERREUR] Aucun bloc-notes n'a pu être mis à jour pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||||
|
notepad.UserId, notepad.InquiryId);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Dto;
|
||||||
|
using Model.OrderCriteria;
|
||||||
|
using Shared;
|
||||||
|
using Asp.Versioning;
|
||||||
|
|
||||||
|
namespace API.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
public class SolutionController : Controller
|
||||||
|
{
|
||||||
|
private readonly ISolutionService<SolutionDto> _solutionDataService;
|
||||||
|
|
||||||
|
private readonly ILogger<SolutionController> _logger;
|
||||||
|
|
||||||
|
public SolutionController(ISolutionService<SolutionDto> solutionDataService, ILogger<SolutionController> logger)
|
||||||
|
{
|
||||||
|
_solutionDataService = solutionDataService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("solution/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(SolutionDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult GetSolutionByInquiryById(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été trouvé.", id);
|
||||||
|
return Ok(_solutionDataService.GetSolutionByInquiryId(id));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class InquiryTableDataServiceAPI(IInquiryTableService<InquiryTableEntity> inquiryTableService) : IInquiryTableService<InquiryTableDto>
|
||||||
|
{
|
||||||
|
public string GetDatabaseNameByInquiryId(int id)
|
||||||
|
{
|
||||||
|
return inquiryTableService.GetDatabaseNameByInquiryId(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
using Shared.Mapper;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class NotepadDataServiceAPI(INotepadService<NotepadEntity> notepadService) : INotepadService<NotepadDto>
|
||||||
|
{
|
||||||
|
public NotepadDto GetNotepadFromUserAndInquiryId(int userId, int inquiryId)
|
||||||
|
{
|
||||||
|
return notepadService.GetNotepadFromUserAndInquiryId(userId, inquiryId).FromEntityToDto();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
notepadService.SetNotepadFromUserAndInquiryId(userId,inquiryId,notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
notepadService.UpdateNotepadFromUserAndInquiryId(userId,inquiryId,notes);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
using Shared.Mapper;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class SolutionDataServiceAPI(ISolutionService<SolutionEntity> solutionService) : ISolutionService<SolutionDto>
|
||||||
|
{
|
||||||
|
public SolutionDto GetSolutionByInquiryId(int id)
|
||||||
|
{
|
||||||
|
return solutionService.GetSolutionByInquiryId(id).FromEntityToDto();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace DbDataManager.Service;
|
||||||
|
|
||||||
|
public class InquiryTableDataService : IInquiryTableService<InquiryTableEntity>
|
||||||
|
{
|
||||||
|
private UserDbContext DbContext { get; set; }
|
||||||
|
|
||||||
|
public InquiryTableDataService(UserDbContext context)
|
||||||
|
{
|
||||||
|
DbContext = context;
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetDatabaseNameByInquiryId(int id)
|
||||||
|
{
|
||||||
|
var inquiryTable = DbContext.InquiryTables.FirstOrDefault(i => i.OwnerId == id);
|
||||||
|
if (inquiryTable == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Erreur, impossible de trouver l'objet InquiryTable pour l'enquête d'id {id}",
|
||||||
|
nameof(id));
|
||||||
|
}
|
||||||
|
return inquiryTable.DatabaseName;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace DbDataManager.Service;
|
||||||
|
|
||||||
|
public class NotepadDataService : INotepadService<NotepadEntity>
|
||||||
|
{
|
||||||
|
private UserDbContext DbContext { get; set; }
|
||||||
|
|
||||||
|
public NotepadDataService(UserDbContext context)
|
||||||
|
{
|
||||||
|
DbContext = context;
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
public NotepadEntity GetNotepadFromUserAndInquiryId(int userId, int inquiryId)
|
||||||
|
{
|
||||||
|
var user = DbContext.Users.FirstOrDefault(u => u.Id == userId);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, aucun utilisateur ne possède l'ID fourni");
|
||||||
|
}
|
||||||
|
var inquiry = DbContext.Inquiries.FirstOrDefault(i => i.Id == inquiryId);
|
||||||
|
if (inquiry == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, aucune enquête ne possède l'ID fourni");
|
||||||
|
}
|
||||||
|
var notepad = DbContext.Notepads.FirstOrDefault(n => n.UserId == userId && n.InquiryId == inquiryId);
|
||||||
|
if (notepad == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, aucun bloc-notes n'existe pour l'utilisateur et l'enquête donnés");
|
||||||
|
}
|
||||||
|
return notepad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
var user = DbContext.Users.FirstOrDefault(u => u.Id == userId);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, aucun utilisateur ne possède l'ID fourni");
|
||||||
|
}
|
||||||
|
var inquiry = DbContext.Inquiries.FirstOrDefault(i => i.Id == inquiryId);
|
||||||
|
if (inquiry == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, aucune enquête ne possède l'ID fourni");
|
||||||
|
}
|
||||||
|
var notepad = DbContext.Notepads.FirstOrDefault(n => n.UserId == userId && n.InquiryId == inquiryId);
|
||||||
|
if (notepad != null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, un bloc-notes existe déjà pour l'utilisateur et l'enquête donnés");
|
||||||
|
}
|
||||||
|
DbContext.Notepads.Add(new NotepadEntity { UserId = userId, InquiryId = inquiryId, Notes = notes });
|
||||||
|
DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
var notepad = GetNotepadFromUserAndInquiryId(userId, inquiryId);
|
||||||
|
notepad.Notes = notes;
|
||||||
|
DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace DbDataManager.Service;
|
||||||
|
|
||||||
|
public class SolutionDataService : ISolutionService<SolutionEntity>
|
||||||
|
{
|
||||||
|
private UserDbContext DbContext { get; set; }
|
||||||
|
|
||||||
|
public SolutionDataService(UserDbContext context)
|
||||||
|
{
|
||||||
|
DbContext = context;
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SolutionEntity GetSolutionByInquiryId(int id)
|
||||||
|
{
|
||||||
|
var solution = DbContext.Solutions.FirstOrDefault(s => s.OwnerId == id);
|
||||||
|
if (solution == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Impossible de trouver la solution pour l'enquête d'id {id}", nameof(id));
|
||||||
|
}
|
||||||
|
return solution;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public interface IInquiryTableService<TInquiryTable>
|
||||||
|
{
|
||||||
|
public string GetDatabaseNameByInquiryId(int id);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public interface INotepadService<TNotepad>
|
||||||
|
{
|
||||||
|
public TNotepad GetNotepadFromUserAndInquiryId(int userId, int inquiryId);
|
||||||
|
|
||||||
|
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes);
|
||||||
|
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes);
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public interface ISolutionService<TSolution>
|
||||||
|
{
|
||||||
|
public TSolution GetSolutionByInquiryId(int id);
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
using API.Controllers;
|
||||||
|
using Dto;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Moq;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace TestAPI;
|
||||||
|
|
||||||
|
public class InquiryTableUnitTest
|
||||||
|
{
|
||||||
|
private readonly Mock<IInquiryTableService<InquiryTableDto>> _inquiryTableService;
|
||||||
|
|
||||||
|
public InquiryTableUnitTest()
|
||||||
|
{
|
||||||
|
_inquiryTableService = new Mock<IInquiryTableService<InquiryTableDto>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDatabaseNameFromInquiryId_Success()
|
||||||
|
{
|
||||||
|
var database = "Inquiry1";
|
||||||
|
_inquiryTableService.Setup(x => x.GetDatabaseNameByInquiryId(42))
|
||||||
|
.Returns(database);
|
||||||
|
var inquiryTableController =
|
||||||
|
new InquiryTableController(_inquiryTableService.Object, new NullLogger<InquiryTableController>());
|
||||||
|
|
||||||
|
var inquiryTableResult = inquiryTableController.GetDatabaseNameByInquiryById(42);
|
||||||
|
|
||||||
|
if (inquiryTableResult is OkObjectResult okObjectResult)
|
||||||
|
{
|
||||||
|
var valeur = okObjectResult.Value;
|
||||||
|
Assert.NotNull(valeur);
|
||||||
|
Assert.Equal(database, ((KeyValuePair<string,string>)valeur).Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDatabaseNameFromInquiryId_Throws_ArgumentException()
|
||||||
|
{
|
||||||
|
_inquiryTableService.Setup(x => x.GetDatabaseNameByInquiryId(42))
|
||||||
|
.Throws<ArgumentException>();
|
||||||
|
var inquiryTableController =
|
||||||
|
new InquiryTableController(_inquiryTableService.Object, new NullLogger<InquiryTableController>());
|
||||||
|
|
||||||
|
var inquiryTableResult = inquiryTableController.GetDatabaseNameByInquiryById(42);
|
||||||
|
|
||||||
|
Assert.NotNull(inquiryTableResult);
|
||||||
|
Assert.Equal(typeof(NotFoundResult), inquiryTableResult.GetType());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,183 @@
|
|||||||
|
using API.Controllers;
|
||||||
|
using Dto;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Moq;
|
||||||
|
using Shared;
|
||||||
|
using TestAPI.Extensions;
|
||||||
|
|
||||||
|
namespace TestAPI;
|
||||||
|
|
||||||
|
public class NotepadUnitTest
|
||||||
|
{
|
||||||
|
private readonly Mock<INotepadService<NotepadDto>> _notepadService;
|
||||||
|
|
||||||
|
public NotepadUnitTest()
|
||||||
|
{
|
||||||
|
_notepadService = new Mock<INotepadService<NotepadDto>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetNotepadFromUserAndInquiryId()
|
||||||
|
{
|
||||||
|
var notepad = new NotepadDto(42, 42, "These are notes example.");
|
||||||
|
_notepadService.Setup(x => x.GetNotepadFromUserAndInquiryId(42, 42))
|
||||||
|
.Returns(notepad);
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.GetNotepadByUserAndInquiryById(42,42);
|
||||||
|
|
||||||
|
if (notepadResult is OkObjectResult okObjectResult)
|
||||||
|
{
|
||||||
|
var valeur = okObjectResult.Value;
|
||||||
|
Assert.NotNull(valeur);
|
||||||
|
Assert.Equal(notepad, valeur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetNotepadFromUserAndInquiryId_ThrowingArgumentException()
|
||||||
|
{
|
||||||
|
var notepad = new NotepadDto(42, 42, "These are notes example.");
|
||||||
|
_notepadService.Setup(x => x.GetNotepadFromUserAndInquiryId(42, 10))
|
||||||
|
.Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.GetNotepadByUserAndInquiryById(42,10);
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(NotFoundResult),notepadResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepadFromUserAndInquiryId_Success()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, 42,"These are notes example."));
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(OkResult),notepadResult.GetType());
|
||||||
|
Assert.Equal(typeof(OkObjectResult) , notepadController.GetNotepadByUserAndInquiryById(42,42).GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepadFromUserAndInquiryId_Negative_UserId()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(-42, 42,"These are notes example.")).Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(-42,42, "These are notes example."));
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(BadRequestResult),notepadResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepadFromUserAndInquiryId_Negative_InquiryId()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, -42,"These are notes example.")).Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,-42, "These are notes example."));
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(BadRequestResult),notepadResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepadFromUserAndInquiryId_Null_Notes()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, 42,"These are notes example.")).Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, null));
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(BadRequestResult),notepadResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepadFromUserAndInquiryId_Throws_ArgumentException()
|
||||||
|
{
|
||||||
|
var notepad = new NotepadDto(42, 42, "These are notes example.");
|
||||||
|
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, 42,"These are notes example.")).Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(notepad);
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(NotFoundResult),notepadResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId_Success()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 42,"These are the new notes"));
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
|
||||||
|
Assert.NotNull(notepadResult);
|
||||||
|
Assert.Equal(typeof(OkResult),notepadResult.GetType());
|
||||||
|
Assert.Equal(typeof(OkObjectResult) , notepadController.GetNotepadByUserAndInquiryById(42,42).GetType());
|
||||||
|
var updateResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are the new notes"));
|
||||||
|
Assert.NotNull(updateResult);
|
||||||
|
Assert.Equal(typeof(OkResult),updateResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId_Negative_UserId()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 42,"These are the new notes"));
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
|
||||||
|
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(-42,42, "These are the new notes"));
|
||||||
|
Assert.NotNull(updateResult);
|
||||||
|
Assert.Equal(typeof(BadRequestResult),updateResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId_Negative_InquiryId()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, -42,"These are the new notes"));
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
|
||||||
|
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(42,-42, "These are the new notes"));
|
||||||
|
Assert.NotNull(updateResult);
|
||||||
|
Assert.Equal(typeof(BadRequestResult),updateResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId_Null_Notes()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 42,null)).Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
|
||||||
|
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(42,42, null));
|
||||||
|
Assert.NotNull(updateResult);
|
||||||
|
Assert.Equal(typeof(BadRequestResult),updateResult.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId_Throws_ArgumentException()
|
||||||
|
{
|
||||||
|
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 10,"These are the new notes")).Throws<ArgumentException>();
|
||||||
|
var notepadController =
|
||||||
|
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
|
||||||
|
|
||||||
|
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
|
||||||
|
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(42,10, "These are the new notes"));
|
||||||
|
Assert.NotNull(updateResult);
|
||||||
|
Assert.Equal(typeof(NotFoundResult),updateResult.GetType());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
using API.Controllers;
|
||||||
|
using Dto;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Moq;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace TestAPI;
|
||||||
|
|
||||||
|
public class SolutionUnitTest
|
||||||
|
{
|
||||||
|
private readonly Mock<ISolutionService<SolutionDto>> _solutionService;
|
||||||
|
|
||||||
|
public SolutionUnitTest()
|
||||||
|
{
|
||||||
|
_solutionService = new Mock<ISolutionService<SolutionDto>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetSolutionFromInquiryId_Success()
|
||||||
|
{
|
||||||
|
var solution = new SolutionDto(42,"Maxime","Sapountzis","La cuisine","Le couteau", "L'explication");
|
||||||
|
_solutionService.Setup(x => x.GetSolutionByInquiryId(42))
|
||||||
|
.Returns(solution);
|
||||||
|
var solutionController =
|
||||||
|
new SolutionController(_solutionService.Object, new NullLogger<SolutionController>());
|
||||||
|
|
||||||
|
var solutionResult = solutionController.GetSolutionByInquiryById(42);
|
||||||
|
|
||||||
|
if (solutionResult is OkObjectResult okObjectResult)
|
||||||
|
{
|
||||||
|
var valeur = okObjectResult.Value;
|
||||||
|
Assert.NotNull(valeur);
|
||||||
|
Assert.Equal(solution, valeur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetSolutionFromInquiryId_Throws_ArgumentException()
|
||||||
|
{
|
||||||
|
var solution = new SolutionDto(42,"Maxime","Sapountzis","La cuisine","Le couteau", "L'explication");
|
||||||
|
_solutionService.Setup(x => x.GetSolutionByInquiryId(42))
|
||||||
|
.Throws<ArgumentException>();
|
||||||
|
var solutionController =
|
||||||
|
new SolutionController(_solutionService.Object, new NullLogger<SolutionController>());
|
||||||
|
|
||||||
|
var solutionResult = solutionController.GetSolutionByInquiryById(42);
|
||||||
|
|
||||||
|
Assert.NotNull(solutionResult);
|
||||||
|
Assert.Equal(typeof(NotFoundResult), solutionResult.GetType());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using DbDataManager.Service;
|
||||||
|
using Entities;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace TestEF.Service;
|
||||||
|
|
||||||
|
public class TestInquiryTableDataService
|
||||||
|
{
|
||||||
|
private readonly UserDbContext _dbContext;
|
||||||
|
private readonly InquiryTableDataService _inquiryTableDataService;
|
||||||
|
|
||||||
|
public TestInquiryTableDataService()
|
||||||
|
{
|
||||||
|
var connection = new SqliteConnection("DataSource=:memory:");
|
||||||
|
connection.Open();
|
||||||
|
var options = new DbContextOptionsBuilder<UserDbContext>()
|
||||||
|
.UseSqlite(connection)
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
_dbContext = new UserDbContext(options);
|
||||||
|
_inquiryTableDataService = new InquiryTableDataService(_dbContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDatabaseFromInquiryId_Success()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
|
||||||
|
var inquiryTable = new InquiryTableEntity()
|
||||||
|
{
|
||||||
|
OwnerId = 42,
|
||||||
|
DatabaseName = "Database",
|
||||||
|
ConnectionInfo = "ConnectionString"
|
||||||
|
};
|
||||||
|
_dbContext.InquiryTables.Add(inquiryTable);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
var result = _inquiryTableDataService.GetDatabaseNameByInquiryId(42);
|
||||||
|
Assert.Equal("Database",result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetSolution_NotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
|
||||||
|
var inquiryTable = new InquiryTableEntity()
|
||||||
|
{
|
||||||
|
OwnerId = 42,
|
||||||
|
DatabaseName = "Database",
|
||||||
|
ConnectionInfo = "ConnectionString"
|
||||||
|
};
|
||||||
|
_dbContext.InquiryTables.Add(inquiryTable);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_inquiryTableDataService.GetDatabaseNameByInquiryId(10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,169 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using DbDataManager.Service;
|
||||||
|
using Entities;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
|
||||||
|
using Model.OrderCriteria;
|
||||||
|
|
||||||
|
namespace TestEF.Service;
|
||||||
|
|
||||||
|
public class TestNotepadDataService
|
||||||
|
{
|
||||||
|
private readonly UserDbContext _dbContext;
|
||||||
|
private readonly NotepadDataService _notepadDataService;
|
||||||
|
|
||||||
|
public TestNotepadDataService()
|
||||||
|
{
|
||||||
|
var connection = new SqliteConnection("DataSource=:memory:");
|
||||||
|
connection.Open();
|
||||||
|
var options = new DbContextOptionsBuilder<UserDbContext>()
|
||||||
|
.UseSqlite(connection)
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
_dbContext = new UserDbContext(options);
|
||||||
|
_notepadDataService = new NotepadDataService(_dbContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetNotepad_Success()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
|
||||||
|
_dbContext.Notepads.Add(notepad);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
|
||||||
|
var result = _notepadDataService.GetNotepadFromUserAndInquiryId(42, 42);
|
||||||
|
|
||||||
|
Assert.Equal(notepad,result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetNotepad_Fail_UserNotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
|
||||||
|
_dbContext.Notepads.Add(notepad);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_notepadDataService.GetNotepadFromUserAndInquiryId(10, 42);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetNotepad_Fail_InquiryNotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
|
||||||
|
_dbContext.Notepads.Add(notepad);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_notepadDataService.GetNotepadFromUserAndInquiryId(42, 10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetNotepad_Fail_NotepadNotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 1, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_notepadDataService.GetNotepadFromUserAndInquiryId(42, 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepad_Success()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "Some notes again" };
|
||||||
|
_notepadDataService.SetNotepadFromUserAndInquiryId(42,42, "Some notes again");
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
|
||||||
|
var result = _notepadDataService.GetNotepadFromUserAndInquiryId(42, 42);
|
||||||
|
|
||||||
|
Assert.Equal(notepad.UserId,result.UserId);
|
||||||
|
Assert.Equal(notepad.InquiryId,result.InquiryId);
|
||||||
|
Assert.Equal(notepad.Notes,result.Notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepad_Fail_UserNotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_notepadDataService.SetNotepadFromUserAndInquiryId(10, 42, "Some notes");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepad_Fail_InquiryNotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_notepadDataService.SetNotepadFromUserAndInquiryId(42, 10, "Some notes");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetNotepad_Fail_NotepadAlreadyExists()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "Some notes" };
|
||||||
|
_dbContext.Notepads.Add(notepad);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_notepadDataService.SetNotepadFromUserAndInquiryId(42, 42, "Some notes");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateNotepad_Success()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
|
||||||
|
_dbContext.Users.Add(new UserEntity
|
||||||
|
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
|
||||||
|
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "Some notes" };
|
||||||
|
_dbContext.Notepads.Add(notepad);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
_notepadDataService.UpdateNotepadFromUserAndInquiryId(42,42, "New Notes");
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
Assert.Equal("New Notes", _notepadDataService.GetNotepadFromUserAndInquiryId(42,42).Notes);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using DbDataManager.Service;
|
||||||
|
using Entities;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace TestEF.Service;
|
||||||
|
|
||||||
|
public class TestSolutionDataService
|
||||||
|
{
|
||||||
|
private readonly UserDbContext _dbContext;
|
||||||
|
private readonly SolutionDataService _solutionDataService;
|
||||||
|
|
||||||
|
public TestSolutionDataService()
|
||||||
|
{
|
||||||
|
var connection = new SqliteConnection("DataSource=:memory:");
|
||||||
|
connection.Open();
|
||||||
|
var options = new DbContextOptionsBuilder<UserDbContext>()
|
||||||
|
.UseSqlite(connection)
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
_dbContext = new UserDbContext(options);
|
||||||
|
_solutionDataService = new SolutionDataService(_dbContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetSolution_Success()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
|
||||||
|
var solution = new SolutionEntity
|
||||||
|
{
|
||||||
|
MurdererFirstName = "Maxime",
|
||||||
|
MurdererLastName = "Sapountzis",
|
||||||
|
MurderPlace = "La cuisine",
|
||||||
|
MurderWeapon = "Le couteau",
|
||||||
|
Explaination = "Parce que",
|
||||||
|
OwnerId = 42,
|
||||||
|
};
|
||||||
|
_dbContext.Solutions.Add(solution);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
|
||||||
|
var result = _solutionDataService.GetSolutionByInquiryId(42);
|
||||||
|
|
||||||
|
Assert.Equal(solution.MurdererFirstName,result.MurdererFirstName);
|
||||||
|
Assert.Equal(solution.MurdererLastName,result.MurdererLastName);
|
||||||
|
Assert.Equal(solution.MurderPlace,result.MurderPlace);
|
||||||
|
Assert.Equal(solution.MurderWeapon,result.MurderWeapon);
|
||||||
|
Assert.Equal(solution.Explaination,result.Explaination);
|
||||||
|
Assert.Equal(solution.OwnerId,result.OwnerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetSolution_NotFound()
|
||||||
|
{
|
||||||
|
_dbContext.Inquiries.Add(new InquiryEntity
|
||||||
|
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
|
||||||
|
var solution = new SolutionEntity
|
||||||
|
{
|
||||||
|
MurdererFirstName = "Maxime",
|
||||||
|
MurdererLastName = "Sapountzis",
|
||||||
|
MurderPlace = "La cuisine",
|
||||||
|
MurderWeapon = "Le couteau",
|
||||||
|
Explaination = "Parce que",
|
||||||
|
OwnerId = 42,
|
||||||
|
};
|
||||||
|
_dbContext.Solutions.Add(solution);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
|
||||||
|
Assert.Throws<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
_solutionDataService.GetSolutionByInquiryId(10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue