From 6c7970fda70b7cb9961055782ad89ba24e34fa7e Mon Sep 17 00:00:00 2001 From: masapountz Date: Mon, 1 Apr 2024 17:58:00 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20Tests=20Unitaires=20sur=20le=20Que?= =?UTF-8?q?ryService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Service/QueryDataServiceApi.cs | 4 +- .../ServiceAPI/UnitTestQueryDataServiceApi.cs | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 API_SQLuedo/TestAPI/ServiceAPI/UnitTestQueryDataServiceApi.cs diff --git a/API_SQLuedo/API/Service/QueryDataServiceApi.cs b/API_SQLuedo/API/Service/QueryDataServiceApi.cs index 284b79c..636f235 100644 --- a/API_SQLuedo/API/Service/QueryDataServiceApi.cs +++ b/API_SQLuedo/API/Service/QueryDataServiceApi.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace API.Service; -public class QueryDataServiceApi : IQueryService -{ +public class QueryDataServiceApi : IQueryService{ + public QueryDto ExecuteQuery(string query, string database) { string connectionString = diff --git a/API_SQLuedo/TestAPI/ServiceAPI/UnitTestQueryDataServiceApi.cs b/API_SQLuedo/TestAPI/ServiceAPI/UnitTestQueryDataServiceApi.cs new file mode 100644 index 0000000..1f82a44 --- /dev/null +++ b/API_SQLuedo/TestAPI/ServiceAPI/UnitTestQueryDataServiceApi.cs @@ -0,0 +1,50 @@ +using DbContextLib; +using DbDataManager.Service; +using Entities; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model.OrderCriteria; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using API.Service; +using Model; +using Newtonsoft.Json; +using StubbedContextLib; + +namespace TestAPI.ServiceAPI +{ + public class UnitTestQueryDataServiceApi + { + private readonly StubbedContext _dbContext; + private readonly QueryDataServiceApi _queryService; + + public UnitTestQueryDataServiceApi() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + _dbContext = new StubbedContext(options); + _queryService = new QueryDataServiceApi(); + + } + + [Fact] + public void ExecuteQuery_Success_When_Select_Users() + { + + var jsonResult = _queryService.ExecuteQuery("Select * from \"User\";", "SQLuedo"); + var result = JsonConvert.DeserializeObject(jsonResult.Result); + + Assert.NotNull(result); + Assert.Equal(11, result.Count()); + + } + + } +}