test fixing for the CI
continuous-integration/drone/push Build is passing Details

Dave_more
David D'ALMEIDA 2 years ago
parent b0802493c0
commit 06a2af01de

@ -0,0 +1,32 @@
using Model;
using System.Net.Http;
namespace ApiLib
{
public partial class ApiManager : IDataManager
{
protected HttpClient HttpClient { get; }
public ApiManager(HttpClient httpClient)
{
ChampionsMgr = new ChampionsManager(this);
/* SkinsMgr = new SkinsManager(this);
RunesMgr = new RunesManager(this);
RunePagesMgr = new RunePagesManager(this);*/
HttpClient = httpClient;
/* HttpClient.BaseAddress = new Uri("https://codefirst.iut.uca.fr/containers/arthurvalin-lolcontainer/api");
*/
}
public IChampionsManager ChampionsMgr { get; }
public ISkinsManager SkinsMgr { get; }
public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; }
}
}

@ -0,0 +1,574 @@
using DTO;
using Model;
using Shared;
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Net;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Xml.Linq;
using ApiMappeur;
namespace ApiLib
{
public partial class ApiManager
{
public class ChampionsManager : IChampionsManager
{
private readonly ApiManager parent;
public ChampionsManager(ApiManager parent)
=> this.parent = parent;
public async Task<Champion?> AddItem(Champion? item)
{
try
{
if (item == null) throw new ArgumentNullException("champions is null");
Uri uri = new Uri($"https://codefirst.iut.uca.fr/containers/arthurvalin-lolcontainer/api/champions");
var response = await parent.HttpClient.PostAsJsonAsync(uri, item.toFullDTO());
if (response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.Created)
{
ChampionDTO newChampion = await response.Content.ReadFromJsonAsync<ChampionDTO>();
Console.WriteLine("Champion {0} inserted", newChampion.Name);
return newChampion.ToModel();
}
else
{
// Log the error status code and reason phrase
Console.WriteLine($"Failed to add item. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return null;
}
}
catch (HttpRequestException ex)
{
// Log the error message from the HttpClient exception
Console.WriteLine($"Failed to add item. {ex.Message}");
return null;
}
catch (JsonException ex)
{
// Log the error message from the JSON serialization exception
Console.WriteLine($"Failed to add item. Error while serializing JSON data. {ex.Message}");
return null;
}
catch (Exception ex)
{
// Log any other exceptions that may occur
Console.WriteLine($"Failed to add item. {ex.Message}");
return null;
}
}
public async Task<bool> DeleteItem(Champion? item)
{
try
{
HttpResponseMessage response = await parent.HttpClient.DeleteAsync($"https://localhost:7234/api/Crafting/{item?.Name}");
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Champion {0} deleted", item?.Name);
return true;
}
else
{
Console.WriteLine($"Failed to delete item. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return false;
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Failed to delete item. {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to delete item. {ex.Message}");
return false;
}
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
try
{
// should use Page request Object but to show that the api is rest
string queryString = $"?index={index}&count={count}";
if (!string.IsNullOrEmpty(orderingPropertyName))
{
queryString += $"&orderBy={orderingPropertyName}";
if (descending)
{
queryString += "&descending=true";
}
}
var response = await parent.HttpClient.GetAsync($"https://codefirst.iut.uca.fr/containers/arthurvalin-lolcontainer/api/champions{queryString}");
if (response.IsSuccessStatusCode)
{
IEnumerable<ChampionDTO?> champions = await response.Content.ReadFromJsonAsync<IEnumerable<ChampionDTO?>>();
Console.WriteLine(champions);
IEnumerable<Champion> res = champions.Select(c => c.ToModel());
return res;
}
else
{
Console.WriteLine($"Failed to retrieve Champions. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return null;
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Failed to retrieve Champions. {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Failed to retrieve Champions. Error while deserializing JSON data. {ex.Message}");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to retrieve Champions. {ex.Message}");
return null;
}
}
public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
try
{
HttpResponseMessage response = await parent.HttpClient.GetAsync($"https://localhost:7234/api/Crafting/characteristic/{charName}?index={index}&count={count}&orderingPropertyName={orderingPropertyName}&descending={descending}");
if (response.IsSuccessStatusCode)
{
List<Champion> champions = await response.Content.ReadFromJsonAsync<List<Champion>>();
Console.WriteLine($"Retrieved {champions.Count} champions with characteristic {charName}");
return champions;
}
else
{
Console.WriteLine($"Failed to retrieve champions with characteristic {charName}. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return null;
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Failed to retrieve champions with characteristic {charName}. {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Failed to retrieve champions with characteristic {charName}. Error while deserializing JSON data. {ex.Message}");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to retrieve champions with characteristic {charName}. {ex.Message}");
return null;
}
}
public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
var queryString = new StringBuilder();
queryString.Append($"Class={championClass}");
queryString.Append($"&Index={index}");
queryString.Append($"&Count={count}");
if (!string.IsNullOrEmpty(orderingPropertyName))
{
queryString.Append($"&OrderingPropertyName={orderingPropertyName}");
queryString.Append($"&Descending={descending}");
}
var uri = new UriBuilder("https://localhost:7234/api/Crafting")
{
Query = queryString.ToString()
}.Uri;
try
{
var response = await parent.HttpClient.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var champions = await response.Content.ReadFromJsonAsync<IEnumerable<Champion?>>();
return champions;
}
else
{
Console.WriteLine($"Failed to retrieve items. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return null;
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Failed to retrieve items. {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Failed to retrieve items. Error while deserializing JSON data. {ex.Message}");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to retrieve items. {ex.Message}");
return null;
}
}
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
try
{
/* string queryString = $"?name={substring}&index={index}&count={count}";
if (!string.IsNullOrEmpty(orderingPropertyName))
{
queryString += $"&orderBy={orderingPropertyName}";
if (descending)
{
queryString += "&descending=true";
}
}*/
Uri uri = new Uri($"https://codefirst.iut.uca.fr/containers/arthurvalin-lolcontainer/api/champions/{substring}");
var response = await parent.HttpClient.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
IEnumerable<ChampionDTO> champions = await response.Content.ReadFromJsonAsync<IEnumerable<ChampionDTO>>();
Console.WriteLine(champions);
IEnumerable<Champion> res = champions.Select(c => c.ToModel());
Console.WriteLine($"Found {res.Count()} champions that match the substring '{substring}'");
return res;
}
else
{
Console.WriteLine($"Failed to retrieve items. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return null;
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Failed to retrieve items. {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Failed to retrieve items. Error while deserializing JSON data. {ex.Message}");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to retrieve items. {ex.Message}");
return null;
}
}
public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
try
{
string queryString = $"?index={index}&count={count}";
if (!string.IsNullOrEmpty(orderingPropertyName))
{
queryString += $"&orderBy={orderingPropertyName}";
if (descending)
{
queryString += "&descending=true";
}
}
if (runePage != null)
{
string runePageQueryString = string.Join("&", runePage.Runes
.Where(kv => kv.Value != null)
.Select(kv => $"{kv.Key}={kv.Value.Name}"));
if (!string.IsNullOrEmpty(runePageQueryString))
{
queryString += $"&{runePageQueryString}";
}
}
Uri uri = new Uri($"https://localhost:7234/api/Crafting{queryString}");
var response = await parent.HttpClient.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
IEnumerable<Champion> champions = await response.Content.ReadFromJsonAsync<IEnumerable<Champion>>();
Console.WriteLine($"Found {champions.Count()} champions that match the Rune Page");
return champions;
}
else
{
Console.WriteLine($"Failed to retrieve items. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}");
return null;
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Failed to retrieve items. {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Failed to retrieve items. Error while deserializing JSON data. {ex.Message}");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to retrieve items. {ex.Message}");
return null;
}
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<int> GetNbItems()
{
int count = 0;
try
{
var response = await parent.HttpClient.GetAsync("https://localhost:7234/api/Crafting/Count");
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
count = int.Parse(responseBody);
}
}
catch (Exception ex)
{
// not sure about the -1 maybe sould juste log info
Console.WriteLine($"An error occurred while fetching the number of Champions: {ex.Message}");
return -1;
}
return count;
}
public async Task<int> GetNbItemsByCharacteristic(string charName)
{
int count = 0;
try
{
var response = await parent.HttpClient.GetAsync($"https://localhost:7234/api/Champion/CountByCharacteristic/{charName}");
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
if (!int.TryParse(responseBody, out count))
{
Console.WriteLine($"Error parsing response body {responseBody} to int");
return -1;
}
}
else
{
Console.WriteLine($"Error getting number of items by characteristic");
return -1;
}
}
catch (Exception ex)
{
// Log the error
Console.WriteLine($"Error getting number of items by characteristic {charName}: {ex.Message}");
return -1;
}
return count;
}
public async Task<int> GetNbItemsByClass(ChampionClass championClass)
{
int count = 0;
try
{
var response = await parent.HttpClient.GetAsync($"https://localhost:7234/api/Champion/CountByClass/{championClass}");
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
if (!int.TryParse(responseBody, out count))
{
Console.WriteLine($"Error parsing response body {responseBody} to int");
return -1;
}
}
else
{
Console.WriteLine($"Error getting number of items by class");
return -1;
}
}
catch (Exception ex)
{
// Log the error
Console.WriteLine($"Error getting number of items by class {championClass}: {ex.Message}");
return -1;
}
return count;
}
public async Task<int> GetNbItemsByName(string substring)
{
int count = 0;
try
{
var response = await parent.HttpClient.GetAsync($"https://localhost:7234/api/Champion/CountByName/{substring}");
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
if (!int.TryParse(responseBody, out count))
{
Console.WriteLine($"Error parsing response body {responseBody} to int");
return -1;
}
}
else
{
Console.WriteLine($"Error getting number of items by name");
return -1;
}
}
catch (Exception ex)
{
// Log the error
Console.WriteLine($"Error getting number of items by name {substring}: {ex.Message}");
return -1;
}
return count;
}
public async Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
int count = 0;
try
{
string requestUri = "https://localhost:7234/api/Champion/CountByRunePage";
if (runePage != null)
{
string runePageQueryString = string.Join("&", runePage.Runes
.Where(kv => kv.Value != null)
.Select(kv => $"{kv.Key}={kv.Value.Name}"));
if (!string.IsNullOrEmpty(runePageQueryString))
{
requestUri += "?runePage=" + Uri.EscapeDataString(runePageQueryString);
}
}
var response = await parent.HttpClient.GetAsync(requestUri);
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
if (!int.TryParse(responseBody, out count))
{
Console.WriteLine($"Error parsing response body {responseBody} to int");
return -1;
}
}
else
{
Console.WriteLine($"Error getting number of items by rune page");
return -1;
}
}
catch (Exception ex)
{
// Log the error
Console.WriteLine($"Error getting number of items by rune page: {ex.Message}");
return -1;
}
return count;
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
if (oldItem == null || newItem == null || oldItem.Name != newItem.Name)
{
Console.WriteLine("Error: oldItem or newItem is null");
return null;
}
try
{
var response = await parent.HttpClient.PutAsJsonAsync($"https://localhost:7234/api/Champion/{oldItem.Name}", newItem);
if (response.IsSuccessStatusCode)
{
var updatedChampion = await response.Content.ReadFromJsonAsync<Champion>();
return updatedChampion;
}
else
{
Console.WriteLine($"Error updating champion {oldItem.Name}");
return null;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error updating champion {oldItem.Name}: {ex.Message}");
return null;
}
}
}
}
}

@ -0,0 +1,367 @@
using Model;
using Shared;
using System.Diagnostics;
using System.Collections.Immutable;
using static System.Console;
namespace ApiLib
{
static class Program
{
static IDataManager dataManager = null!;
static async Task Main(string[] args)
{
try
{
dataManager = new ApiManager(new HttpClient());
var datat = dataManager.ChampionsMgr.GetItemsByName("dave", 0, 0);
WriteLine(datat);
await DisplayMainMenu();
Console.ReadLine();
}
catch (Exception ex)
{
Debug.WriteLine(ex, "Stopped program because of exception");
throw;
}
}
public static async Task DisplayMainMenu()
{
Dictionary<int, string> choices = new Dictionary<int, string>()
{
[1] = "1- Manage Champions",
[2] = "2- Manage Skins",
[3] = "3- Manage Runes",
[4] = "4- Manage Rune Pages",
[99] = "99- Quit"
};
while (true)
{
int input = DisplayAMenu(choices);
switch (input)
{
case 1:
await DisplayChampionsMenu();
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 99:
WriteLine("Bye bye!");
return;
default:
break;
}
}
}
private static int DisplayAMenu(Dictionary<int, string> choices)
{
int input = -1;
while (true)
{
WriteLine("What is your choice?");
WriteLine("--------------------");
foreach (var choice in choices.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value))
{
WriteLine(choice);
}
if (!int.TryParse(ReadLine(), out input) || input == -1)
{
WriteLine("I do not understand what your choice is. Please try again.");
continue;
}
break;
}
WriteLine($"You have chosen: {choices[input]}");
WriteLine();
return input;
}
public static async Task DisplayChampionsMenu()
{
Dictionary<int, string> choices = new Dictionary<int, string>()
{
[0] = "0- Get number of champions",
[1] = "1- Get champions",
[2] = "2- Find champions by name",
[3] = "3- Find champions by characteristic",
[4] = "4- Find champions by class",
[5] = "5- Find champions by skill",
[6] = "6- Add new champion",
[7] = "7- Delete a champion",
[8] = "8- Update a champion",
};
int input = DisplayAMenu(choices);
switch (input)
{
case 0:
int nb = await dataManager.ChampionsMgr.GetNbItems();
WriteLine($"There are {nb} champions");
WriteLine("**********************");
break;
case 1:
{
int index = ReadAnInt("Please enter the page index");
int count = ReadAnInt("Please enter the number of elements to display");
WriteLine($"{count} champions of page {index + 1}");
var champions = await dataManager.ChampionsMgr.GetItems(index, count, nameof(Champion.Name));
foreach (var champion in champions)
{
WriteLine($"\t{champion}");
}
WriteLine("**********************");
}
break;
case 2:
{
string substring = ReadAString("Please enter the substring to look for in the name of a champion");
int index = ReadAnInt("Please enter the page index");
int count = ReadAnInt("Please enter the number of elements to display");
var champions = await dataManager.ChampionsMgr.GetItemsByName(substring, index, count, nameof(Champion.Name));
foreach (var champion in champions)
{
WriteLine($"\t{champion}");
}
WriteLine("**********************");
}
break;
case 3:
{
string substring = ReadAString("Please enter the substring to look for in the characteristics of champions");
int index = ReadAnInt("Please enter the page index");
int count = ReadAnInt("Please enter the number of elements to display");
var champions = await dataManager.ChampionsMgr.GetItemsByCharacteristic(substring, index, count, nameof(Champion.Name));
foreach (var champion in champions)
{
WriteLine($"\t{champion}");
}
WriteLine("**********************");
}
break;
case 4:
{
ChampionClass championClass = ReadAnEnum<ChampionClass>($"Please enter the champion class (possible values are: {Enum.GetNames<ChampionClass>().Aggregate("", (name, chaine) => $"{chaine} {name}")}):");
int index = ReadAnInt("Please enter the page index");
int count = ReadAnInt("Please enter the number of elements to display");
var champions = await dataManager.ChampionsMgr.GetItemsByClass(championClass, index, count, nameof(Champion.Name));
foreach (var champion in champions)
{
WriteLine($"\t{champion}");
}
WriteLine("**********************");
}
break;
case 5:
{
string substring = ReadAString("Please enter the substring to look for in the skills of champions");
int index = ReadAnInt("Please enter the page index");
int count = ReadAnInt("Please enter the number of elements to display");
var champions = await dataManager.ChampionsMgr.GetItemsBySkill(substring, index, count, nameof(Champion.Name));
foreach (var champion in champions)
{
WriteLine($"\t{champion}");
}
WriteLine("**********************");
}
break;
case 6:
{
WriteLine("You are going to create a new champion.");
string name = ReadAString("Please enter the champion name:");
ChampionClass championClass = ReadAnEnum<ChampionClass>($"Please enter the champion class (possible values are: {Enum.GetNames<ChampionClass>().Aggregate("", (name, chaine) => $"{chaine} {name}")}):");
string bio = ReadAString("Please enter the champion bio:");
Champion champion = new Champion(name, championClass, bio: bio);
DisplayCreationChampionMenu(champion);
_ = await dataManager.ChampionsMgr.AddItem(champion);
}
break;
case 7:
{
WriteLine("You are going to delete a champion.");
string name = ReadAString("Please enter the champion name:");
var somechampions = await dataManager.ChampionsMgr.GetItemsByName(name, 0, 10, nameof(Champion.Name));
var someChampionNames = somechampions.Select(c => c!.Name);
var someChampionNamesAsOneString = someChampionNames.Aggregate("", (name, chaine) => $"{chaine} {name}");
string champName = ReadAStringAmongPossibleValues($"Who do you want to delete among these champions? (type \"Cancel\" to ... cancel) {someChampionNamesAsOneString}",
someChampionNames.ToArray());
if (champName != "Cancel")
{
await dataManager.ChampionsMgr.DeleteItem(somechampions.Single(c => c!.Name == champName));
}
}
break;
case 8:
{
WriteLine("You are going to update a champion.");
string name = ReadAString("Please enter the champion name:");
var somechampions = await dataManager.ChampionsMgr.GetItemsByName(name, 0, 10, nameof(Champion.Name));
var someChampionNames = somechampions.Select(c => c!.Name);
var someChampionNamesAsOneString = someChampionNames.Aggregate("", (name, chaine) => $"{chaine} {name}");
string champName = ReadAStringAmongPossibleValues($"Who do you want to update among these champions? (type \"Cancel\" to ... cancel) {someChampionNamesAsOneString}",
someChampionNames.ToArray());
if (champName == "Cancel") break;
ChampionClass championClass = ReadAnEnum<ChampionClass>($"Please enter the champion class (possible values are: {Enum.GetNames<ChampionClass>().Aggregate("", (name, chaine) => $"{chaine} {name}")}):");
string bio = ReadAString("Please enter the champion bio:");
Champion champion = new Champion(champName, championClass, bio: bio);
DisplayCreationChampionMenu(champion);
await dataManager.ChampionsMgr.UpdateItem(somechampions.Single(c => c!.Name == champName), champion);
}
break;
default:
break;
}
}
public static void DisplayCreationChampionMenu(Champion champion)
{
Dictionary<int, string> choices = new Dictionary<int, string>()
{
[1] = "1- Add a skill",
[2] = "2- Add a skin",
[3] = "3- Add a characteristic",
[99] = "99- Finish"
};
while (true)
{
int input = DisplayAMenu(choices);
switch (input)
{
case 1:
string skillName = ReadAString("Please enter the skill name:");
SkillType skillType = ReadAnEnum<SkillType>($"Please enter the skill type (possible values are: {Enum.GetNames<SkillType>().Aggregate("", (name, chaine) => $"{chaine} {name}")}):");
string skillDescription = ReadAString("Please enter the skill description:");
Skill skill = new Skill(skillName, skillType, skillDescription);
champion.AddSkill(skill);
break;
case 2:
string skinName = ReadAString("Please enter the skin name:");
string skinDescription = ReadAString("Please enter the skin description:");
float skinPrice = ReadAFloat("Please enter the price of this skin:");
Skin skin = new Skin(skinName, champion, skinPrice, description: skinDescription);
break;
case 3:
string characteristic = ReadAString("Please enter the characteristic:");
int value = ReadAnInt("Please enter the value associated to this characteristic:");
champion.AddCharacteristics(Tuple.Create(characteristic, value));
break;
case 99:
return;
default:
break;
}
}
}
private static int ReadAnInt(string message)
{
while (true)
{
WriteLine(message);
if (!int.TryParse(ReadLine(), out int result))
{
continue;
}
return result;
}
}
private static float ReadAFloat(string message)
{
while (true)
{
WriteLine(message);
if (!float.TryParse(ReadLine(), out float result))
{
continue;
}
return result;
}
}
private static string ReadAString(string message)
{
while (true)
{
WriteLine(message);
string? line = ReadLine();
if (line == null)
{
continue;
}
return line!;
}
}
private static TEnum ReadAnEnum<TEnum>(string message) where TEnum : struct
{
while (true)
{
WriteLine(message);
if (!Enum.TryParse<TEnum>(ReadLine(), out TEnum result))
{
continue;
}
return result;
}
}
private static string ReadAStringAmongPossibleValues(string message, params string[] possibleValues)
{
while (true)
{
WriteLine(message);
string? result = ReadLine();
if (result == null) continue;
if (result != "Cancel" && !possibleValues.Contains(result!)) continue;
return result!;
}
}
}
}
// Get all champions
/*var champions = await championClient.ChampionsMgr.
Console.WriteLine("All champions:");
foreach (var champion in champions)
{
Console.WriteLine($"{champion.Name} ({champion.Bio})");
}
*/
/*// Add a new champion
var newChampion = new ChampionDto { Name = "Akali", Role = "Assassin" };
championClient.Add(newChampion);
// Delete a champion
var championToDelete = champions.FirstOrDefault(c => c.Name == "Riven");
if (championToDelete != null)
{
championClient.Delete(championToDelete);
Console.WriteLine($"{championToDelete.Name} deleted.");
}
// Update a champion
var championToUpdate = champions.FirstOrDefault(c => c.Name == "Ashe");
if (championToUpdate != null)
{
championToUpdate.Role = "Marksman";
championClient.Update(championToUpdate);
Console.WriteLine($"{championToUpdate.Name} updated.");
}
*/

@ -16,18 +16,18 @@ namespace Test_Api
[TestClass]
public class ChampionControllerTest
{
public ChampionsController championCtrl;
public readonly ChampionsController championCtrl;
private readonly ILogger<ChampionsController> logger = new NullLogger<ChampionsController>();
public readonly IDataManager stubMgr;
public ChampionControllerTest()
{
var stubMgr = new StubData();
stubMgr = new StubData();
championCtrl = new ChampionsController(stubMgr, logger);
}
/*
[TestMethod]
/* [TestMethod]
public async Task TestGetChampions()
{
@ -109,7 +109,7 @@ namespace Test_Api
public async Task TestGetBadRequest_WhenNoChampionsFound()
{
///var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
// need to be empty
var request = new PageRequest
@ -131,7 +131,7 @@ namespace Test_Api
Assert.AreEqual("No chamions found : totalcount is : 0", badRequestResult.Value);
}
*/
*/
/*

Loading…
Cancel
Save