public void Delete_Worker_test() { //Arrange DbContextOptions <WorkersContext> opt; var builder = new DbContextOptionsBuilder <WorkersContext>(); builder.UseInMemoryDatabase(databaseName: "database_test"); opt = builder.Options; var MoqContext = new WorkersContext(opt); var MoqRepo = new SQLrequest(MoqContext, new Logger <SQLrequest>(new LoggerFactory())); MoqRepo.Create(new WorkersModel { Id = 3, Name = "Sveta", Surname = "Svetlanovna", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Worker", Place = "לעס", Culture = "en" }); var worker_delete = MoqRepo.GetWorkers(3); if (worker_delete != null) { MoqRepo.Remove(worker_delete); } }
public void Create_Worker_Test() { //Arrange DbContextOptions <WorkersContext> opt; var builder = new DbContextOptionsBuilder <WorkersContext>(); builder.UseInMemoryDatabase(databaseName: "database_test"); opt = builder.Options; var MoqContext = new WorkersContext(opt); var MoqRepo = new SQLrequest(MoqContext, new Logger <SQLrequest>(new LoggerFactory())); //Act MoqRepo.Create(new WorkersModel { Id = 1, Name = "Diana", Surname = "Vahomskaya", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Admin", Place = "לעס", Culture = "ru" }); }
public void GetWorkers_Test() { //Arrange IQueryable <WorkersModel> worker = new List <WorkersModel> { new WorkersModel { Id = 1, Name = "Diana", Surname = "Vahomskaya", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Admin", Place = "לעס", Culture = "ru" } }.AsQueryable(); var MoqSet = new Mock <DbSet <WorkersModel> >(); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.Provider).Returns(worker.Provider); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.Expression).Returns(worker.Expression); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.ElementType).Returns(worker.ElementType); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.GetEnumerator()).Returns(worker.GetEnumerator()); var MoqContext = new Mock <WorkersContext>(); MoqContext.Setup(c => c.WorkersTable).Returns(MoqSet.Object); //Act var MoqRepo = new SQLrequest(MoqContext.Object, new Logger <SQLrequest>(new LoggerFactory())); var GetWorkers = MoqRepo.GetWorkers_workers(); var GetWorkersId = MoqRepo.GetWorkers(1); var GetWorkersLogin = MoqRepo.GetLogin("di_vahomik"); var result = MoqRepo.NewWorkers(new WorkersModel { Id = 6, Name = "Diana", Surname = "Vahomskaya", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Admin", Place = "לעס", Culture = "ru" }); //Assert Assert.AreEqual(1, GetWorkers.Count()); Assert.IsNotNull(GetWorkersId); Assert.IsNotNull(GetWorkersLogin); Assert.True(result); }
public void Edit_Worker_Test() { //Arrange DbContextOptions <WorkersContext> opt; var builder = new DbContextOptionsBuilder <WorkersContext>(); builder.UseInMemoryDatabase(databaseName: "database_test"); opt = builder.Options; var MoqContext = new WorkersContext(opt); var MoqRepo = new SQLrequest(MoqContext, new Logger <SQLrequest>(new LoggerFactory())); MoqRepo.Create(new WorkersModel { Id = 2, Name = "Mariya", Surname = "Polovinkina", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Worker", Place = "לודאפמם", Culture = "ru" }); if (MoqRepo.GetWorkers(2) != null) { var WorkerEdit = MoqRepo.GetWorkers(2); WorkerEdit.Name = "Dima"; MoqRepo.Edit(WorkerEdit); } var worker = MoqRepo.GetWorkers_workers(); var workerEdit = MoqRepo.GetWorkers(2); Assert.AreEqual(2, worker.Count()); Assert.AreEqual("Dima", workerEdit.Name); }
public void Execute(Arguments cmdLine) { this.CommandLine = cmdLine; // Conversion des paramètres entrées (ANSI to format FR) //ConvertANSI(ref args); Thread oThread = null; // lecture de la configuration now = DateTime.Now; // Affichage de la version du batch IntegratorBatch.InfoLogger.Debug(now + " DEBUT PROGRAMME"); #if !DEBUG Assembly assem = Assembly.GetEntryAssembly(); Assembly execAssem = Assembly.GetExecutingAssembly(); AssemblyName assemName = assem.GetName(); Version ver = assemName.Version; Version execVer = execAssem.GetName().Version; String message = "Application " + assemName.Name + " , Version(entry,exec,public) " + ver.ToString() + " " + execVer.ToString(); try { Version publishVer = ApplicationDeployment.CurrentDeployment.CurrentVersion; message += " " + publishVer.ToString(); } catch { message += " non disponible"; } IntegratorBatch.InfoLogger.Info(message); #endif string[] inutile = CommandLine.Intercept(new string[] { "csvTransfer", "bondPricer", "dbCopy", "csv", "oxlsx", "sql", "paramsql", "xls", "bp2s", "bp2sregex", "ini", "datastore", "nogui" }); // afficher les parametres passés et inutiles // prendre ceux qui commencent par @xxx ou #xxx qui représentent les variables des connecteurs Producers/consumers if (inutile.Length > 0) { if (IntegratorBatch.InfoLogger.IsInfoEnabled) { string liste = "("; foreach (string s in inutile) { if (!s.StartsWith("@") && !s.StartsWith("#")) { liste += s + " "; } } liste += ")"; if (liste.Length > 2) { IntegratorBatch.InfoLogger.Info("Les parametres suivants ne sont pas exploitees: " + liste); } } } //------------------------------------------------------------------------------------------ // programme executé avec des traces en lignes de commande if (CommandLine["nogui"] == null) { Console.WriteLine("FGA Automate: Execution d une extraction :"); Console.WriteLine(CommandLine.ToString()); oThread = new Thread(new ThreadStart(ConsoleSpiner.Go)); oThread.Start(); } //------------------------------------------------------------------------------------------ // fichier de configuration des paramètres de base if (CommandLine["ini"] != null) { IntegratorBatch.InfoLogger.Debug("Lecture d un fichier de configuration " + CommandLine["ini"]); InitFile.loginIni = CommandLine["ini"]; } else { IntegratorBatch.InfoLogger.Debug("Lecture d un fichier de configuration par defaut " + InitFile.loginIni); } //------------------------------------------------------------------------------------------ // fichier de configuration des paramètres de base string datastore = "OMEGA"; if (CommandLine["datastore"] != null) { IntegratorBatch.InfoLogger.Debug("La base de donnees utilisee " + CommandLine["datastore"]); datastore = CommandLine["datastore"]; } //------------------------------------------------------------------------------------------ // option -@xxxx=yyyy : recueillir les parametres personnalises string[] keys, values; // tester si il y a des pararametres personnalise if (CommandLine.GetStartsWith("@", out keys, out values) > 0) { IntegratorBatch.InfoLogger.Debug("Lecture d une requete avec parametres : " + keys); } //------------------------------------------------------------------------------------------ // option -paramsql : executer la requete fournie afin de recuperer une liste de parametres/valeurs sous la forme d 'un tableau string paramsql = CommandLine["paramsql"]; object[] paramsValue = null; string paramsName = null; if (paramsql != null) { DataSet DS_Params = new DataSet(); try { SQLrequest p_1 = null; // tester si il y a des pararametres personnalise if (keys != null && keys.Length > 0) { p_1 = new SQLrequest(paramsql, datastore, keys, values); } else { p_1 = new SQLrequest(paramsql, datastore); } p_1.Execute(out DS_Params); // transformer le dataset en tableau pour le reutiliser sur la requete SQL principale paramsValue = getParamsArray(DS_Params, out paramsName); } catch (Exception e) { IntegratorBatch.ExceptionLogger.Fatal("Impossible d executer la requete " + paramsql, e); throw e; } } //------------------------------------------------------------------------------------------ // lire un fichier csv et le mettre dans une table BDD string csvTransfer = CommandLine["csvTransfer"]; if (csvTransfer != null) { string nomTable = CommandLine["#nomTable"]; string nomSchema = CommandLine["#nomSchema"] ?? "dbo"; CSVtoSQL.DataBaseIntegrate(csvTransfer, datastore, nomSchema, nomTable); } //------------------------------------------------------------------------------------------ if (paramsValue != null) { foreach (object extraValue in paramsValue) { System.Collections.ArrayList _Keys = new System.Collections.ArrayList(keys); _Keys.Add('@' + paramsName); System.Collections.ArrayList _Values = new System.Collections.ArrayList(values); _Values.Add(FGA.Automate.Helpers.Helper.ValueToSQLField(extraValue)); output(datastore, (string[])_Keys.ToArray(typeof(string)), (string[])_Values.ToArray(typeof(string)), paramsName, extraValue.ToString()); } } else { output(datastore, keys, values); } //------------------------------------------------------------------------------------------ // programme executé avec des traces en lignes de commande if (CommandLine["nogui"] == null) { // Le traitement est terminé : arreter propremen la gauge ConsoleSpiner.go = false; oThread.Join(); Console.WriteLine("Pressez une touche pour terminer"); Console.ReadKey(); } IntegratorBatch.InfoLogger.Debug(now + " FIN PROGRAMME"); }
/// <summary> /// /// </summary> /// <param name="datastore"></param> /// <param name="keys">les parametres utilisés dans la requete</param> /// <param name="values"></param> /// <param name="superParamKey">mot cle utilise dans les parametres de nom de fichiers etc...</param> /// <param name="superParamValue">la valeur du mot cle</param> private void output(string datastore, string[] keys = null, string[] values = null, string superParamKey = null, string superParamValue = null) { BP2SText bp2stext = null; string sql = CommandLine["sql"]; DataSet DS = new DataSet(); // fichier de la requete SQL utilisée pour extraire les données if (sql != null) { // formater les paramètres: SQLrequest p = null; try { // tester si il y a des pararametres personnalise if (keys != null && keys.Length > 0) { IntegratorBatch.InfoLogger.Debug("Lecture d une requete avec parametres : " + keys); p = new SQLrequest(sql, datastore, keys, values); } else { p = new SQLrequest(sql, datastore); } p.Execute(out DS); } catch (Exception e) { IntegratorBatch.ExceptionLogger.Fatal("Impossible d executer la requete " + sql, e); throw e; } } else { Console.WriteLine(usage()); IntegratorBatch.ExceptionLogger.Fatal("Parametre obligatoire -sql inexistant"); // sortie car aucune requete à jouer return; } //------------------------------------------------------------------------------------------ // declencher un calcul de BondPricer string bondPricer = CommandLine["bondPricer"]; if (bondPricer != null) { BondPricer.OPTION opt; switch (bondPricer) { case "DURATION": opt = BondPricer.OPTION.DURATION; break; case "ACCRUEDINTEREST": opt = BondPricer.OPTION.ACCRUEDINTEREST; break; case "CLEANPRICE": opt = BondPricer.OPTION.CLEANPRICE; break; case "DIRTYPRICE": opt = BondPricer.OPTION.DIRTYPRICE; break; default: opt = BondPricer.OPTION.ALL; break; } BondPricer bp = new BondPricer(); DS = bp.Execute(DS, opt); } //------------------------------------------------------------------------------------------ if (CommandLine["bp2s"] != null) { bp2stext = new BP2SText(); string bp2sValid = (CommandLine["bp2sregex"] == null ? @"Resources/Consumer/BP2StextValidation.txt" : CommandLine["bp2sregex"]); IntegratorBatch.InfoLogger.Debug("Lecture d un fichier de validation des champs (regex) " + bp2sValid); string bp2s = CommandLine["bp2s"]; bp2stext.ValidationPath = bp2sValid; IntegratorBatch.InfoLogger.Debug("Configuration pour une sortie BP2S " + bp2s); bp2s = bp2s.Replace("YYYYMMDD", now.ToString("yyyyMMdd")); // remplacer le mot cle par sa valeur if (superParamKey != null) { bp2s = bp2s.Replace(superParamKey, superParamValue); } bp2stext.CreateFile(DS, bp2s, now); } //------------------------------------------------------------------------------------------ string excel = CommandLine["xls"]; if (excel != null) { excel = excel.Replace("YYYYMMDD", now.ToString("yyyyMMdd")); // remplacer le mot cle par sa valeur if (superParamKey != null) { excel = excel.Replace(superParamKey, superParamValue); } IntegratorBatch.InfoLogger.Debug("Configuration pour une sortie Excel " + excel); ExcelFile.CreateWorkbook(DS, excel); } //------------------------------------------------------------------------------------------ string openXMLExcel = CommandLine["oxlsx"]; if (openXMLExcel != null) { openXMLExcel = openXMLExcel.Replace("YYYYMMDD", now.ToString("yyyyMMdd")); // remplacer le mot cle par sa valeur if (superParamKey != null) { openXMLExcel = openXMLExcel.Replace(superParamKey, superParamValue); } IntegratorBatch.InfoLogger.Debug("Configuration pour une sortie Open XML Excel " + openXMLExcel); // tester si il y a des pararametres personnalise string date = CommandLine["#date"] == null?now.ToString("yyyyMMdd") : CommandLine["#date"]; string sheetNames = CommandLine["#names"]; string style = CommandLine["#style"]; string template = CommandLine["#template"]; string graph = CommandLine["#graph"]; bool monoSheetFlag = ((CommandLine["#monoSheetFlag"] == null || CommandLine["#monoSheetFlag"] == "F" || CommandLine["#monoSheetFlag"] == "N") ? false : true); OpenXMLFile.CreateExcelWorkbook(DS, openXMLExcel, style, template, graph, date, sheetNames.Split(';'), monoSheetFlag); } //------------------------------------------------------------------------------------------ string csv = CommandLine["csv"]; if (csv != null) { string fileNames = CommandLine["#names"]; if (fileNames != null) { fileNames = fileNames.Replace("YYYYMMDD", now.ToString("yyyyMMdd")); } else { fileNames = ""; } // remplacer le mot cle par sa valeur if (superParamKey != null) { fileNames = fileNames.Replace(superParamKey, superParamValue); } CSVFile.WriteToCSV(DS, csv, fileNames); } //------------------------------------------------------------------------------------------ //Si include et exclude sont vide : copie la BDD en entier //Si include et exclude non vide : aucune table ne sera copiée //Si include est vide : copie tout sauf les tables comprises dans exclude //Si exclude est vide : copie uniquement les tables dans include string bdd = CommandLine["dbCopy"]; if (bdd != null) { MSDBIntegration.InfoLogger = IntegratorBatch.InfoLogger; MSDBIntegration.ExceptionLogger = IntegratorBatch.ExceptionLogger; string connection1 = CommandLine["#connectionSource"]; string connection2 = CommandLine["#connectionDest"]; // une seule liste autorisée List <string> liste = null; ListeMode mode; if (CommandLine["#include"] != null) { liste = CommandLine["#include"].Split(';').ToList(); mode = ListeMode.Include; } else if (CommandLine["#include"] != null) { liste = CommandLine["#exclude"].Split(';').ToList(); mode = ListeMode.Exclude; } else { mode = ListeMode.Aucune; } List <string> nomTable = null; // si il y a une option -sql , le resultat de la requete sera mis dans la ou les tables nommées nomtable if (sql != null) { nomTable = CommandLine["#nomTable"].Split(';').ToList(); DBCopy.DataBaseCopy(connection1, connection2, DS, nomTable); } else { //TODO } } //------------------------------------------------------------------------------------------ }