From d4f6fdad0e4a747e6ab9bd9919cea1d645d7d9e9 Mon Sep 17 00:00:00 2001 From: Louwar Date: Fri, 17 Mar 2023 09:20:50 +0100 Subject: [PATCH] Add test API & Update EFManager --- Sources/EFManager/ManagerChampion.cs | 77 ++++------------------------ Sources/LeagueOfLegends.sln | 7 +++ Sources/TestAPI/TestAPI.csproj | 24 +++++++++ Sources/TestAPI/UnitTest1.cs | 11 ++++ Sources/TestAPI/Usings.cs | 1 + 5 files changed, 53 insertions(+), 67 deletions(-) create mode 100644 Sources/TestAPI/TestAPI.csproj create mode 100644 Sources/TestAPI/UnitTest1.cs create mode 100644 Sources/TestAPI/Usings.cs diff --git a/Sources/EFManager/ManagerChampion.cs b/Sources/EFManager/ManagerChampion.cs index 220261d..a38a70c 100644 --- a/Sources/EFManager/ManagerChampion.cs +++ b/Sources/EFManager/ManagerChampion.cs @@ -1,6 +1,6 @@ using EFlib; using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; +using System.Linq; using Model; namespace EFManager @@ -19,101 +19,44 @@ namespace EFManager return item; } - public Task DeleteItem(Champion? item) + public async Task DeleteItem(Champion? item) { if (item == null) return false; - await context.Remove(item.toEF()); + context.Remove(item.toEF()); await context.SaveChangesAsync(); return true; } public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - IQueryable query = Champions.Skip(index).Take(count); - - if (!string.IsNullOrEmpty(orderingPropertyName)) - { - query = descending ? - query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : - query.OrderBy(c => EF.Property(c, orderingPropertyName)); - } + throw new NotImplementedException(); - return await query.ToListAsync(); } public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) { - IQueryable query = Champions - .Where(c => c.Characteristics.ContainsKey(charName)) - .Skip(index) - .Take(count); - - if (!string.IsNullOrEmpty(orderingPropertyName)) - { - query = descending ? - query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : - query.OrderBy(c => EF.Property(c, orderingPropertyName)); - } - - return await query.ToListAsync(); + throw new NotImplementedException(); } public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) { - IQueryable query = Champions - .Where(c => c.Class == championClass) - .Skip(index) - .Take(count); - - if (!string.IsNullOrEmpty(orderingPropertyName)) - { - query = descending ? - query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : - query.OrderBy(c => EF.Property(c, orderingPropertyName)); - } + throw new NotImplementedException(); - return await query.ToListAsync(); } public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { - IQueryable query = Champions - .Where(c => c.Name.Contains(substring)) - .Skip(index) - .Take(count); - - if (!string.IsNullOrEmpty(orderingPropertyName)) - { - query = descending ? - query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : - query.OrderBy(c => EF.Property(c, orderingPropertyName)); - } + throw new NotImplementedException(); - return await query.ToListAsync(); } public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) { - IQueryable query = Champions; - - if (runePage != null) - { - query = query.Where(c => c.RunePageId == runePage.Id); - } - - query = query.Skip(index).Take(count); - - if (!string.IsNullOrEmpty(orderingPropertyName)) - { - query = descending ? - query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : - query.OrderBy(c => EF.Property(c, orderingPropertyName)); - } + throw new NotImplementedException(); - return await query.ToListAsync(); } public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) @@ -131,9 +74,9 @@ namespace EFManager throw new NotImplementedException(); } - public Task GetNbItemsByCharacteristic(string charName) + public async Task GetNbItemsByCharacteristic(string charName) { - return await context.Where(c => c.Characteristics.Any(ch => ch.Name == charName)).CountAsync(); + throw new NotImplementedException(); } public Task GetNbItemsByClass(ChampionClass championClass) diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 1fe3253..b73957c 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFManager", "EFManager\EFMa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestManagerEF", "Tests\TestManagerEF\TestManagerEF.csproj", "{ECD6BA04-7338-4AFA-AC4B-D5C60C440D4D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAPI", "TestAPI\TestAPI.csproj", "{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -87,6 +89,10 @@ Global {ECD6BA04-7338-4AFA-AC4B-D5C60C440D4D}.Debug|Any CPU.Build.0 = Debug|Any CPU {ECD6BA04-7338-4AFA-AC4B-D5C60C440D4D}.Release|Any CPU.ActiveCfg = Release|Any CPU {ECD6BA04-7338-4AFA-AC4B-D5C60C440D4D}.Release|Any CPU.Build.0 = Release|Any CPU + {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -99,6 +105,7 @@ Global {9807CE1D-F1CF-4CAE-9D03-CDCE14BC36F2} = {F4404CFB-A33D-448E-891C-2C8113B014E4} {17BA906E-798E-4E75-9D8F-D4CD8EDD7FAE} = {F4404CFB-A33D-448E-891C-2C8113B014E4} {ECD6BA04-7338-4AFA-AC4B-D5C60C440D4D} = {3EADD82A-15CF-40CC-BF4F-82F5385676A5} + {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25} = {3EADD82A-15CF-40CC-BF4F-82F5385676A5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/Sources/TestAPI/TestAPI.csproj b/Sources/TestAPI/TestAPI.csproj new file mode 100644 index 0000000..bdd1ae2 --- /dev/null +++ b/Sources/TestAPI/TestAPI.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/Sources/TestAPI/UnitTest1.cs b/Sources/TestAPI/UnitTest1.cs new file mode 100644 index 0000000..c22e82f --- /dev/null +++ b/Sources/TestAPI/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace TestAPI +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} \ No newline at end of file diff --git a/Sources/TestAPI/Usings.cs b/Sources/TestAPI/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Sources/TestAPI/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file