Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
e6bcf72fd1 | 1 year ago |
|
0ac95dfae6 | 1 year ago |
|
a1ea2de7bb | 1 year ago |
|
79f898cd47 | 1 year ago |
@ -1,42 +0,0 @@
|
|||||||
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(_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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
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,19 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
using Shared.Mapper;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class NotePadDataServiceApi(INotePadService<NotepadEntity> notePadService) : INotePadService<NotepadDto>
|
||||||
|
{
|
||||||
|
public NotepadDto GetNotePadById(int id) => notePadService.GetNotePadById(id).FromEntityToDto();
|
||||||
|
|
||||||
|
public NotepadDto GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry) =>
|
||||||
|
notePadService.GetNotePadByIdUserAndIdInquiry(idUser, idInquiry).FromEntityToDto();
|
||||||
|
|
||||||
|
public NotepadDto CreateNotePad(int id, int idUser, int idInquiry, string note) =>
|
||||||
|
notePadService.CreateNotePad(id, idUser, idInquiry, note).FromEntityToDto();
|
||||||
|
|
||||||
|
public bool DeleteNotePad(int id) => notePadService.DeleteNotePad(id);
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
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,64 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace DbDataManager.Service;
|
||||||
|
|
||||||
|
public class NotePadDataService : INotePadService<NotepadEntity>
|
||||||
|
{
|
||||||
|
private UserDbContext DbContext { get; }
|
||||||
|
public NotePadDataService(UserDbContext context)
|
||||||
|
{
|
||||||
|
DbContext = context;
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
|
||||||
|
}
|
||||||
|
public NotepadEntity GetNotePadById(int id)
|
||||||
|
{
|
||||||
|
var notePadEntity = DbContext.Notepads.FirstOrDefault(n => n.Id == id);
|
||||||
|
if (notePadEntity == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("impossible de trouver le bloc note", nameof(id));
|
||||||
|
}
|
||||||
|
return notePadEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotepadEntity GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry)
|
||||||
|
{
|
||||||
|
var notPadEntity = DbContext.Notepads.FirstOrDefault(n => n.InquiryId == idInquiry && n.UserId == idUser);
|
||||||
|
if (notPadEntity == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("impossible de trouver le bloc note", nameof(idInquiry));
|
||||||
|
}
|
||||||
|
|
||||||
|
return notPadEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotepadEntity CreateNotePad(int id, int idUser, int idInquiry, string note)
|
||||||
|
{
|
||||||
|
var notePadEntity = new NotepadEntity
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
UserId = idUser,
|
||||||
|
InquiryId = idInquiry,
|
||||||
|
Notes = note
|
||||||
|
};
|
||||||
|
DbContext.Notepads.Add(notePadEntity);
|
||||||
|
DbContext.SaveChangesAsync();
|
||||||
|
return notePadEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteNotePad(int id)
|
||||||
|
{
|
||||||
|
var notePadEntity = DbContext.Notepads.FirstOrDefault(n => n.Id == id);
|
||||||
|
if (notePadEntity == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DbContext.Notepads.Remove(notePadEntity);
|
||||||
|
DbContext.SaveChangesAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,68 +0,0 @@
|
|||||||
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)
|
|
||||||
{
|
|
||||||
notepad.Notes = notes;
|
|
||||||
//throw new ArgumentException("Erreur, un bloc-notes existe déjà pour l'utilisateur et l'enquête donnée");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
namespace Shared;
|
|
||||||
|
|
||||||
public interface IInquiryTableService<TInquiryTable>
|
|
||||||
{
|
|
||||||
public string GetDatabaseNameByInquiryId(int id);
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
using Dto;
|
||||||
|
|
||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public interface INotePadService<TNotePad>
|
||||||
|
{
|
||||||
|
public TNotePad GetNotePadById(int id);
|
||||||
|
public TNotePad GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry);
|
||||||
|
public TNotePad CreateNotePad(int id, int idUser, int idInquiry, string note);
|
||||||
|
public bool DeleteNotePad(int id);
|
||||||
|
|
||||||
|
}
|
@ -1,10 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
namespace Shared;
|
|
||||||
|
|
||||||
public interface ISolutionService<TSolution>
|
|
||||||
{
|
|
||||||
public TSolution GetSolutionByInquiryId(int id);
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,183 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
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