From bc1503ec10865959ccb7a7075a3f09d4c97fb344 Mon Sep 17 00:00:00 2001 From: etudiant Date: Mon, 12 Dec 2022 20:33:53 +0100 Subject: [PATCH] mauisuite --- src/CalculateurMoyanne/BSN/IDataManager.cs | 7 +- src/CalculateurMoyanne/BSN/Manager.cs | 68 +++++- .../CalculateurApp/App.xaml.cs | 10 +- .../CalculateurApp/AppShell.xaml | 8 +- .../CalculateurApp/AppShell.xaml.cs | 2 +- .../CalculateurApp/CalculDbMaui.cs | 19 ++ .../CalculateurApp/CalculateurApp.csproj | 33 ++- .../CalculateurApp/DataBase_constante.cs | 11 + .../CalculateurApp/MauiProgram.cs | 4 +- .../CalculateurApp/View/BlockView.xaml | 6 +- .../CalculateurApp/View/HomePage.xaml.cs | 2 +- .../CalculateurApp/View/Maquette.xaml | 87 +++++++ .../CalculateurApp/View/Maquette.xaml.cs | 13 ++ .../CalculateurApp/View/MatNote.xaml | 57 +++-- .../CalculateurApp/View/Start.xaml | 2 +- .../CalculateurApp/View/UEPage1.xaml | 13 +- .../CalculateurApp/View/UEPage1.xaml.cs | 6 +- .../CalculateurApp/View/mqt.xaml | 16 +- .../CalculateurApp/ViewModel/BlocViewModel.cs | 21 +- .../ViewModel/MaquetteViewModel.cs | 54 ++++- .../ViewModel/PageAjoutMaquette.cs | 91 ++++++++ .../CalculateurEF/Context/CalculContext.cs | 16 +- .../CalculateurEF/Entities/BlocEntity.cs | 22 +- .../CalculateurEF/Entities/MaquetteEntity.cs | 4 +- .../CalculateurEF/Entities/MatiereEntity.cs | 12 +- .../CalculateurEF/Entities/UEentity.cs | 17 +- ... => 20221211125750_Migrations.Designer.cs} | 54 +++-- ...stCalc.cs => 20221211125750_Migrations.cs} | 68 +++--- .../Migrations/CalculContextModelSnapshot.cs | 50 +++- .../CalculateurEF/calcul.db | Bin 0 -> 45056 bytes .../CalculateurMapping/BlocDbDataManager.cs | 105 ++++++--- .../MaquetteDbDataManager.cs | 106 +++++---- .../MatiereDbDataManager.cs | 9 +- .../CalculateurMapping/UeDbDataManager.cs | 13 +- src/CalculateurMoyanne/CalculateurMoyanne.sln | 2 +- .../CalculateurStub/Stub/StubBloc.cs | 56 +++-- .../CalculateurStub/Stub/StubMaquette.cs | 63 ++--- .../CalculateurStub/Stub/StubMatiere.cs | 30 ++- .../CalculateurStub/Stub/stubUE.cs | 29 ++- .../CalculateurStub/StubCalculateur.csproj | 1 + .../Modele/BlocModel.cs | 82 ++++--- .../Modele/MaquetteModel.cs | 94 +++++--- .../ClassCalculateurMoyenne/Modele/Matiere.cs | 8 +- .../ClassCalculateurMoyenne/Modele/UE.cs | 29 ++- .../Modele/Utilisateur.cs | 6 +- src/CalculateurMoyanne/testpourEf/Program.cs | 56 ++++- .../testpourEf/testpourEf.csproj | 1 + .../LesTests/TestManager.cs | 64 +++++ .../LesTests/UnitTestBloc.cs | 106 +++++---- .../LesTests/UnitTestMaquette.cs | 36 +-- .../LesTests/UnitTestUE.cs | 219 ++++++++---------- .../TestCalculateurMoyanne.csproj | 9 +- 52 files changed, 1344 insertions(+), 553 deletions(-) create mode 100644 src/CalculateurMoyanne/CalculateurApp/CalculDbMaui.cs create mode 100644 src/CalculateurMoyanne/CalculateurApp/DataBase_constante.cs create mode 100644 src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml create mode 100644 src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs create mode 100644 src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs rename src/CalculateurMoyanne/CalculateurEF/Migrations/{20221203193812_TestCalc.Designer.cs => 20221211125750_Migrations.Designer.cs} (71%) rename src/CalculateurMoyanne/CalculateurEF/Migrations/{20221203193812_TestCalc.cs => 20221211125750_Migrations.cs} (69%) create mode 100644 src/CalculateurMoyanne/CalculateurEF/calcul.db create mode 100644 src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs diff --git a/src/CalculateurMoyanne/BSN/IDataManager.cs b/src/CalculateurMoyanne/BSN/IDataManager.cs index 757c9c0..8c2c156 100644 --- a/src/CalculateurMoyanne/BSN/IDataManager.cs +++ b/src/CalculateurMoyanne/BSN/IDataManager.cs @@ -3,15 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ClassCalculateurMoyenne; -namespace BSN +namespace Bussness { public interface IDataManager { Task Add(Data data); + Task Delete(Data data); Task Update(Data data); Task GetDataWithName(string name); - Task> GetAll(); + Task> GetAll(); + Task AddUEBloc(UE data, int blocId); } } diff --git a/src/CalculateurMoyanne/BSN/Manager.cs b/src/CalculateurMoyanne/BSN/Manager.cs index 5008a0e..eb99592 100644 --- a/src/CalculateurMoyanne/BSN/Manager.cs +++ b/src/CalculateurMoyanne/BSN/Manager.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BSN +namespace Bussness { public class Manager { @@ -41,6 +41,7 @@ namespace BSN this.maquetteDbDataManager = maquettemanager; maquette = new ReadOnlyCollection(maquettes); } + public Manager(IDataManagerblocmanager) { this.blocDbDataManager = blocmanager; @@ -72,6 +73,7 @@ namespace BSN #endregion #region Methodes + //Add Maquette public Task AddMaquette(MaquetteModel maqt) { @@ -80,10 +82,10 @@ namespace BSN return Task.FromResult(false); } - return maquetteDbDataManager.Add(maqt); - + return maquetteDbDataManager.Add(maqt); } + //Delete Maquette public async Task Deletemqt(MaquetteModel maqt) { if (maquetteDbDataManager == null) @@ -92,7 +94,7 @@ namespace BSN } return await maquetteDbDataManager.Delete(maqt); } - + //Update Maquette public async Task UpdateMaquette(MaquetteModel maqt) { if (maquetteDbDataManager == null) @@ -101,12 +103,66 @@ namespace BSN } return await maquetteDbDataManager.Update(maqt); } - public async Task> GetAllMaquette() + // GEt all Maquette + public async Task> GetAllMaquette() { return await maquetteDbDataManager.GetAll(); } + // Get maquetteByName + public MaquetteModel GetMaquetteByName(string maquetteName) + { + return maquetteDbDataManager.GetDataWithName(maquetteName).Result; + + } + // add bloc + public Task AddBloc(BlocModel bloc) + { + var response = blocDbDataManager == null; + if (response) + { + return Task.FromResult(false); + } + + return blocDbDataManager.Add(bloc); + } + //public Task Adddansbloc(BlocModel bloc) + //{ + // if (blocDbDataManager == null) + // { + // return Task.FromResult(false); + // } + + // return blocDbDataManager.Add(bloc); + //} + //Delete bloc + public async Task DeleteBloc(BlocModel bl) + { + if (BlocDbDataManager == null) + { + return false; + } + return await BlocDbDataManager.Delete(bl); + } + //public async Task DeleteBlocById(int id) + //{ + + //} + //Update bloc + public async Task UpdateBloc(BlocModel bl) + { + if (BlocDbDataManager == null) + { + return false; + } + return await BlocDbDataManager.Update(bl); + } + //GetAllbloc + public async Task> GetAllBloc() + { + return await BlocDbDataManager.GetAll(); + } + #endregion } - #endregion } diff --git a/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs index 957a8bd..8fda9f3 100644 --- a/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs +++ b/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs @@ -10,11 +10,13 @@ namespace CalculateurApp { InitializeComponent(); - // MainPage = new NavigationPage(new HomePage()); + // MainPage = new NavigationPage(new HomePage()); //MainPage = new AppShell(BlocViewModel c); - MainPage = new Maquette (); - // MainPage = new Start(); - + // MainPage = new EXE (); + MainPage = new AppShell(); + // MainPage = new Maquette(); + + } } } \ No newline at end of file diff --git a/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml b/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml index 82b2e80..2208f7e 100644 --- a/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml +++ b/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml @@ -1,14 +1,14 @@ - + + ContentTemplate="{DataTemplate local:AjtMaquette}" + Route="AjtMaquette" /> diff --git a/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml.cs index 5f5bfca..f88d145 100644 --- a/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml.cs +++ b/src/CalculateurMoyanne/CalculateurApp/AppShell.xaml.cs @@ -7,7 +7,7 @@ namespace CalculateurApp public AppShell() { InitializeComponent(); - Routing.RegisterRoute(nameof(Start), typeof(Start)); + Routing.RegisterRoute(nameof(BlockView), typeof(BlockView)); } } } \ No newline at end of file diff --git a/src/CalculateurMoyanne/CalculateurApp/CalculDbMaui.cs b/src/CalculateurMoyanne/CalculateurApp/CalculDbMaui.cs new file mode 100644 index 0000000..bd30b55 --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/CalculDbMaui.cs @@ -0,0 +1,19 @@ +using System; +using CalculateurEF.Context; +using Microsoft.EntityFrameworkCore; + +namespace CalculateurApp + +{ + public class CalculDbMaui:CalculContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlite($"Data Source={ DataBase_constante.DatabasePath}"); + } + } + } +} + diff --git a/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj b/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj index 5f3dab7..4faf263 100644 --- a/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj +++ b/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj @@ -38,10 +38,6 @@ - - - - @@ -50,12 +46,20 @@ + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + @@ -65,6 +69,9 @@ MaquettePage.xaml + + mqt.xaml + @@ -89,6 +96,24 @@ MSBuild:Compile + + + + + + + + + + + + + + + + + + diff --git a/src/CalculateurMoyanne/CalculateurApp/DataBase_constante.cs b/src/CalculateurMoyanne/CalculateurApp/DataBase_constante.cs new file mode 100644 index 0000000..9569a5e --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/DataBase_constante.cs @@ -0,0 +1,11 @@ +using System; +namespace CalculateurApp +{ + public static class DataBase_constante + { + public const string DatabaseName = "calculDb.db3"; + public const SQLite.SQLiteOpenFlags flags = SQLite.SQLiteOpenFlags.ReadWrite | SQLite.SQLiteOpenFlags.Create | SQLite.SQLiteOpenFlags.SharedCache; + public static string DatabasePath => Path.Combine(FileSystem.AppDataDirectory, DatabaseName); + } +} + diff --git a/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs b/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs index abf0835..0e5ce4b 100644 --- a/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs +++ b/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs @@ -20,8 +20,10 @@ namespace CalculateurApp // builder.Services.AddSingleton(); // builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml b/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml index c11a33c..50dcb5e 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml +++ b/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml @@ -1,11 +1,11 @@  + Title="BlockView"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs new file mode 100644 index 0000000..6985d18 --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs @@ -0,0 +1,13 @@ +using CalculateurApp.ViewModel; + +namespace CalculateurApp.View; + +public partial class AjtMaquette : ContentPage +{ + public AjtMaquette(PageAjoutMaquette vm) + { + InitializeComponent(); + BindingContext = vm; + Routing.RegisterRoute(nameof(BlockView), typeof(BlockView)); + } +} diff --git a/src/CalculateurMoyanne/CalculateurApp/View/MatNote.xaml b/src/CalculateurMoyanne/CalculateurApp/View/MatNote.xaml index 4d527e6..b97be26 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/MatNote.xaml +++ b/src/CalculateurMoyanne/CalculateurApp/View/MatNote.xaml @@ -1,4 +1,4 @@ - + + - - diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs index bfd2d2d..40846a0 100644 --- a/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs @@ -10,14 +10,15 @@ using System.Threading.Tasks; namespace CalculateurApp.ViewModel { - [QueryProperty("Nom", "Nom")] - public partial class BlocViewModel:ObservableObject + + public partial class BlocViewModel:ObservableObject,IQueryAttributable { [ObservableProperty] string nom; public BlocModel blocModel { get; set; } public UE ue { get; set; } + public BlocViewModel() { Items = new ObservableCollection(); @@ -50,12 +51,28 @@ namespace CalculateurApp.ViewModel Items.Remove(bl); } } + [RelayCommand] + void GEtAllUE(UE bl) + { + if (Items.Contains(bl)) + { + Items.Remove(bl); + } + } + [RelayCommand] async Task GoBack() { await Shell.Current.GoToAsync(".."); } + + public void ApplyQueryAttributes(IDictionary query) + { + var Maquette = query["maquette"]as MaquetteModel ; + + blocModel.IDMaquetteFrk = Maquette.Id; + } } diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs index 8466994..6e2e760 100644 --- a/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs @@ -1,6 +1,7 @@ -using BSN; +using Bussness; using CalculateurApp.View; using CalculateurEF.Context; +using CalculateurMapping; using ClassCalculateurMoyenne; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -8,6 +9,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; @@ -15,30 +17,36 @@ namespace CalculateurApp.ViewModel { public partial class MaquetteViewModel:ObservableObject { - // public Maquette maquette { get; set; } + public BlocModel blocModel { get; set; } + // public ReadOnlyObservableCollectionlst { get; set; } + public Manager manager; public MaquetteViewModel() { Items = new ObservableCollection(); - + //foreach (var BB in manager.GetAllBloc().Result) + // Items.Add(BB); blocModel = new BlocModel(); } [ObservableProperty] ObservableCollection items; - + [ObservableProperty] + ObservableCollection lstblc=new ObservableCollection(); + [ObservableProperty] string nom; [RelayCommand] void Add() { + Manager blocDbDataManager = new Manager(new BlocDbDataManager()); if (string.IsNullOrEmpty(blocModel.Nom)) return; - BlocModel u = new BlocModel(blocModel.Nom); - //u.Intitulé = ue.Intitulé; + BlocModel u = new BlocModel(blocModel.Nom); Items.Add(u); - blocModel.Nom = string.Empty; + blocDbDataManager.AddBloc(blocModel); + blocModel.Nom = string.Empty; } [RelayCommand] void Delete(BlocModel bl) @@ -49,6 +57,17 @@ namespace CalculateurApp.ViewModel Items.Remove(bl); } } + + [RelayCommand] + void AjoutUE(BlocModel bl) + + { + if (Items.Contains(bl)) + { + Items.Remove(bl); + } + } + [RelayCommand] @@ -58,10 +77,27 @@ namespace CalculateurApp.ViewModel } [RelayCommand] - public void GetAllUE() + async Task GoBack() + { + await Shell.Current.GoToAsync(".."); + } + + public void ApplyQueryAttributes(IDictionary query) + { + var Maquette = query["maquette"] as MaquetteModel; + + blocModel.IDMaquetteFrk = Maquette.Id; + } + [RelayCommand] + public void GetAllBloc() { - // var result=Manager + var result = manager.GetAllBloc(); + foreach(var item in result.Result) + { + lstblc.Add(item); + + } } } } diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs new file mode 100644 index 0000000..32b622c --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.ObjectModel; +using ClassCalculateurMoyenne; +using CalculateurMapping; +using Bussness; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CalculateurApp.View; +using System.Linq; + +namespace CalculateurApp.ViewModel +{ + public partial class PageAjoutMaquette : ObservableObject + { + public MaquetteModel maquette { get; set; } + public Manager manager; + + + public PageAjoutMaquette() + { + manager = new Manager(new MaquetteDbDataManager()); + + Items = new ObservableCollection(); + foreach(var mm in manager.GetAllMaquette().Result) + Items.Add( mm); + maquette = new MaquetteModel(); + + } + + [ObservableProperty] + ObservableCollection items; + public string NomMaquette + { + get => maquette.NomMaquette; + set => SetProperty(maquette.NomMaquette, value, maquette, (u, v) => u.setNomMaquete(v)); + + } + [RelayCommand] + async void Add() + { + Manager maquetteDbDataManager = new Manager(new MaquetteDbDataManager()); + + if (string.IsNullOrEmpty(NomMaquette)) + return; + MaquetteModel u = maquette; + Items.Add(u); + await maquetteDbDataManager.AddMaquette(maquette); + //maquette.NomMaquette = string.Empty; + + } + [RelayCommand] + async void Delete(MaquetteModel model) + + { + + if (Items.Contains(model)) + { + Items.Remove(model); + await manager.Deletemqt(model); + + var v = await manager.GetAllMaquette(); + Console.WriteLine(v); + + } + } + + + + [RelayCommand] + async void GetAllMaquette() + { + Manager maquetteDbDataManager = new Manager(new MaquetteDbDataManager()); + + await maquetteDbDataManager.GetAllMaquette(); + } + [RelayCommand] + async Task GoBack(string maquetteName) + { + var maquette = manager.GetMaquetteByName(maquetteName); + + var parametre = new Dictionary + { + {"maquette",maquette } + }; + + await Shell.Current.GoToAsync($"{nameof(BlockView)}",parametre); + } + + } +} + diff --git a/src/CalculateurMoyanne/CalculateurEF/Context/CalculContext.cs b/src/CalculateurMoyanne/CalculateurEF/Context/CalculContext.cs index 7384672..38e5207 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Context/CalculContext.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Context/CalculContext.cs @@ -1,5 +1,6 @@ using CalculateurEF.Entities; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; @@ -19,7 +20,20 @@ namespace CalculateurEF.Context protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite("Data Source=calcul.db"); + //optionsBuilder.UseSqlite("Data Source=calcul.db"); + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlite("Data Source=calcul.db"); + } } + public CalculContext() + { + + } + public CalculContext(DbContextOptions options) : base(options) + { + + } + } } diff --git a/src/CalculateurMoyanne/CalculateurEF/Entities/BlocEntity.cs b/src/CalculateurMoyanne/CalculateurEF/Entities/BlocEntity.cs index 8eee4db..af5fec9 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Entities/BlocEntity.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Entities/BlocEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,10 +9,25 @@ namespace CalculateurEF.Entities { public class BlocEntity { - #region Propriétés - public List ue; + #region Propriétés public int Id { get; set; } - public string Nom; + public string Nom { get; set; } + public ICollection UeEntityId { get; set; } = new List(); + + public int IDMaquetteFrk + { + get; set; + } + [ForeignKey("IDMaquetteFrk")] + public MaquetteEntity MaquetteEntity + { + get; set; + } + + + + + //public ICollection ue { get; set; } diff --git a/src/CalculateurMoyanne/CalculateurEF/Entities/MaquetteEntity.cs b/src/CalculateurMoyanne/CalculateurEF/Entities/MaquetteEntity.cs index be68db4..acaf7b3 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Entities/MaquetteEntity.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Entities/MaquetteEntity.cs @@ -13,7 +13,9 @@ namespace CalculateurEF.Entities #region Propriétés public int Id { get; set; } public string NomMaquette { get; set; } - public ICollection Bloc { get; set; } + public ICollection Bloc { get; set; }= new List(); + // public ICollection UeEntityId { get; set; } = new List(); + #endregion #region Constructeurs public MaquetteEntity() diff --git a/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs b/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs index e8696ea..d37c751 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,15 @@ namespace CalculateurEF.Entities public long id { get; set; } public int Note { get; set; } public int Coef { get; set; } - + public long IDUEForeignKey + { + get; set; + } + [ForeignKey("IDUEForeignKey")] + public UEentity UEentity + { + get; set; + } + } } diff --git a/src/CalculateurMoyanne/CalculateurEF/Entities/UEentity.cs b/src/CalculateurMoyanne/CalculateurEF/Entities/UEentity.cs index 7f1039b..da2090e 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Entities/UEentity.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Entities/UEentity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Reflection.Metadata; using System.Text; @@ -10,12 +11,20 @@ namespace CalculateurEF.Entities public class UEentity { public long Id { get; set; } - public int Coefficient { get; set; } public string intitulé { get; set; } - public ICollection mat { get; set; } - public List matiere; - + public ICollection mat { get; set; }= + new List (); + + public int IDForeignKey + { + get; set; + } + [ForeignKey("IDForeignKey")] + public BlocEntity BlocEntity + { + get; set; + } public UEentity() { diff --git a/src/CalculateurMoyanne/CalculateurEF/Migrations/20221203193812_TestCalc.Designer.cs b/src/CalculateurMoyanne/CalculateurEF/Migrations/20221211125750_Migrations.Designer.cs similarity index 71% rename from src/CalculateurMoyanne/CalculateurEF/Migrations/20221203193812_TestCalc.Designer.cs rename to src/CalculateurMoyanne/CalculateurEF/Migrations/20221211125750_Migrations.Designer.cs index 3e05c89..551f5dc 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Migrations/20221203193812_TestCalc.Designer.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Migrations/20221211125750_Migrations.Designer.cs @@ -1,5 +1,4 @@ // -using System; using CalculateurEF.Context; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -11,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CalculateurEF.Migrations { [DbContext(typeof(CalculContext))] - [Migration("20221203193812_TestCalc")] - partial class TestCalc + [Migration("20221211125750_Migrations")] + partial class Migrations { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -26,7 +25,7 @@ namespace CalculateurEF.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); - b.Property("MaquetteEntityId") + b.Property("IDMaquetteFrk") .HasColumnType("INTEGER"); b.Property("Nom") @@ -35,7 +34,7 @@ namespace CalculateurEF.Migrations b.HasKey("Id"); - b.HasIndex("MaquetteEntityId"); + b.HasIndex("IDMaquetteFrk"); b.ToTable("Bloc"); }); @@ -64,6 +63,9 @@ namespace CalculateurEF.Migrations b.Property("Coef") .HasColumnType("INTEGER"); + b.Property("IDUEForeignKey") + .HasColumnType("INTEGER"); + b.Property("Nommatiere") .IsRequired() .HasColumnType("TEXT"); @@ -71,12 +73,9 @@ namespace CalculateurEF.Migrations b.Property("Note") .HasColumnType("INTEGER"); - b.Property("UEentityId") - .HasColumnType("INTEGER"); - b.HasKey("id"); - b.HasIndex("UEentityId"); + b.HasIndex("IDUEForeignKey"); b.ToTable("matier"); }); @@ -90,27 +89,56 @@ namespace CalculateurEF.Migrations b.Property("Coefficient") .HasColumnType("INTEGER"); + b.Property("IDForeignKey") + .HasColumnType("INTEGER"); + b.Property("intitulé") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Id"); + b.HasIndex("IDForeignKey"); + b.ToTable("Ue"); }); modelBuilder.Entity("CalculateurEF.Entities.BlocEntity", b => { - b.HasOne("CalculateurEF.Entities.MaquetteEntity", null) + b.HasOne("CalculateurEF.Entities.MaquetteEntity", "MaquetteEntity") .WithMany("Bloc") - .HasForeignKey("MaquetteEntityId"); + .HasForeignKey("IDMaquetteFrk") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("MaquetteEntity"); }); modelBuilder.Entity("CalculateurEF.Entities.MatiereEntity", b => { - b.HasOne("CalculateurEF.Entities.UEentity", null) + b.HasOne("CalculateurEF.Entities.UEentity", "UEentity") .WithMany("mat") - .HasForeignKey("UEentityId"); + .HasForeignKey("IDUEForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("UEentity"); + }); + + modelBuilder.Entity("CalculateurEF.Entities.UEentity", b => + { + b.HasOne("CalculateurEF.Entities.BlocEntity", "BlocEntity") + .WithMany("UeEntityId") + .HasForeignKey("IDForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BlocEntity"); + }); + + modelBuilder.Entity("CalculateurEF.Entities.BlocEntity", b => + { + b.Navigation("UeEntityId"); }); modelBuilder.Entity("CalculateurEF.Entities.MaquetteEntity", b => diff --git a/src/CalculateurMoyanne/CalculateurEF/Migrations/20221203193812_TestCalc.cs b/src/CalculateurMoyanne/CalculateurEF/Migrations/20221211125750_Migrations.cs similarity index 69% rename from src/CalculateurMoyanne/CalculateurEF/Migrations/20221203193812_TestCalc.cs rename to src/CalculateurMoyanne/CalculateurEF/Migrations/20221211125750_Migrations.cs index ab2553a..eadfc31 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Migrations/20221203193812_TestCalc.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Migrations/20221211125750_Migrations.cs @@ -5,7 +5,7 @@ namespace CalculateurEF.Migrations { /// - public partial class TestCalc : Migration + public partial class Migrations : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -24,36 +24,44 @@ namespace CalculateurEF.Migrations }); migrationBuilder.CreateTable( - name: "Ue", + name: "Bloc", columns: table => new { - Id = table.Column(type: "INTEGER", nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - Coefficient = table.Column(type: "INTEGER", nullable: false), - intitulé = table.Column(type: "TEXT", nullable: false) + Nom = table.Column(type: "TEXT", nullable: false), + IDMaquetteFrk = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Ue", x => x.Id); + table.PrimaryKey("PK_Bloc", x => x.Id); + table.ForeignKey( + name: "FK_Bloc_Maquettes_IDMaquetteFrk", + column: x => x.IDMaquetteFrk, + principalTable: "Maquettes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "Bloc", + name: "Ue", columns: table => new { - Id = table.Column(type: "INTEGER", nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - Nom = table.Column(type: "TEXT", nullable: false), - MaquetteEntityId = table.Column(type: "INTEGER", nullable: true) + Coefficient = table.Column(type: "INTEGER", nullable: false), + intitulé = table.Column(type: "TEXT", nullable: false), + IDForeignKey = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Bloc", x => x.Id); + table.PrimaryKey("PK_Ue", x => x.Id); table.ForeignKey( - name: "FK_Bloc_Maquettes_MaquetteEntityId", - column: x => x.MaquetteEntityId, - principalTable: "Maquettes", - principalColumn: "Id"); + name: "FK_Ue_Bloc_IDForeignKey", + column: x => x.IDForeignKey, + principalTable: "Bloc", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -65,43 +73,49 @@ namespace CalculateurEF.Migrations Nommatiere = table.Column(type: "TEXT", nullable: false), Note = table.Column(type: "INTEGER", nullable: false), Coef = table.Column(type: "INTEGER", nullable: false), - UEentityId = table.Column(type: "INTEGER", nullable: true) + IDUEForeignKey = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_matier", x => x.id); table.ForeignKey( - name: "FK_matier_Ue_UEentityId", - column: x => x.UEentityId, + name: "FK_matier_Ue_IDUEForeignKey", + column: x => x.IDUEForeignKey, principalTable: "Ue", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( - name: "IX_Bloc_MaquetteEntityId", + name: "IX_Bloc_IDMaquetteFrk", table: "Bloc", - column: "MaquetteEntityId"); + column: "IDMaquetteFrk"); migrationBuilder.CreateIndex( - name: "IX_matier_UEentityId", + name: "IX_matier_IDUEForeignKey", table: "matier", - column: "UEentityId"); + column: "IDUEForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_Ue_IDForeignKey", + table: "Ue", + column: "IDForeignKey"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "Bloc"); + name: "matier"); migrationBuilder.DropTable( - name: "matier"); + name: "Ue"); migrationBuilder.DropTable( - name: "Maquettes"); + name: "Bloc"); migrationBuilder.DropTable( - name: "Ue"); + name: "Maquettes"); } } } diff --git a/src/CalculateurMoyanne/CalculateurEF/Migrations/CalculContextModelSnapshot.cs b/src/CalculateurMoyanne/CalculateurEF/Migrations/CalculContextModelSnapshot.cs index c61abe8..9bcde2c 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Migrations/CalculContextModelSnapshot.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Migrations/CalculContextModelSnapshot.cs @@ -1,5 +1,4 @@ // -using System; using CalculateurEF.Context; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -23,7 +22,7 @@ namespace CalculateurEF.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); - b.Property("MaquetteEntityId") + b.Property("IDMaquetteFrk") .HasColumnType("INTEGER"); b.Property("Nom") @@ -32,7 +31,7 @@ namespace CalculateurEF.Migrations b.HasKey("Id"); - b.HasIndex("MaquetteEntityId"); + b.HasIndex("IDMaquetteFrk"); b.ToTable("Bloc"); }); @@ -61,6 +60,9 @@ namespace CalculateurEF.Migrations b.Property("Coef") .HasColumnType("INTEGER"); + b.Property("IDUEForeignKey") + .HasColumnType("INTEGER"); + b.Property("Nommatiere") .IsRequired() .HasColumnType("TEXT"); @@ -68,12 +70,9 @@ namespace CalculateurEF.Migrations b.Property("Note") .HasColumnType("INTEGER"); - b.Property("UEentityId") - .HasColumnType("INTEGER"); - b.HasKey("id"); - b.HasIndex("UEentityId"); + b.HasIndex("IDUEForeignKey"); b.ToTable("matier"); }); @@ -87,27 +86,56 @@ namespace CalculateurEF.Migrations b.Property("Coefficient") .HasColumnType("INTEGER"); + b.Property("IDForeignKey") + .HasColumnType("INTEGER"); + b.Property("intitulé") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Id"); + b.HasIndex("IDForeignKey"); + b.ToTable("Ue"); }); modelBuilder.Entity("CalculateurEF.Entities.BlocEntity", b => { - b.HasOne("CalculateurEF.Entities.MaquetteEntity", null) + b.HasOne("CalculateurEF.Entities.MaquetteEntity", "MaquetteEntity") .WithMany("Bloc") - .HasForeignKey("MaquetteEntityId"); + .HasForeignKey("IDMaquetteFrk") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("MaquetteEntity"); }); modelBuilder.Entity("CalculateurEF.Entities.MatiereEntity", b => { - b.HasOne("CalculateurEF.Entities.UEentity", null) + b.HasOne("CalculateurEF.Entities.UEentity", "UEentity") .WithMany("mat") - .HasForeignKey("UEentityId"); + .HasForeignKey("IDUEForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("UEentity"); + }); + + modelBuilder.Entity("CalculateurEF.Entities.UEentity", b => + { + b.HasOne("CalculateurEF.Entities.BlocEntity", "BlocEntity") + .WithMany("UeEntityId") + .HasForeignKey("IDForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BlocEntity"); + }); + + modelBuilder.Entity("CalculateurEF.Entities.BlocEntity", b => + { + b.Navigation("UeEntityId"); }); modelBuilder.Entity("CalculateurEF.Entities.MaquetteEntity", b => diff --git a/src/CalculateurMoyanne/CalculateurEF/calcul.db b/src/CalculateurMoyanne/CalculateurEF/calcul.db new file mode 100644 index 0000000000000000000000000000000000000000..50f50754aac4e4e761f0bfeb929b26a80ae5800e GIT binary patch literal 45056 zcmeI)&2HmF00(f7oo(WDyQYWADvMNOE)Bb?n!qY2v}BV>iJH14jZrIvtdKY>i#Aph z2hn4y2tWV=5P$##77Bcx&#J|3G9k{OXMfYUuuR)()avfgcAgK8 z?OW5{thQ*SO|^zmqZgV!pGDVB4NW&~UE9~=hw6nJIjerOOD4Nv;p`_N#~!i@O!~Tt zATmE!&BDw66ZzAh|FlR6LC5xU!N-aoMbF5=@`x1G|3O|W!0S>^5WQ+ zS&$CjqnNm)yi_@#!+0gBcyWVH^aKxHAQ)<4@5I58>%0%!#HKs$= z8GEk(-db3TRa_V?v5#54o)@;*MwDL#_CSCD1Rwwb2tWV=5P$##AOHafKwuRG-X+pg zwRBi26-&ipvGk<;iP8??_n^q!C(@oA-a28#*Z&g# z|Np;~m$(PON)Is_4*>{300Izz00bZa0SG_<0{>S5Ig=4oxiakZJDXBQc*vIh*PWg_ zmPH<4s|*GmzW!%7{YQWR1Rwwb2tWV=5P$##AOHafKwympu>N1;!9~{~009U<00Izz z00bZa0SG_<0#gBg|9?sOLs0%z{$@`I5P$##AOHafKmY;|fB*y_009WBgFr@-Nrvwv zz7zTSAAkS94g-rmKmY;|fB*y_009U<00Izz00hznu>McCK?(#Q009U<00Izz00bZa L0SG`~T?GCECBtZi literal 0 HcmV?d00001 diff --git a/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs index 6dead3e..5454a1b 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs @@ -1,4 +1,4 @@ -using BSN; +using Bussness; using CalculateurEF.Context; using CalculateurEF.Entities; using ClassCalculateurMoyenne; @@ -11,84 +11,125 @@ using System.Threading.Tasks; namespace CalculateurMapping { - public class BlocDbDataManager : IDataManager - { - public async Task Add(BlocModel data) + public class BlocDbDataManager: IDataManager where TContext :CalculContext,new() + {//ajout de bloc + public async Task Add(BlocModel blc) { bool resultat = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { BlocEntity entity = new BlocEntity { - Nom = data.Getnom(), - }; - for (int i = 0; i < data.ue.Count; i++) - { - UEentity uEentity = new UEentity - { - intitulé = data.ue[i].Intitulé - - }; + Nom = blc.GetNom(), + IDMaquetteFrk=blc.IDMaquetteFrk + }; context.Bloc.Add(entity); - await context.SaveChangesAsync(); + context.SaveChanges(); resultat = true; - } - return resultat; } - } + return resultat; + }//delete public async Task Delete(BlocModel bloc) { bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { - BlocEntity entity = context.Bloc.Find(bloc.Nom); + BlocEntity entity = context.Bloc.Find(bloc.Id); context.Bloc.Remove(entity); result = await context.SaveChangesAsync() > 0; - } return true; } - public async Task> GetAll() + public async Task DeleteById(int id) { - using (var context = new CalculContext()) + bool result = false; + using (var context = new TContext()) { - return await context.Bloc.Select(e => new BlocModel + BlocEntity entity = context.Bloc.Find(id); + context.Bloc.Remove(entity); + result = await context.SaveChangesAsync() > 0; + } + return true; + } + + public async Task> GetAll() + { //getAll + using (var context = new TContext()) + { + var temp= await context.Bloc.Select(e => new BlocModel ( e.Nom, - e.Id, - e.ue.Select(j => new UE(j.intitulé)).ToArray() + e.Id, new UE[0] + //e.ue.Select(j => new UE(j.intitulé)).ToArray() )).ToListAsync(); + return temp; + } + }//getUEdansblc + public async Task> GetAllUEBloc(int id) + { + List ls=new List(); + using (var context = new TContext()) + { + var temp = context.Bloc.Where(x=>x.Id==id).Select(e => e.UeEntityId).ToList(); + foreach (var item in temp) + { + foreach (var i in item) + { + UE ue = new UE(i.Id, i.Coefficient, i.intitulé, i.mat.Select(m => new Matiere(m.id, m.Note, m.Nommatiere, m.Coef)).ToArray()); + ls.Add(ue); + } + } + + return ls; } } public async Task GetDataWithName(string name) { - using (var context = new CalculContext()) + using (var context = new TContext()) { return await context.Bloc.Where(e => e.Nom == name).Select(e => new BlocModel ( e.Nom, - e.ue.Select(j => new UE(j.intitulé)).ToArray() + e.UeEntityId.Select(j => new UE(j.intitulé)).ToArray() )).FirstOrDefaultAsync(); } } public async Task Update(BlocModel data) - { + {//update bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { BlocEntity entity = context.Bloc.Find(data.Id); entity.Nom = data.Nom ; - entity.ue = data.ue.Select(j => new UEentity + entity.UeEntityId = data.ue.Select(j => new UEentity { intitulé = j.Intitulé, }).ToList(); - result = await context.SaveChangesAsync() > 0; + bool v = await context.SaveChangesAsync() > 0; + result = v; } return result; } + + public async Task AddUEBloc(UE data,int blocId) + {//addUedansbloc + bool resultat = false; + using (var context = new TContext()) + { + UEentity entity = new UEentity + { + intitulé = data.Intitulé, + IDForeignKey = blocId, + }; + context.Ue.Add(entity); + await context.SaveChangesAsync(); + resultat = true; + return resultat; + } + } } } diff --git a/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs index f65b3b3..184f1a0 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs @@ -1,4 +1,4 @@ -using BSN; +using Bussness; using CalculateurEF.Context; using CalculateurEF.Entities; using ClassCalculateurMoyenne; @@ -11,42 +11,54 @@ using System.Threading.Tasks; namespace CalculateurMapping { - public class MaquetteDbDataManager : IDataManager + public class MaquetteDbDataManager : IDataManager where TContext : CalculContext, new() { - public async Task Add(MaquetteModel mqt) + public MaquetteDbDataManager() { + using (var context = new TContext()) + { + context.Database.EnsureCreated(); + } + } + public async Task Add(MaquetteModel mqt) + { //Add mqt bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { + //context.Database.EnsureCreated(); MaquetteEntity entity = new MaquetteEntity { - NomMaquette = mqt.GetNomMaquette(), + NomMaquette = mqt.NomMaquette, }; - for (int i = 0; i < mqt.BLOCS.Count; i++) - { - BlocEntity blocentitie = new BlocEntity - { - Nom = mqt.BLOCS[i].Nom - }; - context.Maquettes.Add(entity); - await context.SaveChangesAsync(); - result = true; - } + context.Maquettes.Add(entity); + context.SaveChanges(); return result; } + + } + //delete maquette + public async Task Delete(MaquetteModel maquette) + { + bool result = false; + using (var context = new TContext()) + { + MaquetteEntity entity = context.Maquettes.Find(maquette.Id); + context.Maquettes.Remove(entity); + result = await context.SaveChangesAsync() > 0; - - - + } + return result; } - public async Task Delete(MaquetteModel maquette) + + //delete maquette + public async Task DeleteById(MaquetteModel maquette) { bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { - MaquetteEntity entity = context.Maquettes.Find(maquette.GetNomMaquette()); + MaquetteEntity entity = context.Maquettes.Find(maquette.Id); context.Maquettes.Remove(entity); result = await context.SaveChangesAsync() > 0; @@ -72,21 +84,12 @@ namespace CalculateurMapping // } // return null; // } - public async Task> GetAll() - { - using (var context = new CalculContext()) - { - List maquettes = new List(); - foreach (var item in await context.Maquettes.ToListAsync()) - maquettes.Add(new MaquetteModel(item.Id, item.NomMaquette)); - return maquettes; - } - } + public async Task GetDataWithName(string name) { - using (var context = new CalculContext()) + using (var context = new TContext()) { MaquetteModel _mqt = null; @@ -95,26 +98,14 @@ namespace CalculateurMapping return _mqt; } } - //using (var context = new CalculContext()) - //{ - // return await context.Maquettes.Where(e => e.NomMaquette == name).Select(e => new MaquetteModel - // ( - //e.Id, - //e.NomMaquette, - //e.Bloc.Select(u => u.ue).ToList(), - //e.Bloc.Select(j => new BlocModel(j.Nom)).ToArray() - // )).FirstOrDefaultAsync(); - //} - - - + public async Task Update(MaquetteModel data) - { + {//update mqt bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { MaquetteEntity entity = context.Maquettes.Find(data.Id); - entity.NomMaquette = data.GetNomMaquette(); + entity.NomMaquette = data.NomMaquette; entity.Bloc = data.BLOCS.Select(j => new BlocEntity { Nom=j.Nom, @@ -123,5 +114,24 @@ namespace CalculateurMapping } return result; } + //getAll mqt + public async Task> GetAll() + { + using (var context = new TContext()) + { + List maquettes = new List(); + foreach (var item in await context.Maquettes.ToListAsync()) + { + // Console.WriteLine(item); + maquettes.Add(new MaquetteModel(item.Id, item.NomMaquette)); + } + return maquettes; + } + } + + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); + } } } diff --git a/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs index 733451c..4fa8a43 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs @@ -1,4 +1,4 @@ -using BSN; +using Bussness; using CalculateurEF.Context; using CalculateurEF.Entities; using ClassCalculateurMoyenne; @@ -31,6 +31,11 @@ namespace CalculateurMapping } } + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); + } + public async Task Delete(Matiere mat) { bool result = false; @@ -43,7 +48,7 @@ namespace CalculateurMapping return result; } - public async Task> GetAll() + public async Task> GetAll() { using (var context = new CalculContext()) { diff --git a/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs index 2dfc8a4..0a38093 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs @@ -1,4 +1,4 @@ -using BSN; +using Bussness; using CalculateurEF.Context; using CalculateurEF.Entities; using ClassCalculateurMoyenne; @@ -38,6 +38,11 @@ namespace CalculateurMapping } } + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); + } + public async Task Delete(UE data) { bool result = false; @@ -51,7 +56,7 @@ namespace CalculateurMapping return true; } - public async Task> GetAll() + public async Task> GetAll() { using (var context = new CalculContext()) { @@ -60,7 +65,7 @@ namespace CalculateurMapping e.Id, e.Coefficient, e.intitulé, - e.matiere.Select(j => new Matiere(j.Nommatiere)).ToArray() + e.mat.Select(j => new Matiere(j.Nommatiere)).ToArray() )).ToListAsync(); } } @@ -77,7 +82,7 @@ namespace CalculateurMapping { UEentity entity = context.Ue.Find(data.Id); entity.intitulé = data.Intitulé; - entity.matiere = data.Matieres.Select(j => new MatiereEntity + entity.mat = data.Matieres.Select(j => new MatiereEntity { Nommatiere = j.Nommatiere, }).ToList(); diff --git a/src/CalculateurMoyanne/CalculateurMoyanne.sln b/src/CalculateurMoyanne/CalculateurMoyanne.sln index dd7a646..7f4f848 100644 --- a/src/CalculateurMoyanne/CalculateurMoyanne.sln +++ b/src/CalculateurMoyanne/CalculateurMoyanne.sln @@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalculateurMapping", "Calcu EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bussness", "BSN\Bussness.csproj", "{EE834623-6D68-4016-94B9-FF3AC58C0E15}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "testpourEf", "testpourEf\testpourEf.csproj", "{48B8C47A-AC35-473C-A9A9-CE9C8D5F6344}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testpourEf", "testpourEf\testpourEf.csproj", "{48B8C47A-AC35-473C-A9A9-CE9C8D5F6344}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs b/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs index 0550469..dced14d 100644 --- a/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs +++ b/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs @@ -1,4 +1,5 @@ -using ClassCalculateurMoyenne; +using Bussness; +using ClassCalculateurMoyenne; //using ClassCalculateurMoyenne.Modele; using System; using System.Collections.Generic; @@ -9,7 +10,7 @@ using System.Threading.Tasks; namespace StubCalculateur.Stub { - public class StubBloc + public class StubBloc: IDataManager { private List listb = new List(); public List ue = new List(); @@ -23,19 +24,9 @@ namespace StubCalculateur.Stub } return false; } - public bool Delete(BlocModel data) - { - if (data != null) - { - listb.Remove(data); - return true; - } - return false; - } - public async Task> GetAll() - { - return listb; - } + + + public async Task Update(BlocModel data) { if (data != null) @@ -46,7 +37,18 @@ namespace StubCalculateur.Stub } return false; } - public IEnumerable GetAllUE(int n = 10) + public async Task> GetAllUEdb(int n = 10) + { + for (int j = 0; j < n; j++) + { + ue.Add(new UE("")); + } + listb.Add(new BlocModel("ue")); + ue.Clear(); + + return listb; + } + public async Task > GetAllBloc(int n = 10) { for (int i = 0; i < n; i++) { @@ -60,10 +62,30 @@ namespace StubCalculateur.Stub return listb; } + public Task Delete(BlocModel data) + { + if (data != null) + { + listb.Remove(data); + return Task.FromResult( true); + } + return Task.FromResult(false); + } + public Task GetDataWithName(string name) + { + throw new NotImplementedException(); + } + public async Task> GetAll() + { + return listb; + } - + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); + } } diff --git a/src/CalculateurMoyanne/CalculateurStub/Stub/StubMaquette.cs b/src/CalculateurMoyanne/CalculateurStub/Stub/StubMaquette.cs index 014970f..6c3ac39 100644 --- a/src/CalculateurMoyanne/CalculateurStub/Stub/StubMaquette.cs +++ b/src/CalculateurMoyanne/CalculateurStub/Stub/StubMaquette.cs @@ -1,42 +1,20 @@ using ClassCalculateurMoyenne; -using ClassCalculateurMoyenne; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Bussness; + namespace StubCalculateur.Stub { - public class StubMaquette + public class StubMaquette: IDataManager { private List listb = new List(); public List ues = new List(); private List lstmqt = new List(); - - public bool Delete(MaquetteModel data) - { - if (data != null) - { - lstmqt.Remove(data); - return true; - } - return false; - } - public bool Add(MaquetteModel data) - { - if(data != null) - { - lstmqt.Add(data); - return true; - } - - return false; - } - public async Task> GetAll() - { - return lstmqt; - } + public async Task> GetAllMaquette(int n = 10) { for (int i = 0; i < n; i++) @@ -64,7 +42,7 @@ namespace StubCalculateur.Stub } for(int v = 0; v < 10; v++) { - listb.Add(new BlocModel("")); + listb.Add(new BlocModel("ghh")); } lstmqt.Add(new MaquetteModel(ues,listb)); ues.Clear(); @@ -72,9 +50,40 @@ namespace StubCalculateur.Stub return lstmqt; } + public Task Add(MaquetteModel data) + { + if (data != null) + { + lstmqt.Add(data); + return Task.FromResult(true); + } + + return Task.FromResult(false); + } + public Task Delete (MaquetteModel data) + { + if (data != null) + { + lstmqt.Remove(data); + return Task.FromResult( true); + } + return Task.FromResult(false); + } + public Task GetDataWithName(string name) + { + throw new NotImplementedException(); + } + public async Task> GetAll() + { + return lstmqt; + } + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); + } } } diff --git a/src/CalculateurMoyanne/CalculateurStub/Stub/StubMatiere.cs b/src/CalculateurMoyanne/CalculateurStub/Stub/StubMatiere.cs index 0cb5b7c..ccccea5 100644 --- a/src/CalculateurMoyanne/CalculateurStub/Stub/StubMatiere.cs +++ b/src/CalculateurMoyanne/CalculateurStub/Stub/StubMatiere.cs @@ -1,4 +1,5 @@ -using ClassCalculateurMoyenne; +using Bussness; +using ClassCalculateurMoyenne; using System; using System.Collections; using System.Collections.Generic; @@ -8,7 +9,7 @@ using System.Threading.Tasks; namespace StubCalculateur.Stub { - public class StubMatiere + public class StubMatiere: IDataManager { private List listMatieres = new List(); @@ -31,12 +32,22 @@ namespace StubCalculateur.Stub } return false; } - public async Task> GetAll() + + public Task Delete(Matiere data) { - return listMatieres; + throw new NotImplementedException(); } - public bool update(Matiere data) + + + public Task GetDataWithName(string name) + { + throw new NotImplementedException(); + } + + + + public async Task Update(Matiere data) { if (data != null) { @@ -47,5 +58,14 @@ namespace StubCalculateur.Stub return false; } + public async Task> GetAll() + { + return listMatieres; + } + + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); + } } } diff --git a/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs b/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs index 89b51ef..ef36ee9 100644 --- a/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs +++ b/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs @@ -1,4 +1,5 @@ -using ClassCalculateurMoyenne; +using Bussness; +using ClassCalculateurMoyenne; using System; using System.Collections; using System.Collections.Generic; @@ -8,10 +9,11 @@ using System.Threading.Tasks; namespace StubCalculateur.Stub { - public class stubUE + public class stubUE : IDataManager { private List listUE = new List(); private List mat = new List(); + public async Task Add(UE data) { if (data != null) @@ -21,10 +23,6 @@ namespace StubCalculateur.Stub } return false; } - - - - public async Task Delete(UE data) { if (data != null) @@ -42,11 +40,7 @@ namespace StubCalculateur.Stub } return listUE; } - public async Task> GetAll() - { - - return listUE; - } + public async Task Update(UE data) { if (data != null) @@ -71,10 +65,21 @@ namespace StubCalculateur.Stub mat.Clear(); } return listUE; + } + public Task GetDataWithName(string name) + { + throw new NotImplementedException(); + } + public async Task> GetAll() + { + return listUE; + } - + public Task AddUEBloc(UE data, int blocId) + { + throw new NotImplementedException(); } } } diff --git a/src/CalculateurMoyanne/CalculateurStub/StubCalculateur.csproj b/src/CalculateurMoyanne/CalculateurStub/StubCalculateur.csproj index ef6377b..38c5e85 100644 --- a/src/CalculateurMoyanne/CalculateurStub/StubCalculateur.csproj +++ b/src/CalculateurMoyanne/CalculateurStub/StubCalculateur.csproj @@ -9,6 +9,7 @@ + diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs index 37dbbae..9864e98 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,47 +13,83 @@ namespace ClassCalculateurMoyenne { [ObservableProperty] private string nom; - public long Id; + public int IDMaquetteFrk { get; set; } + public string GetNom() + { + return nom; + } + public int Id + { + get; + private set; + } + public void setNom(string value) + { + if (string.IsNullOrWhiteSpace(value)) + + { + throw new ArgumentException("Le Nom est obligatoire"); + } + + nom = value; + } + [ObservableProperty] private UE[] uEs; - public ReadOnlyCollection ue { get; private set; } + public ReadOnlyCollection ue { get; private set; }//= new ReadOnlyCollection(new List()); - private readonly List ues = new List(); + private readonly List ues = new List(); public BlocModel(string nombloc) { - nom = nombloc; + + setNom(nombloc); } - public BlocModel(string nombloc,long id, List Ux) + public BlocModel(string nombloc,int id, List Ux) { Id = id; nom = nombloc; - ue = new ReadOnlyCollection(Ux); + ues.AddRange(Ux); + ue = new ReadOnlyCollection(ues); - //Ajouterue(Ux); + } + public BlocModel( List Ux) + { + + ue = new ReadOnlyCollection(Ux); } + public BlocModel(string nombloc, object value) { nom = nombloc; - + } - public BlocModel(string nombloc, int id, UE[] uEs) : this(nombloc) + public BlocModel(string nombloc, int id, UE[] uEs) { + nom = nombloc; Id = id; this.uEs = uEs; } + //public int ueForeignKey + //{ + // get; set; + //} + //[ForeignKey("ueForeignKey")] + //public UE UE + //{ + // get; set; + //} + + //public BlocModel(string v) + //{ + //} public BlocModel() { - } - - public string Getnom() - { - return Getnom(); - } + } private IEnumerable Ajouterue(params UE[] ues) { @@ -61,17 +98,6 @@ namespace ClassCalculateurMoyenne return result; } - - //public override string ToString() - //{ - // return $"{ues}"; - //} - //public IEnumerable Ajouterue(params UE[] ues) - //{ - // List result = new(); - // result.AddRange(ues.Where(a => Ajouterue(a))); - // return result; - //} public bool Ajouterue(UE uu) { if (!IsExist(uu)) @@ -97,7 +123,7 @@ namespace ClassCalculateurMoyenne } public bool Equals(BlocModel other) { - return Nom. Equals(other.Nom); + return nom.Equals(other.GetNom()); } public override bool Equals(object obj) @@ -109,7 +135,7 @@ namespace ClassCalculateurMoyenne } public override int GetHashCode() { - return Nom.GetHashCode(); + return nom.GetHashCode(); } } } diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/MaquetteModel.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/MaquetteModel.cs index 175bf64..f836eb1 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/MaquetteModel.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/MaquetteModel.cs @@ -10,55 +10,77 @@ namespace ClassCalculateurMoyenne { public class MaquetteModel:IEquatable { - public int Id; - public ReadOnlyCollection UES { get; set; } + public int Id + { + get; + set; + } - private readonly List ues = new List(); + private string nomMaquette; - public ReadOnlyCollection BLOCS { get; private set; } - private readonly List blocs = new List(); + public string NomMaquette + { + get { return nomMaquette; } + private set + { + if (string.IsNullOrWhiteSpace(value)) - public string NomMaquette; - public string GetNomMaquette() - { - return GetNomMaquette(); - } - private void SetNomMaquette(string value) - { - - if (string.IsNullOrWhiteSpace(GetNomMaquette())) + { + throw new ArgumentException("Le Nom de la maquette est obligatoire"); + } - { - throw new ArgumentException("Le Nom de la maquette est obligatoire"); + nomMaquette = value; } - } - + //public string GetNomMaquette() + //{ + // return NomMaquette; + //} + //private void SetNomMaquette(string value) + //{ + + // if (string.IsNullOrWhiteSpace(value)) + + // { + // throw new ArgumentException("Le Nom de la maquette est obligatoire"); + // } + + // NomMaquette = value; + //} + public ReadOnlyCollection UES { get; private set; } + private readonly List ues = new List(); + public ReadOnlyCollection BLOCS { get; private set; } + private readonly List blocs = new List(); + + + public MaquetteModel(int id, string nomMaquette, List u, List blc) { Id = id; NomMaquette = nomMaquette; UES = u.AsReadOnly(); - BLOCS = blc.AsReadOnly(); + BLOCS = new ReadOnlyCollection(blocs); + blocs.AddRange(blc); } - public MaquetteModel(List u, List blc) + public MaquetteModel(List u, List blocs) { UES = u.AsReadOnly(); - BLOCS = blc.AsReadOnly(); + //la + BLOCS = new ReadOnlyCollection(blocs); } - public MaquetteModel(long id,string nomMaquette) + public MaquetteModel(int id,string nomMaquette) { - Id = Id; - SetNomMaquette(nomMaquette); + Id = id; + setNomMaquete(nomMaquette); } public MaquetteModel( string nomMaquette) { - SetNomMaquette(nomMaquette); + setNomMaquete(nomMaquette); } @@ -80,10 +102,8 @@ namespace ClassCalculateurMoyenne else { return false; - } - - - } + } + } public bool ajouteBloc(BlocModel b) { if (IsExiste(b)) @@ -118,7 +138,7 @@ namespace ClassCalculateurMoyenne public bool Equals(MaquetteModel other) { - return NomMaquette. Equals(other.GetNomMaquette()); + return NomMaquette. Equals(other.NomMaquette); } public override bool Equals(object obj) { @@ -131,17 +151,19 @@ namespace ClassCalculateurMoyenne public MaquetteModel(string nomMaquette, int id) { - SetNomMaquette(nomMaquette); + setNomMaquete(nomMaquette); Id = id; } - public void setNomMaquete(string nom) + + public MaquetteModel() { - SetNomMaquette(nom); } - - - + //pour faire les tests updt stub + public void setNomMaquete(string value) + { + NomMaquette = value; + } } } diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs index 5a17048..db09489 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs @@ -11,12 +11,12 @@ namespace ClassCalculateurMoyenne { public long Id { get; set; } - public string Nommatiere { get; set; } - public int Note { get; set; } - public int Coef { get; set; } + public string Nommatiere; + public int Note { get; private set; } + public int Coef { get; private set; } public string GetNommatiere() { - return GetNommatiere(); + return Nommatiere; } private void SetNomMaquette(string value) diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs index bd16dc1..5a100ec 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs @@ -10,13 +10,27 @@ namespace ClassCalculateurMoyenne [ObservableProperty] private int coefficient; [ObservableProperty] + private string intitulé; + + public int IDForeignKey { get; set; } + public string GetIntitulé() { - return GetIntitulé(); + return intitulé; } + public void setIntitulé(string value) + { + if(string.IsNullOrEmpty(value)) + + { + throw new ArgumentException("INTITULÉ est obligatoire"); + } - public UE ( long id, int coefficient, string intitulé,params Matiere[] matieres) + intitulé = value; + } + + public UE ( long id, int coefficient, string intitulé,params Matiere[] matieres) { Id = id; Coefficient = coefficient; @@ -24,20 +38,17 @@ namespace ClassCalculateurMoyenne Matieres = new ReadOnlyCollection(matieres); } - public void setIntitulé(string intitulé) - { - Intitulé = intitulé; - } - public UE( List _matieres, int coefficient) + + public UE( List matieres, int coefficient) { - Matieres = new ReadOnlyCollection(_matieres); + Matieres = new ReadOnlyCollection(matieres); Coefficient = coefficient; } public UE(string intitulé) { - this.intitulé = intitulé; + setIntitulé( intitulé); } public UE() { } diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Utilisateur.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Utilisateur.cs index 27ae274..f0307db 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Utilisateur.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Utilisateur.cs @@ -8,8 +8,10 @@ namespace ClassCalculateurMoyenne { public class Utilisateur { - public int id { get; set; } - public string Prenom { get; set; } + public int id { get;private set; } + public string Prenom { get;private set; } + + } } diff --git a/src/CalculateurMoyanne/testpourEf/Program.cs b/src/CalculateurMoyanne/testpourEf/Program.cs index 3ce125c..c88c442 100644 --- a/src/CalculateurMoyanne/testpourEf/Program.cs +++ b/src/CalculateurMoyanne/testpourEf/Program.cs @@ -1,14 +1,56 @@ // See https://aka.ms/new-console-template for more information using CalculateurEF.Context; using CalculateurEF.Entities; +using Bussness; +using CalculateurMapping; +using ClassCalculateurMoyenne; -Console.WriteLine("Hello, World!"); -namespace testpourEF -{ class Program - { - - } -} +public class Program +{ + private static async Task Main(string[] args) + { + Console.WriteLine("Hello, World!"); + Manager blocDbDataManager = new Manager(new BlocDbDataManager()); + // Manager maquetteDbDataManager = new Manager(new MaquetteDbDataManager()); + //Ajout de maquette + //MaquetteModel maquette = new MaquetteModel(); + //maquette.NomMaquette = "M1"; + //await maquetteDbDataManager.AddMaquette(maquette); + //AJOUT DE BLOC + //BlocModel bloc = new BlocModel(); + //bloc.Nom = "Arafa"; + //bloc.IDMaquetteFrk = 1; + //await blocDbDataManager.AddBloc(bloc); + + + + //Modification + BlocModel bloc = new BlocModel(); + var result = await blocDbDataManager.GetAllBloc(); + result.First().Nom = "Elaphi"; + + await blocDbDataManager.UpdateBloc(result.First()); + + + //suppresion de bloc + //BlocDbDataManager blocDbDataManager = new BlocDbDataManager(); + // BlocModel bloc = new BlocModel(); + // var result = await blocDbDataManager.GetAllBloc(); + // await blocDbDataManager.DeleteById(1); + + //ajout de ue dans bloc + //BlocDbDataManager blocDbDataManager1 = new BlocDbDataManager(); + //BlocModel bloc = new BlocModel(); + + + //UE uE = new UE(); + //uE.Intitulé = "f"; + //uE.IDForeignKey = 1; + //await blocDbDataManager.AddUEBloc(bloc); + + + } +} \ No newline at end of file diff --git a/src/CalculateurMoyanne/testpourEf/testpourEf.csproj b/src/CalculateurMoyanne/testpourEf/testpourEf.csproj index f140b78..a7a68c1 100644 --- a/src/CalculateurMoyanne/testpourEf/testpourEf.csproj +++ b/src/CalculateurMoyanne/testpourEf/testpourEf.csproj @@ -5,6 +5,7 @@ net6.0 enable enable + $(MSBuildProjectDirectory)/../CalculateurEF/ diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs b/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs new file mode 100644 index 0000000..8206070 --- /dev/null +++ b/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs @@ -0,0 +1,64 @@ +using System; +using StubCalculateur.Stub; +using ClassCalculateurMoyenne; +using Bussness; +using Xunit; + + + +namespace TestCalculateurMoyanne.LesTests +{ + public class TestManager + { + [Fact] + public void TestAddMaquette() + { + MaquetteModel maquette = new MaquetteModel("B1"); + Manager manager = new Manager(new StubMaquette()); + manager.AddMaquette(maquette); + Assert.Single(manager.MaquetteDbDataManager.GetAll().Result); + } + [Fact] + public void TestAddBloc() + { + BlocModel bloc = new BlocModel("B1"); + Manager manager = new Manager(new StubBloc()); + manager.AddBloc (bloc); + Assert.Single(manager.BlocDbDataManager.GetAll().Result); + } + [Fact] + public void TestGetUEBloc() + { + BlocModel bloc = new BlocModel("B1"); + Manager manager = new Manager(new StubBloc()); + manager.AddBloc(bloc); + + } + [Fact] + public void TestDELETEBloc() + { + BlocModel bloc = new BlocModel("B1"); + Manager manager = new Manager(new StubBloc()); + manager.DeleteBloc(bloc); + + } + public void TestUpdateBloc() + { + BlocModel bloc = new BlocModel("B1"); + Manager manager = new Manager(new StubBloc()); + manager.UpdateBloc( bloc); + + } + [Fact] + public void TestGetAllTEBloc() + { + BlocModel bloc = new BlocModel("B1"); + Manager manager = new Manager(new StubBloc()); + manager.GetAllBloc(); + + } + + + } +} + diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs index 10ed59b..05ece9c 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs @@ -11,48 +11,70 @@ namespace TestCalculateurMoyanne.LesTests { public class UnitTestBloc { - // BlocModel b = new BlocModel(); - // [Fact] - // public void Test() - // { - // Assert.NotNull(b); - // Assert.Equal("L3", b.Nom); - // Assert.NotEqual("E3", b.Nom); - // } - // [Fact] - // public void TestInvalidBloc() - // { - // Assert.Throws(() => new BlocModel(null)); - // } - - - // public class Bloc_InlineData - // { - // [Theory] - // [InlineData(false, "L6", 2, "L3", 2)] - // [InlineData(false, "", 0, "", 0)] - // [InlineData(true, "M1", 0, "M1", 0)] - - // public void TestConstructeur(bool isValid, string expectedNom, int expectedId, - // string Nom, int id) - // { - // if (!isValid) - // { - // Assert.Throws(() => new MaquetteModel(Nom, id)); - // return; - // } - // BlocModel m = new BlocModel(Nom, id); - // Assert.Equal(expectedNom, m.Nom); - // Assert.Equal(expectedId, m.Id); - // } - // [Fact] - // public void TestBlocStub() - // { - // StubBloc stub = new StubBloc(); - // // Assert.Equal(10, stub.GetAllUE(10).Result.Count()); - // } - - // } + BlocModel b = new BlocModel("B3"); + [Fact] + public void Test() + { + Assert.NotNull(b); + Assert.Equal("B3", b.Nom); + Assert.NotEqual("E3", b.Nom); + } + [Fact] + public void TestInvalidBloc() + { + string nom=null; + Assert.Throws(() => new BlocModel(nom)); + } + + + // public class Bloc_InlineData + // { + // [Theory] + // [InlineData(false, "L6", 2, "L3", 2)] + // [InlineData(false, "", 0, "", 0)] + // [InlineData(true, "M1", 0, "M1", 0)] + + // public void TestConstructeur(bool isValid, string expectedNom, int expectedId, + // string Nom, int id) + // { + // if (!isValid) + // { + // Assert.Throws(() => new MaquetteModel(Nom, id)); + // return; + // } + // BlocModel m = new BlocModel(Nom, id); + // Assert.Equal(expectedNom, m.Nom); + // Assert.Equal(expectedId, m.Id); + // } + // } + [Fact] + public void TestBlocStub() + { + StubBloc stub = new StubBloc(); + Assert.Equal(10, stub.GetAllBloc(10).Result.Count()); + } + [Fact] + public void TestRemove() + { + StubBloc stub = new StubBloc(); + BlocModel e = new BlocModel("L1"); + stub.Add(e); + stub.Delete(e); + //Compter le nombre de Maq dans un objet IEnumerable + Assert.Equal(0, stub.GetAll().Result.Count()); + } + [Fact] + public void TestUpdate() + { + StubBloc stub = new StubBloc(); + BlocModel e = new BlocModel("E1"); + stub.Add(e); + e.setNom("L1"); + stub.Update(e); + Assert.Equal("L1", stub.GetAll().Result.First().GetNom()); + } + + } diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs index 36719a4..571978c 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs @@ -16,8 +16,8 @@ namespace TestCalculateurMoyanne.LesTests public void Test() { Assert.NotNull(m); - Assert.Equal("L3", m.GetNomMaquette()); - Assert.NotEqual("E3", m.GetNomMaquette()); + Assert.Equal("L3", m.NomMaquette); + Assert.NotEqual("E3", m.NomMaquette); } [Fact] public void TestInvalidMaquette() @@ -25,23 +25,23 @@ namespace TestCalculateurMoyanne.LesTests Assert.Throws(() => new MaquetteModel(null)); } - [Theory] - [InlineData(false, "L6" ,"L3")] - [InlineData(false, "", "")] - [InlineData(true, "M1", "M1" )] - public void TestConstructor(bool isValid, string expectedNomMaquette, - string NomMaquette) - { - if (!isValid) - { - Assert.Throws( () => new MaquetteModel(NomMaquette)); - return; - } + //[Theory] + //[InlineData(false, "L6" ,"L3")] + //[InlineData(false, "", "")] + //[InlineData(true, "M1", "M1" )] + //public void TestConstructor(bool isValid, string expectedNomMaquette, + // string NomMaquette) + //{ + // if (!isValid) + // { + // Assert.Throws( () => new MaquetteModel(NomMaquette)); + // return; + // } - MaquetteModel m = new MaquetteModel(NomMaquette); - Assert.Equal(expectedNomMaquette, m.GetNomMaquette()); + // MaquetteModel m = new MaquetteModel(NomMaquette); + // Assert.Equal(expectedNomMaquette, m.GetNomMaquette()); - } + //} // test avec stub [Fact] @@ -68,7 +68,7 @@ namespace TestCalculateurMoyanne.LesTests stub.Add(e); e.setNomMaquete("L1"); stub.Update(e); - Assert.Equal("L1", stub.GetAll().Result.First().GetNomMaquette()); + Assert.Equal("L1", stub.GetAll().Result.First().NomMaquette); } } diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs index a8eee8a..bae48f9 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs @@ -13,141 +13,106 @@ namespace TestCalculateurMoyanne.LesTests public class UnitTestUE { - public static IEnumerable Data_AddMatiereToUE() + UE u = new UE("f"); + [Fact] + public void Test() { - yield return new object[] - { - true, - new Matiere[] - { - new Matiere( 1,20,"mat",2), - new Matiere(2,3,"histoire",4), - new Matiere(4,12,"geo",2) - }, - new UE(1,2,"UE2", - new Matiere( 1,20,"mat",2), - new Matiere(2,3,"histoire",4)), - new Matiere(4,12,"geo",2) - - }; - yield return new object[] - { - false, - new Matiere[] - { - new Matiere( 1,20,"mat",2), - new Matiere(2,3,"histoire",4), - new Matiere(4,12,"geo",2) - }, - new UE(1,2,"UE2", - new Matiere( 1,20,"mat",2), - new Matiere(2,3,"histoire",4)), - new Matiere(4,12,"geo",2), - new Matiere(5,2,"arithmetique",3) - }; + Assert.NotNull(u); + Assert.Equal("f", u.Intitulé); + Assert.NotEqual("oo", u.Intitulé); + } + [Fact] + public void testInvalid() + { + Assert.Throws(() => new UE(null)); + } + [Fact] + public void Remove() + { + stubUE stub = new stubUE(); + UE e = new UE("L1"); + stub.Add(e); + stub.Delete(e); + //Compter le nombre de Maq dans un objet IEnumerable + Assert.Equal(0, stub.GetAll().Result.Count()); + } + [Fact] + public void TestUpdate() + { + stubUE stub = new stubUE(); + UE e = new UE("L1"); + stub.Add(e); + e.setIntitulé("L1"); + stub.Update(e); + Assert.Equal("L1", stub.GetAll().Result.First().GetIntitulé()); } - [Theory] - [MemberData(nameof(Data_AddMatiereToUE))] - public void Test_AddMatiereToUE(bool expectedResult, - IEnumerable expectedMatiere, - UE ue, - Matiere matiere) { - // true si l'ajout est réussi et false sinon - bool result = ue.AjouterMatiere(matiere); - // comparaison avec le resultat qu'on espert avoir - Assert.Equal(expectedResult, result); + } +} + + +//public static IEnumerable Data_AddMatiereToUE() +//{ +// yield return new object[] +// { +// true, +// new Matiere[] +// { +// new Matiere( 1,20,"mat",2), +// new Matiere(2,3,"histoire",4), +// new Matiere(4,12,"geo",2) +// }, +// new UE(1,2,"UE2", +// new Matiere( 1,20,"mat",2), +// new Matiere(2,3,"histoire",4)), +// new Matiere(4,12,"geo",2) + +// }; +// yield return new object[] +// { +// false, +// new Matiere[] +// { +// new Matiere( 1,20,"mat",2), +// new Matiere(2,3,"histoire",4), +// new Matiere(4,12,"geo",2) +// }, +// new UE(1,2,"UE2", +// new Matiere( 1,20,"mat",2), +// new Matiere(2,3,"histoire",4)), +// new Matiere(4,12,"geo",2), +// new Matiere(5,2,"arithmetique",3) +// }; + +//[Theory] +// [MemberData(nameof(Data_AddMatiereToUE))] +// public void Test_AddMatiereToUE(bool expectedResult, +// IEnumerable expectedMatiere, +// UE ue, +// Matiere matiere) { + +//// true si l'ajout est réussi et false sinon +// bool result = ue.AjouterMatiere(matiere); + +// // comparaison avec le resultat qu'on espert avoir +// Assert.Equal(expectedResult, result); + +// // +// Assert.Equal(expectedMatiere.Count(), ue.Matieres.Count()); +// Assert.All(expectedMatiere, j => ue.Matieres.Contains(j)); + + +// } + + + + + - // - Assert.Equal(expectedMatiere.Count(), ue.Matieres.Count()); - Assert.All(expectedMatiere, j => ue.Matieres.Contains(j)); - } - } - - - -} - - //true, - //new Artist[] - //{ - // new Artist("Miles", "Davis"), - // new Artist("Wayne", "Shorter"), - // new Artist("Herbie", "Hancock"), - // new Artist("Ron", "Carter"), - // new Artist("Tony", "Williams") - //}, - //new Album("Miles Smiles", new DateTime(1967, 1, 1), - // new Artist("Miles", "Davis"), - // new Artist("Wayne", "Shorter"), - // new Artist("Herbie", "Hancock"), - // new Artist("Ron", "Carter")), - //new Artist("Tony", "Williams") - - - - - - - - - //{ - // [Theory] - // [InlineData(false, "Mathematique", 2, "MTH", 2)] - // [InlineData(false, "", 0, "", 0)] - // [InlineData(true, "Mathematique", 0, "Mathematique", 0)] - - - // public void TestConstructor(bool isValid, string expectedMatiere, int expectedcoef, - // string intitulé, int coefficient) - // { - // if (!isValid) - // { - // Assert.Throws( - // () => new UE(intitulé, coefficient)); - // return; - // } - - // UE e = new UE(intitulé, coefficient); - // Assert.Equal(expectedMatiere,e.Intitulé); - // Assert.Equal(expectedcoef, e.Coefficient); - // } - - // // test avec stub - - // [Fact] - // public void TestUeStub() - // { - // stubUE stub = new stubUE(); - // Assert.Equal(10, stub.GetAllUE(10).Result.Count()); - // } - // [Fact] - // public void TestRemove() - // { - // stubUE stub = new stubUE(); - // UE e = new UE("E1"); - // stub.Add(e); - // stub.Delete(e); - // //Compter le nombre de UE dans un objet IEnumerable - // Assert.Equal(0, stub.GetAll().Result.Count()); - // } - // public void TestUpdate() - // { - // stubUE stub = new stubUE(); - // UE e = new UE("E1"); - // stub.Add(e); - // e.setIntitulé("UE1"); - // stub.Update(e); - // Assert.Equal("UE1", stub.GetAll().Result.First().Intitulé); - // } - - //} - - \ No newline at end of file diff --git a/src/Tests/TestCalculateurMoyanne/TestCalculateurMoyanne.csproj b/src/Tests/TestCalculateurMoyanne/TestCalculateurMoyanne.csproj index ed12298..4c7593a 100644 --- a/src/Tests/TestCalculateurMoyanne/TestCalculateurMoyanne.csproj +++ b/src/Tests/TestCalculateurMoyanne/TestCalculateurMoyanne.csproj @@ -10,10 +10,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -26,6 +26,7 @@ +