diff --git a/Sources/DataManagers/ChampChanger.cs b/Sources/DataManagers/ChampChanger.cs index 6f9d3f4..0e12c1c 100644 --- a/Sources/DataManagers/ChampChanger.cs +++ b/Sources/DataManagers/ChampChanger.cs @@ -12,13 +12,14 @@ namespace DataManagers } public static ChampionEntity ToEntity(this Champion champion) => new ChampionEntity - { - Id = champion.Id, - Name = champion.Name, - Bio = champion.Bio, - Icon = champion.Icon, - ChampClass = champion.Class, - }; + { + Id = champion.Id, + Name = champion.Name, + Bio = champion.Bio, + Icon = champion.Icon, + ChampClass = champion.Class, + }; + public static IEnumerable ToPocos(this IEnumerable champs) { diff --git a/Sources/DataManagers/DbChampionManager.cs b/Sources/DataManagers/DbChampionManager.cs index 9b631af..01c2fa1 100644 --- a/Sources/DataManagers/DbChampionManager.cs +++ b/Sources/DataManagers/DbChampionManager.cs @@ -17,19 +17,16 @@ namespace DataManagers private IEnumerable SortChampions(IEnumerable champs, int index, int count, string? orderingPropertyName = null, bool descending = false) { switch (orderingPropertyName?.ToLower()) - { - case "name": - champs = champs.OrderBy(arg => arg.Name).ToList(); - break; + { case "bio": - champs = champs.OrderBy(arg => arg.Bio).ToList(); + champs = champs.OrderBy(arg => arg.Bio.ToLower()).ToList(); break; case "class": champs = champs.OrderBy(arg => arg.Class).ToList(); break; default: + champs = champs.OrderBy(arg => arg.Name.ToLower()).ToList(); break; - } if (descending) { @@ -41,7 +38,7 @@ namespace DataManagers public async Task AddItem(Champion? item) { - if (item != null) + if (item != null && Context.Champions.SingleOrDefault((ChampionEntity arg) => arg.Name == item.Name)?.ToPoco() == null) { await Context.Champions.AddAsync(item.ToEntity()); await Context.SaveChangesAsync(); @@ -141,7 +138,7 @@ namespace DataManagers public async Task UpdateItem(Champion? oldItem, Champion? newItem) { - ChampionEntity? champ = await Context.Champions.SingleOrDefaultAsync((arg) => arg.Name == oldItem.Name); + ChampionEntity? champ = await Context.Champions.SingleOrDefaultAsync((arg) => arg.Id == oldItem.Id); if (champ != null) { champ.Bio = newItem.Bio; diff --git a/Sources/LolApp/AddChampionPage.xaml b/Sources/LolApp/AddChampionPage.xaml new file mode 100644 index 0000000..85d8abd --- /dev/null +++ b/Sources/LolApp/AddChampionPage.xaml @@ -0,0 +1,142 @@ + + + + + + + + + diff --git a/Sources/LolApp/ChampionsPage.xaml.cs b/Sources/LolApp/ChampionsPage.xaml.cs new file mode 100644 index 0000000..6aa38a7 --- /dev/null +++ b/Sources/LolApp/ChampionsPage.xaml.cs @@ -0,0 +1,17 @@ +using LolApp.ViewModels; +using ViewModels; + +namespace LolApp; + +public partial class ChampionsPage : ContentPage +{ + public ApplicationVM AppVM { get; } + public ChampionsPageVM VM { get; } + public ChampionsPage(ApplicationVM appVM) + { + InitializeComponent(); + AppVM = appVM; + VM = new ChampionsPageVM(AppVM.ChampionsMgrVM); + BindingContext = this; + } +} diff --git a/Sources/LolApp/ContentViews/ChampionClassSelector.xaml b/Sources/LolApp/ContentViews/ChampionClassSelector.xaml new file mode 100644 index 0000000..e1b1fe4 --- /dev/null +++ b/Sources/LolApp/ContentViews/ChampionClassSelector.xaml @@ -0,0 +1,126 @@ + + + + + Assassin + Fighter + Mage + Marksman + Support + Tank + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/LolApp/ContentViews/ChampionClassSelector.xaml.cs b/Sources/LolApp/ContentViews/ChampionClassSelector.xaml.cs new file mode 100644 index 0000000..20cd487 --- /dev/null +++ b/Sources/LolApp/ContentViews/ChampionClassSelector.xaml.cs @@ -0,0 +1,35 @@ +using Model; + +namespace LolApp.ContentViews; + +public partial class ChampionClassSelector : ContentView +{ + public ChampionClassSelector() + { + InitializeComponent(); + } + + public static readonly BindableProperty SelectedValueProperty = BindableProperty.Create(nameof(SelectedValue), typeof(ChampionClass), typeof(ChampionClassSelector), ChampionClass.Unknown, BindingMode.TwoWay, + validateValue: (a,b) => { int coucou=0; return true;}); + public ChampionClass SelectedValue + { + get => (ChampionClass)GetValue(SelectedValueProperty); + set => SetValue(SelectedValueProperty, value); + } + + public static readonly BindableProperty CheckedColorProperty = BindableProperty.Create(nameof(CheckedColor), typeof(Color), typeof(ChampionClassSelector), Colors.DarkSalmon); + + public Color CheckedColor + { + get => (Color)GetValue(CheckedColorProperty); + set => SetValue(CheckedColorProperty, value); + } + + public static readonly BindableProperty UncheckedColorProperty = BindableProperty.Create(nameof(UncheckedColor), typeof(Color), typeof(ChampionClassSelector), Colors.DarkSalmon); + + public Color UncheckedColor + { + get => (Color)GetValue(UncheckedColorProperty); + set => SetValue(UncheckedColorProperty, value); + } +} diff --git a/Sources/LolApp/ContentViews/SearchByStringView.cs b/Sources/LolApp/ContentViews/SearchByStringView.cs new file mode 100644 index 0000000..308ce0d --- /dev/null +++ b/Sources/LolApp/ContentViews/SearchByStringView.cs @@ -0,0 +1,38 @@ +using System.Windows.Input; + +namespace LolApp.ContentViews; + +public class SearchByStringView : ContentView +{ + public static readonly BindableProperty PlaceHolderProperty = BindableProperty.Create(nameof(PlaceHolder), typeof(string), typeof(SearchByStringView), string.Empty); + + public string PlaceHolder + { + get => (string)GetValue(PlaceHolderProperty); + set => SetValue(PlaceHolderProperty, value); + } + + public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(SearchByStringView), string.Empty); + + public string Text + { + get => (string)GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(SearchByStringView), null); + + public ICommand Command + { + get => (ICommand)GetValue(CommandProperty); + set => SetValue(CommandProperty, value); + } + + public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(SearchByStringView), null); + + public object CommandParameter + { + get => GetValue(CommandParameterProperty); + set => SetValue(CommandParameterProperty, value); + } +} diff --git a/Sources/LolApp/LolApp.csproj b/Sources/LolApp/LolApp.csproj new file mode 100644 index 0000000..cde1acb --- /dev/null +++ b/Sources/LolApp/LolApp.csproj @@ -0,0 +1,95 @@ + + + + net7.0-android;net7.0-ios;net7.0-maccatalyst + Exe + LolApp + true + true + enable + + + LolApp + + + fr.uca.iut.lolapp + d3cd18a9-c614-4933-bd36-3008e72004d5 + + + 1.0 + 1 + + 14.2 + 14.0 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + {0C898A04-092A-49AA-BE65-8AE818A2AF50} + + + + false + appleIUT_TP2022 + iPhone Developer: Cedric BOUHOURS (M2E3ZQNZ3K) + + + false + Developer ID Application + 3rd Party Mac Developer Installer + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/LolApp/MainPage.xaml b/Sources/LolApp/MainPage.xaml new file mode 100644 index 0000000..9db8163 --- /dev/null +++ b/Sources/LolApp/MainPage.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + diff --git a/Sources/LolApp/MainPage.xaml.cs b/Sources/LolApp/MainPage.xaml.cs new file mode 100644 index 0000000..0750b67 --- /dev/null +++ b/Sources/LolApp/MainPage.xaml.cs @@ -0,0 +1,11 @@ +namespace LolApp; + +public partial class MainPage : ContentPage +{ + public MainPage() + { + InitializeComponent(); + } +} + + diff --git a/Sources/LolApp/MauiProgram.cs b/Sources/LolApp/MauiProgram.cs new file mode 100644 index 0000000..c12deff --- /dev/null +++ b/Sources/LolApp/MauiProgram.cs @@ -0,0 +1,39 @@ +using CommunityToolkit.Maui; +using LolApp.ViewModels; +using Microsoft.Extensions.Logging; +using Microsoft.Maui.Handlers; +using Microsoft.Maui.Platform; +using Model; +using StubLib; +using ViewModels; + +namespace LolApp; + +public static class MauiProgram +{ + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .UseMauiCommunityToolkit() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + fonts.AddFont("Font Awesome 6 Free-Solid-900.otf", "FASolid"); + }); + builder.Services.AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton(); + +#if DEBUG + builder.Logging.AddDebug(); +#endif + + return builder.Build(); + } +} + diff --git a/Sources/LolApp/Platforms/Android/AndroidManifest.xml b/Sources/LolApp/Platforms/Android/AndroidManifest.xml new file mode 100644 index 0000000..e6c8a36 --- /dev/null +++ b/Sources/LolApp/Platforms/Android/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Sources/LolApp/Platforms/Android/MainActivity.cs b/Sources/LolApp/Platforms/Android/MainActivity.cs new file mode 100644 index 0000000..016887c --- /dev/null +++ b/Sources/LolApp/Platforms/Android/MainActivity.cs @@ -0,0 +1,11 @@ +using Android.App; +using Android.Content.PM; +using Android.OS; + +namespace LolApp; + +[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] +public class MainActivity : MauiAppCompatActivity +{ +} + diff --git a/Sources/LolApp/Platforms/Android/MainApplication.cs b/Sources/LolApp/Platforms/Android/MainApplication.cs new file mode 100644 index 0000000..95e1d92 --- /dev/null +++ b/Sources/LolApp/Platforms/Android/MainApplication.cs @@ -0,0 +1,16 @@ +using Android.App; +using Android.Runtime; + +namespace LolApp; + +[Application] +public class MainApplication : MauiApplication +{ + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} + diff --git a/Sources/LolApp/Platforms/Android/Resources/values/colors.xml b/Sources/LolApp/Platforms/Android/Resources/values/colors.xml new file mode 100644 index 0000000..c2794f7 --- /dev/null +++ b/Sources/LolApp/Platforms/Android/Resources/values/colors.xml @@ -0,0 +1,7 @@ + + + #512BD4 + #2B0B98 + #2B0B98 + + diff --git a/Sources/LolApp/Platforms/MacCatalyst/AppDelegate.cs b/Sources/LolApp/Platforms/MacCatalyst/AppDelegate.cs new file mode 100644 index 0000000..d5d15a5 --- /dev/null +++ b/Sources/LolApp/Platforms/MacCatalyst/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace LolApp; + +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate +{ + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} + diff --git a/Sources/LolApp/Platforms/MacCatalyst/Info.plist b/Sources/LolApp/Platforms/MacCatalyst/Info.plist new file mode 100644 index 0000000..ec44095 --- /dev/null +++ b/Sources/LolApp/Platforms/MacCatalyst/Info.plist @@ -0,0 +1,36 @@ + + + + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + NSCameraUsageDescription + New Entry + NSPhotoLibraryUsageDescription + New Entry + NSPhotoLibraryAddUsageDescription + New Entry + + diff --git a/Sources/LolApp/Platforms/MacCatalyst/Program.cs b/Sources/LolApp/Platforms/MacCatalyst/Program.cs new file mode 100644 index 0000000..f1b8f29 --- /dev/null +++ b/Sources/LolApp/Platforms/MacCatalyst/Program.cs @@ -0,0 +1,16 @@ +using ObjCRuntime; +using UIKit; + +namespace LolApp; + +public class Program +{ + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } +} + diff --git a/Sources/LolApp/Platforms/Tizen/Main.cs b/Sources/LolApp/Platforms/Tizen/Main.cs new file mode 100644 index 0000000..d58b3d9 --- /dev/null +++ b/Sources/LolApp/Platforms/Tizen/Main.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Maui; +using Microsoft.Maui.Hosting; + +namespace LolApp; + +class Program : MauiApplication +{ + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } +} + diff --git a/Sources/LolApp/Platforms/Tizen/tizen-manifest.xml b/Sources/LolApp/Platforms/Tizen/tizen-manifest.xml new file mode 100644 index 0000000..109d29f --- /dev/null +++ b/Sources/LolApp/Platforms/Tizen/tizen-manifest.xml @@ -0,0 +1,15 @@ + + + + + + maui-appicon-placeholder + + + + + http://tizen.org/privilege/internet + + + + diff --git a/Sources/LolApp/Platforms/Windows/App.xaml b/Sources/LolApp/Platforms/Windows/App.xaml new file mode 100644 index 0000000..23c64b9 --- /dev/null +++ b/Sources/LolApp/Platforms/Windows/App.xaml @@ -0,0 +1,9 @@ + + + + diff --git a/Sources/LolApp/Platforms/Windows/App.xaml.cs b/Sources/LolApp/Platforms/Windows/App.xaml.cs new file mode 100644 index 0000000..c3b0669 --- /dev/null +++ b/Sources/LolApp/Platforms/Windows/App.xaml.cs @@ -0,0 +1,25 @@ +using Microsoft.UI.Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace LolApp.WinUI; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +public partial class App : MauiWinUIApplication +{ + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + public App() + { + this.InitializeComponent(); + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} + + diff --git a/Sources/LolApp/Platforms/Windows/Package.appxmanifest b/Sources/LolApp/Platforms/Windows/Package.appxmanifest new file mode 100644 index 0000000..52b7801 --- /dev/null +++ b/Sources/LolApp/Platforms/Windows/Package.appxmanifest @@ -0,0 +1,47 @@ + + + + + + + + + $placeholder$ + User Name + $placeholder$.png + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/LolApp/Platforms/Windows/app.manifest b/Sources/LolApp/Platforms/Windows/app.manifest new file mode 100644 index 0000000..91a1b32 --- /dev/null +++ b/Sources/LolApp/Platforms/Windows/app.manifest @@ -0,0 +1,16 @@ + + + + + + + + true/PM + PerMonitorV2, PerMonitor + + + + diff --git a/Sources/LolApp/Platforms/iOS/AppDelegate.cs b/Sources/LolApp/Platforms/iOS/AppDelegate.cs new file mode 100644 index 0000000..d5d15a5 --- /dev/null +++ b/Sources/LolApp/Platforms/iOS/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace LolApp; + +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate +{ + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} + diff --git a/Sources/LolApp/Platforms/iOS/Info.plist b/Sources/LolApp/Platforms/iOS/Info.plist new file mode 100644 index 0000000..352a326 --- /dev/null +++ b/Sources/LolApp/Platforms/iOS/Info.plist @@ -0,0 +1,38 @@ + + + + + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + NSCameraUsageDescription + New Entry + NSPhotoLibraryUsageDescription + Pour accéder aux images... + NSPhotoLibraryAddUsageDescription + Pour accéder aux images... + + diff --git a/Sources/LolApp/Platforms/iOS/Program.cs b/Sources/LolApp/Platforms/iOS/Program.cs new file mode 100644 index 0000000..f1b8f29 --- /dev/null +++ b/Sources/LolApp/Platforms/iOS/Program.cs @@ -0,0 +1,16 @@ +using ObjCRuntime; +using UIKit; + +namespace LolApp; + +public class Program +{ + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } +} + diff --git a/Sources/LolApp/Properties/launchSettings.json b/Sources/LolApp/Properties/launchSettings.json new file mode 100644 index 0000000..90f92d9 --- /dev/null +++ b/Sources/LolApp/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Windows Machine": { + "commandName": "MsixPackage", + "nativeDebugging": false + } + } +} diff --git a/Sources/LolApp/Resources/AppIcon/appicon.png b/Sources/LolApp/Resources/AppIcon/appicon.png new file mode 100644 index 0000000..8263b46 Binary files /dev/null and b/Sources/LolApp/Resources/AppIcon/appicon.png differ diff --git a/Sources/LolApp/Resources/AppIcon/appiconfg.svg b/Sources/LolApp/Resources/AppIcon/appiconfg.svg new file mode 100644 index 0000000..e9b7139 --- /dev/null +++ b/Sources/LolApp/Resources/AppIcon/appiconfg.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Sources/LolApp/Resources/Converters/Base64ToImageSourceConverter.cs b/Sources/LolApp/Resources/Converters/Base64ToImageSourceConverter.cs new file mode 100644 index 0000000..e258576 --- /dev/null +++ b/Sources/LolApp/Resources/Converters/Base64ToImageSourceConverter.cs @@ -0,0 +1,34 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using CommunityToolkit.Maui.Converters; + +namespace LolApp.Resources.Converters +{ + public class Base64ToImageSourceConverter : ByteArrayToImageSourceConverter, IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string base64 = value as string; + if (string.IsNullOrWhiteSpace(base64)) return null; + try + { + byte[] bytes = System.Convert.FromBase64String(base64); + return base.ConvertFrom(bytes, culture); + } + catch + { + return null; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + ImageSource source = value as ImageSource; + if (source == null) return null; + byte[] bytes = base.ConvertBackTo(source, culture) as byte[]; + return System.Convert.ToBase64String(bytes); + } + } +} + diff --git a/Sources/LolApp/Resources/Converters/ChampionClassToIconConverter.cs b/Sources/LolApp/Resources/Converters/ChampionClassToIconConverter.cs new file mode 100644 index 0000000..946b9a6 --- /dev/null +++ b/Sources/LolApp/Resources/Converters/ChampionClassToIconConverter.cs @@ -0,0 +1,42 @@ +using System; +using System.Globalization; +using Model; + +namespace LolApp.Resources.Converters +{ + public class ChampionClassToIconConverter : IValueConverter + { + private static Dictionary icons = new() + { + [ChampionClass.Assassin] = "assassin.png", + [ChampionClass.Fighter] = "fighter.png", + [ChampionClass.Mage] = "mage.png", + [ChampionClass.Marksman] = "marksman.png", + [ChampionClass.Support] = "support.png", + [ChampionClass.Tank] = "tank.png" + }; + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + try + { + ChampionClass champClass = (ChampionClass)value; + if(!icons.TryGetValue(champClass, out string icon)) + { + return ""; + } + return ImageSource.FromFile($"{icon}"); + } + catch + { + return ""; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/LolApp/Resources/Converters/ImageRatioConverter.cs b/Sources/LolApp/Resources/Converters/ImageRatioConverter.cs new file mode 100644 index 0000000..a3e0b7e --- /dev/null +++ b/Sources/LolApp/Resources/Converters/ImageRatioConverter.cs @@ -0,0 +1,28 @@ +using System; +using System.Globalization; + +namespace LolApp.Resources.Converters +{ + public class ImageRatioConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + try + { + double parentWidth = (double)value; + double ratio = (double)parameter; + return parentWidth*ratio; + } + catch + { + return 0.0; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/LolApp/Resources/Converters/PlusOneConverter.cs b/Sources/LolApp/Resources/Converters/PlusOneConverter.cs new file mode 100644 index 0000000..2d9eaec --- /dev/null +++ b/Sources/LolApp/Resources/Converters/PlusOneConverter.cs @@ -0,0 +1,28 @@ +using System; +using System.Globalization; + +namespace LolApp.Resources.Converters +{ + public class PlusOneConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + int i = -1; + try + { + i = (int)value; + } + catch (InvalidCastException e) + { + throw new InvalidCastException("PlusOneConverter : the value must be an int"); + } + return i + 1; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/LolApp/Resources/Fonts/Font Awesome 6 Free-Solid-900.otf b/Sources/LolApp/Resources/Fonts/Font Awesome 6 Free-Solid-900.otf new file mode 100644 index 0000000..f1d88fc Binary files /dev/null and b/Sources/LolApp/Resources/Fonts/Font Awesome 6 Free-Solid-900.otf differ diff --git a/Sources/LolApp/Resources/Fonts/OpenSans-Regular.ttf b/Sources/LolApp/Resources/Fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000..a49f11d Binary files /dev/null and b/Sources/LolApp/Resources/Fonts/OpenSans-Regular.ttf differ diff --git a/Sources/LolApp/Resources/Fonts/OpenSans-Semibold.ttf b/Sources/LolApp/Resources/Fonts/OpenSans-Semibold.ttf new file mode 100644 index 0000000..23911e4 Binary files /dev/null and b/Sources/LolApp/Resources/Fonts/OpenSans-Semibold.ttf differ diff --git a/Sources/LolApp/Resources/Images/assassin.svg b/Sources/LolApp/Resources/Images/assassin.svg new file mode 100644 index 0000000..fb86680 --- /dev/null +++ b/Sources/LolApp/Resources/Images/assassin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sources/LolApp/Resources/Images/fighter.svg b/Sources/LolApp/Resources/Images/fighter.svg new file mode 100644 index 0000000..42cb7df --- /dev/null +++ b/Sources/LolApp/Resources/Images/fighter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sources/LolApp/Resources/Images/lol.png b/Sources/LolApp/Resources/Images/lol.png new file mode 100644 index 0000000..10a552c Binary files /dev/null and b/Sources/LolApp/Resources/Images/lol.png differ diff --git a/Sources/LolApp/Resources/Images/lollogo.jpg b/Sources/LolApp/Resources/Images/lollogo.jpg new file mode 100644 index 0000000..a1b82b5 Binary files /dev/null and b/Sources/LolApp/Resources/Images/lollogo.jpg differ diff --git a/Sources/LolApp/Resources/Images/mage.svg b/Sources/LolApp/Resources/Images/mage.svg new file mode 100644 index 0000000..45d627b --- /dev/null +++ b/Sources/LolApp/Resources/Images/mage.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sources/LolApp/Resources/Images/marksman.svg b/Sources/LolApp/Resources/Images/marksman.svg new file mode 100644 index 0000000..f91066f --- /dev/null +++ b/Sources/LolApp/Resources/Images/marksman.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sources/LolApp/Resources/Images/rp.png b/Sources/LolApp/Resources/Images/rp.png new file mode 100644 index 0000000..e025310 Binary files /dev/null and b/Sources/LolApp/Resources/Images/rp.png differ diff --git a/Sources/LolApp/Resources/Images/support.svg b/Sources/LolApp/Resources/Images/support.svg new file mode 100644 index 0000000..2d1f053 --- /dev/null +++ b/Sources/LolApp/Resources/Images/support.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sources/LolApp/Resources/Images/sword.png b/Sources/LolApp/Resources/Images/sword.png new file mode 100644 index 0000000..fb87c07 Binary files /dev/null and b/Sources/LolApp/Resources/Images/sword.png differ diff --git a/Sources/LolApp/Resources/Images/tank.svg b/Sources/LolApp/Resources/Images/tank.svg new file mode 100644 index 0000000..2ec01a3 --- /dev/null +++ b/Sources/LolApp/Resources/Images/tank.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sources/LolApp/Resources/Raw/AboutAssets.txt b/Sources/LolApp/Resources/Raw/AboutAssets.txt new file mode 100644 index 0000000..808d6d3 --- /dev/null +++ b/Sources/LolApp/Resources/Raw/AboutAssets.txt @@ -0,0 +1,17 @@ +Any raw assets you want to be deployed with your application can be placed in +this directory (and child directories). Deployment of the asset to your application +is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. + + + +These files will be deployed with you package and will be accessible using Essentials: + + async Task LoadMauiAsset() + { + using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); + using var reader = new StreamReader(stream); + + var contents = reader.ReadToEnd(); + } + + diff --git a/Sources/LolApp/Resources/Splash/splash.png b/Sources/LolApp/Resources/Splash/splash.png new file mode 100644 index 0000000..e89e1c2 Binary files /dev/null and b/Sources/LolApp/Resources/Splash/splash.png differ diff --git a/Sources/LolApp/Resources/Styles/Colors.xaml b/Sources/LolApp/Resources/Styles/Colors.xaml new file mode 100644 index 0000000..286775e --- /dev/null +++ b/Sources/LolApp/Resources/Styles/Colors.xaml @@ -0,0 +1,46 @@ + + + + + #D2B977 + #F0E7B7 + #2B0B98 + White + Black + #E1E1E1 + #C8C8C8 + #ACACAC + #919191 + #6E6E6E + #404040 + #212121 + #141414 + + + + + + + + + + + + + + + #F7B548 + #FFD590 + #FFE5B9 + #28C2D1 + #7BDDEF + #C3F2F4 + #3E8EED + #72ACF1 + #A7CBF6 + + Transparent + + diff --git a/Sources/LolApp/Resources/Styles/FontAwesomeGlyphs.xaml b/Sources/LolApp/Resources/Styles/FontAwesomeGlyphs.xaml new file mode 100644 index 0000000..a53b993 --- /dev/null +++ b/Sources/LolApp/Resources/Styles/FontAwesomeGlyphs.xaml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/Sources/LolApp/Resources/Styles/MyStyles.xaml b/Sources/LolApp/Resources/Styles/MyStyles.xaml new file mode 100644 index 0000000..b988753 --- /dev/null +++ b/Sources/LolApp/Resources/Styles/MyStyles.xaml @@ -0,0 +1,102 @@ + + + + + 0.59 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/LolApp/Resources/Styles/Styles.xaml b/Sources/LolApp/Resources/Styles/Styles.xaml new file mode 100644 index 0000000..d23a11d --- /dev/null +++ b/Sources/LolApp/Resources/Styles/Styles.xaml @@ -0,0 +1,406 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/LolApp/SkinPage.xaml b/Sources/LolApp/SkinPage.xaml new file mode 100644 index 0000000..0b082ab --- /dev/null +++ b/Sources/LolApp/SkinPage.xaml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/LolApp/SkinPage.xaml.cs b/Sources/LolApp/SkinPage.xaml.cs new file mode 100644 index 0000000..f4ac283 --- /dev/null +++ b/Sources/LolApp/SkinPage.xaml.cs @@ -0,0 +1,18 @@ +using LolApp.ViewModels; +using ViewModels; + +namespace LolApp; + +public partial class SkinPage : ContentPage +{ + public ApplicationVM AppVM { get; set; } + public SkinVM SkinVM { get; } + + public SkinPage(SkinVM svm, ApplicationVM appVM) + { + BindingContext = SkinVM = svm; + AppVM = appVM; + + InitializeComponent(); + } +} diff --git a/Sources/LolApp/ViewModels/AddChampionPageVM.cs b/Sources/LolApp/ViewModels/AddChampionPageVM.cs new file mode 100644 index 0000000..ac7fd6a --- /dev/null +++ b/Sources/LolApp/ViewModels/AddChampionPageVM.cs @@ -0,0 +1,80 @@ +using System; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Microsoft.Maui.Graphics.Platform; +using ViewModels; + +namespace LolApp.ViewModels +{ + [ObservableObject] + public partial class AddChampionPageVM + { + ChampionsMgrVM ChampionsMgrVM { get; } + + public AddChampionPageVM(ChampionsMgrVM championsMgrVM, ChampionVM champion = null) + { + ChampionsMgrVM = championsMgrVM; + if(champion == null) return; + + oldChampion = champion; + IsNew = false; + this.champion = new EditableChampionVM(oldChampion); + } + + private ChampionVM oldChampion; + + [ObservableProperty] + bool isNew = true; + + [ObservableProperty] + EditableChampionVM champion = new (); + + [RelayCommand] + public async void PickIcon() => Champion.IconBase64 = await PickIconsAndImagesUtils.PickPhoto(42); + + [RelayCommand] + public async void PickLargeImage() => Champion.LargeImageBase64 = await PickIconsAndImagesUtils.PickPhoto(1000); + + [RelayCommand] + async Task Cancel() + => await App.Current.MainPage.Navigation.PopAsync(); + + [RelayCommand] + async Task AddChampion() + { + ChampionVM champVM = Champion.ToChampionVM(); + await ChampionsMgrVM.AddChampion(champVM); + await App.Current.MainPage.Navigation.PopAsync(); + } + + [RelayCommand] + async Task EditChampion() + { + ChampionVM newChampion = Champion.ToChampionVM(); + await ChampionsMgrVM.EditChampion(oldChampion, newChampion); + await App.Current.MainPage.Navigation.PopAsync(); + } + + [ObservableProperty] + string newCharacteristicDescription; + + [ObservableProperty] + int newCharacteristicValue; + + [RelayCommand] + void AddCharacteristic() + { + Champion?.AddCharacteristic(newCharacteristicDescription, newCharacteristicValue); + } + + [RelayCommand] + void RemoveCharacteristic(KeyValuePair characteristic) + => Champion?.RemoveCharacteristic(characteristic); + + [RelayCommand] + async Task AddSkill() + => await App.Current.MainPage.Navigation.PushModalAsync(new AddSkill(Champion)); + + } +} + diff --git a/Sources/LolApp/ViewModels/AddOrEditSkinPageVM.cs b/Sources/LolApp/ViewModels/AddOrEditSkinPageVM.cs new file mode 100644 index 0000000..09a134c --- /dev/null +++ b/Sources/LolApp/ViewModels/AddOrEditSkinPageVM.cs @@ -0,0 +1,64 @@ +using System; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Model; +using ViewModels; + +namespace LolApp.ViewModels +{ + [ObservableObject] + public partial class AddOrEditSkinPageVM + { + SkinsMgrVM SkinsMgrVM { get; } + + private SkinVM oldSkin; + + [ObservableProperty] + bool isNew = true; + + [ObservableProperty] + EditableSkinVM skin; + + public AddOrEditSkinPageVM(SkinsMgrVM skinsMgrVM, SkinVM oldSkin) + { + SkinsMgrVM = skinsMgrVM; + + this.oldSkin = oldSkin; + IsNew = false; + this.skin = new EditableSkinVM(oldSkin); + } + + public AddOrEditSkinPageVM(SkinsMgrVM skinsMgrVM, ChampionVM champion) + { + SkinsMgrVM = skinsMgrVM; + skin = new EditableSkinVM(champion); + } + + [RelayCommand] + public async void PickIcon() => Skin.IconBase64 = await PickIconsAndImagesUtils.PickPhoto(42); + + [RelayCommand] + public async void PickLargeImage() => Skin.LargeImageBase64 = await PickIconsAndImagesUtils.PickPhoto(1000); + + [RelayCommand] + async Task Cancel() + => await App.Current.MainPage.Navigation.PopAsync(); + + [RelayCommand] + async Task AddSkin() + { + SkinVM skinVM = Skin.ToSkinVM(); + await SkinsMgrVM.AddSkin(skinVM); + await App.Current.MainPage.Navigation.PopAsync(); + } + + [RelayCommand] + async Task EditSkin() + { + SkinVM newSkin = Skin.ToSkinVM(); + await SkinsMgrVM.EditSkin(oldSkin, newSkin); + await App.Current.MainPage.Navigation.PopAsync(); + } + } +} + diff --git a/Sources/LolApp/ViewModels/AddSkillVM.cs b/Sources/LolApp/ViewModels/AddSkillVM.cs new file mode 100644 index 0000000..ef40e97 --- /dev/null +++ b/Sources/LolApp/ViewModels/AddSkillVM.cs @@ -0,0 +1,46 @@ +using System; +using System.Linq; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Model; +using ViewModels; + +namespace LolApp.ViewModels +{ + public partial class AddSkillVM : ObservableObject + { + public AddSkillVM(EditableChampionVM champion) + { + Champion = champion; + } + + [ObservableProperty] + SkillType skillType; + + [ObservableProperty] + string name; + + [ObservableProperty] + string description; + + [ObservableProperty] + EditableChampionVM champion; + + [RelayCommand] + async void AddSkillToChampion() + { + champion.Skills.Add(new SkillVM(new Skill(name, skillType, description))); + await App.Current.MainPage.Navigation.PopModalAsync(); + } + + [RelayCommand] + async void Cancel() + { + await App.Current.MainPage.Navigation.PopModalAsync(); + } + + public IEnumerable AllSkills { get; } + = Enum.GetValues(typeof(SkillType)).Cast().Except(new SkillType[] {SkillType.Unknown}).ToList(); + } +} + diff --git a/Sources/LolApp/ViewModels/ApplicationVM.cs b/Sources/LolApp/ViewModels/ApplicationVM.cs new file mode 100644 index 0000000..691298c --- /dev/null +++ b/Sources/LolApp/ViewModels/ApplicationVM.cs @@ -0,0 +1,57 @@ +using System; +using CommunityToolkit.Mvvm.Input; +using Model; +using ViewModels; + +namespace LolApp.ViewModels +{ + public partial class ApplicationVM + { + public ChampionsMgrVM ChampionsMgrVM { get; set; } + + public SkinsMgrVM SkinsMgrVM { get; set; } + + public ApplicationVM(ChampionsMgrVM championsMgrVM, SkinsMgrVM skinsMgrVM) + { + ChampionsMgrVM = championsMgrVM; + SkinsMgrVM = skinsMgrVM; + } + + [RelayCommand] + async Task NavigateToChampionDetailsPage(ChampionVM cvm) + { + SkinsMgrVM.Champion = cvm; + SkinsMgrVM.Index = 0; + SkinsMgrVM.Count = 5; + await SkinsMgrVM.LoadSkinsCommand.ExecuteAsync(cvm); + await App.Current.MainPage.Navigation.PushAsync(new ChampionPage(cvm, this)); + } + + [RelayCommand] + async Task NavigateToAddNewChampionPage() + => await App.Current.MainPage.Navigation.PushAsync(new AddChampionPage(ChampionsMgrVM)); + + [RelayCommand(CanExecute = nameof(CanNavigateToEditChampionPage))] + async Task NavigateToEditChampionPage(ChampionVM champ) + => await App.Current.MainPage.Navigation.PushAsync(new AddChampionPage(ChampionsMgrVM, champ)); + + bool CanNavigateToEditChampionPage(ChampionVM champ) => champ != null; + + [RelayCommand] + async Task NavigateToSkinDetailsPage(SkinVM svm) + { + await App.Current.MainPage.Navigation.PushAsync(new SkinPage(svm, this)); + } + + [RelayCommand] + async Task NavigateToAddNewSkinPage(ChampionVM champion) + => await App.Current.MainPage.Navigation.PushAsync(new AddOrEditSkinPage(SkinsMgrVM, champion)); + + [RelayCommand(CanExecute = nameof(CanNavigateToEditSkinPage))] + async Task NavigateToEditSkinPage(SkinVM skin) + => await App.Current.MainPage.Navigation.PushAsync(new AddOrEditSkinPage(SkinsMgrVM, skin)); + + bool CanNavigateToEditSkinPage(SkinVM skin) => skin != null; + } +} + diff --git a/Sources/LolApp/ViewModels/ChampionClassVM.cs b/Sources/LolApp/ViewModels/ChampionClassVM.cs new file mode 100644 index 0000000..992f45f --- /dev/null +++ b/Sources/LolApp/ViewModels/ChampionClassVM.cs @@ -0,0 +1,27 @@ +using System; +using System.Linq; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; + +namespace LolApp.ViewModels +{ + [ObservableObject] + public partial class ChampionClassVM + { + [ObservableProperty] + private ChampionClass model; + + [ObservableProperty] + private bool isSelected; + + public ChampionClassVM(ChampionClass model) + { + Model = model; + } + + public static IEnumerable Classes { get; } + = Enum.GetValues(typeof(ChampionClass)).Cast().Except(new ChampionClass[] {ChampionClass.Unknown}) + .Select(cc => new ChampionClassVM(cc)); + } +} + diff --git a/Sources/LolApp/ViewModels/ChampionsPageVM.cs b/Sources/LolApp/ViewModels/ChampionsPageVM.cs new file mode 100644 index 0000000..906875a --- /dev/null +++ b/Sources/LolApp/ViewModels/ChampionsPageVM.cs @@ -0,0 +1,111 @@ +using System; +using System.Reflection; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Model; +using ViewModels; + +namespace LolApp.ViewModels +{ + [ObservableObject] + public partial class ChampionsPageVM + { + public ChampionsMgrVM ChampionsMgrVM { get; set; } + + public ChampionsPageVM(ChampionsMgrVM championsMgrVM) + { + ChampionsMgrVM = championsMgrVM; + PropertyChanged += ChampionsMgrVM_PropertyChanged; + + } + + [ObservableProperty] + private ChampionClassVM selectedClass; + + + [RelayCommand] + public async Task SelectedChampionClassChanged(ChampionClassVM champClass) + { + if(SelectedClass != null) SelectedClass.IsSelected = false; + if(champClass.Model == ChampionClass.Unknown + || champClass.Model == SelectedClass?.Model) + { + SelectedClass = null; + return; + } + SelectedClass = champClass; + SelectedClass.IsSelected = true; + await ChampionsMgrVM.LoadChampionsByClass(SelectedClass.Model);//ChampionsMgrVM.SelectedClass); + + } + + + [ObservableProperty] + private ChampionVM selectedChampion; + + [ObservableProperty] + private string searchedName; + + + + [ObservableProperty] + private string searchedSkill; + + [ObservableProperty] + private string searchedCharacteristic; + + private static string[] searchedStrings = { nameof(SearchedName), nameof(SearchedSkill), nameof(SearchedCharacteristic), nameof(SelectedClass) }; + + private async void ChampionsMgrVM_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if(searchedStrings.Any(s => e.PropertyName == s)) + { + if(GetProperty(e.PropertyName).GetValue(this) != GetProperty(e.PropertyName).GetDefaultValue()) + { + foreach(string s in searchedStrings.Except(new string[]{e.PropertyName })) + { + var prop = GetProperty(s); + prop.ResetPropertyValue(this); + } + return; + } + ChampionsMgrVM.Index=0; + if(searchedStrings.All(s => GetProperty(s).GetValue(this) == GetProperty(s).GetDefaultValue())) + { + await ChampionsMgrVM.LoadChampions(); + } + } + } + + private PropertyInfo? GetProperty(string propName) + => typeof(ChampionsPageVM).GetProperty(propName); + + } + + public static class Extensions + { + public static void ResetPropertyValue(this PropertyInfo pi, ChampionsPageVM instance) + { + if(pi.PropertyType == typeof(ChampionClassVM)) + { + var temp = pi.GetValue(instance); + if(temp != null) + (temp as ChampionClassVM).IsSelected = false; + return; + } + pi.SetValue(instance, pi.GetDefaultValue()); + } + + public static object GetDefaultValue(this Type t) + { + if (t.IsValueType) + return Activator.CreateInstance(t); + + return null; + } + + public static object GetDefaultValue(this PropertyInfo pi) + => pi.PropertyType.GetDefaultValue(); + } +} + diff --git a/Sources/LolApp/ViewModels/PickIconsAndImagesUtils.cs b/Sources/LolApp/ViewModels/PickIconsAndImagesUtils.cs new file mode 100644 index 0000000..01bb468 --- /dev/null +++ b/Sources/LolApp/ViewModels/PickIconsAndImagesUtils.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.Maui.Graphics.Platform; + +namespace LolApp.ViewModels +{ + public static class PickIconsAndImagesUtils + { + public async static Task PickPhoto(float maxWidthAndHeight) + { + FileResult photo = await MediaPicker.Default.PickPhotoAsync(); + return photo != null ? await ToBase64(photo, maxWidthAndHeight) : null; + } + + public async static Task ToBase64(FileResult photo, float maxWidthAndHeight) + { + using (var stream = await photo.OpenReadAsync()) + using (var memoryStream = new MemoryStream()) + { + var image = PlatformImage.FromStream(stream); + if(image != null) + { + var newImage = image.Downsize(maxWidthAndHeight, true); + return newImage.AsBase64(); + } + } + return null; + } + } +} + diff --git a/Sources/Model/Champion.cs b/Sources/Model/Champion.cs index 7fb808c..df3000d 100644 --- a/Sources/Model/Champion.cs +++ b/Sources/Model/Champion.cs @@ -9,13 +9,10 @@ public class Champion : IEquatable public int Id { - get => id; - private init - { - id = value; - } + get; + private init; } - private readonly int id; + private readonly int id=0; public string Name { @@ -67,6 +64,7 @@ public class Champion : IEquatable public Champion(string name, ChampionClass champClass = ChampionClass.Unknown, string icon = "", string image = "", string bio = "") { + Id = 0; Name = name; Class = champClass; Icon = icon; @@ -143,7 +141,14 @@ public class Champion : IEquatable => Name.GetHashCode() % 997; public bool Equals(Champion? other) - => Name.Equals(other?.Name); + { + if (id == 0 || other?.id == 0) + { + return Name.Equals(other?.Name); + } + return id.Equals(other?.id); + + } public override string ToString() { diff --git a/Sources/Tests/DbChampionManager_UT.cs b/Sources/Tests/DbChampionManager_UT.cs index d992a4f..102e22a 100644 --- a/Sources/Tests/DbChampionManager_UT.cs +++ b/Sources/Tests/DbChampionManager_UT.cs @@ -9,6 +9,7 @@ using Model; public class DbChampionManager_UT { + [Fact] public async Task Add_TestAsync() { @@ -19,22 +20,24 @@ public class DbChampionManager_UT .UseSqlite(connection) .Options; + using (var db = new DbDataManager(new EFLib.LolContext(options))) { db.EnsureCreated(); + Champion champion = new Champion("Aurelien", ChampionClass.Tank, "tro bo le type"); Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "tro bon le type"); - Champion champion3 = new Champion("Mathilde", ChampionClass.Unknown, "Chut mathilde"); + Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "Chut mathilde"); await db.ChampionsMgr.AddItem(champion); await db.ChampionsMgr.AddItem(champion2); await db.ChampionsMgr.AddItem(champion3); - } using (var db = new DbDataManager(new EFLib.LolContext(options))) { db.EnsureCreated(); Assert.Equal(3, await db.ChampionsMgr.GetNbItems()); + Assert.Null(await db.ChampionsMgr.AddItem(new Champion("Aurelien", ChampionClass.Tank, "tro bo le type"))); } @@ -56,12 +59,10 @@ public class DbChampionManager_UT Champion champion = new Champion("Aurelien", ChampionClass.Tank, "tro bo le type"); Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "tro bon le type"); - Champion champion3 = new Champion("Mathilde", ChampionClass.Unknown, "Chut mathilde"); + Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "Chut mathilde"); await db.ChampionsMgr.AddItem(champion); await db.ChampionsMgr.AddItem(champion2); await db.ChampionsMgr.AddItem(champion3); - - Assert.Equal(3, await db.ChampionsMgr.GetNbItems()); } using (var db = new DbDataManager(new EFLib.LolContext(options))) @@ -94,14 +95,11 @@ public class DbChampionManager_UT Champion champion = new Champion("Aurelien", ChampionClass.Tank, "tro bo le type"); Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "tro bon le type"); - Champion champion3 = new Champion("Mathilde", ChampionClass.Unknown, "Chut mathilde"); + Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "Chut mathilde"); await db.ChampionsMgr.AddItem(champion); await db.ChampionsMgr.AddItem(champion2); await db.ChampionsMgr.AddItem(champion3); - - Assert.Equal(3, await db.ChampionsMgr.GetNbItems()); } - using (var db = new DbDataManager(new EFLib.LolContext(options))) { db.EnsureCreated(); @@ -119,4 +117,41 @@ public class DbChampionManager_UT Assert.Equal("Test", champ.First().Name); } } + + [Fact] + public async Task GetItems_TestAsync() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var db = new DbDataManager(new EFLib.LolContext(options))) + { + db.EnsureCreated(); + + Champion champion = new Champion("Aurelien", ChampionClass.Tank, "hey bo le type"); + Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "Ztro bon le type"); + Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "ah mathilde"); + await db.ChampionsMgr.AddItem(champion); + await db.ChampionsMgr.AddItem(champion2); + await db.ChampionsMgr.AddItem(champion3); + } + + using (var db = new DbDataManager(new EFLib.LolContext(options))) + { + db.EnsureCreated(); + var list = await db.ChampionsMgr.GetItems(0, 10, "bio", false); + Assert.Equal(3, list.Count()); + list = await db.ChampionsMgr.GetItems(0, 3, "autre", true); + Assert.Equal("Aurelien", list.Last().Name); + list = await db.ChampionsMgr.GetItems(0, 3, "class", true); + Assert.Equal("Aurelien", list.First().Name); + } + } + + + } \ No newline at end of file