diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 257d98e1cb..034fa9dccc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -133,7 +133,7 @@ jobs: (cd PublishWinForms ; echo 7z a -mx=9 ../dist/rdmp-${{ steps.version.outputs.rdmpversion }}-client.zip . | cmd) - name: Install Perl dependencies - uses: shogo82148/actions-setup-perl@v1.23.0 + uses: shogo82148/actions-setup-perl@v1.23.1 with: install-modules-with: cpanm install-modules: Archive::Zip Archive::Tar diff --git a/.nuget/packages.config b/.nuget/packages.config index 4aed222aba..8588e1c7c2 100644 --- a/.nuget/packages.config +++ b/.nuget/packages.config @@ -1,4 +1,5 @@  + diff --git a/Application/ResearchDataManagementPlatform/Menus/MenuItems/DataExportMenu.cs b/Application/ResearchDataManagementPlatform/Menus/MenuItems/DataExportMenu.cs index 3a0b087346..c6017ef0e9 100644 --- a/Application/ResearchDataManagementPlatform/Menus/MenuItems/DataExportMenu.cs +++ b/Application/ResearchDataManagementPlatform/Menus/MenuItems/DataExportMenu.cs @@ -14,9 +14,8 @@ namespace ResearchDataManagementPlatform.Menus.MenuItems; internal class DataExportMenu : RDMPToolStripMenuItem { - public DataExportMenu(IActivateItems activator):base(activator,"Data Export Options") + public DataExportMenu(IActivateItems activator) : base(activator, "Data Export Options") { - Enabled = _activator.RepositoryLocator.DataExportRepository != null; DropDownItems.Add(new ToolStripMenuItem("Configure Disclaimer", null, ConfigureDisclaimer)); diff --git a/Application/ResearchDataManagementPlatform/Menus/MenuItems/LaunchTutorialMenuItem.cs b/Application/ResearchDataManagementPlatform/Menus/MenuItems/LaunchTutorialMenuItem.cs index 0125482f74..7740f6ef77 100644 --- a/Application/ResearchDataManagementPlatform/Menus/MenuItems/LaunchTutorialMenuItem.cs +++ b/Application/ResearchDataManagementPlatform/Menus/MenuItems/LaunchTutorialMenuItem.cs @@ -21,9 +21,10 @@ public class LaunchTutorialMenuItem : ToolStripMenuItem private readonly Tutorial _tutorial; private readonly TutorialTracker _tracker; - public LaunchTutorialMenuItem(ToolStripMenuItem parent,IActivateItems activator, Tutorial tutorial, TutorialTracker tracker) + public LaunchTutorialMenuItem(ToolStripMenuItem parent, IActivateItems activator, Tutorial tutorial, + TutorialTracker tracker) { - parent.DropDownOpening += parent_DropDownOpening; + parent.DropDownOpening += parent_DropDownOpening; _activator = activator; _tutorial = tutorial; _tracker = tracker; diff --git a/Application/ResearchDataManagementPlatform/Menus/MenuItems/ResetTutorialsMenuItem.cs b/Application/ResearchDataManagementPlatform/Menus/MenuItems/ResetTutorialsMenuItem.cs index 357a89abb9..164e6f502b 100644 --- a/Application/ResearchDataManagementPlatform/Menus/MenuItems/ResetTutorialsMenuItem.cs +++ b/Application/ResearchDataManagementPlatform/Menus/MenuItems/ResetTutorialsMenuItem.cs @@ -36,6 +36,4 @@ private void parent_DropDownOpening(object sender, EventArgs e) { Enabled = _tracker.IsClearable(); } - - } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/Menus/RDMPTopMenuStripUI.cs b/Application/ResearchDataManagementPlatform/Menus/RDMPTopMenuStripUI.cs index b3a107229f..074556ac2b 100644 --- a/Application/ResearchDataManagementPlatform/Menus/RDMPTopMenuStripUI.cs +++ b/Application/ResearchDataManagementPlatform/Menus/RDMPTopMenuStripUI.cs @@ -85,10 +85,7 @@ private void BuildSwitchInstanceMenuItems() var args = RDMPBootStrapper.ApplicationArguments; // somehow app was launched without populating the load args - if (args == null) - { - return; - } + if (args == null) return; var origYamlFile = args.ConnectionStringsFileLoaded; @@ -107,13 +104,11 @@ private void BuildSwitchInstanceMenuItems() // also add yaml files from wherever they got their original yaml file if (origYamlFile?.FileLoaded != null && !exeDir.FullName.Equals(origYamlFile.FileLoaded.Directory.FullName)) - { AddMenuItemsForSwitchingToInstancesInYamlFilesOf(origYamlFile, origYamlFile.FileLoaded.Directory); - } - } - private void AddMenuItemsForSwitchingToInstancesInYamlFilesOf(ConnectionStringsYamlFile origYamlFile, DirectoryInfo dir) + private void AddMenuItemsForSwitchingToInstancesInYamlFilesOf(ConnectionStringsYamlFile origYamlFile, + DirectoryInfo dir) { foreach (var yaml in dir.GetFiles("*.yaml")) { @@ -121,15 +116,18 @@ private void AddMenuItemsForSwitchingToInstancesInYamlFilesOf(ConnectionStringsY if (!ConnectionStringsYamlFile.TryLoadFrom(yaml, out var connectionStrings)) continue; - var isSameAsCurrent = origYamlFile?.FileLoaded != null && yaml.FullName.Equals(origYamlFile.FileLoaded.FullName); + var isSameAsCurrent = origYamlFile?.FileLoaded != null && + yaml.FullName.Equals(origYamlFile.FileLoaded.FullName); - var launchNew = new ToolStripMenuItem(connectionStrings.Name ?? yaml.Name, null, (s, e) => { LaunchNew(connectionStrings); }) + var launchNew = new ToolStripMenuItem(connectionStrings.Name ?? yaml.Name, null, + (s, e) => { LaunchNew(connectionStrings); }) { Checked = isSameAsCurrent, ToolTipText = connectionStrings.Description ?? yaml.FullName }; - var switchTo = new ToolStripMenuItem(connectionStrings.Name ?? yaml.Name, null, (s, e) => { SwitchTo(connectionStrings); }) + var switchTo = new ToolStripMenuItem(connectionStrings.Name ?? yaml.Name, null, + (s, e) => { SwitchTo(connectionStrings); }) { Enabled = !isSameAsCurrent, Checked = isSameAsCurrent, @@ -138,7 +136,6 @@ private void AddMenuItemsForSwitchingToInstancesInYamlFilesOf(ConnectionStringsY launchAnotherInstanceToolStripMenuItem.DropDownItems.Add(launchNew); switchToInstanceToolStripMenuItem.DropDownItems.Add(switchTo); - } } @@ -151,15 +148,13 @@ private static void SwitchTo(ConnectionStringsYamlFile yaml) private static void LaunchNew(ConnectionStringsYamlFile yaml) { - var exeName = Path.Combine(UsefulStuff.GetExecutableDirectory().FullName, Process.GetCurrentProcess().ProcessName); - if(yaml == null) - { + var exeName = Path.Combine(UsefulStuff.GetExecutableDirectory().FullName, + Process.GetCurrentProcess().ProcessName); + if (yaml == null) Process.Start(exeName); - } else - { - Process.Start(exeName, $"--{nameof(RDMPCommandLineOptions.ConnectionStringsFile)} \"{yaml.FileLoaded.FullName}\""); - } + Process.Start(exeName, + $"--{nameof(RDMPCommandLineOptions.ConnectionStringsFile)} \"{yaml.FileLoaded.FullName}\""); } private void configureExternalServersToolStripMenuItem_Click(object sender, EventArgs e) @@ -176,9 +171,11 @@ private void setTicketingSystemToolStripMenuItem_Click(object sender, EventArgs private void governanceReportToolStripMenuItem_Click(object sender, EventArgs e) { - var generator = new GovernanceReport(new DatasetTimespanCalculator(), Activator.RepositoryLocator.CatalogueRepository); + var generator = new GovernanceReport(new DatasetTimespanCalculator(), + Activator.RepositoryLocator.CatalogueRepository); generator.GenerateReport(); } + private void logViewerToolStripMenuItem_Click(object sender, EventArgs e) { var cmd = new ExecuteCommandViewLogs(Activator, new LogViewerFilter(LoggingTables.DataLoadTask)); @@ -219,7 +216,6 @@ private void showPerformanceCounterToolStripMenuItem_Click(object sender, EventA private void openExeDirectoryToolStripMenuItem_Click(object sender, EventArgs e) { - try { UsefulStuff.ShowPathInWindowsExplorer(UsefulStuff.GetExecutableDirectory()); @@ -254,7 +250,7 @@ private void generateClassTableSummaryToolStripMenuItem_Click(object sender, Eve private void showHelpToolStripMenuItem_Click(object sender, EventArgs e) { - if(_windowManager.Navigation.Current is RDMPSingleControlTab t) + if (_windowManager.Navigation.Current is RDMPSingleControlTab t) t.ShowHelp(Activator); } @@ -264,7 +260,7 @@ public void SetWindowManager(WindowManager windowManager) _windowManager = windowManager; _atomicCommandUIFactory = new AtomicCommandUIFactory(Activator); - + //top menu strip setup / adjustment LocationsMenu.DropDownItems.Add(new DataExportMenu(Activator)); @@ -274,14 +270,15 @@ public void SetWindowManager(WindowManager windowManager) Name = "saveToolStripMenuItem", Size = new System.Drawing.Size(214, 22) }; - fileToolStripMenuItem.DropDownItems.Insert(3,_saveToolStripMenuItem); + fileToolStripMenuItem.DropDownItems.Insert(3, _saveToolStripMenuItem); _windowManager.TabChanged += WindowFactory_TabChanged; - _windowManager.Navigation.Changed += (s,e)=>UpdateForwardBackEnabled(); + _windowManager.Navigation.Changed += (s, e) => UpdateForwardBackEnabled(); var tracker = new TutorialTracker(Activator); foreach (var t in tracker.TutorialsAvailable) - tutorialsToolStripMenuItem.DropDownItems.Add(new LaunchTutorialMenuItem(tutorialsToolStripMenuItem, Activator, t, tracker)); + tutorialsToolStripMenuItem.DropDownItems.Add(new LaunchTutorialMenuItem(tutorialsToolStripMenuItem, + Activator, t, tracker)); tutorialsToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator()); @@ -294,7 +291,8 @@ public void SetWindowManager(WindowManager windowManager) // Location menu instancesToolStripMenuItem.DropDownItems.Add(_atomicCommandUIFactory.CreateMenuItem( - new ExecuteCommandChoosePlatformDatabase(Activator.RepositoryLocator) { OverrideCommandName = "Change Default Instance" })); + new ExecuteCommandChoosePlatformDatabase(Activator.RepositoryLocator) + { OverrideCommandName = "Change Default Instance" })); Activator.Theme.ApplyTo(menuStrip1); @@ -307,18 +305,21 @@ public void SetWindowManager(WindowManager windowManager) Activator.GlobalErrorCheckNotifier.OnCheckPerformed( new CheckEventArgs("Failed to BuildSwitchInstanceMenuItems", CheckResult.Fail, ex)); } - - launchAnotherInstanceToolStripMenuItem.ToolTipText = "Start another copy of the RDMP process targetting the same (or another) RDMP platform database"; - if(switchToInstanceToolStripMenuItem.DropDownItems.Count > 1) + launchAnotherInstanceToolStripMenuItem.ToolTipText = + "Start another copy of the RDMP process targetting the same (or another) RDMP platform database"; + + if (switchToInstanceToolStripMenuItem.DropDownItems.Count > 1) { switchToInstanceToolStripMenuItem.Enabled = true; - switchToInstanceToolStripMenuItem.ToolTipText = "Close the application and start another copy of the RDMP process targetting another RDMP platform database"; + switchToInstanceToolStripMenuItem.ToolTipText = + "Close the application and start another copy of the RDMP process targetting another RDMP platform database"; } else { switchToInstanceToolStripMenuItem.Enabled = false; - switchToInstanceToolStripMenuItem.ToolTipText = "There are no other RDMP platform databases configured, create a .yaml file with connection strings to enable this feature"; + switchToInstanceToolStripMenuItem.ToolTipText = + "There are no other RDMP platform databases configured, create a .yaml file with connection strings to enable this feature"; } } @@ -330,15 +331,15 @@ private IAtomicCommand[] GetNewCommands() { new ExecuteCommandCreateNewCatalogueByImportingFileUI(Activator), new ExecuteCommandCreateNewCatalogueByImportingExistingDataTable(Activator), - new ExecuteCommandImportTableInfo(Activator,null,false), + new ExecuteCommandImportTableInfo(Activator, null, false), new ExecuteCommandCreateNewCohortIdentificationConfiguration(Activator), new ExecuteCommandCreateNewLoadMetadata(Activator), new ExecuteCommandCreateNewStandardRegex(Activator), new ExecuteCommandCreateNewCohortDatabaseUsingWizard(Activator), - new ExecuteCommandCreateNewCohortByExecutingACohortIdentificationConfiguration(Activator,null), - new ExecuteCommandCreateNewCohortFromFile(Activator,null), + new ExecuteCommandCreateNewCohortByExecutingACohortIdentificationConfiguration(Activator, null), + new ExecuteCommandCreateNewCohortFromFile(Activator, null), new ExecuteCommandCreateNewCohortFromCatalogue(Activator), - new ExecuteCommandCreateNewCohortFromTable(Activator,null), + new ExecuteCommandCreateNewCohortFromTable(Activator, null), new ExecuteCommandCreateNewExtractableDataSetPackage(Activator), new ExecuteCommandCreateNewDataExtractionProject(Activator), new ExecuteCommandRelease(Activator) { OverrideCommandName = "New Release..." }, @@ -360,20 +361,21 @@ private void WindowFactory_TabChanged(object sender, IDockContent newTab) var saveable = singleObjectControlTab.Control as ISaveableUI; //if user wants to emphasise on tab change and there's an object we can emphasise associated with the control - if (singleObjectControlTab.Control is IRDMPSingleDatabaseObjectControl singleObject && UserSettings.EmphasiseOnTabChanged && singleObject.DatabaseObject != null) + if (singleObjectControlTab.Control is IRDMPSingleDatabaseObjectControl singleObject && + UserSettings.EmphasiseOnTabChanged && singleObject.DatabaseObject != null) { - var isCicChild = Activator.CoreChildProvider.GetDescendancyListIfAnyFor(singleObject.DatabaseObject)?.Parents?.Any(p=>p is CohortIdentificationConfiguration); + var isCicChild = Activator.CoreChildProvider.GetDescendancyListIfAnyFor(singleObject.DatabaseObject) + ?.Parents?.Any(p => p is CohortIdentificationConfiguration); //don't emphasise things that live under cics because it doesn't result in a collection being opened but instead opens the cic Tab (which could result in you being unable to get to your original tab!) - if(isCicChild == false) + if (isCicChild == false) { _windowManager.Navigation.Suspend(); Activator.RequestItemEmphasis(this, new EmphasiseRequest(singleObject.DatabaseObject)); _windowManager.Navigation.Resume(); } - } - + _saveToolStripMenuItem.Saveable = saveable; } @@ -433,7 +435,6 @@ private void findToolStripMenuItem_Click(object sender, EventArgs e) InitialSearchTextGuid = new Guid("00a0733b-848f-4bf3-bcde-7028fe159050"), IsFind = true, TaskDescription = "Enter the name of an object or part of the name or the dataset/project it is in." - }, o => Activator.RequestItemEmphasis(this, new EmphasiseRequest(o))); } @@ -444,7 +445,7 @@ private void closeToolStripMenuItem_Click(object sender, EventArgs e) private void findAndReplaceToolStripMenuItem_Click(object sender, EventArgs e) { - Activator.ShowWindow(new FindAndReplaceUI(Activator),true); + Activator.ShowWindow(new FindAndReplaceUI(Activator), true); } private void navigateBackwardToolStripMenuItem_Click(object sender, EventArgs e) @@ -466,7 +467,7 @@ private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e) var url = "https://raw.githubusercontent.com/HicServices/RDMP/main/rdmp-client.xml"; // Give user a chance to change the URL that is updating from - if(!Activator.TypeText("Update Location","Url:",int.MaxValue,url,out url,false)) + if (!Activator.TypeText("Update Location", "Url:", int.MaxValue, url, out url, false)) return; try @@ -483,7 +484,8 @@ private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e) private void ListAllTypesToolStripMenuItem_Click(object sender, EventArgs e) { var file = new FileInfo(Path.GetTempFileName()); - File.WriteAllLines(file.FullName,Activator.RepositoryLocator.CatalogueRepository.MEF.GetAllTypes().Select(t=>t.FullName)); + File.WriteAllLines(file.FullName, + Activator.RepositoryLocator.CatalogueRepository.MEF.GetAllTypes().Select(t => t.FullName)); UsefulStuff.ShowPathInWindowsExplorer(file); } @@ -493,7 +495,7 @@ private void NewToolStripMenuItem_Click(object sender, EventArgs e) { WindowTitle = "Create New", TaskDescription = "What do you want to create?" - },Activator,GetNewCommands(),false); + }, Activator, GetNewCommands(), false); if (dlg.ShowDialog() == DialogResult.OK) { @@ -509,7 +511,7 @@ private void quitToolStripMenuItem_Click(object sender, EventArgs e) private void newSessionToolStripMenuItem_Click(object sender, EventArgs e) { - var cmd = new ExecuteCommandStartSession(Activator,null,null); + var cmd = new ExecuteCommandStartSession(Activator, null, null); cmd.Execute(); } @@ -523,7 +525,7 @@ private void queryDataExport_Click(object sender, EventArgs e) Activator.Show("Cannot Query Database", cmd.ReasonCommandImpossible); return; } - + cmd.Execute(); } @@ -533,15 +535,17 @@ private void queryCatalogue_Click(object sender, EventArgs e) if (cmd.IsImpossible) { - Activator.Show("Cannot Query Database",cmd.ReasonCommandImpossible); + Activator.Show("Cannot Query Database", cmd.ReasonCommandImpossible); return; } + cmd.Execute(); } private void restartApplicationToolStripMenuItem_Click(object sender, EventArgs e) { - if (UserSettings.ConfirmApplicationExiting && Activator.Confirm("Restart Application?", "Confirm Restart") == false) + if (UserSettings.ConfirmApplicationExiting && + Activator.Confirm("Restart Application?", "Confirm Restart") == false) return; @@ -566,10 +570,7 @@ private void launchNewInstanceWithUserSettings_Click(object sender, EventArgs e) private void terminateProcessToolStripMenuItem_Click(object sender, EventArgs e) { - if(Activator.YesNo("Terminate the process without saving?","Terminate")) - { - Process.GetCurrentProcess().Kill(); - } + if (Activator.YesNo("Terminate the process without saving?", "Terminate")) Process.GetCurrentProcess().Kill(); } private void findMultipleToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/Application/ResearchDataManagementPlatform/NLog.template.config b/Application/ResearchDataManagementPlatform/NLog.template.config index 8e584958bc..348ad21979 100644 --- a/Application/ResearchDataManagementPlatform/NLog.template.config +++ b/Application/ResearchDataManagementPlatform/NLog.template.config @@ -1,4 +1,5 @@ - + + - - - + + + - - + \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/Program.cs b/Application/ResearchDataManagementPlatform/Program.cs index 7f0fcf28a3..fa83c3b172 100644 --- a/Application/ResearchDataManagementPlatform/Program.cs +++ b/Application/ResearchDataManagementPlatform/Program.cs @@ -23,31 +23,31 @@ internal static class Program [DllImport("kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool AttachConsole([MarshalAs(UnmanagedType.U4)] int dwProcessId); - - /// - /// The main entry point for the application. - /// - [STAThread] + + /// + /// The main entry point for the application. + /// + [STAThread] private static void Main(string[] args) - { - // if user has the command line built and runnable from the windows - // client then don't load the dlls (or we end up with 2 copies!). - SafeDirectoryCatalog.IgnoreDll = f => Path.GetFileName(f.DirectoryName)?.Equals("cli")==true; + { + // if user has the command line built and runnable from the windows + // client then don't load the dlls (or we end up with 2 copies!). + SafeDirectoryCatalog.IgnoreDll = f => Path.GetFileName(f.DirectoryName)?.Equals("cli") == true; - try - { - AttachConsole(-1); - } - catch (Exception) - { - Console.WriteLine("Couldn't redirect console. Never mind"); - } + try + { + AttachConsole(-1); + } + catch (Exception) + { + Console.WriteLine("Couldn't redirect console. Never mind"); + } - Startup.PreStartup(); + Startup.PreStartup(); - UsefulStuff.GetParser() - .ParseArguments(args) - .MapResult(RunApp, err => -1); + UsefulStuff.GetParser() + .ParseArguments(args) + .MapResult(RunApp, err => -1); } private static object RunApp(ResearchDataManagementPlatformOptions arg) @@ -56,7 +56,7 @@ private static object RunApp(ResearchDataManagementPlatformOptions arg) { arg.PopulateConnectionStringsFromYamlIfMissing(new ThrowImmediatelyCheckNotifier()); } - catch(Exception ex) + catch (Exception ex) { ExceptionViewer.Show(ex); return -500; diff --git a/Application/ResearchDataManagementPlatform/Properties/AssemblyInfo.cs b/Application/ResearchDataManagementPlatform/Properties/AssemblyInfo.cs index edb8d4291b..d3033bf4ac 100644 --- a/Application/ResearchDataManagementPlatform/Properties/AssemblyInfo.cs +++ b/Application/ResearchDataManagementPlatform/Properties/AssemblyInfo.cs @@ -6,4 +6,4 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("cac9817c-fc66-48e8-9333-c740af6ab5b9")] +[assembly: Guid("cac9817c-fc66-48e8-9333-c740af6ab5b9")] \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/RDMP.nuspec b/Application/ResearchDataManagementPlatform/RDMP.nuspec index 2c0a9ed8eb..895bcc7243 100644 --- a/Application/ResearchDataManagementPlatform/RDMP.nuspec +++ b/Application/ResearchDataManagementPlatform/RDMP.nuspec @@ -1,15 +1,16 @@ + - - ResearchDataManagementPlatform - $version$ - Health Informatics Service, University of Dundee - Research Data Management Platform - + + ResearchDataManagementPlatform + $version$ + Health Informatics Service, University of Dundee + Research Data Management Platform + - - - + + + \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/RDMPMainForm.cs b/Application/ResearchDataManagementPlatform/RDMPMainForm.cs index 7ac447d098..a3ebd55b00 100644 --- a/Application/ResearchDataManagementPlatform/RDMPMainForm.cs +++ b/Application/ResearchDataManagementPlatform/RDMPMainForm.cs @@ -60,10 +60,12 @@ public RDMPMainForm() if (!string.IsNullOrWhiteSpace(t)) { var type = Type.GetType(t); - _theme = type == null ? new MyVS2015BlueTheme() : (ITheme) System.Activator.CreateInstance(type); + _theme = type == null ? new MyVS2015BlueTheme() : (ITheme)System.Activator.CreateInstance(type); } else + { _theme = new MyVS2015BlueTheme(); + } } catch (Exception) { @@ -103,52 +105,51 @@ private void RDMPMainForm_Load(object sender, EventArgs e) _globalErrorCheckNotifier = exceptionCounter; _rdmpTopMenuStrip1.InjectButton(exceptionCounter); - _windowManager = new WindowManager(_theme,this,_refreshBus, dockPanel1, RepositoryLocator, exceptionCounter); + _windowManager = new WindowManager(_theme, this, _refreshBus, dockPanel1, RepositoryLocator, exceptionCounter); SetItemActivator(_windowManager.ActivateItems); _rdmpTopMenuStrip1.SetWindowManager(_windowManager); - + //put the version of the software into the window title - - _version = StartupUI.GetVersion(); - + + _version = StartupUI.GetVersion(); + //put the current platform database into the window title too if (Activator?.RepositoryLocator?.CatalogueRepository is TableRepository connectedTo) { var database = connectedTo.DiscoveredServer?.GetCurrentDatabase(); var instanceDescription = ""; - var connectionStringsFileLoaded = RDMPBootStrapper.ApplicationArguments?.ConnectionStringsFileLoaded; + var connectionStringsFileLoaded = + RDMPBootStrapper.ApplicationArguments?.ConnectionStringsFileLoaded; if (connectionStringsFileLoaded != null) - { instanceDescription = $" - {connectionStringsFileLoaded.Name ?? connectionStringsFileLoaded.FileLoaded.Name}"; - } - if (database != null) + if (database != null) _connectedTo = $"({database.GetRuntimeName()} on {database.Server.Name}){instanceDescription}"; } - + Text = "Research Data Management Platform"; - var rdmpDir = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RDMP")); - if(!rdmpDir.Exists) + var rdmpDir = + new DirectoryInfo( + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RDMP")); + if (!rdmpDir.Exists) rdmpDir.Create(); - _persistenceFile = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"RDMP", "RDMPDockPanelPersist.xml")); + _persistenceFile = + new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RDMP", + "RDMPDockPanelPersist.xml")); //if there is no persist file or user wants to show the home screen always on startup if (!_persistenceFile.Exists || UserSettings.ShowHomeOnStartup) - { _windowManager.PopHome(); - } else - { try { if (_persistenceFile.Exists) LoadFromXml(new FileStream(_persistenceFile.FullName, FileMode.Open)); - - //load the state using the method + //load the state using the method } catch (Exception ex) { @@ -161,13 +162,13 @@ private void RDMPMainForm_Load(object sender, EventArgs e) _persistenceFile.Delete(); ApplicationRestarter.Restart(); } - } - + FormClosing += CloseForm; Loading = false; } - public override string Text { + public override string Text + { get => base.Text; set => base.Text = (value + " v" + _version + " " + _connectedTo).Trim(); } @@ -175,19 +176,15 @@ public override string Text { public void LoadFromXml(Stream stream) { if (dockPanel1.DocumentStyle == DocumentStyle.SystemMdi) - { foreach (var form in MdiChildren) form.Close(); - } else - { foreach (var document in dockPanel1.DocumentsToArray()) { // IMPORANT: dispose all panes. document.DockHandler.DockPanel = null; document.DockHandler.Close(); } - } foreach (var pane in dockPanel1.Panes.ToList()) { @@ -198,17 +195,18 @@ public void LoadFromXml(Stream stream) // IMPORTANT: dispose all float windows. foreach (var window in dockPanel1.FloatWindows.ToList()) window.Dispose(); - + System.Diagnostics.Debug.Assert(dockPanel1.Panes.Count == 0); System.Diagnostics.Debug.Assert(dockPanel1.Contents.Count == 0); System.Diagnostics.Debug.Assert(dockPanel1.FloatWindows.Count == 0); dockPanel1.LoadFromXml(stream, DeserializeContent); } + public void LoadFromXml(WindowLayout target) { var uniEncoding = new UnicodeEncoding(); - + // You might not want to use the outer using statement that I have // I wasn't sure how long you would need the MemoryStream object using (var ms = new MemoryStream()) @@ -217,7 +215,7 @@ public void LoadFromXml(WindowLayout target) try { sw.Write(target.LayoutData); - sw.Flush();//otherwise you are risking empty stream + sw.Flush(); //otherwise you are risking empty stream ms.Seek(0, SeekOrigin.Begin); LoadFromXml(ms); @@ -256,10 +254,7 @@ private void CloseForm(object sender, FormClosingEventArgs e) // give the window manager a chance to cancel closing _windowManager.OnFormClosing(e); - if (e.Cancel) - { - return; - } + if (e.Cancel) return; if (e.CloseReason == CloseReason.UserClosing && UserSettings.ConfirmApplicationExiting) if (!Activator.YesNo("Are you sure you want to Exit?", "Confirm Exit")) @@ -278,9 +273,9 @@ private void CloseForm(object sender, FormClosingEventArgs e) dockPanel1.SaveAsXml(_persistenceFile.FullName); //save when Form closes } } - catch(Exception ex) + catch (Exception ex) { - ExceptionViewer.Show("Could not write persistence file",ex); + ExceptionViewer.Show("Could not write persistence file", ex); } } @@ -295,17 +290,19 @@ private IDockContent DeserializeContent(string persiststring) return toolboxInstance; } - var instruction = PersistenceDecisionFactory.ShouldCreateBasicControl(persiststring,RepositoryLocator) ?? - PersistenceDecisionFactory.ShouldCreateSingleObjectControl(persiststring,RepositoryLocator) ?? + var instruction = PersistenceDecisionFactory.ShouldCreateBasicControl(persiststring, RepositoryLocator) ?? + PersistenceDecisionFactory.ShouldCreateSingleObjectControl(persiststring, + RepositoryLocator) ?? PersistenceDecisionFactory.ShouldCreateObjectCollection(persiststring, RepositoryLocator); if (instruction != null) - return _windowManager.ActivateItems.Activate(instruction,_windowManager.ActivateItems); + return _windowManager.ActivateItems.Activate(instruction, _windowManager.ActivateItems); } catch (Exception e) { _globalErrorCheckNotifier.OnCheckPerformed(new CheckEventArgs( - $"Could not work out what window to show for persistence string '{persiststring}'",CheckResult.Fail, e)); + $"Could not work out what window to show for persistence string '{persiststring}'", CheckResult.Fail, + e)); } return null; diff --git a/Application/ResearchDataManagementPlatform/Theme/ThemeExtender.cs b/Application/ResearchDataManagementPlatform/Theme/ThemeExtender.cs index b1bbaf0767..b2f6ca5464 100644 --- a/Application/ResearchDataManagementPlatform/Theme/ThemeExtender.cs +++ b/Application/ResearchDataManagementPlatform/Theme/ThemeExtender.cs @@ -18,7 +18,7 @@ internal class ThemeExtender private const string Env = "Environment"; public Color TextBoxBackground { get; set; } - + public Color ComboBoxBackground { get; set; } public Color ComboBoxText { get; set; } @@ -27,7 +27,7 @@ public ThemeExtender(byte[] bytes) { _xml = XDocument.Load(new StreamReader(new MemoryStream(bytes))); TextBoxBackground = ColorTranslatorFromHtml("CommonControls", "TextBoxBackground"); - + ComboBoxBackground = ColorTranslatorFromHtml(Env, "ComboBoxBackground"); ComboBoxText = ColorTranslatorFromHtml(Env, "ComboBoxText"); } @@ -36,9 +36,11 @@ private Color ColorTranslatorFromHtml(string category, string name, bool foregro { string color = null; - var environmentElement = _xml.Root.Element("Theme").Elements("Category").FirstOrDefault(item => item.Attribute("Name").Value == category); + var environmentElement = _xml.Root.Element("Theme").Elements("Category") + .FirstOrDefault(item => item.Attribute("Name").Value == category); - var colourElement = environmentElement?.Elements("Color").FirstOrDefault(item => item.Attribute("Name").Value == name); + var colourElement = environmentElement?.Elements("Color") + .FirstOrDefault(item => item.Attribute("Name").Value == name); if (colourElement != null) color = colourElement.Element(foreground ? "Foreground" : "Background").Attribute("Source").Value; diff --git a/Application/ResearchDataManagementPlatform/Theme/Themes.cs b/Application/ResearchDataManagementPlatform/Theme/Themes.cs index 7d87614d61..7708d2abf3 100644 --- a/Application/ResearchDataManagementPlatform/Theme/Themes.cs +++ b/Application/ResearchDataManagementPlatform/Theme/Themes.cs @@ -17,18 +17,19 @@ public class MyVS2015BlueTheme : VS2015BlueTheme, ITheme { private ThemeExtender _extender; public bool ApplyThemeToMenus { get; set; } - + public MyVS2015BlueTheme() { - var manager = new System.Resources.ResourceManager("WeifenLuo.WinFormsUI.ThemeVS2015.Resources", typeof(WeifenLuo.WinFormsUI.ThemeVS2015.VS2015ThemeBase).Assembly); - var bytes = (byte[]) manager.GetObject("vs2015blue_vstheme",CultureInfo.CurrentCulture); + var manager = new System.Resources.ResourceManager("WeifenLuo.WinFormsUI.ThemeVS2015.Resources", + typeof(WeifenLuo.WinFormsUI.ThemeVS2015.VS2015ThemeBase).Assembly); + var bytes = (byte[])manager.GetObject("vs2015blue_vstheme", CultureInfo.CurrentCulture); _extender = new ThemeExtender(Decompress(bytes)); } public new void ApplyTo(ToolStrip item) { - if(ApplyThemeToMenus) + if (ApplyThemeToMenus) { base.ApplyTo(item); _extender.ApplyTo(item); @@ -43,7 +44,8 @@ public class MyVS2015DarkTheme : VS2015DarkTheme, ITheme public MyVS2015DarkTheme() { - var manager = new System.Resources.ResourceManager("WeifenLuo.WinFormsUI.ThemeVS2015.Resources", typeof(WeifenLuo.WinFormsUI.ThemeVS2015.VS2015ThemeBase).Assembly); + var manager = new System.Resources.ResourceManager("WeifenLuo.WinFormsUI.ThemeVS2015.Resources", + typeof(WeifenLuo.WinFormsUI.ThemeVS2015.VS2015ThemeBase).Assembly); var bytes = (byte[])manager.GetObject("vs2015dark_vstheme", CultureInfo.CurrentCulture); _extender = new ThemeExtender(Decompress(bytes)); @@ -66,7 +68,8 @@ public class MyVS2015LightTheme : VS2015LightTheme, ITheme public MyVS2015LightTheme() { - var manager = new System.Resources.ResourceManager("WeifenLuo.WinFormsUI.ThemeVS2015.Resources", typeof(WeifenLuo.WinFormsUI.ThemeVS2015.VS2015ThemeBase).Assembly); + var manager = new System.Resources.ResourceManager("WeifenLuo.WinFormsUI.ThemeVS2015.Resources", + typeof(WeifenLuo.WinFormsUI.ThemeVS2015.VS2015ThemeBase).Assembly); var bytes = (byte[])manager.GetObject("vs2015light_vstheme", CultureInfo.CurrentCulture); _extender = new ThemeExtender(Decompress(bytes)); diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ActivateItems.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ActivateItems.cs index 56dbd17151..8eb9210228 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ActivateItems.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ActivateItems.cs @@ -92,8 +92,8 @@ public class ActivateItems : BasicActivateItems, IActivateItems, IRefreshBusSubs public override void Publish(IMapsDirectlyToDatabaseTable databaseEntity) { - if(databaseEntity is DatabaseEntity de) - RefreshBus.Publish(this,new RefreshObjectEventArgs(de)); + if (databaseEntity is DatabaseEntity de) + RefreshBus.Publish(this, new RefreshObjectEventArgs(de)); } public override void Show(string title, string message) @@ -105,7 +105,7 @@ public override void Show(string title, string message) return; } - WideMessageBox.Show(title,message,Environment.StackTrace,true,null,WideMessageBoxTheme.Help); + WideMessageBox.Show(title, message, Environment.StackTrace, true, null, WideMessageBoxTheme.Help); } public ICombineableFactory CommandFactory { get; private set; } @@ -114,7 +114,10 @@ public override void Show(string title, string message) public List ProblemProviders { get; private set; } - public ActivateItems(ITheme theme,RefreshBus refreshBus, DockPanel mainDockPanel, IRDMPPlatformRepositoryServiceLocator repositoryLocator, WindowFactory windowFactory, WindowManager windowManager, ICheckNotifier globalErrorCheckNotifier):base(repositoryLocator,globalErrorCheckNotifier) + public ActivateItems(ITheme theme, RefreshBus refreshBus, DockPanel mainDockPanel, + IRDMPPlatformRepositoryServiceLocator repositoryLocator, WindowFactory windowFactory, + WindowManager windowManager, ICheckNotifier globalErrorCheckNotifier) : base(repositoryLocator, + globalErrorCheckNotifier) { Theme = theme; IsWinForms = true; @@ -128,7 +131,7 @@ public ActivateItems(ITheme theme,RefreshBus refreshBus, DockPanel mainDockPanel HistoryProvider = new HistoryProvider(repositoryLocator); - WindowArranger = new WindowArranger(this,_windowManager,_mainDockPanel); + WindowArranger = new WindowArranger(this, _windowManager, _mainDockPanel); CommandFactory = new RDMPCombineableFactory(); CommandExecutionFactory = new RDMPCommandExecutionFactory(this); @@ -150,10 +153,7 @@ protected override ICoreChildProvider GetChildProvider() { var provider = base.GetChildProvider(); - if (RefreshBus != null) - { - RefreshBus.ChildProvider = provider; - } + if (RefreshBus != null) RefreshBus.ChildProvider = provider; return provider; } @@ -163,19 +163,17 @@ public Form ShowWindow(Control singleControlForm, bool asDocument = false) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { return _mainDockPanel.Invoke
(() => ShowWindow(singleControlForm, asDocument)); - } var width = singleControlForm.Size.Width + SystemInformation.BorderSize.Width; var height = singleControlForm.Size.Height + SystemInformation.BorderSize.Height; //use the .Text or fallback on .Name var name = string.IsNullOrWhiteSpace(singleControlForm.Text) - ? singleControlForm.Name ?? singleControlForm.GetType().Name//or worst case scenario use the type name! + ? singleControlForm.Name ?? singleControlForm.GetType().Name //or worst case scenario use the type name! : singleControlForm.Text; - if(singleControlForm is Form && asDocument) + if (singleControlForm is Form && asDocument) throw new Exception( $"Control '{singleControlForm}' is a Form and asDocument was passed as true. When asDocument is true you must be a Control not a Form e.g. inherit from RDMPUserControl instead of RDMPForm"); @@ -183,12 +181,12 @@ public Form ShowWindow(Control singleControlForm, bool asDocument = false) c?.SetItemActivator(this); - var content = WindowFactory.Create(this,singleControlForm,name , null); + var content = WindowFactory.Create(this, singleControlForm, name, null); if (asDocument) - content.Show(_mainDockPanel,DockState.Document); + content.Show(_mainDockPanel, DockState.Document); else - content.Show(_mainDockPanel,new Rectangle(0,0,width,height)); + content.Show(_mainDockPanel, new Rectangle(0, 0, width, height)); return content; } @@ -213,21 +211,20 @@ public override void RequestItemEmphasis(object sender, EmphasiseRequest request if (root is CohortIdentificationConfiguration cic) Activate(cic); - else - if (root != null) + else if (root != null) _windowManager.ShowCollectionWhichSupportsRootObjectType(root); //really should be a listener now btw since we just launched the relevant Toolbox if it wasn't there before //Look at assignments to Sender, the invocation list can change the Sender! var args = new EmphasiseEventArgs(request); - OnEmphasise(this,args); + OnEmphasise(this, args); //might be different than sender that was passed in - if(args.Sender is DockContent content) + if (args.Sender is DockContent content) content.Activate(); //user is being shown the given object so track it as a recent (e.g. GoTo etc) - if(args.Request.ObjectToEmphasise is IMapsDirectlyToDatabaseTable m) + if (args.Request.ObjectToEmphasise is IMapsDirectlyToDatabaseTable m) HistoryProvider.Add(m); } @@ -237,7 +234,7 @@ public override bool SelectEnum(DialogArgs args, Type enumType, out Enum chosen) if (_mainDockPanel?.InvokeRequired ?? false) { Enum result = default; - var rtn = _mainDockPanel.Invoke(()=>SelectEnum(args, enumType, out result)); + var rtn = _mainDockPanel.Invoke(() => SelectEnum(args, enumType, out result)); chosen = result; return rtn; } @@ -245,15 +242,11 @@ public override bool SelectEnum(DialogArgs args, Type enumType, out Enum chosen) return SelectObject(args, Enum.GetValues(enumType).Cast().ToArray(), out chosen); } - public override bool SelectType(DialogArgs args, Type[] available,out Type chosen) - { - return SelectObject(args, available, out chosen); - } + public override bool SelectType(DialogArgs args, Type[] available, out Type chosen) => + SelectObject(args, available, out chosen); + + public override bool CanActivate(object target) => CommandExecutionFactory.CanActivate(target); - public override bool CanActivate(object target) - { - return CommandExecutionFactory.CanActivate(target); - } protected override void ActivateImpl(object o) { // if on wrong Thread @@ -297,20 +290,15 @@ public string DescribeProblemIfAny(object model) return ProblemProviders.Select(p => p.DescribeProblem(model)).FirstOrDefault(desc => desc != null); } - public string GetDocumentation(Type type) - { - return RepositoryLocator.CatalogueRepository.CommentStore.GetTypeDocumentationIfExists(type); - } + public string GetDocumentation(Type type) => + RepositoryLocator.CatalogueRepository.CommentStore.GetTypeDocumentationIfExists(type); public string CurrentDirectory => Environment.CurrentDirectory; public DialogResult ShowDialog(Form form) { // if on wrong Thread - if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => ShowDialog(form)); - } + if (_mainDockPanel?.InvokeRequired ?? false) return _mainDockPanel.Invoke(() => ShowDialog(form)); return form.ShowDialog(); } @@ -320,13 +308,14 @@ public void KillForm(Form f, Exception reason) // if on wrong Thread if (f.InvokeRequired) { - f.Invoke(() => KillForm(f,reason)); + f.Invoke(() => KillForm(f, reason)); return; } f.Close(); - ExceptionViewer.Show("Window Closed",reason); + ExceptionViewer.Show("Window Closed", reason); } + public void KillForm(Form f, string reason) { // if on wrong Thread @@ -337,8 +326,9 @@ public void KillForm(Form f, string reason) } f.Close(); - WideMessageBox.Show("Window Closed",reason); + WideMessageBox.Show("Window Closed", reason); } + public void OnRuleRegistered(IBinderRule rule) { //no special action required @@ -349,29 +339,25 @@ public void OnRuleRegistered(IBinderRule rule) /// /// /// - public bool ShouldReloadFreshCopy(DatabaseEntity databaseEntity) - { - return YesNo($"{databaseEntity} is out of date with database, would you like to reload a fresh copy?", + public bool ShouldReloadFreshCopy(DatabaseEntity databaseEntity) => + YesNo($"{databaseEntity} is out of date with database, would you like to reload a fresh copy?", "Object Changed"); - } public T Activate(T2 databaseObject) where T : RDMPSingleDatabaseObjectControl, new() - where T2 : DatabaseEntity - { - return Activate(databaseObject, CoreIconProvider.GetImage(databaseObject)); - } + where T2 : DatabaseEntity => + Activate(databaseObject, CoreIconProvider.GetImage(databaseObject)); public T Activate(IPersistableObjectCollection collection) - where T: Control,IObjectCollectionControl,new() + where T : Control, IObjectCollectionControl, new() { //if the window is already open if (PopExisting(typeof(T), collection, out var existingHostedControlInstance)) { //just update its state - var existing = (T) existingHostedControlInstance; - existing.SetCollection(this,collection); + var existing = (T)existingHostedControlInstance; + existing.SetCollection(this, collection); return existing; } @@ -391,16 +377,17 @@ private T Activate(T2 databaseObject, Image tabImage) return (T)existingHostedControlInstance; var uiInstance = new T(); - var floatable = WindowFactory.Create(this,RefreshBus, uiInstance, tabImage, databaseObject); + var floatable = WindowFactory.Create(this, RefreshBus, uiInstance, tabImage, databaseObject); floatable.Show(_mainDockPanel, DockState.Document); uiInstance.SetDatabaseObject(this, databaseObject); - SetTabText(floatable,uiInstance); + SetTabText(floatable, uiInstance); return uiInstance; } - private bool PopExisting(Type windowType, IMapsDirectlyToDatabaseTable databaseObject, out Control existingHostedControlInstance) + private bool PopExisting(Type windowType, IMapsDirectlyToDatabaseTable databaseObject, + out Control existingHostedControlInstance) { var existing = _windowManager.GetActiveWindowIfAnyFor(windowType, databaseObject); existingHostedControlInstance = null; @@ -411,14 +398,16 @@ private bool PopExisting(Type windowType, IMapsDirectlyToDatabaseTable databaseO existing.Activate(); // only refresh if there are changes to the underlying object - if(databaseObject is IRevertable r && r.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent) + if (databaseObject is IRevertable r && + r.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent) existing.HandleUserRequestingTabRefresh(this); } return existing != null; } - private bool PopExisting(Type windowType, IPersistableObjectCollection collection, out Control existingHostedControlInstance) + private bool PopExisting(Type windowType, IPersistableObjectCollection collection, + out Control existingHostedControlInstance) { var existing = _windowManager.GetActiveWindowIfAnyFor(windowType, collection); existingHostedControlInstance = null; @@ -429,18 +418,21 @@ private bool PopExisting(Type windowType, IPersistableObjectCollection collectio existing.Activate(); // only refresh if there are changes to some of the underlying objects - if(collection.DatabaseObjects.OfType().Any(r=>r.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent)) + if (collection.DatabaseObjects.OfType().Any(r => + r.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent)) existing.HandleUserRequestingTabRefresh(this); } return existing != null; } + public DockContent Activate(DeserializeInstruction instruction, IActivateItems activator) { if (instruction.DatabaseObject != null && instruction.ObjectCollection != null) - throw new ArgumentException("DeserializeInstruction cannot have both a DatabaseObject and an ObjectCollection"); + throw new ArgumentException( + "DeserializeInstruction cannot have both a DatabaseObject and an ObjectCollection"); - var c = (Control)UIObjectConstructor.Construct(instruction.UIControlType,activator,true); + var c = (Control)UIObjectConstructor.Construct(instruction.UIControlType, activator, true); //it has a database object so call SetDatabaseObject @@ -455,23 +447,26 @@ public DockContent Activate(DeserializeInstruction instruction, IActivateItems a if (databaseObject == null) return null; - DockContent floatable = WindowFactory.Create(this,RefreshBus, uiInstance,CoreIconProvider.GetImage(databaseObject), databaseObject); + DockContent floatable = WindowFactory.Create(this, RefreshBus, uiInstance, + CoreIconProvider.GetImage(databaseObject), databaseObject); floatable.Show(_mainDockPanel, DockState.Document); try { - uiInstance.SetDatabaseObject(this,(DatabaseEntity) databaseObject); - SetTabText(floatable,uiInstance); + uiInstance.SetDatabaseObject(this, (DatabaseEntity)databaseObject); + SetTabText(floatable, uiInstance); } catch (Exception e) { floatable.Close(); throw new Exception( - $"SetDatabaseObject failed on Control of Type '{instruction.UIControlType.Name}', control closed, see inner Exception for details",e); + $"SetDatabaseObject failed on Control of Type '{instruction.UIControlType.Name}', control closed, see inner Exception for details", + e); } return floatable; } + return (DockContent)activator.ShowWindow(c, true); } @@ -489,9 +484,10 @@ private static void SetTabText(DockContent floatable, INamedTab tab) floatable.ParentForm.Text = $"{tabText} - RDMP"; } - public PersistableObjectCollectionDockContent Activate(IObjectCollectionControl collectionControl, IPersistableObjectCollection objectCollection) + public PersistableObjectCollectionDockContent Activate(IObjectCollectionControl collectionControl, + IPersistableObjectCollection objectCollection) { - var floatable = WindowFactory.Create(this,collectionControl,objectCollection, null); + var floatable = WindowFactory.Create(this, collectionControl, objectCollection, null); floatable.Show(_mainDockPanel, DockState.Document); return floatable; } @@ -499,12 +495,13 @@ public PersistableObjectCollectionDockContent Activate(IObjectCollectionControl public void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e) { // if we don't want to do selective refresh or can't (because partial refreshes are not supported on the type) - if(HardRefresh || !UserSettings.SelectiveRefresh || !CoreChildProvider.SelectiveRefresh(e.Object)) + if (HardRefresh || !UserSettings.SelectiveRefresh || !CoreChildProvider.SelectiveRefresh(e.Object)) { //update the child provider with a full refresh GetChildProvider(); HardRefresh = false; } + RefreshProblemProviders(); } @@ -515,7 +512,7 @@ private void RefreshProblemProviders() } /// - public override bool YesNo(DialogArgs args,out bool chosen) + public override bool YesNo(DialogArgs args, out bool chosen) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) @@ -544,21 +541,24 @@ public override bool YesNo(DialogArgs args,out bool chosen) return false; } - public override bool TypeText(DialogArgs args, int maxLength, string initialText, out string text, bool requireSaneHeaderText) + public override bool TypeText(DialogArgs args, int maxLength, string initialText, out string text, + bool requireSaneHeaderText) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) { string result = default; - var rtn = _mainDockPanel.Invoke(() => TypeText(args,maxLength,initialText,out result,requireSaneHeaderText)); + var rtn = _mainDockPanel.Invoke(() => + TypeText(args, maxLength, initialText, out result, requireSaneHeaderText)); text = result; return rtn; } - var textTyper = new TypeTextOrCancelDialog(args, maxLength, initialText, allowBlankText: false, multiLine: maxLength > MultiLineLengthThreshold) - { - RequireSaneHeaderText = requireSaneHeaderText - }; + var textTyper = + new TypeTextOrCancelDialog(args, maxLength, initialText, false, maxLength > MultiLineLengthThreshold) + { + RequireSaneHeaderText = requireSaneHeaderText + }; text = textTyper.ShowDialog() == DialogResult.OK ? textTyper.ResultText : null; return !string.IsNullOrWhiteSpace(text); @@ -568,11 +568,9 @@ public override DiscoveredDatabase SelectDatabase(bool allowDatabaseCreation, st { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => SelectDatabase(allowDatabaseCreation,taskDescription)); - } + return _mainDockPanel.Invoke(() => SelectDatabase(allowDatabaseCreation, taskDescription)); - var dialog = new ServerDatabaseTableSelectorDialog(taskDescription,false,true,this); + var dialog = new ServerDatabaseTableSelectorDialog(taskDescription, false, true, this); dialog.ShowDialog(); if (dialog.DialogResult != DialogResult.OK) @@ -585,9 +583,7 @@ public override DiscoveredTable SelectTable(bool allowDatabaseCreation, string t { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { return _mainDockPanel.Invoke(() => SelectTable(allowDatabaseCreation, taskDescription)); - } var dialog = new ServerDatabaseTableSelectorDialog(taskDescription, true, true, this) { @@ -619,11 +615,11 @@ public override void Wait(string title, Task task, CancellationTokenSource cts) // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) { - _mainDockPanel.Invoke(() => Wait(title,task,cts)); + _mainDockPanel.Invoke(() => Wait(title, task, cts)); return; } - var ui = new WaitUI(title,task,cts); + var ui = new WaitUI(title, task, cts); ui.ShowDialog(); } @@ -632,18 +628,17 @@ public override IEnumerable GetIgnoredCommands() { yield return typeof(ExecuteCommandRefreshObject); yield return typeof(ExecuteCommandChangeExtractability); - yield return typeof (ExecuteCommandOpenInExplorer); - yield return typeof (ExecuteCommandCreateNewFileBasedProcessTask); + yield return typeof(ExecuteCommandOpenInExplorer); + yield return typeof(ExecuteCommandCreateNewFileBasedProcessTask); } - public override IMapsDirectlyToDatabaseTable SelectOne(DialogArgs args, IMapsDirectlyToDatabaseTable[] availableObjects) + public override IMapsDirectlyToDatabaseTable SelectOne(DialogArgs args, + IMapsDirectlyToDatabaseTable[] availableObjects) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { return _mainDockPanel.Invoke(() => SelectOne(args, availableObjects)); - } if (!availableObjects.Any()) { @@ -653,15 +648,10 @@ public override IMapsDirectlyToDatabaseTable SelectOne(DialogArgs args, IMapsDir //if there is only one object available to select if (availableObjects.Length == 1) - if(args.AllowAutoSelect) - { + if (args.AllowAutoSelect) return availableObjects[0]; - } - if(SelectObject(args,availableObjects, out var selected)) - { - return selected; - } + if (SelectObject(args, availableObjects, out var selected)) return selected; return null; //user didn't select one of the IMapsDirectlyToDatabaseTable objects shown in the dialog } @@ -677,7 +667,7 @@ public override bool SelectObject(DialogArgs args, T[] available, out T selec return rtn; } - var pick = new SelectDialog(args,this,available,false); + var pick = new SelectDialog(args, this, available, false); if (pick.ShowDialog() == DialogResult.OK) { @@ -714,13 +704,11 @@ public override bool SelectObjects(DialogArgs args, T[] available, out T[] se selected = default; return false; } + public override DirectoryInfo SelectDirectory(string prompt) { // if on wrong Thread - if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => SelectDirectory(prompt)); - } + if (_mainDockPanel?.InvokeRequired ?? false) return _mainDockPanel.Invoke(() => SelectDirectory(prompt)); using (var fb = new FolderBrowserDialog()) { @@ -734,10 +722,7 @@ public override DirectoryInfo SelectDirectory(string prompt) public override FileInfo SelectFile(string prompt) { // if on wrong Thread - if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => SelectFile(prompt)); - } + if (_mainDockPanel?.InvokeRequired ?? false) return _mainDockPanel.Invoke(() => SelectFile(prompt)); return SelectFile(prompt, null, null); } @@ -746,11 +731,9 @@ public override FileInfo SelectFile(string prompt, string patternDescription, st { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => SelectFile(prompt, patternDescription,pattern)); - } + return _mainDockPanel.Invoke(() => SelectFile(prompt, patternDescription, pattern)); - using (var fb = new OpenFileDialog {CheckFileExists = false,Multiselect = false}) + using (var fb = new OpenFileDialog { CheckFileExists = false, Multiselect = false }) { if (patternDescription != null && pattern != null) fb.Filter = $"{patternDescription}|{pattern}"; @@ -758,7 +741,7 @@ public override FileInfo SelectFile(string prompt, string patternDescription, st if (fb.ShowDialog() == DialogResult.OK) { // entering "null" in a winforms file dialog will return something like "D:\Blah\null" - if (string.Equals(Path.GetFileName(fb.FileName),"null", StringComparison.CurrentCultureIgnoreCase)) + if (string.Equals(Path.GetFileName(fb.FileName), "null", StringComparison.CurrentCultureIgnoreCase)) return null; return new FileInfo(fb.FileName); @@ -772,17 +755,15 @@ public override FileInfo[] SelectFiles(string prompt, string patternDescription, { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { return _mainDockPanel.Invoke(() => SelectFiles(prompt, patternDescription, pattern)); - } - using (var fb = new OpenFileDialog {CheckFileExists = false,Multiselect = true}) + using (var fb = new OpenFileDialog { CheckFileExists = false, Multiselect = true }) { if (patternDescription != null && pattern != null) fb.Filter = $"{patternDescription}|{pattern}"; if (fb.ShowDialog() == DialogResult.OK) - return fb.FileNames.Select(f=>new FileInfo(f)).ToArray(); + return fb.FileNames.Select(f => new FileInfo(f)).ToArray(); return null; } @@ -800,7 +781,7 @@ protected override bool SelectValueTypeImpl(DialogArgs args, Type paramType, obj } //whatever else it is use string - var typeTextDialog = new TypeTextOrCancelDialog(args,1000,initialValue?.ToString()); + var typeTextDialog = new TypeTextOrCancelDialog(args, 1000, initialValue?.ToString()); if (typeTextDialog.ShowDialog() == DialogResult.OK) { @@ -817,9 +798,7 @@ public override IMapsDirectlyToDatabaseTable[] SelectMany(DialogArgs args, Type { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { return _mainDockPanel.Invoke(() => SelectMany(args, arrayElementType, availableObjects)); - } if (!availableObjects.Any()) { @@ -837,8 +816,8 @@ public override IMapsDirectlyToDatabaseTable[] SelectMany(DialogArgs args, Type var ms = selectDialog.MultiSelected.ToList(); var toReturn = Array.CreateInstance(arrayElementType, ms.Count); - for(var i = 0;i().ToArray(); } @@ -850,44 +829,44 @@ public override List GetDelegates() { return new List { - new CommandInvokerDelegate(typeof(IActivateItems),true,p=>this) + new(typeof(IActivateItems), true, p => this) }; } - public void StartSession(string sessionName, IEnumerable initialObjects, string initialSearch) + + public void StartSession(string sessionName, IEnumerable initialObjects, + string initialSearch) { - if(initialObjects == null) + if (initialObjects == null) { - initialObjects = SelectMany(new DialogArgs + initialObjects = SelectMany(new DialogArgs { - WindowTitle = sessionName.StartsWith(ExecuteCommandStartSession.FindResultsTitle) ? "Find Multiple" : "Session Objects", - TaskDescription = "Pick which objects you want added to the session window. You can always add more later", + WindowTitle = sessionName.StartsWith(ExecuteCommandStartSession.FindResultsTitle) + ? "Find Multiple" + : "Session Objects", + TaskDescription = + "Pick which objects you want added to the session window. You can always add more later", InitialSearchText = initialSearch, IsFind = sessionName.StartsWith(ExecuteCommandStartSession.FindResultsTitle) - },typeof(IMapsDirectlyToDatabaseTable),CoreChildProvider.GetAllSearchables().Keys.ToArray())?.ToList(); + }, typeof(IMapsDirectlyToDatabaseTable), CoreChildProvider.GetAllSearchables().Keys.ToArray())?.ToList(); - if(initialObjects == null || !initialObjects.Any()) - { + if (initialObjects == null || !initialObjects.Any()) // user cancelled picking objects return; - } } - var panel = WindowFactory.Create(this,new SessionCollectionUI(),new SessionCollection(sessionName) + var panel = WindowFactory.Create(this, new SessionCollectionUI(), new SessionCollection(sessionName) { DatabaseObjects = initialObjects.ToList() - },Image.Load(CatalogueIcons.WindowLayout)); - panel.Show(_mainDockPanel,DockState.DockLeft); + }, Image.Load(CatalogueIcons.WindowLayout)); + panel.Show(_mainDockPanel, DockState.DockLeft); } /// - public IEnumerable GetSessions() - { - return _windowManager.GetAllWindows(); - } + public IEnumerable GetSessions() => _windowManager.GetAllWindows(); - public override IPipelineRunner GetPipelineRunner(DialogArgs args,IPipelineUseCase useCase, IPipeline pipeline) + public override IPipelineRunner GetPipelineRunner(DialogArgs args, IPipelineUseCase useCase, IPipeline pipeline) { var configureAndExecuteDialog = new ConfigureAndExecutePipelineUI(args, useCase, this) { @@ -897,17 +876,17 @@ public override IPipelineRunner GetPipelineRunner(DialogArgs args,IPipelineUseCa return configureAndExecuteDialog; } - public override CohortCreationRequest GetCohortCreationRequest(ExternalCohortTable externalCohortTable, IProject project, string cohortInitialDescription) + public override CohortCreationRequest GetCohortCreationRequest(ExternalCohortTable externalCohortTable, + IProject project, string cohortInitialDescription) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => GetCohortCreationRequest(externalCohortTable, project, cohortInitialDescription)); - } + return _mainDockPanel.Invoke(() => + GetCohortCreationRequest(externalCohortTable, project, cohortInitialDescription)); - var ui = new CohortCreationRequestUI(this,externalCohortTable,project); + var ui = new CohortCreationRequestUI(this, externalCohortTable, project); - if(!string.IsNullOrWhiteSpace(cohortInitialDescription)) + if (!string.IsNullOrWhiteSpace(cohortInitialDescription)) ui.CohortDescription = $"{cohortInitialDescription} ({Environment.UserName} - {DateTime.Now})"; if (ui.ShowDialog() != DialogResult.OK) @@ -916,13 +895,13 @@ public override CohortCreationRequest GetCohortCreationRequest(ExternalCohortTab return ui.Result; } - public override ICatalogue CreateAndConfigureCatalogue(ITableInfo tableInfo, ColumnInfo[] extractionIdentifierColumns, string initialDescription, IProject projectSpecific, string folder) + public override ICatalogue CreateAndConfigureCatalogue(ITableInfo tableInfo, + ColumnInfo[] extractionIdentifierColumns, string initialDescription, IProject projectSpecific, string folder) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => CreateAndConfigureCatalogue(tableInfo, extractionIdentifierColumns, initialDescription,projectSpecific,folder)); - } + return _mainDockPanel.Invoke(() => CreateAndConfigureCatalogue(tableInfo, extractionIdentifierColumns, + initialDescription, projectSpecific, folder)); var ui = new ConfigureCatalogueExtractabilityUI(this, tableInfo, initialDescription, projectSpecific) { @@ -932,16 +911,17 @@ public override ICatalogue CreateAndConfigureCatalogue(ITableInfo tableInfo, Col return ui.CatalogueCreatedIfAny; } - public override ExternalDatabaseServer CreateNewPlatformDatabase(ICatalogueRepository catalogueRepository, PermissableDefaults defaultToSet, IPatcher patcher, DiscoveredDatabase db) + + public override ExternalDatabaseServer CreateNewPlatformDatabase(ICatalogueRepository catalogueRepository, + PermissableDefaults defaultToSet, IPatcher patcher, DiscoveredDatabase db) { // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) - { - return _mainDockPanel.Invoke(() => CreateNewPlatformDatabase(catalogueRepository, defaultToSet, patcher, db)); - } + return _mainDockPanel.Invoke( + () => CreateNewPlatformDatabase(catalogueRepository, defaultToSet, patcher, db)); //launch the winforms UI for creating a database - return CreatePlatformDatabase.CreateNewExternalServer(catalogueRepository,defaultToSet,patcher); + return CreatePlatformDatabase.CreateNewExternalServer(catalogueRepository, defaultToSet, patcher); } public override bool ShowCohortWizard(out CohortIdentificationConfiguration cic) @@ -968,17 +948,14 @@ public override void SelectAnythingThen(DialogArgs args, Action SelectAnythingThen(args,callback)); + _mainDockPanel.Invoke(() => SelectAnythingThen(args, callback)); return; } var select = new SelectDialog( args, this, CoreChildProvider.GetAllSearchables().Select(k => k.Key), false); - if(select.ShowDialog() == DialogResult.OK && select.Selected != null) - { - callback(select.Selected); - } + if (select.ShowDialog() == DialogResult.OK && select.Selected != null) callback(select.Selected); } public override void ShowData(IViewSQLAndResultsCollection collection) @@ -1010,13 +987,13 @@ public override void ShowLogs(ExternalDatabaseServer loggingServer, LogViewerFil // if on wrong Thread if (_mainDockPanel?.InvokeRequired ?? false) { - _mainDockPanel.Invoke(() => ShowLogs(loggingServer,filter)); + _mainDockPanel.Invoke(() => ShowLogs(loggingServer, filter)); return; } - var loggingTabUI = Activate(loggingServer); - if(filter != null) + var loggingTabUI = Activate(loggingServer); + if (filter != null) loggingTabUI.SetFilter(filter); } diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/CollectionNavigation.cs b/Application/ResearchDataManagementPlatform/WindowManagement/CollectionNavigation.cs index 4464f525ac..4bd4e65925 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/CollectionNavigation.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/CollectionNavigation.cs @@ -14,7 +14,7 @@ namespace ResearchDataManagementPlatform.WindowManagement; /// /// Records the fact that the user visited a specific object in a tree collection /// -public class CollectionNavigation: INavigation +public class CollectionNavigation : INavigation { public IMapsDirectlyToDatabaseTable Object { get; } @@ -22,12 +22,12 @@ public bool IsAlive { get { - if(Object is IMightNotExist o) + if (Object is IMightNotExist o) return o.Exists(); return true; } - } + } public CollectionNavigation(IMapsDirectlyToDatabaseTable Object) { @@ -36,23 +36,18 @@ public CollectionNavigation(IMapsDirectlyToDatabaseTable Object) public void Activate(ActivateItems activateItems) { - activateItems.RequestItemEmphasis(this,new EmphasiseRequest(Object,0)); + activateItems.RequestItemEmphasis(this, new EmphasiseRequest(Object, 0)); } public void Close() { - - } - public override string ToString() - { - return Object.ToString(); } - public override bool Equals(object obj) - { - return obj is CollectionNavigation other && - Object.Equals(other.Object); - } + public override string ToString() => Object.ToString(); + + public override bool Equals(object obj) => + obj is CollectionNavigation other && + Object.Equals(other.Object); public override int GetHashCode() { diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableObjectCollectionDockContent.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableObjectCollectionDockContent.cs index 9bb352f56d..d12e9ec46d 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableObjectCollectionDockContent.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableObjectCollectionDockContent.cs @@ -34,14 +34,15 @@ public class PersistableObjectCollectionDockContent : RDMPSingleControlTab public IPersistableObjectCollection Collection => _control.GetCollection(); - public PersistableObjectCollectionDockContent(IActivateItems activator, IObjectCollectionControl control, IPersistableObjectCollection collection):base(activator.RefreshBus) + public PersistableObjectCollectionDockContent(IActivateItems activator, IObjectCollectionControl control, + IPersistableObjectCollection collection) : base(activator.RefreshBus) { _control = control; Control = (Control)control; //tell the control what its collection is control.SetCollection(activator, collection); - + //ask the control what it wants its name to be TabText = _control.GetTabName(); } @@ -55,7 +56,7 @@ protected override string GetPersistString() var sb = new StringBuilder(); //Output ::: - sb.Append(Prefix + s + _control.GetType().FullName + s + collection.GetType().Name + s); + sb.Append(Prefix + s + _control.GetType().FullName + s + collection.GetType().Name + s); sb.Append(PersistStringHelper.GetObjectCollectionPersistString(collection.DatabaseObjects.ToArray())); @@ -69,7 +70,6 @@ protected override string GetPersistString() } - public override void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e) { var newTabName = _control.GetTabName(); @@ -80,8 +80,7 @@ public override void RefreshBus_RefreshObject(object sender, RefreshObjectEventA TabText = newTabName; //pass the info on to the control - _control.RefreshBus_RefreshObject(sender,e); - + _control.RefreshBus_RefreshObject(sender, e); } public override void HandleUserRequestingTabRefresh(IActivateItems activator) @@ -94,7 +93,7 @@ public override void HandleUserRequestingTabRefresh(IActivateItems activator) revertable?.RevertToDatabaseState(); } - _control.SetCollection(activator,collection); + _control.SetCollection(activator, collection); } @@ -102,12 +101,12 @@ public override void HandleUserRequestingEmphasis(IActivateItems activator) { var collection = _control.GetCollection(); - if(collection != null) + if (collection != null) if (collection.DatabaseObjects.Count >= 1) { - var o = activator.SelectOne("Show", collection.DatabaseObjects.ToArray(),null,true); + var o = activator.SelectOne("Show", collection.DatabaseObjects.ToArray(), null, true); - if(o != null) + if (o != null) activator.RequestItemEmphasis(this, new EmphasiseRequest(o)); } } diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableSingleDatabaseObjectDockContent.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableSingleDatabaseObjectDockContent.cs index 422a237e76..70f7888bc1 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableSingleDatabaseObjectDockContent.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableSingleDatabaseObjectDockContent.cs @@ -32,20 +32,21 @@ public class PersistableSingleDatabaseObjectDockContent : RDMPSingleControlTab public const string Prefix = "RDMPSingleDatabaseObjectControl"; - public PersistableSingleDatabaseObjectDockContent(IRDMPSingleDatabaseObjectControl control, IMapsDirectlyToDatabaseTable databaseObject,RefreshBus refreshBus):base(refreshBus) + public PersistableSingleDatabaseObjectDockContent(IRDMPSingleDatabaseObjectControl control, + IMapsDirectlyToDatabaseTable databaseObject, RefreshBus refreshBus) : base(refreshBus) { Control = (Control)control; - + DatabaseObject = databaseObject; TabText = "Loading..."; control.UnSavedChanges += OnUnSavedChanges; - Closing += (s,e)=>control.UnSavedChanges -= OnUnSavedChanges; + Closing += (s, e) => control.UnSavedChanges -= OnUnSavedChanges; } private void OnUnSavedChanges(object sender, bool unsavedChanges) { - if(TabText == null) + if (TabText == null) return; TabText = unsavedChanges ? $"{TabText.TrimEnd('*')}*" : TabText.TrimEnd('*'); @@ -54,12 +55,13 @@ private void OnUnSavedChanges(object sender, bool unsavedChanges) protected override string GetPersistString() { const char s = PersistStringHelper.Separator; - return Prefix + s + Control.GetType().FullName + s + DatabaseObject.Repository.GetType().FullName + s + DatabaseObject.GetType().FullName + s + DatabaseObject.ID; + return Prefix + s + Control.GetType().FullName + s + DatabaseObject.Repository.GetType().FullName + s + + DatabaseObject.GetType().FullName + s + DatabaseObject.ID; } public override void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e) { - var newTabName = ((IRDMPSingleDatabaseObjectControl) Control).GetTabName(); + var newTabName = ((IRDMPSingleDatabaseObjectControl)Control).GetTabName(); if (ParentForm is CustomFloatWindow floatWindow) floatWindow.Text = newTabName; @@ -77,6 +79,6 @@ public override void HandleUserRequestingTabRefresh(IActivateItems activator) public override void HandleUserRequestingEmphasis(IActivateItems activator) { - activator.RequestItemEmphasis(this,new EmphasiseRequest(DatabaseObject)); + activator.RequestItemEmphasis(this, new EmphasiseRequest(DatabaseObject)); } } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableToolboxDockContent.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableToolboxDockContent.cs index 09f8cbd33a..525e491d28 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableToolboxDockContent.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistableToolboxDockContent.cs @@ -22,7 +22,7 @@ namespace ResearchDataManagementPlatform.WindowManagement.ContentWindowTracking. /// [TechnicalUI] [System.ComponentModel.DesignerCategory("")] -public class PersistableToolboxDockContent:DockContent +public class PersistableToolboxDockContent : DockContent { public const string Prefix = "Toolbox"; @@ -33,11 +33,9 @@ public PersistableToolboxDockContent(RDMPCollection collectionType) { CollectionType = collectionType; } + protected override string GetPersistString() { - - - var args = new Dictionary { { "Toolbox", CollectionType.ToString() } @@ -46,10 +44,8 @@ protected override string GetPersistString() return Prefix + PersistStringHelper.Separator + PersistStringHelper.SaveDictionaryToString(args); } - public RDMPCollectionUI GetCollection() - { - return Controls.OfType().SingleOrDefault(); - } + + public RDMPCollectionUI GetCollection() => Controls.OfType().SingleOrDefault(); public static RDMPCollection? GetToolboxFromPersistString(string persistString) { diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistenceDecisionFactory.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistenceDecisionFactory.cs index 5f1f6b4464..7d5412ad92 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistenceDecisionFactory.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/PersistenceDecisionFactory.cs @@ -28,7 +28,7 @@ public class PersistenceDecisionFactory public PersistenceDecisionFactory() { //ensure dashboard UI assembly is loaded - Assembly.Load(typeof (RacewayRenderAreaUI).Assembly.FullName); + Assembly.Load(typeof(RacewayRenderAreaUI).Assembly.FullName); //ensure data export UI assembly is loaded Assembly.Load(typeof(ExtractionConfigurationUI).Assembly.FullName); //ensure DLE UI assembly is loaded @@ -44,7 +44,8 @@ public PersistenceDecisionFactory() /// /// /// - public static DeserializeInstruction ShouldCreateBasicControl(string persistString, IRDMPPlatformRepositoryServiceLocator repositoryLocator) + public static DeserializeInstruction ShouldCreateBasicControl(string persistString, + IRDMPPlatformRepositoryServiceLocator repositoryLocator) { if (!persistString.StartsWith(RDMPSingleControlTab.BasicPrefix)) return null; @@ -69,7 +70,8 @@ public static DeserializeInstruction ShouldCreateBasicControl(string persistStri return PersistableToolboxDockContent.GetToolboxFromPersistString(persistString); } - public static DeserializeInstruction ShouldCreateSingleObjectControl(string persistString, IRDMPPlatformRepositoryServiceLocator repositoryLocator) + public static DeserializeInstruction ShouldCreateSingleObjectControl(string persistString, + IRDMPPlatformRepositoryServiceLocator repositoryLocator) { if (!persistString.StartsWith(PersistableSingleDatabaseObjectDockContent.Prefix)) return null; @@ -83,45 +85,48 @@ public static DeserializeInstruction ShouldCreateSingleObjectControl(string pers var controlType = GetTypeByName(tokens[1], typeof(Control), repositoryLocator); var o = repositoryLocator.GetArbitraryDatabaseObject(tokens[2], tokens[3], int.Parse(tokens[4])); - - return new DeserializeInstruction(controlType,o); + return new DeserializeInstruction(controlType, o); } - public static DeserializeInstruction ShouldCreateObjectCollection(string persistString, IRDMPPlatformRepositoryServiceLocator repositoryLocator) + public static DeserializeInstruction ShouldCreateObjectCollection(string persistString, + IRDMPPlatformRepositoryServiceLocator repositoryLocator) { if (!persistString.StartsWith(PersistableObjectCollectionDockContent.Prefix)) return null; - - if(!persistString.Contains(PersistStringHelper.ExtraText)) + + if (!persistString.Contains(PersistStringHelper.ExtraText)) throw new PersistenceException($"Persistence string did not contain '{PersistStringHelper.ExtraText}"); //Looks something like this RDMPObjectCollection:MyCoolControlUI:MyControlUIsBundleOfObjects:[CatalogueRepository:AggregateConfiguration:105,CatalogueRepository:AggregateConfiguration:102,CatalogueRepository:AggregateConfiguration:101]###EXTRA_TEXT###I've got a lovely bunch of coconuts var tokens = persistString.Split(PersistStringHelper.Separator); - var uiType = GetTypeByName(tokens[1],typeof(Control),repositoryLocator); - var collectionType = GetTypeByName(tokens[2], typeof (IPersistableObjectCollection), repositoryLocator); + var uiType = GetTypeByName(tokens[1], typeof(Control), repositoryLocator); + var collectionType = GetTypeByName(tokens[2], typeof(IPersistableObjectCollection), repositoryLocator); var objectConstructor = new ObjectConstructor(); var collectionInstance = (IPersistableObjectCollection)ObjectConstructor.Construct(collectionType); - - if(collectionInstance.DatabaseObjects == null) + + if (collectionInstance.DatabaseObjects == null) throw new PersistenceException( $"Constructor of Type '{collectionType}' did not initialise property DatabaseObjects"); var allObjectsString = PersistStringHelper.MatchCollectionInString(persistString); - collectionInstance.DatabaseObjects.AddRange(PersistStringHelper.GetObjectCollectionFromPersistString(allObjectsString,repositoryLocator)); + collectionInstance.DatabaseObjects.AddRange( + PersistStringHelper.GetObjectCollectionFromPersistString(allObjectsString, repositoryLocator)); var extraText = PersistStringHelper.GetExtraText(persistString); collectionInstance.LoadExtraText(extraText); - return new DeserializeInstruction(uiType,collectionInstance); + return new DeserializeInstruction(uiType, collectionInstance); } - private static Type GetTypeByName(string s, Type expectedBaseClassType,IRDMPPlatformRepositoryServiceLocator repositoryLocator) + private static Type GetTypeByName(string s, Type expectedBaseClassType, + IRDMPPlatformRepositoryServiceLocator repositoryLocator) { - var toReturn = repositoryLocator.CatalogueRepository.MEF.GetType(s) ?? throw new TypeLoadException($"Could not find Type called '{s}'"); + var toReturn = repositoryLocator.CatalogueRepository.MEF.GetType(s) ?? + throw new TypeLoadException($"Could not find Type called '{s}'"); if (expectedBaseClassType != null) if (!expectedBaseClassType.IsAssignableFrom(toReturn)) throw new TypeLoadException( @@ -129,5 +134,4 @@ private static Type GetTypeByName(string s, Type expectedBaseClassType,IRDMPPlat return toReturn; } - } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/RDMPSingleControlTab.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/RDMPSingleControlTab.cs index 4d54276e74..87ec6121dc 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/RDMPSingleControlTab.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ContentWindowTracking/Persistence/RDMPSingleControlTab.cs @@ -12,8 +12,6 @@ using Rdmp.UI.ItemActivation; using Rdmp.UI.Refreshing; using Rdmp.UI.SimpleDialogs; - - using WeifenLuo.WinFormsUI.Docking; namespace ResearchDataManagementPlatform.WindowManagement.ContentWindowTracking.Persistence; @@ -23,12 +21,13 @@ namespace ResearchDataManagementPlatform.WindowManagement.ContentWindowTracking. /// [System.ComponentModel.DesignerCategory("")] [TechnicalUI] -public class RDMPSingleControlTab:DockContent,IRefreshBusSubscriber +public class RDMPSingleControlTab : DockContent, IRefreshBusSubscriber { /// /// The control hosted on this tab /// public Control Control { get; protected set; } + public const string BasicPrefix = "BASIC"; protected RDMPSingleControlTab(RefreshBus refreshBus) @@ -52,17 +51,16 @@ public RDMPSingleControlTab(RefreshBus refreshBus, Control c) public virtual void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e) { - } + public virtual void HandleUserRequestingTabRefresh(IActivateItems activator) { - } public virtual void HandleUserRequestingEmphasis(IActivateItems activator) { - } + protected override string GetPersistString() { const char s = PersistStringHelper.Separator; @@ -82,11 +80,12 @@ public void ShowHelp(IActivateItems activator) { firstMatch ??= c.GetType().Name; - sb.AppendLine(typeDocs.GetDocumentationIfExists(c.GetType().Name,false,true)); + sb.AppendLine(typeDocs.GetDocumentationIfExists(c.GetType().Name, false, true)); sb.AppendLine(); } if (sb.Length > 0) - WideMessageBox.Show(firstMatch, sb.ToString(),Environment.StackTrace, true, firstMatch,WideMessageBoxTheme.Help); + WideMessageBox.Show(firstMatch, sb.ToString(), Environment.StackTrace, true, firstMatch, + WideMessageBoxTheme.Help); } } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindow.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindow.cs index 90d07fc4b9..94af6aebea 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindow.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindow.cs @@ -10,7 +10,6 @@ using Rdmp.UI.Menus.MenuItems; using Rdmp.UI.SimpleControls; using ResearchDataManagementPlatform.WindowManagement.ContentWindowTracking.Persistence; - using WeifenLuo.WinFormsUI.Docking; namespace ResearchDataManagementPlatform.WindowManagement.ExtenderFunctionality; @@ -21,14 +20,15 @@ namespace ResearchDataManagementPlatform.WindowManagement.ExtenderFunctionality; /// [TechnicalUI] [System.ComponentModel.DesignerCategory("")] -public class CustomFloatWindow:FloatWindow +public class CustomFloatWindow : FloatWindow { protected internal CustomFloatWindow(DockPanel dockPanel, DockPane pane) : base(dockPanel, pane) { Initialize(); - } - protected internal CustomFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds): base(dockPanel, pane, bounds) + + protected internal CustomFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds) : base(dockPanel, pane, + bounds) { Initialize(); } diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindowFactory.cs b/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindowFactory.cs index 702586fa90..e34dc54c9c 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindowFactory.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/ExtenderFunctionality/CustomFloatWindowFactory.cs @@ -12,15 +12,10 @@ namespace ResearchDataManagementPlatform.WindowManagement.ExtenderFunctionality; /// /// Factory that creates custom Forms when a docked tab is dragged out into a new window (See CustomFloatWindow for implementation) /// -public class CustomFloatWindowFactory: DockPanelExtender.IFloatWindowFactory +public class CustomFloatWindowFactory : DockPanelExtender.IFloatWindowFactory { - public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane) - { - return new CustomFloatWindow(dockPanel,pane); - } + public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane) => new CustomFloatWindow(dockPanel, pane); - public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds) - { - return new CustomFloatWindow(dockPanel,pane,bounds); - } + public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds) => + new CustomFloatWindow(dockPanel, pane, bounds); } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeBoxUI.cs b/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeBoxUI.cs index 234c55c193..2ce722c7be 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeBoxUI.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeBoxUI.cs @@ -27,18 +27,20 @@ public partial class HomeBoxUI : UserControl private bool _doneSetup = false; private Type _openType; - private RDMPCollectionCommonFunctionality CommonTreeFunctionality { get;} = new RDMPCollectionCommonFunctionality(); + private RDMPCollectionCommonFunctionality CommonTreeFunctionality { get; } = new(); public HomeBoxUI() { InitializeComponent(); olvRecent.ItemActivate += OlvRecent_ItemActivate; } - public void SetUp(IActivateItems activator,string title, Type openType,AtomicCommandUIFactory factory, params IAtomicCommand[] newCommands) + + public void SetUp(IActivateItems activator, string title, Type openType, AtomicCommandUIFactory factory, + params IAtomicCommand[] newCommands) { _openType = openType; - + if (!_doneSetup) { _activator = activator; @@ -56,34 +58,34 @@ public void SetUp(IActivateItems activator,string title, Type openType,AtomicCom btnOpen.DisplayStyle = ToolStripItemDisplayStyle.Text; btnOpen.Click += (s, e) => { - if(activator.SelectObject(new DialogArgs - { - WindowTitle = "Open" - },activator.GetAll(openType).ToArray(),out var selected)) - { + if (activator.SelectObject(new DialogArgs + { + WindowTitle = "Open" + }, activator.GetAll(openType).ToArray(), out var selected)) Open(selected); - } }; - + //if there's only one command for new if (newCommands.Length == 1) { //don't use the dropdown toolStrip1.Items.Remove(btnNewDropdown); - btnNew.Click += (s,e)=>newCommands.Single().Execute(); + btnNew.Click += (s, e) => newCommands.Single().Execute(); } else { toolStrip1.Items.Remove(btnNew); - btnNewDropdown.DropDownItems.AddRange(newCommands.Select(factory.CreateMenuItem).Cast().ToArray()); + btnNewDropdown.DropDownItems.AddRange(newCommands.Select(factory.CreateMenuItem).Cast() + .ToArray()); } olvName.AspectGetter = o => ((HistoryEntry)o).Object.ToString(); - CommonTreeFunctionality.SetUp(RDMPCollection.None,olvRecent,activator,olvName,olvName,new RDMPCollectionCommonFunctionalitySettings - { - SuppressChildrenAdder = true - }); + CommonTreeFunctionality.SetUp(RDMPCollection.None, olvRecent, activator, olvName, olvName, + new RDMPCollectionCommonFunctionalitySettings + { + SuppressChildrenAdder = true + }); _doneSetup = true; } @@ -94,12 +96,12 @@ public void SetUp(IActivateItems activator,string title, Type openType,AtomicCom private void RefreshHistory() { olvRecent.ClearObjects(); - olvRecent.AddObjects(_activator.HistoryProvider.History.Where(h=>h.Object.GetType() == _openType).ToArray()); + olvRecent.AddObjects(_activator.HistoryProvider.History.Where(h => h.Object.GetType() == _openType).ToArray()); } private void Open(IMapsDirectlyToDatabaseTable o) { - if (!((DatabaseEntity) o).Exists()) + if (!((DatabaseEntity)o).Exists()) { if (_activator.YesNo($"'{o}' no longer exists, remove from Recent list?", "No longer exists")) { diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeUI.cs b/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeUI.cs index 6f8f110392..4f57024a56 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeUI.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/HomePane/HomeUI.cs @@ -27,7 +27,7 @@ namespace ResearchDataManagementPlatform.WindowManagement.HomePane; /// /// You can access the HomeUI at any time by clicking the home icon in the top left of the RDMP tool bar. /// -public partial class HomeUI : RDMPUserControl,ILifetimeSubscriber +public partial class HomeUI : RDMPUserControl, ILifetimeSubscriber { private readonly IActivateItems _activator; private readonly AtomicCommandUIFactory _uiFactory; @@ -41,7 +41,7 @@ public HomeUI(IActivateItems activator) private void BuildCommandLists() { - boxCatalogue.SetUp(Activator,"Catalogue",typeof(Catalogue),_uiFactory, + boxCatalogue.SetUp(Activator, "Catalogue", typeof(Catalogue), _uiFactory, new ExecuteCommandCreateNewCatalogueByImportingFileUI(_activator) { OverrideCommandName = GlobalStrings.FromFile @@ -50,27 +50,28 @@ private void BuildCommandLists() { OverrideCommandName = GlobalStrings.FromDatabase }); - boxProject.SetUp(Activator,"Project",typeof(Project),_uiFactory, new ExecuteCommandCreateNewDataExtractionProject(_activator)); - - boxCohort.SetUp(Activator,"Cohort Builder", typeof(CohortIdentificationConfiguration),_uiFactory, + boxProject.SetUp(Activator, "Project", typeof(Project), _uiFactory, + new ExecuteCommandCreateNewDataExtractionProject(_activator)); + + boxCohort.SetUp(Activator, "Cohort Builder", typeof(CohortIdentificationConfiguration), _uiFactory, new ExecuteCommandCreateNewCohortIdentificationConfiguration(_activator) { OverrideCommandName = "Cohort Builder Query", PromptToPickAProject = true - }, - new ExecuteCommandCreateNewCohortFromFile(_activator,null,null) + new ExecuteCommandCreateNewCohortFromFile(_activator, null, null) { OverrideCommandName = GlobalStrings.FromFile } ); - boxDataLoad.SetUp(Activator,"Data Load",typeof(LoadMetadata),_uiFactory,new ExecuteCommandCreateNewLoadMetadata(_activator)); + boxDataLoad.SetUp(Activator, "Data Load", typeof(LoadMetadata), _uiFactory, + new ExecuteCommandCreateNewLoadMetadata(_activator)); } - + protected override void OnLoad(EventArgs e) { base.OnLoad(e); - + SetItemActivator(_activator); BuildCommandLists(); diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/Licenses/License.cs b/Application/ResearchDataManagementPlatform/WindowManagement/Licenses/License.cs index ac5c3587de..52517686d5 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/Licenses/License.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/Licenses/License.cs @@ -58,7 +58,8 @@ public string GetLicenseText() private Stream GetStream() { - var stream = typeof (License).Assembly.GetManifestResourceStream(_resourceFilename) ?? throw new Exception($"Could not find EmbeddedResource '{_resourceFilename}'"); + var stream = typeof(License).Assembly.GetManifestResourceStream(_resourceFilename) ?? + throw new Exception($"Could not find EmbeddedResource '{_resourceFilename}'"); return stream; } } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/TabNavigation.cs b/Application/ResearchDataManagementPlatform/WindowManagement/TabNavigation.cs index b04b8abeb1..d598d51cb9 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/TabNavigation.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/TabNavigation.cs @@ -12,7 +12,7 @@ namespace ResearchDataManagementPlatform.WindowManagement; /// /// Records the fact that the user visited a specific (Tab) /// -public class TabNavigation: INavigation +public class TabNavigation : INavigation { public DockContent Tab { get; } @@ -32,22 +32,18 @@ public void Close() { Tab.Close(); } - public override string ToString() - { - return Tab.TabText; - } - public override bool Equals(object obj) - { - return obj is TabNavigation navigation && - EqualityComparer.Default.Equals(Tab, navigation.Tab); - } + public override string ToString() => Tab.TabText; + + public override bool Equals(object obj) => + obj is TabNavigation navigation && + EqualityComparer.Default.Equals(Tab, navigation.Tab); public override int GetHashCode() { unchecked { return -2031380020 + EqualityComparer.Default.GetHashCode(Tab); - } + } } } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/TabPageContextMenus/RDMPSingleControlTabMenu.cs b/Application/ResearchDataManagementPlatform/WindowManagement/TabPageContextMenus/RDMPSingleControlTabMenu.cs index 380ce48905..9d2e3093c2 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/TabPageContextMenus/RDMPSingleControlTabMenu.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/TabPageContextMenus/RDMPSingleControlTabMenu.cs @@ -39,20 +39,23 @@ public RDMPSingleControlTabMenu(IActivateItems activator, RDMPSingleControlTab t var uiFactory = new AtomicCommandUIFactory(activator); var builder = new GoToCommandFactory(activator); - var gotoMenu = new ToolStripMenuItem(AtomicCommandFactory.GoTo){Enabled = false }; + var gotoMenu = new ToolStripMenuItem(AtomicCommandFactory.GoTo) { Enabled = false }; Items.Add(gotoMenu); - foreach(var cmd in builder.GetCommands(single.DatabaseObject).OfType()) + foreach (var cmd in builder.GetCommands(single.DatabaseObject).OfType()) { gotoMenu.DropDownItems.Add(uiFactory.CreateMenuItem(cmd)); gotoMenu.Enabled = true; } + RDMPContextMenuStrip.RegisterFetchGoToObjecstCallback(gotoMenu); } - Items.Add("Refresh", FamFamFamIcons.arrow_refresh.ImageToBitmap(), (s, e) => _tab.HandleUserRequestingTabRefresh(activator)); + Items.Add("Refresh", FamFamFamIcons.arrow_refresh.ImageToBitmap(), + (s, e) => _tab.HandleUserRequestingTabRefresh(activator)); - var help = new ToolStripMenuItem("Help", FamFamFamIcons.help.ImageToBitmap(), (s, e) => _tab.ShowHelp(activator)) + var help = new ToolStripMenuItem("Help", FamFamFamIcons.help.ImageToBitmap(), + (s, e) => _tab.ShowHelp(activator)) { ShortcutKeys = Keys.F1 }; diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/TopBar/RDMPTaskBarUI.cs b/Application/ResearchDataManagementPlatform/WindowManagement/TopBar/RDMPTaskBarUI.cs index c315d0e8ae..9883ccf518 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/TopBar/RDMPTaskBarUI.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/TopBar/RDMPTaskBarUI.cs @@ -25,7 +25,7 @@ namespace ResearchDataManagementPlatform.WindowManagement.TopBar; public partial class RDMPTaskBarUI : UserControl { private WindowManager _manager; - + private const string CreateNewLayout = "<>"; public RDMPTaskBarUI() @@ -34,23 +34,26 @@ public RDMPTaskBarUI() btnHome.Image = FamFamFamIcons.application_home.ImageToBitmap(); btnCatalogues.Image = CatalogueIcons.Catalogue.ImageToBitmap(); - btnCatalogues.BackgroundImage = BackColorProvider.GetBackgroundImage(btnCatalogues.Size, RDMPCollection.Catalogue); + btnCatalogues.BackgroundImage = + BackColorProvider.GetBackgroundImage(btnCatalogues.Size, RDMPCollection.Catalogue); btnCohorts.Image = CatalogueIcons.CohortIdentificationConfiguration.ImageToBitmap(); btnCohorts.BackgroundImage = BackColorProvider.GetBackgroundImage(btnCohorts.Size, RDMPCollection.Cohort); btnSavedCohorts.Image = CatalogueIcons.AllCohortsNode.ImageToBitmap(); - btnSavedCohorts.BackgroundImage = BackColorProvider.GetBackgroundImage(btnSavedCohorts.Size, RDMPCollection.SavedCohorts); + btnSavedCohorts.BackgroundImage = + BackColorProvider.GetBackgroundImage(btnSavedCohorts.Size, RDMPCollection.SavedCohorts); btnDataExport.Image = CatalogueIcons.Project.ImageToBitmap(); - btnDataExport.BackgroundImage = BackColorProvider.GetBackgroundImage(btnDataExport.Size, RDMPCollection.DataExport); + btnDataExport.BackgroundImage = + BackColorProvider.GetBackgroundImage(btnDataExport.Size, RDMPCollection.DataExport); btnTables.Image = CatalogueIcons.TableInfo.ImageToBitmap(); btnTables.BackgroundImage = BackColorProvider.GetBackgroundImage(btnTables.Size, RDMPCollection.Tables); btnLoad.Image = CatalogueIcons.LoadMetadata.ImageToBitmap(); btnLoad.BackgroundImage = BackColorProvider.GetBackgroundImage(btnLoad.Size, RDMPCollection.DataLoad); - + btnFavourites.Image = CatalogueIcons.Favourite.ImageToBitmap(); btnDeleteLayout.Image = FamFamFamIcons.delete.ImageToBitmap(); @@ -65,23 +68,22 @@ public void SetWindowManager(WindowManager manager) _manager = manager; //Update task bar buttons enabledness when the user navigates somewhere - _manager.Navigation.Changed += (s,e)=> UpdateForwardBackEnabled(); + _manager.Navigation.Changed += (s, e) => UpdateForwardBackEnabled(); btnDataExport.Enabled = manager.RepositoryLocator.DataExportRepository != null; - + ReCreateDropDowns(); - + SetupToolTipText(); _manager.ActivateItems.Theme.ApplyTo(toolStrip1); // if we don't support commit system then disable the task bar button for it - if(!_manager.ActivateItems.RepositoryLocator.CatalogueRepository.SupportsCommits) + if (!_manager.ActivateItems.RepositoryLocator.CatalogueRepository.SupportsCommits) { cbCommits.Enabled = false; cbCommits.Text = "Repository does not support commits"; } - } /// @@ -109,9 +111,9 @@ private void SetupToolTipText() } catch (Exception e) { - _manager.ActivateItems.GlobalErrorCheckNotifier.OnCheckPerformed(new CheckEventArgs("Failed to setup tool tips", CheckResult.Fail, e)); + _manager.ActivateItems.GlobalErrorCheckNotifier.OnCheckPerformed( + new CheckEventArgs("Failed to setup tool tips", CheckResult.Fail, e)); } - } private void ReCreateDropDowns() @@ -119,13 +121,14 @@ private void ReCreateDropDowns() CreateDropDown(cbxLayouts, CreateNewLayout); } - private void CreateDropDown(ToolStripComboBox cbx, string createNewDashboard) where T:IMapsDirectlyToDatabaseTable, INamed + private void CreateDropDown(ToolStripComboBox cbx, string createNewDashboard) + where T : IMapsDirectlyToDatabaseTable, INamed { const int xPaddingForComboText = 10; if (cbx.ComboBox == null) throw new Exception("Expected combo box!"); - + cbx.ComboBox.Items.Clear(); var objects = _manager.RepositoryLocator.CatalogueRepository.GetAllObjects(); @@ -171,17 +174,13 @@ private RDMPCollection ButtonToEnum(object button) if (button == btnCatalogues) collectionToToggle = RDMPCollection.Catalogue; - else - if (button == btnCohorts) + else if (button == btnCohorts) collectionToToggle = RDMPCollection.Cohort; - else - if (button == btnDataExport) + else if (button == btnDataExport) collectionToToggle = RDMPCollection.DataExport; - else - if (button == btnTables) + else if (button == btnTables) collectionToToggle = RDMPCollection.Tables; - else - if (button == btnLoad) + else if (button == btnLoad) collectionToToggle = RDMPCollection.DataLoad; else if (button == btnSavedCohorts) collectionToToggle = RDMPCollection.SavedCohorts; @@ -193,7 +192,7 @@ private RDMPCollection ButtonToEnum(object button) return collectionToToggle; } - + private void cbx_DropDownClosed(object sender, EventArgs e) { var cbx = (ToolStripComboBox)sender; @@ -211,7 +210,6 @@ private void cbx_DropDownClosed(object sender, EventArgs e) } - private void cbx_SelectedIndexChanged(object sender, EventArgs e) { UpdateButtonEnabledness(); @@ -230,7 +228,7 @@ private void AddNewLayout() var dialog = new TypeTextOrCancelDialog("Layout Name", "Name", 100, null, false); if (dialog.ShowDialog() == DialogResult.OK) { - var layout = new WindowLayout(_manager.RepositoryLocator.CatalogueRepository, dialog.ResultText,xml); + var layout = new WindowLayout(_manager.RepositoryLocator.CatalogueRepository, dialog.ResultText, xml); var cmd = new ExecuteCommandActivate(_manager.ActivateItems, layout); cmd.Execute(); @@ -262,7 +260,7 @@ private void btnDelete_Click(object sender, EventArgs e) private void btnSaveWindowLayout_Click(object sender, EventArgs e) { - if(cbxLayouts.SelectedItem is WindowLayout layout) + if (cbxLayouts.SelectedItem is WindowLayout layout) { var xml = _manager.MainForm.GetCurrentLayoutXml(); @@ -290,7 +288,7 @@ private void btnBack_DropDownOpening(object sender, EventArgs e) foreach (var history in _manager.Navigation.GetHistory(16)) { var i = backIndex++; - btnBack.DropDownItems.Add(history.ToString(),null,(a,b)=>_manager.Navigation.Back(i,true)); + btnBack.DropDownItems.Add(history.ToString(), null, (a, b) => _manager.Navigation.Back(i, true)); } } } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/UIObjectConstructor.cs b/Application/ResearchDataManagementPlatform/WindowManagement/UIObjectConstructor.cs index 7257c8295c..dcf6724ef4 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/UIObjectConstructor.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/UIObjectConstructor.cs @@ -13,10 +13,8 @@ namespace ResearchDataManagementPlatform.WindowManagement; /// /// Provides UI specific helpful overloads to ObjectConstructor (which is defined in a data class) /// -public class UIObjectConstructor:ObjectConstructor +public class UIObjectConstructor : ObjectConstructor { - public static object Construct(Type t,IActivateItems itemActivator, bool allowBlankConstructors = true) - { - return ObjectConstructor.Construct(t, itemActivator, allowBlankConstructors); - } + public static object Construct(Type t, IActivateItems itemActivator, bool allowBlankConstructors = true) => + ObjectConstructor.Construct(t, itemActivator, allowBlankConstructors); } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/WindowArranging/WindowArranger.cs b/Application/ResearchDataManagementPlatform/WindowManagement/WindowArranging/WindowArranger.cs index 9c4520ff96..712016bcef 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/WindowArranging/WindowArranger.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/WindowArranging/WindowArranger.cs @@ -25,11 +25,11 @@ public class WindowArranger : IArrangeWindows public WindowArranger(IActivateItems activator, WindowManager windowManager, DockPanel mainDockPanel) { _activator = activator; - _windowManager =windowManager; + _windowManager = windowManager; } - + public void SetupEditAnything(object sender, IMapsDirectlyToDatabaseTable o) - { + { _activator.RequestItemEmphasis(this, new EmphasiseRequest(o)); var activate = new ExecuteCommandActivate(_activator, o); @@ -39,7 +39,6 @@ public void SetupEditAnything(object sender, IMapsDirectlyToDatabaseTable o) activate.Execute(); else _activator.RequestItemEmphasis(this, new EmphasiseRequest(o, 1)); //otherwise just show it - } public void Setup(WindowLayout target) @@ -48,9 +47,9 @@ public void Setup(WindowLayout target) var oldXml = _windowManager.MainForm.GetCurrentLayoutXml(); var newXml = target.LayoutData; - if(AreBasicallyTheSameLayout(oldXml, newXml)) + if (AreBasicallyTheSameLayout(oldXml, newXml)) return; - + _windowManager.CloseAllToolboxes(); _windowManager.CloseAllWindows(); _windowManager.MainForm.LoadFromXml(target); diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/WindowFactory.cs b/Application/ResearchDataManagementPlatform/WindowManagement/WindowFactory.cs index 7d52d5c285..099b32cdb1 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/WindowFactory.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/WindowFactory.cs @@ -40,43 +40,46 @@ public class WindowFactory private readonly IconFactory _iconFactory = IconFactory.Instance; - + public WindowFactory(IRDMPPlatformRepositoryServiceLocator repositoryLocator, WindowManager windowManager) { _windowManager = windowManager; RepositoryLocator = repositoryLocator; } - public PersistableToolboxDockContent Create(IActivateItems activator,Control control, string label, Image image, RDMPCollection collection) + public PersistableToolboxDockContent Create(IActivateItems activator, Control control, string label, + Image image, RDMPCollection collection) { var content = new PersistableToolboxDockContent(collection); - + AddControlToDockContent(activator, control, content, label, image); return content; } - - public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activator, RefreshBus refreshBus,IRDMPSingleDatabaseObjectControl control, Image image, IMapsDirectlyToDatabaseTable databaseObject) + + public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activator, RefreshBus refreshBus, + IRDMPSingleDatabaseObjectControl control, Image image, IMapsDirectlyToDatabaseTable databaseObject) { - var content = new PersistableSingleDatabaseObjectDockContent(control, databaseObject,refreshBus); + var content = new PersistableSingleDatabaseObjectDockContent(control, databaseObject, refreshBus); _windowManager.AddWindow(content); - AddControlToDockContent(activator, (Control)control,content,"Loading...",image); - + AddControlToDockContent(activator, (Control)control, content, "Loading...", image); + if (!RDMPMainForm.Loading) activator.HistoryProvider.Add(databaseObject); return content; } - public PersistableObjectCollectionDockContent Create(IActivateItems activator, IObjectCollectionControl control, IPersistableObjectCollection objectCollection, Image image) + public PersistableObjectCollectionDockContent Create(IActivateItems activator, IObjectCollectionControl control, + IPersistableObjectCollection objectCollection, Image image) { //create a new persistable docking tab - var content = new PersistableObjectCollectionDockContent(activator,control,objectCollection); + var content = new PersistableObjectCollectionDockContent(activator, control, objectCollection); //add the control to the tab - AddControlToDockContent(activator,(Control)control, content,content.TabText, image); - + AddControlToDockContent(activator, (Control)control, content, content.TabText, image); + //add to the window tracker _windowManager.AddWindow(content); @@ -84,7 +87,8 @@ public PersistableObjectCollectionDockContent Create(IActivateItems activator, I return content; } - public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activator, IRDMPSingleDatabaseObjectControl control, DatabaseEntity entity) + public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activator, + IRDMPSingleDatabaseObjectControl control, DatabaseEntity entity) { var content = new PersistableSingleDatabaseObjectDockContent(control, entity, activator.RefreshBus); @@ -100,33 +104,30 @@ public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activato public DockContent Create(IActivateItems activator, Control control, string label, Image image) { - DockContent content = new RDMPSingleControlTab(activator.RefreshBus,control); - - AddControlToDockContent(activator, control, content,label, image); + DockContent content = new RDMPSingleControlTab(activator.RefreshBus, control); + + AddControlToDockContent(activator, control, content, label, image); _windowManager.AddAdhocWindow(content); return content; } - private void AddControlToDockContent(IActivateItems activator, Control control,DockContent content, string label, Image image) + private void AddControlToDockContent(IActivateItems activator, Control control, DockContent content, string label, + Image image) { control.Dock = DockStyle.Fill; content.Controls.Add(control); content.TabText = label; - - if(image != null) - { - content.Icon = _iconFactory.GetIcon(image); - } - - + + if (image != null) content.Icon = _iconFactory.GetIcon(image); + if (control is IConsultableBeforeClosing consult) content.FormClosing += consult.ConsultAboutClosing; - if(control is ISaveableUI saveable) - content.FormClosing += (s,e)=>saveable.GetObjectSaverButton()?.CheckForUnsavedChangesAnOfferToSave(); + if (control is ISaveableUI saveable) + content.FormClosing += (s, e) => saveable.GetObjectSaverButton()?.CheckForUnsavedChangesAnOfferToSave(); content.KeyPreview = true; @@ -136,21 +137,18 @@ private void AddControlToDockContent(IActivateItems activator, Control control,D //Create handler for AfterPublish RefreshObjectEventHandler handler = null; - handler = (s,e)=> - { + handler = (s, e) => + { // After global changes, rebuild the context menu - if(!content.IsDisposed) + if (!content.IsDisposed) content.TabPageContextMenuStrip = new RDMPSingleControlTabMenu(activator, tab, _windowManager); - else - if(handler != null) + else if (handler != null) activator.RefreshBus.AfterPublish -= handler; //don't leak handlers }; //register the event handler activator.RefreshBus.AfterPublish += handler; - } - } } \ No newline at end of file diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs b/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs index aad67b5ddb..a660577ea1 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs @@ -38,7 +38,7 @@ namespace ResearchDataManagementPlatform.WindowManagement; public class WindowManager { private readonly Dictionary _visibleToolboxes = new(); - private readonly List _trackedWindows = new(); + private readonly List _trackedWindows = new(); private readonly List _trackedAdhocWindows = new(); public NavigationTrack Navigation { get; private set; } @@ -61,26 +61,29 @@ public class WindowManager private HomeUI _home; private DockContent _homeContent; - public WindowManager(ITheme theme,RDMPMainForm mainForm, RefreshBus refreshBus, DockPanel mainDockPanel, IRDMPPlatformRepositoryServiceLocator repositoryLocator, ICheckNotifier globalErrorCheckNotifier) + public WindowManager(ITheme theme, RDMPMainForm mainForm, RefreshBus refreshBus, DockPanel mainDockPanel, + IRDMPPlatformRepositoryServiceLocator repositoryLocator, ICheckNotifier globalErrorCheckNotifier) { - _windowFactory = new WindowFactory(repositoryLocator,this); - ActivateItems = new ActivateItems(theme,refreshBus, mainDockPanel, repositoryLocator, _windowFactory, this, globalErrorCheckNotifier); + _windowFactory = new WindowFactory(repositoryLocator, this); + ActivateItems = new ActivateItems(theme, refreshBus, mainDockPanel, repositoryLocator, _windowFactory, this, + globalErrorCheckNotifier); - GlobalExceptionHandler.Instance.Handler = e=>globalErrorCheckNotifier.OnCheckPerformed(new CheckEventArgs(e.Message,CheckResult.Fail,e)); + GlobalExceptionHandler.Instance.Handler = e => + globalErrorCheckNotifier.OnCheckPerformed(new CheckEventArgs(e.Message, CheckResult.Fail, e)); _mainDockPanel = mainDockPanel; - + MainForm = mainForm; RepositoryLocator = repositoryLocator; - Navigation = new NavigationTrack(c=>c.IsAlive,c=>c.Activate(ActivateItems)); + Navigation = new NavigationTrack(c => c.IsAlive, c => c.Activate(ActivateItems)); mainDockPanel.ActiveDocumentChanged += mainDockPanel_ActiveDocumentChanged; ActivateItems.Emphasise += RecordEmphasis; } private void RecordEmphasis(object sender, EmphasiseEventArgs args) { - if(args.Request.ObjectToEmphasise is IMapsDirectlyToDatabaseTable m) + if (args.Request.ObjectToEmphasise is IMapsDirectlyToDatabaseTable m) Navigation.Append(new CollectionNavigation(m)); } @@ -90,7 +93,8 @@ private void RecordEmphasis(object sender, EmphasiseEventArgs args) /// /// /// - public PersistableToolboxDockContent Create(RDMPCollection collectionToCreate, DockState position = DockState.DockLeft) + public PersistableToolboxDockContent Create(RDMPCollection collectionToCreate, + DockState position = DockState.DockLeft) { PersistableToolboxDockContent toReturn; RDMPCollectionUI collection; @@ -99,41 +103,49 @@ public PersistableToolboxDockContent Create(RDMPCollection collectionToCreate, D { case RDMPCollection.Catalogue: collection = new CatalogueCollectionUI(); - toReturn = Show(RDMPCollection.Catalogue, collection, "Catalogues", Image.Load(CatalogueIcons.Catalogue)); + toReturn = Show(RDMPCollection.Catalogue, collection, "Catalogues", + Image.Load(CatalogueIcons.Catalogue)); break; case RDMPCollection.DataLoad: collection = new LoadMetadataCollectionUI(); - toReturn = Show(RDMPCollection.DataLoad, collection, "Load Configurations", Image.Load(CatalogueIcons.LoadMetadata)); + toReturn = Show(RDMPCollection.DataLoad, collection, "Load Configurations", + Image.Load(CatalogueIcons.LoadMetadata)); break; case RDMPCollection.Tables: collection = new TableInfoCollectionUI(); - toReturn = Show(RDMPCollection.Tables, collection, "Tables",Image.Load(CatalogueIcons.TableInfo)); + toReturn = Show(RDMPCollection.Tables, collection, "Tables", + Image.Load(CatalogueIcons.TableInfo)); break; case RDMPCollection.DataExport: if (RepositoryLocator.DataExportRepository == null) { - WideMessageBox.Show("Data export database unavailable","Cannot create DataExport Toolbox because DataExportRepository has not been set/created yet"); + WideMessageBox.Show("Data export database unavailable", + "Cannot create DataExport Toolbox because DataExportRepository has not been set/created yet"); return null; } collection = new DataExportCollectionUI(); - toReturn = Show(RDMPCollection.DataExport,collection, "Projects", Image.Load(CatalogueIcons.Project)); + toReturn = Show(RDMPCollection.DataExport, collection, "Projects", + Image.Load(CatalogueIcons.Project)); break; case RDMPCollection.Cohort: collection = new CohortIdentificationCollectionUI(); - toReturn = Show(RDMPCollection.Cohort, collection, "Cohort Builder", Image.Load(CatalogueIcons.CohortIdentificationConfiguration)); + toReturn = Show(RDMPCollection.Cohort, collection, "Cohort Builder", + Image.Load(CatalogueIcons.CohortIdentificationConfiguration)); break; case RDMPCollection.SavedCohorts: collection = new SavedCohortsCollectionUI(); - toReturn = Show(RDMPCollection.SavedCohorts, collection, "Saved Cohorts", Image.Load(CatalogueIcons.AllCohortsNode)); + toReturn = Show(RDMPCollection.SavedCohorts, collection, "Saved Cohorts", + Image.Load(CatalogueIcons.AllCohortsNode)); break; case RDMPCollection.Favourites: collection = new FavouritesCollectionUI(); - toReturn = Show(RDMPCollection.Favourites, collection, "Favourites", Image.Load(CatalogueIcons.Favourite)); + toReturn = Show(RDMPCollection.Favourites, collection, "Favourites", + Image.Load(CatalogueIcons.Favourite)); break; default: throw new ArgumentOutOfRangeException(nameof(collectionToCreate)); @@ -145,9 +157,9 @@ public PersistableToolboxDockContent Create(RDMPCollection collectionToCreate, D CollectionCreated?.Invoke(this, new RDMPCollectionCreatedEventHandlerArgs(collectionToCreate)); - collection.CommonTreeFunctionality.Tree.SelectionChanged += (s,e)=> + collection.CommonTreeFunctionality.Tree.SelectionChanged += (s, e) => { - if(collection.CommonTreeFunctionality.Tree.SelectedObject is IMapsDirectlyToDatabaseTable im) + if (collection.CommonTreeFunctionality.Tree.SelectedObject is IMapsDirectlyToDatabaseTable im) Navigation.Append(new CollectionNavigation(im)); }; @@ -155,15 +167,17 @@ public PersistableToolboxDockContent Create(RDMPCollection collectionToCreate, D } - - private PersistableToolboxDockContent Show(RDMPCollection collection,RDMPCollectionUI control, string label, Image image) + private PersistableToolboxDockContent Show(RDMPCollection collection, RDMPCollectionUI control, string label, + Image image) { - var content = _windowFactory.Create(ActivateItems,control, label, image, collection);//these are collections so are not tracked with a window tracker. + var content = + _windowFactory.Create(ActivateItems, control, label, image, + collection); //these are collections so are not tracked with a window tracker. content.Closed += (s, e) => content_Closed(collection); _visibleToolboxes.Add(collection, content); content.Show(_mainDockPanel, DockState.DockLeft); - + return content; } @@ -207,10 +221,7 @@ public void Pop(RDMPCollection collection) /// /// /// - public bool IsVisible(RDMPCollection collection) - { - return _visibleToolboxes.ContainsKey(collection); - } + public bool IsVisible(RDMPCollection collection) => _visibleToolboxes.ContainsKey(collection); public RDMPCollection GetFocusedCollection() { @@ -219,18 +230,13 @@ public RDMPCollection GetFocusedCollection() internal void OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) { - foreach(var c in _trackedWindows) - { - if(c.Control is IConsultableBeforeClosing consult) + foreach (var c in _trackedWindows) + if (c.Control is IConsultableBeforeClosing consult) { consult.ConsultAboutClosing(this, e); - if(e.Cancel) - { - return; - } + if (e.Cancel) return; } - } } @@ -244,10 +250,10 @@ public void ShowCollectionWhichSupportsRootObjectType(object root) { var collection = GetCollectionForRootObject(root); - if(collection == RDMPCollection.None) + if (collection == RDMPCollection.None) return; - if(IsVisible(collection)) + if (IsVisible(collection)) { Pop(collection); return; @@ -258,25 +264,25 @@ public void ShowCollectionWhichSupportsRootObjectType(object root) public RDMPCollection GetCollectionForRootObject(object root) { - if (FavouritesCollectionUI.IsRootObject(ActivateItems,root)) + if (FavouritesCollectionUI.IsRootObject(ActivateItems, root)) return RDMPCollection.Favourites; - if(CatalogueCollectionUI.IsRootObject(root)) + if (CatalogueCollectionUI.IsRootObject(root)) return RDMPCollection.Catalogue; - if(CohortIdentificationCollectionUI.IsRootObject(root)) + if (CohortIdentificationCollectionUI.IsRootObject(root)) return RDMPCollection.Cohort; - if(DataExportCollectionUI.IsRootObject(root)) + if (DataExportCollectionUI.IsRootObject(root)) return RDMPCollection.DataExport; - if(LoadMetadataCollectionUI.IsRootObject(root)) + if (LoadMetadataCollectionUI.IsRootObject(root)) return RDMPCollection.DataLoad; - if(TableInfoCollectionUI.IsRootObject(root)) + if (TableInfoCollectionUI.IsRootObject(root)) return RDMPCollection.Tables; - if(SavedCohortsCollectionUI.IsRootObject(root)) + if (SavedCohortsCollectionUI.IsRootObject(root)) return RDMPCollection.SavedCohorts; return RDMPCollection.None; @@ -287,11 +293,12 @@ public RDMPCollection GetCollectionForRootObject(object root) /// public void PopHome() { - if(_home == null) + if (_home == null) { _home = new HomeUI(ActivateItems); - _homeContent = _windowFactory.Create(ActivateItems, _home, "Home", Image.Load(FamFamFamIcons.application_home)); + _homeContent = _windowFactory.Create(ActivateItems, _home, "Home", + Image.Load(FamFamFamIcons.application_home)); _homeContent.Closed += (s, e) => _home = null; _homeContent.Show(_mainDockPanel, DockState.Document); } @@ -306,7 +313,7 @@ public void PopHome() /// public void CloseAllToolboxes() { - foreach (RDMPCollection collection in Enum.GetValues(typeof (RDMPCollection))) + foreach (RDMPCollection collection in Enum.GetValues(typeof(RDMPCollection))) if (IsVisible(collection)) Destroy(collection); } @@ -326,7 +333,7 @@ public void CloseAllWindows() /// public void CloseAllWindows(RDMPSingleControlTab tab) { - if(tab != null) + if (tab != null) { CloseAllButThis(tab); tab.Close(); @@ -343,9 +350,9 @@ public void CloseAllWindows(RDMPSingleControlTab tab) private void mainDockPanel_ActiveDocumentChanged(object sender, EventArgs e) { - var newTab = (DockContent) _mainDockPanel.ActiveDocument; - - if(newTab != null && newTab.ParentForm != null) + var newTab = (DockContent)_mainDockPanel.ActiveDocument; + + if (newTab != null && newTab.ParentForm != null) { Navigation.Append(new TabNavigation(newTab)); newTab.ParentForm.Text = $"{newTab.TabText} - RDMP"; @@ -363,13 +370,14 @@ private void mainDockPanel_ActiveDocumentChanged(object sender, EventArgs e) /// public void AddWindow(RDMPSingleControlTab window) { - if(window is PersistableSingleDatabaseObjectDockContent singleObjectUI) - if(AlreadyActive(singleObjectUI.Control.GetType(),singleObjectUI.DatabaseObject)) - throw new ArgumentOutOfRangeException($"Cannot create another window for object {singleObjectUI.DatabaseObject} of type {singleObjectUI.Control.GetType()} because there is already a window active for that object/window type"); - + if (window is PersistableSingleDatabaseObjectDockContent singleObjectUI) + if (AlreadyActive(singleObjectUI.Control.GetType(), singleObjectUI.DatabaseObject)) + throw new ArgumentOutOfRangeException( + $"Cannot create another window for object {singleObjectUI.DatabaseObject} of type {singleObjectUI.Control.GetType()} because there is already a window active for that object/window type"); + _trackedWindows.Add(window); - window.FormClosed += (s,e)=>Remove(window); + window.FormClosed += (s, e) => Remove(window); } /// @@ -387,15 +395,20 @@ private void Remove(RDMPSingleControlTab window) _trackedWindows.Remove(window); } - public PersistableSingleDatabaseObjectDockContent GetActiveWindowIfAnyFor(Type windowType, IMapsDirectlyToDatabaseTable databaseObject) + public PersistableSingleDatabaseObjectDockContent GetActiveWindowIfAnyFor(Type windowType, + IMapsDirectlyToDatabaseTable databaseObject) { - return _trackedWindows.OfType().SingleOrDefault(t => t.Control.GetType() == windowType && t.DatabaseObject.Equals(databaseObject)); + return _trackedWindows.OfType().SingleOrDefault(t => + t.Control.GetType() == windowType && t.DatabaseObject.Equals(databaseObject)); } - public PersistableObjectCollectionDockContent GetActiveWindowIfAnyFor(Type windowType, IPersistableObjectCollection collection) + public PersistableObjectCollectionDockContent GetActiveWindowIfAnyFor(Type windowType, + IPersistableObjectCollection collection) { - return _trackedWindows.OfType().SingleOrDefault(t => t.Control.GetType() == windowType && t.Collection.Equals(collection)); + return _trackedWindows.OfType() + .SingleOrDefault(t => t.Control.GetType() == windowType && t.Collection.Equals(collection)); } + /// /// Check whether a given RDMPSingleControlTab is already showing with the given DatabaseObject (e.g. is user currently editing Catalogue bob in CatalogueUI) /// @@ -408,7 +421,8 @@ public bool AlreadyActive(Type windowType, IMapsDirectlyToDatabaseTable database if (!typeof(IRDMPSingleDatabaseObjectControl).IsAssignableFrom(windowType)) throw new ArgumentException("windowType must be a Type derrived from RDMPSingleControlTab"); - return _trackedWindows.OfType().Any(t => t.Control.GetType() == windowType && t.DatabaseObject.Equals(databaseObject)); + return _trackedWindows.OfType().Any(t => + t.Control.GetType() == windowType && t.DatabaseObject.Equals(databaseObject)); } /// @@ -449,7 +463,7 @@ public void CloseCurrentTab() finally { Navigation.Resume(); - if(_mainDockPanel.ActiveDocument is DockContent dc) + if (_mainDockPanel.ActiveDocument is DockContent dc) Navigation.Append(new TabNavigation(dc)); } } diff --git a/Documentation/CodeTutorials/CreatingANewCollectionTreeNode.md b/Documentation/CodeTutorials/CreatingANewCollectionTreeNode.md index e91a76df4d..8d0f84cabb 100644 --- a/Documentation/CodeTutorials/CreatingANewCollectionTreeNode.md +++ b/Documentation/CodeTutorials/CreatingANewCollectionTreeNode.md @@ -74,10 +74,7 @@ private class FrozenExtractionConfigurationsNode Project = project; } - public override string ToString() - { - return "Frozen Extraction Configurations"; - } + public override string ToString() => "Frozen Extraction Configurations"; } ``` @@ -94,28 +91,19 @@ private class FrozenExtractionConfigurationsNode Project = project; } - public override string ToString() - { - return "Frozen Extraction Configurations"; - } + public override string ToString() => "Frozen Extraction Configurations"; - protected bool Equals(FrozenExtractionConfigurationsNode other) - { - return Equals(Project, other.Project); - } + protected bool Equals(FrozenExtractionConfigurationsNode other) => Equals(Project, other.Project); public override bool Equals(object obj) { if (obj is null) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != GetType()) return false; - return Equals((FrozenExtractionConfigurationsNode) obj); + return Equals((FrozenExtractionConfigurationsNode)obj); } - public override int GetHashCode() - { - return Project != null ? Project.GetHashCode() : 0; - } + public override int GetHashCode() => Project?.GetHashCode() ?? 0; } ``` @@ -144,7 +132,7 @@ private void AddChildren(ExtractionConfigurationsNode extractionConfigurationsNo var frozenConfigurationsNode = new FrozenExtractionConfigurationsNode(extractionConfigurationsNode.Project); children.Add(frozenConfigurationsNode); - var configs = ExtractionConfigurations.Where(c => c.Project_ID == extractionConfigurationsNode.Project.ID).ToArray(); + var configs = ExtractionConfigurations .Where(c => c.Project_ID == extractionConfigurationsNode.Project.ID).ToArray(); foreach (var config in configs) { AddChildren(config, descendancy.Add(config)); @@ -250,11 +238,11 @@ private void AddChildren(ExtractionConfigurationsNode extractionConfigurationsNo children.Add(frozenConfigurationsNode); //Add children to the frozen folder - AddChildren(frozenConfigurationsNode,descendancy.Add(frozenConfigurationsNode)); + AddChildren(frozenConfigurationsNode, descendancy.Add(frozenConfigurationsNode)); //Add ExtractionConfigurations which are not released (frozen) - var configs = ExtractionConfigurations.Where(c => c.Project_ID == extractionConfigurationsNode.Project.ID).ToArray(); - foreach (var config in configs.Where(c=>!c.IsReleased)) + var configs = ExtractionConfigurations .Where(c => c.Project_ID == extractionConfigurationsNode.Project.ID).ToArray(); + foreach (var config in configs.Where(c => !c.IsReleased)) { AddChildren(config, descendancy.Add(config)); children.Add(config); @@ -268,14 +256,14 @@ private void AddChildren(FrozenExtractionConfigurationsNode frozenExtractionConf var children = new HashSet(); //Add ExtractionConfigurations which are not released (frozen) - var configs = ExtractionConfigurations.Where(c => c.Project_ID == frozenExtractionConfigurationsNode.Project.ID).ToArray(); + var configs = ExtractionConfigurations .Where(c => c.Project_ID == frozenExtractionConfigurationsNode.Project.ID).ToArray(); foreach (var config in configs.Where(c => c.IsReleased)) { AddChildren(config, descendancy.Add(config)); children.Add(config); } - AddToDictionaries(children,descendancy); + AddToDictionaries(children, descendancy); } ``` Now when you run RDMP, the final tree should look something like: diff --git a/Documentation/CodeTutorials/DoubleClickAndDragDrop.md b/Documentation/CodeTutorials/DoubleClickAndDragDrop.md index f850515396..bb41226e65 100644 --- a/Documentation/CodeTutorials/DoubleClickAndDragDrop.md +++ b/Documentation/CodeTutorials/DoubleClickAndDragDrop.md @@ -31,26 +31,20 @@ Create a new class called `ProposeExecutionWhenTargetIs` in namespace ```csharp -private class ProposeExecutionWhenTargetIsPipeline:RDMPCommandExecutionProposal +private class ProposeExecutionWhenTargetIsPipeline : RDMPCommandExecutionProposal { public ProposeExecutionWhenTargetIsPipeline(IActivateItems itemActivator) : base(itemActivator) { } - public override bool CanActivate(Pipeline target) - { - return true; - } + public override bool CanActivate(Pipeline target) => true; public override void Activate(Pipeline target) { MessageBox.Show("Double clicked"); } - public override ICommandExecution ProposeExecution(ICombineToMakeCommand cmd, Pipeline target, InsertOption insertOption = InsertOption.Default) - { - return null; - } + public override ICommandExecution ProposeExecution(ICombineToMakeCommand cmd, Pipeline target, InsertOption insertOption = InsertOption.Default) => null; } ``` @@ -100,8 +94,8 @@ To add support for dropping an object with an existing `ICombineToMakeCommand` y ```csharp public override ICommandExecution ProposeExecution(ICombineToMakeCommand cmd, Pipeline target, InsertOption insertOption = InsertOption.Default) { - if(cmd is CatalogueCombineable sourceCatalogueCombineable) - return new ExecuteCommandDelete(ItemActivator,sourceCatalogueCombineable.Catalogue); + if (cmd is CatalogueCombineable sourceCatalogueCombineable) + return new ExecuteCommandDelete(ItemActivator, sourceCatalogueCombineable.Catalogue); return null; } @@ -147,10 +141,7 @@ public class PipelineCombineable : ICombineToMakeCommand IsEmpty = Pipeline.PipelineComponents.Count == 0; } - public string GetSqlString() - { - return ""; - } + public string GetSqlString() => ""; } ``` diff --git a/Rdmp.Core.Tests/Caching/Integration/CachingHostTests.cs b/Rdmp.Core.Tests/Caching/Integration/CachingHostTests.cs index ca8b87751c..8f042e4ef4 100644 --- a/Rdmp.Core.Tests/Caching/Integration/CachingHostTests.cs +++ b/Rdmp.Core.Tests/Caching/Integration/CachingHostTests.cs @@ -45,7 +45,7 @@ public void CacheHostOutwithPermissionWindow() // This feels a bit nasty, but quick and much better than having the test wait for an arbitrary time period. var listener = new ExpectedNotificationListener("Download not permitted at this time, sleeping for 60 seconds"); - + cp.CacheFillProgress = DateTime.Now.AddDays(-1); cp.PermissionWindow_ID = 1; @@ -59,9 +59,9 @@ public void CacheHostOutwithPermissionWindow() //Create a time period that we are outwith (1 hour ago to 30 minutes ago). - var start = DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0,1,0,0)); - var stop = DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0,0,30,0)); - permissionWindow.SetPermissionWindowPeriods(new List(new [] + var start = DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 1, 0, 0)); + var stop = DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 0, 30, 0)); + permissionWindow.SetPermissionWindowPeriods(new List(new[] { new PermissionWindowPeriod( (int)DateTime.Now.DayOfWeek, @@ -85,7 +85,8 @@ public void CacheHostOutwithPermissionWindow() var abortTokenSource = new CancellationTokenSource(); var cancellationToken = new GracefulCancellationToken(stopTokenSource.Token, abortTokenSource.Token); - var task = Task.Run(() => cacheHost.Start(listener, cancellationToken), cancellationToken.CreateLinkedSource().Token); + var task = Task.Run(() => cacheHost.Start(listener, cancellationToken), + cancellationToken.CreateLinkedSource().Token); // Don't want to cancel before the DownloadUntilFinished loop starts and we receive the first "Download not permitted at this time, sleeping for 60 seconds" message listener.ReceivedMessage += abortTokenSource.Cancel; @@ -97,18 +98,17 @@ public void CacheHostOutwithPermissionWindow() catch (AggregateException e) { Assert.AreEqual(1, e.InnerExceptions.Count); - Assert.IsInstanceOf(typeof (TaskCanceledException), e.InnerExceptions[0], e.InnerExceptions[0].Message); + Assert.IsInstanceOf(typeof(TaskCanceledException), e.InnerExceptions[0], e.InnerExceptions[0].Message); } finally { testDir.Delete(true); } } - - } internal delegate void ReceivedMessageHandler(); + internal class ExpectedNotificationListener : IDataLoadEventListener { private readonly string _expectedNotificationString; diff --git a/Rdmp.Core.Tests/Caching/Integration/CustomDateCachingTests.cs b/Rdmp.Core.Tests/Caching/Integration/CustomDateCachingTests.cs index 86d9a8e6e2..8786834fe0 100644 --- a/Rdmp.Core.Tests/Caching/Integration/CustomDateCachingTests.cs +++ b/Rdmp.Core.Tests/Caching/Integration/CustomDateCachingTests.cs @@ -39,45 +39,46 @@ public void FetchMultipleDays_Success(bool singleDay) mef.AddTypeToCatalogForTesting(typeof(TestCacheDestination)); // Create a pipeline that will record the cache chunks - var sourceComponent = Mock.Of(x=> + var sourceComponent = Mock.Of(x => x.Class == "CachingEngineTests.Integration.TestCacheSource" && - x.GetClassAsSystemType()==typeof (TestCacheSource) && - x.GetAllArguments()==Array.Empty()); + x.GetClassAsSystemType() == typeof(TestCacheSource) && + x.GetAllArguments() == Array.Empty()); - var destinationComponent = Mock.Of(x=> + var destinationComponent = Mock.Of(x => x.Class == "CachingEngineTests.Integration.TestCacheDestination" && - x.GetClassAsSystemType()==typeof (TestCacheDestination) && - x.GetAllArguments()==Array.Empty()); + x.GetClassAsSystemType() == typeof(TestCacheDestination) && + x.GetAllArguments() == Array.Empty()); - var pipeline = Mock.Of(p=> + var pipeline = Mock.Of(p => p.Repository == CatalogueRepository && - p.Source==sourceComponent && - p.Destination==destinationComponent && + p.Source == sourceComponent && + p.Destination == destinationComponent && p.Repository == CatalogueRepository && - p.PipelineComponents==Enumerable.Empty().OrderBy(o => o).ToList()); + p.PipelineComponents == Enumerable.Empty().OrderBy(o => o).ToList()); - var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"delme",true); + var projDir = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", + true); var lmd = Mock.Of(); lmd.LocationOfFlatFiles = projDir.RootPath.FullName; - var loadProgress = Mock.Of(l=> - l.OriginDate == new DateTime(2001,01,01) && - l.LoadMetadata==lmd); - - var cacheProgress = Mock.Of(c=> + var loadProgress = Mock.Of(l => + l.OriginDate == new DateTime(2001, 01, 01) && + l.LoadMetadata == lmd); + var cacheProgress = Mock.Of(c => c.Pipeline_ID == -123 && - c.Pipeline==pipeline && + c.Pipeline == pipeline && c.ChunkPeriod == new TimeSpan(1, 0, 0, 0) && c.LoadProgress_ID == -1 && c.Repository == CatalogueRepository && - c.LoadProgress ==loadProgress && + c.LoadProgress == loadProgress && c.CacheFillProgress == new DateTime(2020, 1, 1)); var caching = new CustomDateCaching(cacheProgress, RepositoryLocator.CatalogueRepository); var startDate = new DateTime(2016, 1, 1); - var endDate = singleDay? new DateTime(2016, 1, 1): new DateTime(2016, 1, 3); + var endDate = singleDay ? new DateTime(2016, 1, 1) : new DateTime(2016, 1, 3); var listener = new LoggingListener(); var task = caching.Fetch(startDate, endDate, new GracefulCancellationToken(), listener); @@ -88,7 +89,7 @@ public void FetchMultipleDays_Success(bool singleDay) .ToArray(); //should not have been updated because this is a backfill request - Assert.AreEqual(new DateTime(2020,1,1),cacheProgress.CacheFillProgress); + Assert.AreEqual(new DateTime(2020, 1, 1), cacheProgress.CacheFillProgress); Assert.IsTrue(task.IsCompleted); Assert.IsTrue(dateNotifications.Contains(startDate.ToString("g"))); @@ -124,15 +125,14 @@ public class TestCacheChunk : ICacheChunk public TestCacheChunk(DateTime fetchDate) { - Request = new CacheFetchRequest(null,fetchDate){ChunkPeriod = new TimeSpan(1,0,0)}; + Request = new CacheFetchRequest(null, fetchDate) { ChunkPeriod = new TimeSpan(1, 0, 0) }; } - - } public class TestCacheSource : CacheSource { - public override TestCacheChunk DoGetChunk(ICacheFetchRequest request, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) + public override TestCacheChunk DoGetChunk(ICacheFetchRequest request, IDataLoadEventListener listener, + GracefulCancellationToken cancellationToken) { var c = new TestCacheChunk(Request.Start); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"!!{request.Start:g}")); @@ -147,28 +147,22 @@ public override void Abort(IDataLoadEventListener listener) { } - public override TestCacheChunk TryGetPreview() - { - throw new NotImplementedException(); - } + public override TestCacheChunk TryGetPreview() => throw new NotImplementedException(); public override void Check(ICheckNotifier notifier) { } } -public class TestCacheDestination : IPluginDataFlowComponent, IDataFlowDestination, ICacheFileSystemDestination +public class TestCacheDestination : IPluginDataFlowComponent, IDataFlowDestination, + ICacheFileSystemDestination { - public static TestCacheChunk ProcessPipelineData(TestCacheChunk toProcess, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) - { - return toProcess; - } + public static TestCacheChunk ProcessPipelineData(TestCacheChunk toProcess, IDataLoadEventListener listener, + GracefulCancellationToken cancellationToken) => toProcess; public ICacheChunk ProcessPipelineData(ICacheChunk toProcess, IDataLoadEventListener listener, - GracefulCancellationToken cancellationToken) - { - return ProcessPipelineData((TestCacheChunk) toProcess, listener, cancellationToken); - } + GracefulCancellationToken cancellationToken) => + ProcessPipelineData((TestCacheChunk)toProcess, listener, cancellationToken); public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -183,14 +177,11 @@ public void Check(ICheckNotifier notifier) } private ILoadDirectory project; + public void PreInitialize(ILoadDirectory value, IDataLoadEventListener listener) { project = value; } - public ICacheLayout CreateCacheLayout() - { - return new BasicCacheLayout(project.Cache); - } - + public ICacheLayout CreateCacheLayout() => new BasicCacheLayout(project.Cache); } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Caching/Unit/PipelineExecutionTests.cs b/Rdmp.Core.Tests/Caching/Unit/PipelineExecutionTests.cs index 5f5bb63661..fb291d0dcb 100644 --- a/Rdmp.Core.Tests/Caching/Unit/PipelineExecutionTests.cs +++ b/Rdmp.Core.Tests/Caching/Unit/PipelineExecutionTests.cs @@ -37,13 +37,13 @@ public static void TestSerialPipelineExecution() var pipelineExecutor = new SerialPipelineExecution(); // Act - pipelineExecutor.Execute(new [] {engine1.Object, engine2.Object}, tokenSource.Token, listener); + pipelineExecutor.Execute(new[] { engine1.Object, engine2.Object }, tokenSource.Token, listener); // engine1 should have been executed once - engine1.Verify(e=>e.ExecutePipeline(It.IsAny()),Times.Once); + engine1.Verify(e => e.ExecutePipeline(It.IsAny()), Times.Once); // engine2 should also have been run (locking isn't a thing any more) - engine2.Verify(e=>e.ExecutePipeline(It.IsAny()),Times.Once); + engine2.Verify(e => e.ExecutePipeline(It.IsAny()), Times.Once); } [Ignore("Tests locking we don't actually have")] diff --git a/Rdmp.Core.Tests/Caching/Unit/TestIFileDataFlowComponents.cs b/Rdmp.Core.Tests/Caching/Unit/TestIFileDataFlowComponents.cs index 757edee8bd..28e90c63f8 100644 --- a/Rdmp.Core.Tests/Caching/Unit/TestIFileDataFlowComponents.cs +++ b/Rdmp.Core.Tests/Caching/Unit/TestIFileDataFlowComponents.cs @@ -52,7 +52,8 @@ public void Dispose(IDataLoadEventListener listener) } } -public class FilesystemCacheDestination : IFileDataFlowDestination, IPipelineRequirement, IPipelineRequirement +public class FilesystemCacheDestination : IFileDataFlowDestination, IPipelineRequirement, + IPipelineRequirement { public CacheProgress CacheProgress { get; set; } public DirectoryInfo CacheDirectory { get; set; } @@ -72,8 +73,9 @@ public IList ProcessPipelineData(IList toProcess, IDataLoadE // ? where does the date come from? // either going to be CacheFillProgress or CacheFillProgress + period, depending on fetch logic if (CacheProgress.CacheFillProgress == null) - throw new Exception("Should throw, but currently on first cache it is valid for the CacheFIllProgress to be null"); - + throw new Exception( + "Should throw, but currently on first cache it is valid for the CacheFIllProgress to be null"); + return toProcess; } @@ -92,5 +94,4 @@ public void PreInitialize(DirectoryInfo cacheDirectory, IDataLoadEventListener l { CacheDirectory = cacheDirectory; } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Caching/Unit/ZipTests.cs b/Rdmp.Core.Tests/Caching/Unit/ZipTests.cs index 7ee8610b60..2aa678654b 100644 --- a/Rdmp.Core.Tests/Caching/Unit/ZipTests.cs +++ b/Rdmp.Core.Tests/Caching/Unit/ZipTests.cs @@ -28,7 +28,7 @@ public ZipTestLayout(DirectoryInfo dir, string dateFormat, CacheArchiveType cach public new void ArchiveFiles(FileInfo[] fi, DateTime dt, IDataLoadEventListener l) { - base.ArchiveFiles(fi,dt,l); + base.ArchiveFiles(fi, dt, l); } } @@ -36,35 +36,48 @@ public ZipTestLayout(DirectoryInfo dir, string dateFormat, CacheArchiveType cach public void CreateAndUpdateZip() { var _dir = TestContext.CurrentContext.WorkDirectory; - var _zt = new ZipTestLayout(new DirectoryInfo(_dir), "yyyy-MM-dd", CacheArchiveType.Zip, CacheFileGranularity.Hour, new NoSubdirectoriesCachePathResolver()); + var _zt = new ZipTestLayout(new DirectoryInfo(_dir), "yyyy-MM-dd", CacheArchiveType.Zip, + CacheFileGranularity.Hour, new NoSubdirectoriesCachePathResolver()); var _listener = new ThrowImmediatelyDataLoadEventListener(); var when = DateTime.Now; var targetzip = _zt.GetArchiveFileInfoForDate(when, _listener); - var files =new List(); + var files = new List(); // First create a zip file with one item in File.Delete(targetzip.FullName); files.Add(new FileInfo(Path.Combine(_dir, Path.GetRandomFileName()))); - using (var sw =new StreamWriter(files[0].FullName)) + using (var sw = new StreamWriter(files[0].FullName)) + { sw.WriteLine("Example data file"); + } + _zt.ArchiveFiles(files.ToArray(), when, _listener); using (var zip = ZipFile.Open(targetzip.FullName, ZipArchiveMode.Read)) + { Assert.True(zip.Entries.Count == 1); + } // Create a second file and add that to the zip too - files.Add(new FileInfo(Path.Combine(_dir,Path.GetRandomFileName()))); + files.Add(new FileInfo(Path.Combine(_dir, Path.GetRandomFileName()))); using (var sw = new StreamWriter(files[1].FullName)) + { sw.WriteLine("Another example data file"); + } + _zt.ArchiveFiles(files.ToArray(), when, _listener); - using (var zip = ZipFile.Open(targetzip.FullName,ZipArchiveMode.Read)) - Assert.True(zip.Entries.Count==2); + using (var zip = ZipFile.Open(targetzip.FullName, ZipArchiveMode.Read)) + { + Assert.True(zip.Entries.Count == 2); + } // Re-add just the first file: resulting zip should still contain both files - _zt.ArchiveFiles(files.GetRange(0,1).ToArray(), when, _listener); + _zt.ArchiveFiles(files.GetRange(0, 1).ToArray(), when, _listener); using (var zip = ZipFile.Open(targetzip.FullName, ZipArchiveMode.Read)) + { Assert.True(zip.Entries.Count == 2); + } - files.ForEach( s => File.Delete(s.FullName)); + files.ForEach(s => File.Delete(s.FullName)); File.Delete(targetzip.FullName); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCommitting/CommitCohortExample.cs b/Rdmp.Core.Tests/CohortCommitting/CommitCohortExample.cs index 2ac81b4f22..b007217b51 100644 --- a/Rdmp.Core.Tests/CohortCommitting/CommitCohortExample.cs +++ b/Rdmp.Core.Tests/CohortCommitting/CommitCohortExample.cs @@ -20,12 +20,12 @@ namespace Rdmp.Core.Tests.CohortCommitting; -internal class CommitCohortExample: DatabaseTests +internal class CommitCohortExample : DatabaseTests { - [TestCase(DatabaseType.MicrosoftSQLServer,"varchar(10)")] - [TestCase(DatabaseType.MySql,"varchar(10)")] - [TestCase(DatabaseType.Oracle,"varchar2(10)")] - public void CommitCohortExampleTest(DatabaseType dbType,string privateDataType) + [TestCase(DatabaseType.MicrosoftSQLServer, "varchar(10)")] + [TestCase(DatabaseType.MySql, "varchar(10)")] + [TestCase(DatabaseType.Oracle, "varchar2(10)")] + public void CommitCohortExampleTest(DatabaseType dbType, string privateDataType) { RunBlitzDatabases(RepositoryLocator); @@ -33,11 +33,11 @@ public void CommitCohortExampleTest(DatabaseType dbType,string privateDataType) var db = GetCleanedServer(dbType); //create the cohort store table - var wizard = new CreateNewCohortDatabaseWizard(db,CatalogueRepository,DataExportRepository,false); + var wizard = new CreateNewCohortDatabaseWizard(db, CatalogueRepository, DataExportRepository, false); var privateColumn = new PrivateIdentifierPrototype("chi", privateDataType); - var externalCohortTable = wizard.CreateDatabase(privateColumn,new ThrowImmediatelyCheckNotifier()); + var externalCohortTable = wizard.CreateDatabase(privateColumn, new ThrowImmediatelyCheckNotifier()); - Assert.AreEqual(dbType,externalCohortTable.DatabaseType); + Assert.AreEqual(dbType, externalCohortTable.DatabaseType); //create a project into which we want to import a cohort var project = new Project(DataExportRepository, "MyProject") @@ -64,11 +64,13 @@ public void CommitCohortExampleTest(DatabaseType dbType,string privateDataType) //initialize the destination pipelineDestination.PreInitialize( - new CohortCreationRequest(project, definition, DataExportRepository,"A cohort created in an example unit test"), + new CohortCreationRequest(project, definition, DataExportRepository, + "A cohort created in an example unit test"), new ThrowImmediatelyDataLoadEventListener()); //process the cohort data table - pipelineDestination.ProcessPipelineData(dt,new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + pipelineDestination.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); //there should be no cohorts yet Assert.IsEmpty(DataExportRepository.GetAllObjects()); @@ -81,17 +83,17 @@ public void CommitCohortExampleTest(DatabaseType dbType,string privateDataType) //make sure we are all on the same page about what the DBMS type is (nothing cached etc) Assert.AreEqual(dbType, cohort.ExternalCohortTable.DatabaseType); - Assert.AreEqual(dbType,cohort.GetQuerySyntaxHelper().DatabaseType); + Assert.AreEqual(dbType, cohort.GetQuerySyntaxHelper().DatabaseType); - Assert.AreEqual(500,cohort.ExternalProjectNumber); - Assert.AreEqual(2,cohort.CountDistinct); + Assert.AreEqual(500, cohort.ExternalProjectNumber); + Assert.AreEqual(2, cohort.CountDistinct); var tbl = externalCohortTable.DiscoverCohortTable(); - Assert.AreEqual(2,tbl.GetRowCount()); + Assert.AreEqual(2, tbl.GetRowCount()); var dtInDatabase = tbl.GetDataTable(); - + //guid will be something like "6fb23de5-e8eb-46eb-84b5-dd368da21073" - Assert.AreEqual(36,dtInDatabase.Rows[0]["ReleaseId"].ToString().Length); - Assert.AreEqual("0101010101",dtInDatabase.Rows[0]["chi"]); + Assert.AreEqual(36, dtInDatabase.Rows[0]["ReleaseId"].ToString().Length); + Assert.AreEqual("0101010101", dtInDatabase.Rows[0]["chi"]); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCommitting/CreateNewCohortDatabaseWizardTests.cs b/Rdmp.Core.Tests/CohortCommitting/CreateNewCohortDatabaseWizardTests.cs index 2a9f3636d8..71b13741b5 100644 --- a/Rdmp.Core.Tests/CohortCommitting/CreateNewCohortDatabaseWizardTests.cs +++ b/Rdmp.Core.Tests/CohortCommitting/CreateNewCohortDatabaseWizardTests.cs @@ -24,7 +24,7 @@ namespace Rdmp.Core.Tests.CohortCommitting; -public class CreateNewCohortDatabaseWizardTests:DatabaseTests +public class CreateNewCohortDatabaseWizardTests : DatabaseTests { private Catalogue _cata1; private Catalogue _cata2; @@ -37,7 +37,7 @@ public class CreateNewCohortDatabaseWizardTests:DatabaseTests private ExtractionInformation _extractionInfo1; private ExtractionInformation _extractionInfo2; - + [SetUp] protected override void SetUp() { @@ -47,16 +47,16 @@ protected override void SetUp() _cata1 = new Catalogue(CatalogueRepository, "Dataset1"); _cata2 = new Catalogue(CatalogueRepository, "Dataset2"); - + _t1 = new TableInfo(CatalogueRepository, "T1"); _t2 = new TableInfo(CatalogueRepository, "T2"); - + _c1 = new ColumnInfo(CatalogueRepository, "PrivateIdentifierA", "varchar(10)", _t1); _c2 = new ColumnInfo(CatalogueRepository, "PrivateIdentifierB", "int", _t2); - + _ci1 = new CatalogueItem(CatalogueRepository, _cata1, "PrivateIdentifierA"); _ci2 = new CatalogueItem(CatalogueRepository, _cata2, "PrivateIdentifierB"); - + _extractionInfo1 = new ExtractionInformation(CatalogueRepository, _ci1, _c1, _c1.ToString()); _extractionInfo2 = new ExtractionInformation(CatalogueRepository, _ci2, _c2, _c2.ToString()); @@ -65,34 +65,35 @@ protected override void SetUp() private string cohortDatabaseName; - + [Test] public void TestMissingColumnInfos() { _extractionInfo1.IsExtractionIdentifier = true; _extractionInfo1.SaveToDatabase(); - var wizard = new CreateNewCohortDatabaseWizard(null,CatalogueRepository, DataExportRepository,false); + var wizard = new CreateNewCohortDatabaseWizard(null, CatalogueRepository, DataExportRepository, false); //it finds it! - Assert.IsTrue(wizard.GetPrivateIdentifierCandidates().Any(prototype => prototype.RuntimeName.Equals("PrivateIdentifierA"))); + Assert.IsTrue(wizard.GetPrivateIdentifierCandidates() + .Any(prototype => prototype.RuntimeName.Equals("PrivateIdentifierA"))); //delete the column info to make it a missing reference _c1.DeleteInDatabase(); - + //now it should gracefully skip over it Assert.IsFalse(wizard.GetPrivateIdentifierCandidates() .Any(prototype => prototype.RuntimeName.Equals("PrivateIdentifierA"))); - } [Test] public void ProposePrivateIdentifierDatatypes() { - var wizard = new CreateNewCohortDatabaseWizard(null,CatalogueRepository, DataExportRepository,false); + var wizard = new CreateNewCohortDatabaseWizard(null, CatalogueRepository, DataExportRepository, false); var candidates = wizard.GetPrivateIdentifierCandidates(); - Assert.IsFalse(candidates.Any(c => c.RuntimeName.Equals("PrivateIdentifierA") || c.RuntimeName.Equals("PrivateIdentifierB"))); + Assert.IsFalse(candidates.Any(c => + c.RuntimeName.Equals("PrivateIdentifierA") || c.RuntimeName.Equals("PrivateIdentifierB"))); _extractionInfo1.IsExtractionIdentifier = true; _extractionInfo1.SaveToDatabase(); @@ -100,7 +101,7 @@ public void ProposePrivateIdentifierDatatypes() var candidate = candidates.Single(c => c.RuntimeName.Equals("PrivateIdentifierA")); Assert.AreEqual("varchar(10)", candidate.DataType); - Assert.IsTrue(candidate.MatchingExtractionInformations.Single().ID== _extractionInfo1.ID); + Assert.IsTrue(candidate.MatchingExtractionInformations.Single().ID == _extractionInfo1.ID); } [TestCase("text")] @@ -120,18 +121,20 @@ public void TestVarcharMaxNotAllowed(string term) _extractionInfo2.SaveToDatabase(); var candidate = wizard.GetPrivateIdentifierCandidates().Single(c => c.RuntimeName.Equals("PrivateIdentifierB")); - var ex = Assert.Throws(()=>wizard.CreateDatabase( + var ex = Assert.Throws(() => wizard.CreateDatabase( candidate, new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Private identifier datatype cannot be varchar(max) style as this prevents Primary Key creation on the table", ex.Message); + Assert.AreEqual( + "Private identifier datatype cannot be varchar(max) style as this prevents Primary Key creation on the table", + ex.Message); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void TestActuallyCreatingIt(DatabaseType type) { var db = GetCleanedServer(type); - var wizard = new CreateNewCohortDatabaseWizard(db,CatalogueRepository, DataExportRepository,false); + var wizard = new CreateNewCohortDatabaseWizard(db, CatalogueRepository, DataExportRepository, false); _extractionInfo2.IsExtractionIdentifier = true; _extractionInfo2.SaveToDatabase(); @@ -141,14 +144,14 @@ public void TestActuallyCreatingIt(DatabaseType type) candidate, new ThrowImmediatelyCheckNotifier()); - Assert.AreEqual(type,ect.DatabaseType); + Assert.AreEqual(type, ect.DatabaseType); //database should exist DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(cohortDatabaseName); Assert.IsTrue(db.Exists()); - + //did it create the correct type? - Assert.AreEqual(type,ect.DatabaseType); + Assert.AreEqual(type, ect.DatabaseType); //the ExternalCohortTable should pass tests ect.Check(new ThrowImmediatelyCheckNotifier()); @@ -162,7 +165,8 @@ public void TestActuallyCreatingIt(DatabaseType type) project.SaveToDatabase(); //the request to put it under there - var request = new CohortCreationRequest(project, new CohortDefinition(null, "My cohort", 1, 10, ect), DataExportRepository,"Blah"); + var request = new CohortCreationRequest(project, new CohortDefinition(null, "My cohort", 1, 10, ect), + DataExportRepository, "Blah"); //the actual cohort data var dt = new DataTable(); @@ -173,10 +177,10 @@ public void TestActuallyCreatingIt(DatabaseType type) var dest = new BasicCohortDestination(); dest.PreInitialize(request, new ThrowImmediatelyDataLoadEventListener()); - + //tell it to use the guid allocator - dest.ReleaseIdentifierAllocator = typeof (GuidReleaseIdentifierAllocator); - + dest.ReleaseIdentifierAllocator = typeof(GuidReleaseIdentifierAllocator); + dest.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); dest.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); @@ -184,25 +188,25 @@ public void TestActuallyCreatingIt(DatabaseType type) Assert.IsNotNull(cohort); var externalData = cohort.GetExternalData(); - Assert.AreEqual(10,externalData.ExternalProjectNumber); + Assert.AreEqual(10, externalData.ExternalProjectNumber); Assert.IsFalse(string.IsNullOrEmpty(externalData.ExternalDescription)); Assert.AreEqual(DateTime.Now.Year, externalData.ExternalCohortCreationDate.Value.Year); Assert.AreEqual(DateTime.Now.Month, externalData.ExternalCohortCreationDate.Value.Month); - Assert.AreEqual(DateTime.Now.Day, externalData.ExternalCohortCreationDate.Value.Day); + Assert.AreEqual(DateTime.Now.Day, externalData.ExternalCohortCreationDate.Value.Day); Assert.AreEqual(DateTime.Now.Hour, externalData.ExternalCohortCreationDate.Value.Hour); cohort.AppendToAuditLog("Test"); - + Assert.IsTrue(cohort.AuditLog.Contains("Test")); - Assert.AreEqual(1,cohort.Count); - Assert.AreEqual(1,cohort.CountDistinct); + Assert.AreEqual(1, cohort.Count); + Assert.AreEqual(1, cohort.CountDistinct); var cohortTable = cohort.FetchEntireCohort(); - Assert.AreEqual(1,cohortTable.Rows.Count); + Assert.AreEqual(1, cohortTable.Rows.Count); var helper = ect.GetQuerySyntaxHelper(); @@ -226,7 +230,7 @@ public void TestActuallyCreatingIt(DatabaseType type) Assert.AreEqual("101243", dtAno.Rows[1][cohort.GetPrivateIdentifier(true)]); //make sure that it shows up in the child provider (provides fast object access in CLI and builds tree model for UI) - var repo = new DataExportChildProvider(RepositoryLocator, null,new ThrowImmediatelyCheckNotifier(),null); + var repo = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null); var descendancy = repo.GetDescendancyListIfAnyFor(cohort); Assert.IsNotNull(descendancy); } @@ -236,7 +240,7 @@ public void Test_IdentifiableExtractions() { var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); - var wizard = new CreateNewCohortDatabaseWizard(db,CatalogueRepository, DataExportRepository,false); + var wizard = new CreateNewCohortDatabaseWizard(db, CatalogueRepository, DataExportRepository, false); _extractionInfo2.IsExtractionIdentifier = true; _extractionInfo2.SaveToDatabase(); @@ -251,16 +255,17 @@ public void Test_IdentifiableExtractions() ect.ReleaseIdentifierField = ect.PrivateIdentifierField; ect.SaveToDatabase(); - UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable,CheckResult.Fail); + UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable, CheckResult.Fail); - var ex = Assert.Throws(()=>ect.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("R004 PrivateIdentifierField and ReleaseIdentifierField are the same, this means your cohort will extract identifiable data (no cohort identifier substitution takes place)", ex.Message); + var ex = Assert.Throws(() => ect.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual( + "R004 PrivateIdentifierField and ReleaseIdentifierField are the same, this means your cohort will extract identifiable data (no cohort identifier substitution takes place)", + ex.Message); UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable, CheckResult.Warning); ect.Check(new ThrowImmediatelyCheckNotifier()); UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable, CheckResult.Fail); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/AggregateFilterPublishingTests.cs b/Rdmp.Core.Tests/CohortCreation/AggregateFilterPublishingTests.cs index ec9b3fd815..16c6911894 100644 --- a/Rdmp.Core.Tests/CohortCreation/AggregateFilterPublishingTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/AggregateFilterPublishingTests.cs @@ -17,50 +17,58 @@ namespace Rdmp.Core.Tests.CohortCreation; -public class AggregateFilterPublishingTests:CohortIdentificationTests +public class AggregateFilterPublishingTests : CohortIdentificationTests { - private AggregateFilter _filter; private AggregateFilterContainer _container; private ExtractionInformation _chiExtractionInformation; - + [OneTimeSetUp] protected override void SetUp() { base.SetUp(); - aggregate1.RootFilterContainer_ID = new AggregateFilterContainer(CatalogueRepository,FilterContainerOperation.AND).ID; + aggregate1.RootFilterContainer_ID = + new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND).ID; aggregate1.SaveToDatabase(); _chiExtractionInformation = aggregate1.AggregateDimensions.Single().ExtractionInformation; _container = (AggregateFilterContainer)aggregate1.RootFilterContainer; - _filter = new AggregateFilter(CatalogueRepository,"folk", _container); + _filter = new AggregateFilter(CatalogueRepository, "folk", _container); } [Test] public void NotPopulated_Description() { - var ex = Assert.Throws(()=>new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container,_filter, null)); - Assert.AreEqual("Cannot clone filter called 'folk' because:There is no description",ex?.Message); + var ex = Assert.Throws(() => + new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container, + _filter, null)); + Assert.AreEqual("Cannot clone filter called 'folk' because:There is no description", ex?.Message); } [Test] public void NotPopulated_DescriptionTooShort() { _filter.Description = "fish"; - var ex = Assert.Throws(()=>new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container, _filter, null)); - Assert.AreEqual("Cannot clone filter called 'folk' because:Description is not long enough (minimum length is 20 characters)",ex?.Message); + var ex = Assert.Throws(() => + new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container, + _filter, null)); + Assert.AreEqual( + "Cannot clone filter called 'folk' because:Description is not long enough (minimum length is 20 characters)", + ex?.Message); } [Test] public void NotPopulated_WhereSQLNotSet() { _filter.Description = "fish swim in the sea and make people happy to be"; - var ex = Assert.Throws(()=>new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container, _filter, null)); - Assert.AreEqual("Cannot clone filter called 'folk' because:WhereSQL is not populated",ex?.Message); + var ex = Assert.Throws(() => + new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container, + _filter, null)); + Assert.AreEqual("Cannot clone filter called 'folk' because:WhereSQL is not populated", ex?.Message); } /// @@ -74,7 +82,9 @@ public void NotPopulated_ParameterNoComment() _filter.SaveToDatabase(); new ParameterCreator(new AggregateFilterFactory(CatalogueRepository), null, null).CreateAll(_filter, null); - var importedFilter = new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(null, _filter, null); + var importedFilter = + new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(null, _filter, + null); Assert.AreEqual("folk", importedFilter.Name); } @@ -84,16 +94,19 @@ public void NotPopulated_ParameterNotSet() { _filter.Description = "fish swim in the sea and make people happy to be"; _filter.WhereSQL = "LovelyCoconuts = @coconutCount"; - + new ParameterCreator(new AggregateFilterFactory(CatalogueRepository), null, null).CreateAll(_filter, null); var parameter = _filter.GetAllParameters().Single(); parameter.Comment = "It's coconut time!"; - parameter.Value = null;//clear its value + parameter.Value = null; //clear its value parameter.SaveToDatabase(); - var ex = Assert.Throws(()=>new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation),null).ImportFilter(_container, _filter,null)); - Assert.AreEqual("Cannot clone filter called 'folk' because:Parameter '@coconutCount' was rejected :There is no value/default value listed",ex?.Message); - + var ex = Assert.Throws(() => + new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(_container, + _filter, null)); + Assert.AreEqual( + "Cannot clone filter called 'folk' because:Parameter '@coconutCount' was rejected :There is no value/default value listed", + ex?.Message); } [Test] @@ -102,16 +115,17 @@ public void ShortcutFiltersWork_ProperlyReplicatesParentAndHasFK() _filter.WhereSQL = "folk=1"; _filter.SaveToDatabase(); - var sql = new CohortQueryBuilder(aggregate1, null,null).SQL; + var sql = new CohortQueryBuilder(aggregate1, null, null).SQL; Console.WriteLine(sql); Assert.IsTrue(sql.Contains("folk=1")); var shortcutAggregate = - new AggregateConfiguration(CatalogueRepository,testData.catalogue, "UnitTestShortcutAggregate"); + new AggregateConfiguration(CatalogueRepository, testData.catalogue, "UnitTestShortcutAggregate"); - _=new AggregateDimension(CatalogueRepository,testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("sex")), shortcutAggregate); + _ = new AggregateDimension(CatalogueRepository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("sex")), shortcutAggregate); //before it is a shortcut it has no filters Assert.IsFalse(shortcutAggregate.GetQueryBuilder().SQL.Contains("WHERE")); @@ -121,11 +135,11 @@ public void ShortcutFiltersWork_ProperlyReplicatesParentAndHasFK() shortcutAggregate.SaveToDatabase(); var sqlShortcut = shortcutAggregate.GetQueryBuilder().SQL; - + //shortcut should have its own dimensions Assert.IsTrue(sqlShortcut.Contains("[sex]")); Assert.IsFalse(sqlShortcut.Contains("[chi]")); - + //but should have a REFERENCE (not a clone!) to aggregate 1's filters Assert.IsTrue(sqlShortcut.Contains("folk=1")); @@ -135,10 +149,7 @@ public void ShortcutFiltersWork_ProperlyReplicatesParentAndHasFK() Assert.IsTrue(shortcutAggregate.GetQueryBuilder().SQL.Contains("folk=2")); //shouldn't work because of the dependency of the child - should give a foreign key error - if(CatalogueRepository is TableRepository) - { - Assert.Throws(aggregate1.DeleteInDatabase); - } + if (CatalogueRepository is TableRepository) Assert.Throws(aggregate1.DeleteInDatabase); //delete the child shortcutAggregate.DeleteInDatabase(); @@ -151,9 +162,13 @@ public void ShortcutFiltersWork_ProperlyReplicatesParentAndHasFK() public void ShortcutFilters_AlreadyHasFilter() { Assert.IsNotNull(aggregate1.RootFilterContainer_ID); - var ex = Assert.Throws(()=>aggregate1.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID = -500);//not ok - Assert.AreEqual("Cannot set OverrideFiltersByUsingParentAggregateConfigurationInstead_ID because this AggregateConfiguration already has a filter container set (if you were to be a shortcut and also have a filter tree set it would be very confusing)",ex?.Message); + var ex = Assert.Throws(() => + aggregate1.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID = -500); //not ok + Assert.AreEqual( + "Cannot set OverrideFiltersByUsingParentAggregateConfigurationInstead_ID because this AggregateConfiguration already has a filter container set (if you were to be a shortcut and also have a filter tree set it would be very confusing)", + ex?.Message); } + [Test] public void ShortcutFilters_AlreadyHasFilter_ButSettingItToNull() { @@ -167,10 +182,18 @@ public void ShortcutFilters_AlreadyHasFilter_ButSettingItToNull() public void ShortcutFilters_DoesNotHaveFilter_SetOne() { aggregate1.RootFilterContainer_ID = null; - Assert.DoesNotThrow(() => { aggregate1.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID = null; }); // is ok - Assert.DoesNotThrow(() => { aggregate1.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID = -19; }); // is ok - var ex = Assert.Throws(()=>aggregate1.RootFilterContainer_ID = 123); - Assert.AreEqual("This AggregateConfiguration has a shortcut to another AggregateConfiguration's Filters (its OverrideFiltersByUsingParentAggregateConfigurationInstead_ID is -19) which means it cannot be assigned its own RootFilterContainerID",ex?.Message); + Assert.DoesNotThrow(() => + { + aggregate1.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID = null; + }); // is ok + Assert.DoesNotThrow(() => + { + aggregate1.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID = -19; + }); // is ok + var ex = Assert.Throws(() => aggregate1.RootFilterContainer_ID = 123); + Assert.AreEqual( + "This AggregateConfiguration has a shortcut to another AggregateConfiguration's Filters (its OverrideFiltersByUsingParentAggregateConfigurationInstead_ID is -19) which means it cannot be assigned its own RootFilterContainerID", + ex?.Message); } [Test] @@ -190,16 +213,19 @@ public void CloneWorks_AllPropertiesMatchIncludingParameters() parameter.Value = "3"; parameter.SaveToDatabase(); - var newMaster = new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(null, _filter, null); + var newMaster = + new FilterImporter(new ExtractionFilterFactory(_chiExtractionInformation), null).ImportFilter(null, _filter, + null); //we should now be a clone of the master we just created - Assert.AreEqual(_filter.ClonedFromExtractionFilter_ID,newMaster.ID); + Assert.AreEqual(_filter.ClonedFromExtractionFilter_ID, newMaster.ID); Assert.IsTrue(newMaster.Description.StartsWith(_filter.Description)); //it adds some addendum stuff onto it - Assert.AreEqual(_filter.WhereSQL,newMaster.WhereSQL); + Assert.AreEqual(_filter.WhereSQL, newMaster.WhereSQL); - Assert.AreEqual(_filter.GetAllParameters().Single().ParameterName, newMaster.GetAllParameters().Single().ParameterName); - Assert.AreEqual(_filter.GetAllParameters().Single().ParameterSQL, newMaster.GetAllParameters().Single().ParameterSQL); + Assert.AreEqual(_filter.GetAllParameters().Single().ParameterName, + newMaster.GetAllParameters().Single().ParameterName); + Assert.AreEqual(_filter.GetAllParameters().Single().ParameterSQL, + newMaster.GetAllParameters().Single().ParameterSQL); Assert.AreEqual(_filter.GetAllParameters().Single().Value, newMaster.GetAllParameters().Single().Value); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/CohortCompilerRunnerTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortCompilerRunnerTests.cs index 792704eec6..3ca6faf83a 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortCompilerRunnerTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortCompilerRunnerTests.cs @@ -21,13 +21,12 @@ namespace Rdmp.Core.Tests.CohortCreation; -public class CohortCompilerRunnerTests:DatabaseTests +public class CohortCompilerRunnerTests : DatabaseTests { [Test] public void CacheIdentifierListWithRunner_SimpleCase() { - - SetupCohort(out DiscoveredDatabase db, out var cic, out var dt); + SetupCohort(out var db, out var cic, out var dt); var compiler = new CohortCompiler(cic); @@ -37,12 +36,12 @@ public void CacheIdentifierListWithRunner_SimpleCase() Assert.AreEqual(CohortCompilerRunner.Phase.Finished, runner.ExecutionPhase); var rootTask = runner.Compiler.Tasks.Single(t => t.Key is AggregationContainerTask); - + Assert.IsTrue(rootTask.Value.IsResultsForRootContainer); Assert.IsNull(rootTask.Key.CrashMessage); Assert.AreEqual(CompilationState.Finished, rootTask.Key.State); - Assert.AreEqual(dt.Rows.Count,rootTask.Value.Identifiers.Rows.Count); + Assert.AreEqual(dt.Rows.Count, rootTask.Value.Identifiers.Rows.Count); } [Test] @@ -52,7 +51,7 @@ public void CacheIdentifierListWithRunner_WithCaching() var e = new MasterDatabaseScriptExecutor(db); var p = new QueryCachingPatcher(); - e.CreateAndPatchDatabase(p,new AcceptAllCheckNotifier()); + e.CreateAndPatchDatabase(p, new AcceptAllCheckNotifier()); var serverReference = new ExternalDatabaseServer(CatalogueRepository, "Cache", p); serverReference.SetProperties(db); @@ -77,6 +76,7 @@ public void CacheIdentifierListWithRunner_WithCaching() Assert.AreEqual(dt.Rows.Count, rootTask.Value.Identifiers.Rows.Count); } + private void SetupCohort(out DiscoveredDatabase db, out CohortIdentificationConfiguration cic, out DataTable dt) { dt = new DataTable(); diff --git a/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs index aaf8231141..d0ceb810ed 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs @@ -17,13 +17,13 @@ namespace Rdmp.Core.Tests.CohortCreation; -public class CohortCompilerTests:CohortIdentificationTests +public class CohortCompilerTests : CohortIdentificationTests { [Test] public void AddSameTaskTwice_StaysAtOne() { var compiler = new CohortCompiler(cohortIdentificationConfiguration); - container1.AddChild(aggregate1,0); + container1.AddChild(aggregate1, 0); try { compiler.AddTask(aggregate1, null); @@ -56,7 +56,6 @@ public void AddSameTaskTwice_StaysAtOne() Assert.AreNotSame(oldTask, compiler.Tasks.Single()); //new task should not be the same as the old one Assert.IsFalse(compiler.Tasks.Single().Key.CancellationToken.IsCancellationRequested); //new task should not be cancelled} finally { - } finally { @@ -70,7 +69,7 @@ public void AddContainer_StaysAtOne() var compiler = new CohortCompiler(cohortIdentificationConfiguration); rootcontainer.AddChild(aggregate1, 1); - compiler.AddTask(rootcontainer, null);//add the root container + compiler.AddTask(rootcontainer, null); //add the root container Assert.AreEqual(1, compiler.Tasks.Count); var oldTask = compiler.Tasks.First(); @@ -83,13 +82,14 @@ public void AddContainer_StaysAtOne() rootcontainer.AddChild(aggregate2, 1); compiler.AddTask(rootcontainer, null); - Assert.AreEqual(1, compiler.Tasks.Count);//should still be 1 task + Assert.AreEqual(1, compiler.Tasks.Count); //should still be 1 task // TN: Task was never asked to start so was still at NotScheduled so cancellation wouldn't actually happen //old task should have been asked to cancel //Assert.IsTrue(oldTask.Key.CancellationToken.IsCancellationRequested); - Assert.AreNotSame(oldTask, compiler.Tasks.Single());//new task should not be the same as the old one - Assert.IsFalse(compiler.Tasks.Single().Key.CancellationToken.IsCancellationRequested);//new task should not be cancelled + Assert.AreNotSame(oldTask, compiler.Tasks.Single()); //new task should not be the same as the old one + Assert.IsFalse(compiler.Tasks.Single().Key.CancellationToken + .IsCancellationRequested); //new task should not be cancelled rootcontainer.RemoveChild(aggregate1); rootcontainer.RemoveChild(aggregate2); @@ -102,13 +102,13 @@ public enum TestCompilerAddAllTasksTestCase Subcontainer } - [TestCase(TestCompilerAddAllTasksTestCase.CIC,true)] + [TestCase(TestCompilerAddAllTasksTestCase.CIC, true)] [TestCase(TestCompilerAddAllTasksTestCase.CIC, false)] [TestCase(TestCompilerAddAllTasksTestCase.RootContainer, true)] [TestCase(TestCompilerAddAllTasksTestCase.RootContainer, false)] [TestCase(TestCompilerAddAllTasksTestCase.Subcontainer, true)] [TestCase(TestCompilerAddAllTasksTestCase.Subcontainer, false)] - public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase,bool includeSubcontainers) + public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase, bool includeSubcontainers) { var aggregate4 = new AggregateConfiguration(CatalogueRepository, testData.catalogue, "UnitTestAggregate4") @@ -116,7 +116,8 @@ public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase,boo CountSQL = null }; aggregate4.SaveToDatabase(); - new AggregateDimension(CatalogueRepository, testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate4); + new AggregateDimension(CatalogueRepository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate4); var aggregate5 = new AggregateConfiguration(CatalogueRepository, testData.catalogue, "UnitTestAggregate5") @@ -124,11 +125,14 @@ public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase,boo CountSQL = null }; aggregate5.SaveToDatabase(); - new AggregateDimension(CatalogueRepository, testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate5); + new AggregateDimension(CatalogueRepository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate5); + + var joinable = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate5); - var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository,cohortIdentificationConfiguration, aggregate5); - try { //EXCEPT @@ -148,29 +152,34 @@ public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase,boo rootcontainer.AddChild(aggregate2, 3); - container1.AddChild(aggregate3,1); + container1.AddChild(aggregate3, 1); container1.AddChild(aggregate4, 2); cohortIdentificationConfiguration.RootCohortAggregateContainer_ID = rootcontainer.ID; cohortIdentificationConfiguration.SaveToDatabase(); - + //The bit we are testing List tasks; switch (testCase) { case TestCompilerAddAllTasksTestCase.CIC: tasks = compiler.AddAllTasks(includeSubcontainers); - Assert.AreEqual(joinable,tasks.OfType().Single().Joinable); //should be a single joinable - Assert.AreEqual(includeSubcontainers?7:6,tasks.Count); //all joinables, aggregates and root container + Assert.AreEqual(joinable, + tasks.OfType().Single().Joinable); //should be a single joinable + Assert.AreEqual(includeSubcontainers ? 7 : 6, + tasks.Count); //all joinables, aggregates and root container break; case TestCompilerAddAllTasksTestCase.RootContainer: - tasks = compiler.AddTasksRecursively(Array.Empty(), cohortIdentificationConfiguration.RootCohortAggregateContainer, includeSubcontainers); - Assert.AreEqual(includeSubcontainers?6:5,tasks.Count); //all aggregates and root container (but not joinables) + tasks = compiler.AddTasksRecursively(Array.Empty(), + cohortIdentificationConfiguration.RootCohortAggregateContainer, includeSubcontainers); + Assert.AreEqual(includeSubcontainers ? 6 : 5, + tasks.Count); //all aggregates and root container (but not joinables) break; case TestCompilerAddAllTasksTestCase.Subcontainer: - tasks = compiler.AddTasksRecursively(Array.Empty(), container1, includeSubcontainers); - Assert.AreEqual(includeSubcontainers?3:2,tasks.Count); //subcontainer and its aggregates + tasks = compiler.AddTasksRecursively(Array.Empty(), container1, + includeSubcontainers); + Assert.AreEqual(includeSubcontainers ? 3 : 2, tasks.Count); //subcontainer and its aggregates break; default: throw new ArgumentOutOfRangeException(nameof(testCase)); @@ -183,7 +192,6 @@ public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase,boo container1.RemoveChild(aggregate3); container1.RemoveChild(aggregate4); container1.MakeIntoAnOrphan(); - } finally { diff --git a/Rdmp.Core.Tests/CohortCreation/CohortContainerAndCloningTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortContainerAndCloningTests.cs index c00dfe85b8..a783fc26ec 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortContainerAndCloningTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortContainerAndCloningTests.cs @@ -53,13 +53,12 @@ public void AggregateOrdering_ExplicitSetting_CorrectOrder() [Test] public void CloneChild_NamingCorrectNewObject() { - //should not follow naming convention aggregate1.Name = "fish"; Assert.IsFalse(cohortIdentificationConfiguration.IsValidNamedConfiguration(aggregate1)); //add a clone using aggregate1 as a template - var clone = cohortIdentificationConfiguration.ImportAggregateConfigurationAsIdentifierList(aggregate1,null); + var clone = cohortIdentificationConfiguration.ImportAggregateConfigurationAsIdentifierList(aggregate1, null); //add the clone rootcontainer.AddChild(clone, 0); @@ -74,7 +73,6 @@ public void CloneChild_NamingCorrectNewObject() //clone should have a different ID - also it was created after so should be higher ID Assert.Greater(aggregateConfigurations[0].ID, aggregate1.ID); - } finally { @@ -87,6 +85,7 @@ public void CloneChild_NamingCorrectNewObject() clone.DeleteInDatabase(); } } + [Test] public void CloneChildWithFilter_IDsDifferent() { @@ -114,7 +113,7 @@ public void CloneChildWithFilter_IDsDifferent() var clone = cohortIdentificationConfiguration.ImportAggregateConfigurationAsIdentifierList(aggregate1, null); //since its a cohort aggregate it should be identical to the origin Aggregate except it has a different ID and no count SQL - Assert.AreEqual(clone.CountSQL,null); + Assert.AreEqual(clone.CountSQL, null); //get the original sql var aggregateSql = aggregate1.GetQueryBuilder().SQL; @@ -135,20 +134,20 @@ public void CloneChildWithFilter_IDsDifferent() Assert.AreNotEqual(cloneParameter.ID, param.ID); //it has a different ID and is part of an aggregate filter container (It is presumed to be involved with cohort identification cohortIdentificationConfiguration) which means it will be called cic_X_ - var cohortAggregateSql = new CohortQueryBuilder(clone,null,null).SQL; + var cohortAggregateSql = new CohortQueryBuilder(clone, null, null).SQL; //the basic aggregate has the filter, parameter and group by Assert.AreEqual(CollapseWhitespace( - string.Format( - @"DECLARE @sex AS varchar(50); + string.Format( + @"DECLARE @sex AS varchar(50); SET @sex='M'; /*cic_{0}_UnitTestAggregate1*/ SELECT -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi], +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi], count(*) FROM -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] WHERE ( /*MyFilter*/ @@ -156,9 +155,10 @@ public void CloneChildWithFilter_IDsDifferent() ) group by -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] order by -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi]",cohortIdentificationConfiguration.ID)), CollapseWhitespace(aggregateSql)); +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi]", cohortIdentificationConfiguration.ID)), + CollapseWhitespace(aggregateSql)); //the expected differences are //1. should not have the count @@ -199,8 +199,8 @@ public void CohortIdentificationConfiguration_CloneEntirely() rootcontainer.AddChild(aggregate1, 5); rootcontainer.AddChild(container1); - container1.AddChild(aggregate2,1); - container1.AddChild(aggregate3,2); + container1.AddChild(aggregate2, 1); + container1.AddChild(aggregate3, 2); //create a filter too @@ -213,7 +213,7 @@ public void CohortIdentificationConfiguration_CloneEntirely() { WhereSQL = "sex=@sex" }; - new ParameterCreator(new AggregateFilterFactory(CatalogueRepository), null, null).CreateAll(filter,null); + new ParameterCreator(new AggregateFilterFactory(CatalogueRepository), null, null).CreateAll(filter, null); filter.SaveToDatabase(); //with a parameter too @@ -232,28 +232,28 @@ public void CohortIdentificationConfiguration_CloneEntirely() Assert.AreNotEqual(cohortIdentificationConfiguration.ID, clone.ID); Assert.IsTrue(clone.Name.EndsWith("(Clone)")); - Assert.AreNotEqual(clone.RootCohortAggregateContainer_ID, cohortIdentificationConfiguration.RootCohortAggregateContainer_ID); + Assert.AreNotEqual(clone.RootCohortAggregateContainer_ID, + cohortIdentificationConfiguration.RootCohortAggregateContainer_ID); Assert.IsNotNull(clone.RootCohortAggregateContainer_ID); - var beforeSQL = new CohortQueryBuilder(cohortIdentificationConfiguration,null).SQL; - var cloneSQL = new CohortQueryBuilder(clone,null).SQL; + var beforeSQL = new CohortQueryBuilder(cohortIdentificationConfiguration, null).SQL; + var cloneSQL = new CohortQueryBuilder(clone, null).SQL; beforeSQL = Regex.Replace(beforeSQL, "cic_[0-9]+_", ""); cloneSQL = Regex.Replace(cloneSQL, "cic_[0-9]+_", ""); //the SQL should be the same for them - Assert.AreEqual(beforeSQL,cloneSQL); + Assert.AreEqual(beforeSQL, cloneSQL); var containerClone = clone.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively() .Where(a => a.RootFilterContainer_ID != null) .Select(ag => ag.RootFilterContainer).Single(); Assert.AreNotEqual(container, containerClone); - + //cleanup phase clone.DeleteInDatabase(); containerClone.DeleteInDatabase(); - } finally { @@ -265,5 +265,4 @@ public void CohortIdentificationConfiguration_CloneEntirely() container.DeleteInDatabase(); } } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/CohortIdentificationConfigurationMergerTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortIdentificationConfigurationMergerTests.cs index 8ac0f4fb36..73991efe6a 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortIdentificationConfigurationMergerTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortIdentificationConfigurationMergerTests.cs @@ -17,40 +17,47 @@ public void TestSimpleMerge() { var merger = new CohortIdentificationConfigurationMerger(CatalogueRepository); - var cic1 = new CohortIdentificationConfiguration(CatalogueRepository,"cic1"); - var cic2 = new CohortIdentificationConfiguration(CatalogueRepository,"cic2"); + var cic1 = new CohortIdentificationConfiguration(CatalogueRepository, "cic1"); + var cic2 = new CohortIdentificationConfiguration(CatalogueRepository, "cic2"); cic1.CreateRootContainerIfNotExists(); var root1 = cic1.RootCohortAggregateContainer; root1.Name = "Root1"; root1.SaveToDatabase(); - root1.AddChild(aggregate1,1); + root1.AddChild(aggregate1, 1); cic2.CreateRootContainerIfNotExists(); var root2 = cic2.RootCohortAggregateContainer; root2.Name = "Root2"; root2.SaveToDatabase(); - root2.AddChild(aggregate2,2); + root2.AddChild(aggregate2, 2); - Assert.AreEqual(1,cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - Assert.AreEqual(1,cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); var numberOfCicsBefore = CatalogueRepository.GetAllObjects().Length; - var result = merger.Merge(new []{cic1,cic2 },SetOperation.UNION); + var result = merger.Merge(new[] { cic1, cic2 }, SetOperation.UNION); //original should still be intact - Assert.AreEqual(1,cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - Assert.AreEqual(1,cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); //the new merged set should contain both - Assert.AreEqual(2,result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(2, result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - Assert.IsFalse(result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Any(c=>c.Equals(aggregate1)),"Expected the merge to include clone aggregates not the originals! (aggregate1)"); - Assert.IsFalse(result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Any(c=>c.Equals(aggregate2)),"Expected the merge to include clone aggregates not the originals! (aggregate2)"); + Assert.IsFalse( + result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively() + .Any(c => c.Equals(aggregate1)), + "Expected the merge to include clone aggregates not the originals! (aggregate1)"); + Assert.IsFalse( + result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively() + .Any(c => c.Equals(aggregate2)), + "Expected the merge to include clone aggregates not the originals! (aggregate2)"); // Now should be a new one - Assert.AreEqual(numberOfCicsBefore + 1, CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(numberOfCicsBefore + 1, + CatalogueRepository.GetAllObjects().Length); var newCicId = result.ID; @@ -61,13 +68,12 @@ public void TestSimpleMerge() // And should have Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate2", newRoot2.GetAggregateConfigurations()[0].Name); - Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate1",newRoot1.GetAggregateConfigurations()[0].Name); + Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate1", newRoot1.GetAggregateConfigurations()[0].Name); - Assert.AreEqual($"Merged cics (IDs {cic1.ID},{cic2.ID})",result.Name); + Assert.AreEqual($"Merged cics (IDs {cic1.ID},{cic2.ID})", result.Name); Assert.IsTrue(cic1.Exists()); Assert.IsTrue(cic2.Exists()); - } [Test] @@ -75,20 +81,20 @@ public void TestSimpleUnMerge() { var merger = new CohortIdentificationConfigurationMerger(CatalogueRepository); - var cicInput = new CohortIdentificationConfiguration(CatalogueRepository,"cic99"); + var cicInput = new CohortIdentificationConfiguration(CatalogueRepository, "cic99"); cicInput.CreateRootContainerIfNotExists(); var root = cicInput.RootCohortAggregateContainer; root.Name = "Root"; root.SaveToDatabase(); - var sub1 = new CohortAggregateContainer(CatalogueRepository,SetOperation.INTERSECT) + var sub1 = new CohortAggregateContainer(CatalogueRepository, SetOperation.INTERSECT) { Order = 1 }; sub1.SaveToDatabase(); - var sub2 = new CohortAggregateContainer(CatalogueRepository,SetOperation.EXCEPT) + var sub2 = new CohortAggregateContainer(CatalogueRepository, SetOperation.EXCEPT) { Order = 2 }; @@ -97,28 +103,32 @@ public void TestSimpleUnMerge() root.AddChild(sub1); root.AddChild(sub2); - sub1.AddChild(aggregate1,0); - sub2.AddChild(aggregate2,0); - sub2.AddChild(aggregate3,1); + sub1.AddChild(aggregate1, 0); + sub2.AddChild(aggregate2, 0); + sub2.AddChild(aggregate3, 1); var numberOfCicsBefore = CatalogueRepository.GetAllObjects().Length; var results = merger.UnMerge(root); // Now should be two new ones - Assert.AreEqual(numberOfCicsBefore + 2, CatalogueRepository.GetAllObjects().Length); - Assert.AreEqual(2,results.Length); + Assert.AreEqual(numberOfCicsBefore + 2, + CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(2, results.Length); - Assert.AreEqual(SetOperation.INTERSECT,results[0].RootCohortAggregateContainer.Operation); - Assert.AreEqual(1,results[0].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - - Assert.IsFalse(results[0].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Intersect(new []{ aggregate1,aggregate2,aggregate3}).Any(),"Expected new aggregates to be new!"); + Assert.AreEqual(SetOperation.INTERSECT, results[0].RootCohortAggregateContainer.Operation); + Assert.AreEqual(1, results[0].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - Assert.AreEqual(SetOperation.EXCEPT,results[1].RootCohortAggregateContainer.Operation); - Assert.AreEqual(2,results[1].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.IsFalse( + results[0].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively() + .Intersect(new[] { aggregate1, aggregate2, aggregate3 }).Any(), "Expected new aggregates to be new!"); - Assert.IsFalse(results[1].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Intersect(new []{ aggregate1,aggregate2,aggregate3}).Any(),"Expected new aggregates to be new!"); + Assert.AreEqual(SetOperation.EXCEPT, results[1].RootCohortAggregateContainer.Operation); + Assert.AreEqual(2, results[1].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.IsFalse( + results[1].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively() + .Intersect(new[] { aggregate1, aggregate2, aggregate3 }).Any(), "Expected new aggregates to be new!"); } [Test] @@ -126,37 +136,37 @@ public void TestSimpleImportCic() { var merger = new CohortIdentificationConfigurationMerger(CatalogueRepository); - var cic1 = new CohortIdentificationConfiguration(CatalogueRepository,"cic1"); - var cic2 = new CohortIdentificationConfiguration(CatalogueRepository,"cic2"); + var cic1 = new CohortIdentificationConfiguration(CatalogueRepository, "cic1"); + var cic2 = new CohortIdentificationConfiguration(CatalogueRepository, "cic2"); cic1.CreateRootContainerIfNotExists(); var root1 = cic1.RootCohortAggregateContainer; root1.Name = "Root1"; root1.SaveToDatabase(); - root1.AddChild(aggregate1,1); + root1.AddChild(aggregate1, 1); cic2.CreateRootContainerIfNotExists(); var root2 = cic2.RootCohortAggregateContainer; root2.Name = "Root2"; root2.SaveToDatabase(); - root2.AddChild(aggregate2,2); + root2.AddChild(aggregate2, 2); - Assert.AreEqual(1,cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - Assert.AreEqual(1,cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); var numberOfCicsBefore = CatalogueRepository.GetAllObjects().Length; //import 2 into 1 - merger.Import(new []{cic2 },cic1.RootCohortAggregateContainer); + merger.Import(new[] { cic2 }, cic1.RootCohortAggregateContainer); //no new cics - Assert.AreEqual(numberOfCicsBefore, CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(numberOfCicsBefore, + CatalogueRepository.GetAllObjects().Length); // cic 1 should now have both aggregates - Assert.AreEqual(2,cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); - - Assert.AreEqual("Root1",cic1.RootCohortAggregateContainer.Name); - Assert.AreEqual("Root2",cic1.RootCohortAggregateContainer.GetSubContainers()[0].Name); + Assert.AreEqual(2, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count); + Assert.AreEqual("Root1", cic1.RootCohortAggregateContainer.Name); + Assert.AreEqual("Root2", cic1.RootCohortAggregateContainer.GetSubContainers()[0].Name); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/CohortIdentificationTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortIdentificationTests.cs index 6dd2d8f721..f5f6702618 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortIdentificationTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortIdentificationTests.cs @@ -34,7 +34,7 @@ protected override void SetUp() SetupTestData(CatalogueRepository); } - + public void SetupTestData(ICatalogueRepository repository) { BlitzMainDataTables(); @@ -53,7 +53,8 @@ public void SetupTestData(ICatalogueRepository repository) }; aggregate1.SaveToDatabase(); - new AggregateDimension(repository, testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate1); + new AggregateDimension(repository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate1); aggregate2 = new AggregateConfiguration(repository, testData.catalogue, "UnitTestAggregate2") @@ -63,7 +64,8 @@ public void SetupTestData(ICatalogueRepository repository) aggregate2.SaveToDatabase(); - new AggregateDimension(repository, testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate2); + new AggregateDimension(repository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate2); aggregate3 = new AggregateConfiguration(repository, testData.catalogue, "UnitTestAggregate3") @@ -72,7 +74,8 @@ public void SetupTestData(ICatalogueRepository repository) }; aggregate3.SaveToDatabase(); - new AggregateDimension(repository, testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate3); + new AggregateDimension(repository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate3); cohortIdentificationConfiguration = new CohortIdentificationConfiguration(repository, "UnitTestIdentification"); diff --git a/Rdmp.Core.Tests/CohortCreation/CohortMandatoryFilterImportingTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortMandatoryFilterImportingTests.cs index 6a85ee6e24..a76de6d34d 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortMandatoryFilterImportingTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortMandatoryFilterImportingTests.cs @@ -20,7 +20,8 @@ public class CohortMandatoryFilterImportingTests : CohortIdentificationTests [Test] public void NoMandatoryFilters() { - var importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); + var importedAggregate = + cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); var importedAggregateFilterContainer = importedAggregate.RootFilterContainer; //Must have a root container @@ -33,10 +34,10 @@ public void NoMandatoryFilters() public void ImportCatalogueWithMandatoryFilter() { var filter = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0]) - { - IsMandatory = true, - WhereSQL = "There Be Dragons" - }; + { + IsMandatory = true, + WhereSQL = "There Be Dragons" + }; filter.SaveToDatabase(); //ensure that it is picked SetUp @@ -45,11 +46,11 @@ public void ImportCatalogueWithMandatoryFilter() Assert.AreEqual(filter, mandatoryFilters[0]); AggregateConfiguration importedAggregate = null; - + try { - - importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue,null); + importedAggregate = + cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); Assert.AreEqual(ChangeDescription.NoChanges, importedAggregate.HasLocalChanges().Evaluation); @@ -59,24 +60,23 @@ public void ImportCatalogueWithMandatoryFilter() Assert.IsNotNull(importedAggregateFilterContainer); //With an AND operation - Assert.AreEqual(FilterContainerOperation.AND,importedAggregateFilterContainer.Operation); + Assert.AreEqual(FilterContainerOperation.AND, importedAggregateFilterContainer.Operation); var importedFilters = importedAggregateFilterContainer.GetFilters(); Assert.AreEqual(1, importedFilters.Length); - + //they are not the same object Assert.AreNotEqual(filter, importedFilters[0]); //the deployed filter knows its parent it was cloned from Assert.AreEqual(filter.ID, importedFilters[0].ClonedFromExtractionFilter_ID); //the WHERE SQL of the filters should be the same Assert.AreEqual(filter.WhereSQL, importedFilters[0].WhereSQL); - } finally { filter.DeleteInDatabase(); - if(importedAggregate != null) + if (importedAggregate != null) { importedAggregate.RootFilterContainer.DeleteInDatabase(); importedAggregate.DeleteInDatabase(); @@ -92,14 +92,15 @@ public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalO var parameterSQL = "DECLARE @dragonCount as varchar(100)"; var filter = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0]) - { - IsMandatory = true, - WhereSQL = "There Be Dragons AND @dragonCount = 1" - }; + { + IsMandatory = true, + WhereSQL = "There Be Dragons AND @dragonCount = 1" + }; filter.SaveToDatabase(); //Should result in the creation of a parameter - new ParameterCreator(new ExtractionFilterFactory(testData.extractionInformations[0]),null,null).CreateAll(filter,null); + new ParameterCreator(new ExtractionFilterFactory(testData.extractionInformations[0]), null, null) + .CreateAll(filter, null); var filterParameters = filter.ExtractionFilterParameters.ToArray(); Assert.AreEqual(1, filterParameters.Length); @@ -111,11 +112,11 @@ public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalO AnyTableSqlParameter global = null; if (createAGlobalOverrideBeforeHand) - { - global = new AnyTableSqlParameter(CatalogueRepository, cohortIdentificationConfiguration,parameterSQL) - { - Value = "'At Least 1000 Dragons'" - }; + { + global = new AnyTableSqlParameter(CatalogueRepository, cohortIdentificationConfiguration, parameterSQL) + { + Value = "'At Least 1000 Dragons'" + }; global.SaveToDatabase(); } @@ -129,7 +130,8 @@ public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalO try { - importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); + importedAggregate = + cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); var importedAggregateFilterContainer = importedAggregate.RootFilterContainer; //Must have a root container @@ -142,8 +144,10 @@ public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalO Assert.AreEqual(1, importedFilters.Length); //Because the configuration already has a parameter with the same declaration it should not bother to import the parameter from the underlying filter - if(createAGlobalOverrideBeforeHand) - Assert.AreEqual(0,importedFilters[0].GetAllParameters().Length); + if (createAGlobalOverrideBeforeHand) + { + Assert.AreEqual(0, importedFilters[0].GetAllParameters().Length); + } else { //Because there is no global we should be creating a clone of the parameter too @@ -151,14 +155,13 @@ public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalO Assert.AreEqual(1, paramClones.Length); //clone should have same SQL and Value - Assert.AreEqual(parameterSQL,paramClones[0].ParameterSQL); + Assert.AreEqual(parameterSQL, paramClones[0].ParameterSQL); Assert.AreEqual(filterParameters[0].ParameterSQL, paramClones[0].ParameterSQL); Assert.AreEqual(filterParameters[0].Value, paramClones[0].Value); //but not be the same object in database Assert.AreNotEqual(filterParameters[0], paramClones[0]); } - } finally { @@ -172,35 +175,33 @@ public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalO importedAggregate.DeleteInDatabase(); } } - } [Test] public void ImportCatalogueWithMultipleMandatoryFilters() { - //First mandatory var filter1 = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0]) - { - IsMandatory = true, - WhereSQL = "There Be Dragons" - }; + { + IsMandatory = true, + WhereSQL = "There Be Dragons" + }; filter1.SaveToDatabase(); //Second mandatory var filter2 = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[1]) - { - IsMandatory = true, - WhereSQL = "And Months" - }; + { + IsMandatory = true, + WhereSQL = "And Months" + }; filter2.SaveToDatabase(); //Then one that is not mandatory var filter3 = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[2]) - { - IsMandatory = false, - WhereSQL = "But Can Also Be Flies" - }; + { + IsMandatory = false, + WhereSQL = "But Can Also Be Flies" + }; filter3.SaveToDatabase(); //ensure that both are picked SetUp as mandatory filters by catalogue @@ -212,7 +213,8 @@ public void ImportCatalogueWithMultipleMandatoryFilters() try { //import the Catalogue - importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); + importedAggregate = + cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); var importedAggregateFilterContainer = importedAggregate.RootFilterContainer; //Must have a root container @@ -231,7 +233,7 @@ public void ImportCatalogueWithMultipleMandatoryFilters() filter2.DeleteInDatabase(); filter3.DeleteInDatabase(); - if(importedAggregate != null) + if (importedAggregate != null) { importedAggregate.RootFilterContainer.DeleteInDatabase(); importedAggregate.DeleteInDatabase(); diff --git a/Rdmp.Core.Tests/CohortCreation/PluginCohortCompilerTests.cs b/Rdmp.Core.Tests/CohortCreation/PluginCohortCompilerTests.cs index 932c60cbec..2ffaf3f092 100644 --- a/Rdmp.Core.Tests/CohortCreation/PluginCohortCompilerTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/PluginCohortCompilerTests.cs @@ -28,7 +28,8 @@ public class PluginCohortCompilerTests : CohortQueryBuilderWithCacheTests [Test] public void TestIPluginCohortCompiler_PopulatesCacheCorrectly() { - var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; + var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) + { DisallowInput = true }; // create a cohort config var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic") @@ -44,7 +45,8 @@ public void TestIPluginCohortCompiler_PopulatesCacheCorrectly() cic.CreateRootContainerIfNotExists(); // create a use of the API as an AggregateConfiguration - var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi),cic.RootCohortAggregateContainer); + var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, + new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer); Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); @@ -52,7 +54,7 @@ public void TestIPluginCohortCompiler_PopulatesCacheCorrectly() // run the cic var source = new CohortIdentificationConfigurationSource(); source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener()); - var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); // 5 random chi numbers Assert.AreEqual(5, dt.Rows.Count); @@ -82,12 +84,13 @@ public void TestIPluginCohortCompiler_PopulatesCacheCorrectly() Assert.AreEqual(results[0], results2[0]); Assert.AreEqual(results[1], results2[1]); - } + [Test] public void TestIPluginCohortCompiler_TestCloneCic() { - var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; + var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) + { DisallowInput = true }; // create a cohort config var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic") @@ -103,7 +106,8 @@ public void TestIPluginCohortCompiler_TestCloneCic() cic.CreateRootContainerIfNotExists(); // create a use of the API as an AggregateConfiguration - var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer); + var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, + new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer); Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); cmd.AggregateCreatedIfAny.Description = "33"; @@ -121,7 +125,8 @@ public void TestIPluginCohortCompiler_TestCloneCic() [Test] public void TestIPluginCohortCompiler_APIsCantHavePatientIndexTables() { - var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; + var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) + { DisallowInput = true }; // create a cohort config var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic") @@ -137,7 +142,8 @@ public void TestIPluginCohortCompiler_APIsCantHavePatientIndexTables() cic.CreateRootContainerIfNotExists(); // We need something in the root container otherwise the cic won't build - var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer); + var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, + new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer); Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); var regularAggregate = cmd.AggregateCreatedIfAny; @@ -152,17 +158,19 @@ public void TestIPluginCohortCompiler_APIsCantHavePatientIndexTables() var joinables = cic.GetAllJoinables(); // make them join one another - var ex = Assert.Throws(()=> + var ex = Assert.Throws(() => new JoinableCohortAggregateConfigurationUse(CatalogueRepository, regularAggregate, joinables[0])); - Assert.AreEqual("API calls cannot join with PatientIndexTables (The API call must be self contained)", ex.Message); + Assert.AreEqual("API calls cannot join with PatientIndexTables (The API call must be self contained)", + ex.Message); } [Test] public void TestIPluginCohortCompiler_AsPatientIndexTable() { - var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; + var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) + { DisallowInput = true }; // Create a regular normal boring old table that will join into the results of the API call var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -170,7 +178,7 @@ public void TestIPluginCohortCompiler_AsPatientIndexTable() dt.Columns.Add("chi"); dt.Rows.Add("0101010101"); - var tbl = db.CreateTable("RegularBoringOldTable",dt); + var tbl = db.CreateTable("RegularBoringOldTable", dt); var cata = (Catalogue)Import(tbl); var eiChi = cata.GetAllExtractionInformation()[0]; @@ -191,7 +199,8 @@ public void TestIPluginCohortCompiler_AsPatientIndexTable() cic.CreateRootContainerIfNotExists(); // Add the regular table - var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(cata), cic.RootCohortAggregateContainer); + var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, + new CatalogueCombineable(cata), cic.RootCohortAggregateContainer); Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); var regularAggregate = cmd.AggregateCreatedIfAny; diff --git a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortCompilerCacheJoinableTest.cs b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortCompilerCacheJoinableTest.cs index f507c14533..0852492dce 100644 --- a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortCompilerCacheJoinableTest.cs +++ b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortCompilerCacheJoinableTest.cs @@ -26,7 +26,7 @@ namespace Rdmp.Core.Tests.CohortCreation.QueryTests; /// /// Tests caching the results of an which hits up multiple underlying tables. /// -internal class CohortCompilerCacheJoinableTest:FromToDatabaseTests +internal class CohortCompilerCacheJoinableTest : FromToDatabaseTests { [Test] public void CohortIdentificationConfiguration_Join_PatientIndexTable() @@ -37,20 +37,20 @@ public void CohortIdentificationConfiguration_Join_PatientIndexTable() header.Columns.Add("Age"); header.Columns.Add("Date"); header.Columns.Add("Healthboard"); - header.PrimaryKey = new []{header.Columns["ID"] }; + header.PrimaryKey = new[] { header.Columns["ID"] }; - header.Rows.Add("1","0101010101",50,new DateTime(2001,1,1),"T"); + header.Rows.Add("1", "0101010101", 50, new DateTime(2001, 1, 1), "T"); header.Rows.Add("2", "0202020202", 50, new DateTime(2002, 2, 2), "T"); - var hTbl = From.CreateTable("header",header); - var cata = Import(hTbl,out var hTi, out _); + var hTbl = From.CreateTable("header", header); + var cata = Import(hTbl, out var hTi, out _); cata.Name = "My Combo Join Catalogue"; cata.SaveToDatabase(); var scripter = new MasterDatabaseScriptExecutor(To); var patcher = new QueryCachingPatcher(); - scripter.CreateAndPatchDatabase(patcher,new AcceptAllCheckNotifier()); - var edsCache = new ExternalDatabaseServer(CatalogueRepository,"Cache", new QueryCachingPatcher()); + scripter.CreateAndPatchDatabase(patcher, new AcceptAllCheckNotifier()); + var edsCache = new ExternalDatabaseServer(CatalogueRepository, "Cache", new QueryCachingPatcher()); edsCache.SetProperties(To); var results = new DataTable(); @@ -58,78 +58,82 @@ public void CohortIdentificationConfiguration_Join_PatientIndexTable() results.Columns.Add("TestCode"); results.Columns.Add("Result"); - results.Rows.Add("1","HBA1C",50); + results.Rows.Add("1", "HBA1C", 50); results.Rows.Add("1", "ECOM", "Hi fellas"); results.Rows.Add("1", "ALB", 100); results.Rows.Add("2", "ALB", 50); var rTbl = From.CreateTable("results", results); - var importer = new TableInfoImporter(CatalogueRepository,rTbl); + var importer = new TableInfoImporter(CatalogueRepository, rTbl); importer.DoImport(out var rTi, out var rColInfos); - var fe = new ForwardEngineerCatalogue(rTi,rColInfos); + var fe = new ForwardEngineerCatalogue(rTi, rColInfos); fe.ExecuteForwardEngineering(cata); - + //Should now be 1 Catalogue with all the columns (tables will have to be joined to build the query though) - Assert.AreEqual(8,cata.GetAllExtractionInformation(ExtractionCategory.Core).Length); + Assert.AreEqual(8, cata.GetAllExtractionInformation(ExtractionCategory.Core).Length); var ji = new JoinInfo(CatalogueRepository, - rTi.ColumnInfos.Single(ci=>ci.GetRuntimeName().Equals("Header_ID",StringComparison.CurrentCultureIgnoreCase)), + rTi.ColumnInfos.Single(ci => + ci.GetRuntimeName().Equals("Header_ID", StringComparison.CurrentCultureIgnoreCase)), hTi.ColumnInfos.Single(ci => ci.GetRuntimeName().Equals("ID", StringComparison.CurrentCultureIgnoreCase)), ExtractionJoinType.Right, null ); //setup a cic that uses the cache - var cic = new CohortIdentificationConfiguration(CatalogueRepository,"MyCic"); + var cic = new CohortIdentificationConfiguration(CatalogueRepository, "MyCic"); cic.CreateRootContainerIfNotExists(); cic.QueryCachingServer_ID = edsCache.ID; cic.SaveToDatabase(); //create a patient index table that shows all the times that they had a test in any HB (with the HB being part of the result set) - var acPatIndex = new AggregateConfiguration(CatalogueRepository,cata,"My PatIndes"); + var acPatIndex = new AggregateConfiguration(CatalogueRepository, cata, "My PatIndes"); - var eiChi = cata.GetAllExtractionInformation(ExtractionCategory.Core).Single(ei => ei.GetRuntimeName().Equals("Chi")); + var eiChi = cata.GetAllExtractionInformation(ExtractionCategory.Core) + .Single(ei => ei.GetRuntimeName().Equals("Chi")); eiChi.IsExtractionIdentifier = true; acPatIndex.CountSQL = null; eiChi.SaveToDatabase(); acPatIndex.AddDimension(eiChi); - acPatIndex.AddDimension(cata.GetAllExtractionInformation(ExtractionCategory.Core).Single(ei => ei.GetRuntimeName().Equals("Date"))); - acPatIndex.AddDimension(cata.GetAllExtractionInformation(ExtractionCategory.Core).Single(ei => ei.GetRuntimeName().Equals("Healthboard"))); - + acPatIndex.AddDimension(cata.GetAllExtractionInformation(ExtractionCategory.Core) + .Single(ei => ei.GetRuntimeName().Equals("Date"))); + acPatIndex.AddDimension(cata.GetAllExtractionInformation(ExtractionCategory.Core) + .Single(ei => ei.GetRuntimeName().Equals("Healthboard"))); + cic.EnsureNamingConvention(acPatIndex); - var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository,cic,acPatIndex); - + var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cic, acPatIndex); + Assert.IsTrue(acPatIndex.IsCohortIdentificationAggregate); Assert.IsTrue(acPatIndex.IsJoinablePatientIndexTable()); var compiler = new CohortCompiler(cic); - var runner = new CohortCompilerRunner(compiler,50); + var runner = new CohortCompilerRunner(compiler, 50); var cancellation = new System.Threading.CancellationToken(); runner.Run(cancellation); //they should not be executing and should be completed - Assert.IsFalse(compiler.Tasks.Any(t=>t.Value.IsExecuting)); - Assert.AreEqual(Phase.Finished,runner.ExecutionPhase); + Assert.IsFalse(compiler.Tasks.Any(t => t.Value.IsExecuting)); + Assert.AreEqual(Phase.Finished, runner.ExecutionPhase); var manager = new CachedAggregateConfigurationResultsManager(edsCache); - var cacheTableName = manager.GetLatestResultsTableUnsafe(acPatIndex,AggregateOperation.JoinableInceptionQuery); + var cacheTableName = manager.GetLatestResultsTableUnsafe(acPatIndex, AggregateOperation.JoinableInceptionQuery); - Assert.IsNotNull(cacheTableName,"No results were cached!"); + Assert.IsNotNull(cacheTableName, "No results were cached!"); var cacheTable = To.ExpectTable(cacheTableName.GetRuntimeName()); - + //chi, Date and TestCode - Assert.AreEqual(3,cacheTable.DiscoverColumns().Length); + Assert.AreEqual(3, cacheTable.DiscoverColumns().Length); //healthboard should be a string - Assert.AreEqual(typeof(string),cacheTable.DiscoverColumn("Healthboard").DataType.GetCSharpDataType()); + Assert.AreEqual(typeof(string), cacheTable.DiscoverColumn("Healthboard").DataType.GetCSharpDataType()); /* Query Cache contains this: * diff --git a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTests.cs b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTests.cs index 702ae21af1..dce4a1ba69 100644 --- a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTests.cs @@ -20,32 +20,34 @@ namespace Rdmp.Core.Tests.CohortCreation.QueryTests; public class CohortQueryBuilderTests : CohortIdentificationTests { private readonly string _scratchDatabaseName = TestDatabaseNames.GetConsistentName("ScratchArea"); - + [Test] public void TestGettingAggregateJustFromConfig_DistinctCHISelect() { - var builder = new CohortQueryBuilder(aggregate1,null,null); + var builder = new CohortQueryBuilder(aggregate1, null, null); Assert.AreEqual(CollapseWhitespace(string.Format(@"/*cic_{0}_UnitTestAggregate1*/ SELECT distinct [" + _scratchDatabaseName + @"].[dbo].[BulkData].[chi] FROM -[" + _scratchDatabaseName + @"].[dbo].[BulkData]", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); +[" + _scratchDatabaseName + @"].[dbo].[BulkData]", cohortIdentificationConfiguration.ID)), + CollapseWhitespace(builder.SQL)); } - + [Test] public void TestGettingAggregateJustFromConfig_SelectStar() { - var builder = new CohortQueryBuilder(aggregate1, null,null); + var builder = new CohortQueryBuilder(aggregate1, null, null); Assert.AreEqual(CollapseWhitespace( - string.Format(@"/*cic_{0}_UnitTestAggregate1*/ + string.Format(@"/*cic_{0}_UnitTestAggregate1*/ SELECT TOP 1000 * FROM - [" + _scratchDatabaseName + @"].[dbo].[BulkData]",cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.GetDatasetSampleSQL())); + [" + _scratchDatabaseName + @"].[dbo].[BulkData]", cohortIdentificationConfiguration.ID)), + CollapseWhitespace(builder.GetDatasetSampleSQL())); } @@ -59,7 +61,7 @@ public void Test_GetDatasetSampleSQL_WithHAVING() { aggregate1.HavingSQL = "count(*)>1"; - var builder = new CohortQueryBuilder(aggregate1, null,null); + var builder = new CohortQueryBuilder(aggregate1, null, null); Assert.AreEqual(CollapseWhitespace( string.Format(@"/*cic_{0}_UnitTestAggregate1*/ @@ -85,13 +87,12 @@ public void TestGettingAggregateSQLFromEntirity() rootcontainer.AddChild(aggregate2, 1); rootcontainer.AddChild(aggregate1, 5); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); - Assert.AreEqual(rootcontainer,aggregate1.GetCohortAggregateContainerIfAny()); + Assert.AreEqual(rootcontainer, aggregate1.GetCohortAggregateContainerIfAny()); try { Assert.AreEqual( - CollapseWhitespace(string.Format( @"( /*cic_{0}_UnitTestAggregate2*/ @@ -110,11 +111,10 @@ public void TestGettingAggregateSQLFromEntirity() FROM [" + _scratchDatabaseName + @"].[dbo].[BulkData] )" - - ,cohortIdentificationConfiguration.ID)) + , cohortIdentificationConfiguration.ID)) , CollapseWhitespace(builder.SQL)); } - finally + finally { rootcontainer.RemoveChild(aggregate1); rootcontainer.RemoveChild(aggregate2); @@ -136,7 +136,7 @@ public void TestOrdering_AggregateThenContainer() container1.AddChild(aggregate2, 1); container1.AddChild(aggregate3, 2); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); try { @@ -176,7 +176,7 @@ public void TestOrdering_AggregateThenContainer() [" + _scratchDatabaseName + @"].[dbo].[BulkData] ) -)",cohortIdentificationConfiguration.ID)) +)", cohortIdentificationConfiguration.ID)) , CollapseWhitespace(builder.SQL)); } @@ -203,7 +203,7 @@ public void TestOrdering_ContainerThenAggregate() container1.AddChild(aggregate2, 1); container1.AddChild(aggregate3, 2); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); try { @@ -239,7 +239,7 @@ public void TestOrdering_ContainerThenAggregate() [" + _scratchDatabaseName + @"].[dbo].[BulkData].[chi] FROM [" + _scratchDatabaseName + @"].[dbo].[BulkData] -)",cohortIdentificationConfiguration.ID)) +)", cohortIdentificationConfiguration.ID)) , CollapseWhitespace(builder.SQL)); } finally @@ -254,8 +254,8 @@ public void TestOrdering_ContainerThenAggregate() public void TestGettingAggregateSQLFromEntirity_IncludingParametersAtTop() { //setup a filter (all filters must be in a container so the container is a default AND container) - var AND = new AggregateFilterContainer(CatalogueRepository,FilterContainerOperation.AND); - var filter = new AggregateFilter(CatalogueRepository,"hithere",AND) + var AND = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND); + var filter = new AggregateFilter(CatalogueRepository, "hithere", AND) { //give the filter an implicit parameter requiring bit of SQL WhereSQL = "1=@abracadabra" @@ -271,19 +271,17 @@ public void TestGettingAggregateSQLFromEntirity_IncludingParametersAtTop() new ParameterCreator(new AggregateFilterFactory(CatalogueRepository), null, null).CreateAll(filter, null); //get the parameter it just created, set its value and save it - var param = (AggregateFilterParameter) filter.GetAllParameters().Single(); + var param = (AggregateFilterParameter)filter.GetAllParameters().Single(); param.Value = "1"; param.ParameterSQL = "DECLARE @abracadabra AS int;"; param.SaveToDatabase(); - - - + //set the order so that 2 comes before 1 rootcontainer.AddChild(aggregate2, 1); rootcontainer.AddChild(aggregate1, 5); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); try { @@ -315,13 +313,12 @@ public void TestGettingAggregateSQLFromEntirity_IncludingParametersAtTop() 1=@abracadabra ) ) -",cohortIdentificationConfiguration.ID)) +", cohortIdentificationConfiguration.ID)) , CollapseWhitespace(builder.SQL)); - var builder2 = new CohortQueryBuilder(aggregate1, null,null); + var builder2 = new CohortQueryBuilder(aggregate1, null, null); Assert.AreEqual( - CollapseWhitespace( string.Format( @"DECLARE @abracadabra AS int; @@ -336,16 +333,15 @@ public void TestGettingAggregateSQLFromEntirity_IncludingParametersAtTop() ( /*hithere*/ 1=@abracadabra -)",cohortIdentificationConfiguration.ID)), +)", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder2.SQL)); - var selectStar = new CohortQueryBuilder(aggregate1,null,null).GetDatasetSampleSQL(); + var selectStar = new CohortQueryBuilder(aggregate1, null, null).GetDatasetSampleSQL(); Assert.AreEqual( CollapseWhitespace( string.Format( - @"DECLARE @abracadabra AS int; SET @abracadabra=1; @@ -354,14 +350,13 @@ public void TestGettingAggregateSQLFromEntirity_IncludingParametersAtTop() TOP 1000 * FROM - [" + TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] WHERE ( /*hithere*/ 1=@abracadabra - )",cohortIdentificationConfiguration.ID)), + )", cohortIdentificationConfiguration.ID)), CollapseWhitespace(selectStar)); - } finally { @@ -370,7 +365,6 @@ TOP 1000 rootcontainer.RemoveChild(aggregate1); rootcontainer.RemoveChild(aggregate2); - } } @@ -378,11 +372,11 @@ TOP 1000 [Test] public void TestGettingAggregateSQLFromEntirity_StopEarly() { - rootcontainer.AddChild(aggregate1,1); - rootcontainer.AddChild(aggregate2,2); - rootcontainer.AddChild(aggregate3,3); + rootcontainer.AddChild(aggregate1, 1); + rootcontainer.AddChild(aggregate2, 2); + rootcontainer.AddChild(aggregate3, 3); - var builder = new CohortQueryBuilder(rootcontainer, null,null) + var builder = new CohortQueryBuilder(rootcontainer, null, null) { StopContainerWhenYouReach = aggregate2 }; @@ -392,7 +386,6 @@ public void TestGettingAggregateSQLFromEntirity_StopEarly() Assert.AreEqual( CollapseWhitespace( string.Format( - @" ( /*cic_{0}_UnitTestAggregate1*/ @@ -411,11 +404,11 @@ public void TestGettingAggregateSQLFromEntirity_StopEarly() FROM [" + _scratchDatabaseName + @"].[dbo].[BulkData] ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); - var builder2 = new CohortQueryBuilder(rootcontainer, null,null) + var builder2 = new CohortQueryBuilder(rootcontainer, null, null) { StopContainerWhenYouReach = null }; @@ -449,7 +442,7 @@ public void TestGettingAggregateSQLFromEntirity_StopEarly() FROM [" + _scratchDatabaseName + @"].[dbo].[BulkData] ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder2.SQL)); } finally @@ -457,7 +450,6 @@ public void TestGettingAggregateSQLFromEntirity_StopEarly() rootcontainer.RemoveChild(aggregate1); rootcontainer.RemoveChild(aggregate2); rootcontainer.RemoveChild(aggregate3); - } } @@ -468,18 +460,19 @@ public void TestGettingAggregateSQLFromEntirity_StopEarlyContainer() container1.AddChild(aggregate2, 2); container1.AddChild(aggregate3, 3); - + rootcontainer.AddChild(container1); var aggregate4 = new AggregateConfiguration(CatalogueRepository, testData.catalogue, "UnitTestAggregate4"); - new AggregateDimension(CatalogueRepository, testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate4); + new AggregateDimension(CatalogueRepository, + testData.extractionInformations.Single(e => e.GetRuntimeName().Equals("chi")), aggregate4); - rootcontainer.AddChild(aggregate4,5); - var builder = new CohortQueryBuilder(rootcontainer, null,null) + rootcontainer.AddChild(aggregate4, 5); + var builder = new CohortQueryBuilder(rootcontainer, null, null) { //Looks like: /* - * + * EXCEPT Aggregate 1 UNION <-----We tell it to stop after this container @@ -526,7 +519,7 @@ Aggregate 4 ) ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); } finally @@ -554,10 +547,9 @@ public void TestHavingSQL() aggregate1.SaveToDatabase(); try { - rootcontainer.AddChild(container1); - var builder = new CohortQueryBuilder(rootcontainer, null,null); + var builder = new CohortQueryBuilder(rootcontainer, null, null); Assert.AreEqual( CollapseWhitespace( string.Format( @@ -600,9 +592,8 @@ group by ) ) -",cohortIdentificationConfiguration.ID)) +", cohortIdentificationConfiguration.ID)) , CollapseWhitespace(builder.SQL)); - } finally { @@ -619,11 +610,12 @@ group by } [Test] - [TestCase(true,true)] + [TestCase(true, true)] [TestCase(true, false)] - [TestCase(false,true)] + [TestCase(false, true)] [TestCase(false, false)] - public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bool valuesAreSame,bool memoryRepository) + public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bool valuesAreSame, + bool memoryRepository) { var repo = memoryRepository ? (ICatalogueRepository)new MemoryCatalogueRepository() : CatalogueRepository; @@ -631,14 +623,14 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo SetupTestData(repo); //setup a filter (all filters must be in a container so the container is a default AND container) - var AND1 = new AggregateFilterContainer(repo,FilterContainerOperation.AND); - var filter1_1 = new AggregateFilter(repo,"filter1_1",AND1); - var filter1_2 = new AggregateFilter(repo,"filter1_2",AND1); - - var AND2 = new AggregateFilterContainer(repo,FilterContainerOperation.AND); - var filter2_1 = new AggregateFilter(repo,"filter2_1",AND2); - var filter2_2 = new AggregateFilter(repo,"filter2_2",AND2); - + var AND1 = new AggregateFilterContainer(repo, FilterContainerOperation.AND); + var filter1_1 = new AggregateFilter(repo, "filter1_1", AND1); + var filter1_2 = new AggregateFilter(repo, "filter1_2", AND1); + + var AND2 = new AggregateFilterContainer(repo, FilterContainerOperation.AND); + var filter2_1 = new AggregateFilter(repo, "filter2_1", AND2); + var filter2_2 = new AggregateFilter(repo, "filter2_2", AND2); + //Filters must belong to containers BEFORE parameter creation //Make aggregate1 use the filter set we just setup aggregate1.RootFilterContainer_ID = AND1.ID; @@ -653,18 +645,18 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo rootcontainer.AddChild(aggregate1, 5); //give the filter an implicit parameter requiring bit of SQL - foreach (var filter in new IFilter[]{filter1_1,filter1_2,filter2_1,filter2_2}) + foreach (var filter in new IFilter[] { filter1_1, filter1_2, filter2_1, filter2_2 }) { filter.WhereSQL = "@bob = 'bob'"; - filter.SaveToDatabase(); + filter.SaveToDatabase(); //get it to create the parameters for us new ParameterCreator(new AggregateFilterFactory(repo), null, null).CreateAll(filter, null); //get the parameter it just created, set its value and save it - var param = (AggregateFilterParameter) filter.GetAllParameters().Single(); + var param = (AggregateFilterParameter)filter.GetAllParameters().Single(); param.Value = "'Boom!'"; param.ParameterSQL = "DECLARE @bob AS varchar(10);"; - + //if test case is different values then we change the values of the parameters if (!valuesAreSame && (filter.Equals(filter2_1) || Equals(filter, filter2_2))) param.Value = "'Grenades Are Go'"; @@ -672,13 +664,12 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo param.SaveToDatabase(); } - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); - Console.WriteLine( builder.SQL); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); + Console.WriteLine(builder.SQL); try { if (valuesAreSame) - { Assert.AreEqual( CollapseWhitespace( string.Format( @@ -718,14 +709,11 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo @bob = 'bob' ) ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); - } else - { Assert.AreEqual( - - CollapseWhitespace( + CollapseWhitespace( string.Format( @"DECLARE @bob AS varchar(10); SET @bob='Grenades Are Go'; @@ -736,9 +724,9 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo /*cic_{0}_UnitTestAggregate2*/ SELECT distinct - [" + TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM - ["+TestDatabaseNames.Prefix+ @"ScratchArea].[dbo].[BulkData] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] WHERE ( /*filter2_1*/ @@ -753,9 +741,9 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo /*cic_{0}_UnitTestAggregate1*/ SELECT distinct - [" + TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM - ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] WHERE ( /*filter1_1*/ @@ -765,9 +753,8 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo @bob_2 = 'bob' ) ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); - } } finally { @@ -778,10 +765,9 @@ public void TestGettingAggregateSQLFromEntirity_TwoFilterParametersPerDataset(bo filter1_2.DeleteInDatabase(); filter2_1.DeleteInDatabase(); filter2_2.DeleteInDatabase(); - + AND1.DeleteInDatabase(); AND2.DeleteInDatabase(); - } } @@ -800,11 +786,10 @@ public void TestGettingAggregateSQL_Aggregate_IsDisabled() Assert.AreEqual(rootcontainer, aggregate1.GetCohortAggregateContainerIfAny()); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); try { Assert.AreEqual( - CollapseWhitespace(string.Format( @"( /*cic_{0}_UnitTestAggregate2*/ @@ -814,13 +799,11 @@ public void TestGettingAggregateSQL_Aggregate_IsDisabled() FROM [" + _scratchDatabaseName + @"].[dbo].[BulkData] )" - , cohortIdentificationConfiguration.ID)) , CollapseWhitespace(builder.SQL)); } finally { - aggregate1.IsDisabled = false; aggregate1.SaveToDatabase(); @@ -828,7 +811,7 @@ public void TestGettingAggregateSQL_Aggregate_IsDisabled() rootcontainer.RemoveChild(aggregate2); } } - + [Test] public void TestGettingAggregateSQLFromEntirity_Filter_IsDisabled() { @@ -877,7 +860,7 @@ public void TestGettingAggregateSQLFromEntirity_Filter_IsDisabled() param.SaveToDatabase(); } - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); Console.WriteLine(builder.SQL); @@ -886,7 +869,6 @@ public void TestGettingAggregateSQLFromEntirity_Filter_IsDisabled() Assert.AreEqual( CollapseWhitespace( string.Format( - @"DECLARE @bob AS varchar(10); SET @bob='Grenades Are Go'; DECLARE @bob_2 AS varchar(10); @@ -924,11 +906,9 @@ public void TestGettingAggregateSQLFromEntirity_Filter_IsDisabled() ) ", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); - } finally { - filter2_2.IsDisabled = false; filter2_2.SaveToDatabase(); @@ -942,7 +922,6 @@ public void TestGettingAggregateSQLFromEntirity_Filter_IsDisabled() AND1.DeleteInDatabase(); AND2.DeleteInDatabase(); - } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTestsInvolvingTableValuedParameters.cs b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTestsInvolvingTableValuedParameters.cs index e9dc5409c5..032b99c501 100644 --- a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTestsInvolvingTableValuedParameters.cs +++ b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderTestsInvolvingTableValuedParameters.cs @@ -13,10 +13,10 @@ namespace Rdmp.Core.Tests.CohortCreation.QueryTests; -public class CohortQueryBuilderTestsInvolvingTableValuedParameters:DatabaseTests +public class CohortQueryBuilderTestsInvolvingTableValuedParameters : DatabaseTests { private TestableTableValuedFunction _function = new(); - + public void CreateFunction() { _function.Create(GetCleanedServer(DatabaseType.MicrosoftSQLServer), CatalogueRepository); @@ -28,20 +28,23 @@ public void CohortGenerationDifferingTableValuedParametersTest() CreateFunction(); //In this example we have 2 configurations which both target the same table valued function but which must have different parameter values - var config1 = new AggregateConfiguration(CatalogueRepository,_function.Cata, "CohortGenerationDifferingTableValuedParametersTest_1") - { - CountSQL = null - }; + var config1 = new AggregateConfiguration(CatalogueRepository, _function.Cata, + "CohortGenerationDifferingTableValuedParametersTest_1") + { + CountSQL = null + }; config1.SaveToDatabase(); - var config2 = new AggregateConfiguration(CatalogueRepository,_function.Cata, "CohortGenerationDifferingTableValuedParametersTest_2") - { - CountSQL = null - }; + var config2 = new AggregateConfiguration(CatalogueRepository, _function.Cata, + "CohortGenerationDifferingTableValuedParametersTest_2") + { + CountSQL = null + }; config2.SaveToDatabase(); - var cic = new CohortIdentificationConfiguration(CatalogueRepository,"CohortGenerationDifferingTableValuedParametersTest"); - + var cic = new CohortIdentificationConfiguration(CatalogueRepository, + "CohortGenerationDifferingTableValuedParametersTest"); + cic.EnsureNamingConvention(config1); cic.EnsureNamingConvention(config2); @@ -50,15 +53,15 @@ public void CohortGenerationDifferingTableValuedParametersTest() //make the string column the extraction identifier _function.ExtractionInformations[1].IsExtractionIdentifier = true; _function.ExtractionInformations[1].SaveToDatabase(); - + //add the extraction identtifier as the only dimension one ach of the aggregate configurations that we will use for the cohort identification query - new AggregateDimension(CatalogueRepository,_function.ExtractionInformations[1], config1); - new AggregateDimension(CatalogueRepository,_function.ExtractionInformations[1], config2); + new AggregateDimension(CatalogueRepository, _function.ExtractionInformations[1], config1); + new AggregateDimension(CatalogueRepository, _function.ExtractionInformations[1], config2); Assert.IsNull(cic.RootCohortAggregateContainer_ID); //create a root container for it - var container = new CohortAggregateContainer(CatalogueRepository,SetOperation.INTERSECT); + var container = new CohortAggregateContainer(CatalogueRepository, SetOperation.INTERSECT); //set the container as the root container for the cohort identification task object cic.RootCohortAggregateContainer_ID = container.ID; @@ -68,7 +71,7 @@ public void CohortGenerationDifferingTableValuedParametersTest() container.AddChild(config1, 0); container.AddChild(config2, 1); - var builder = new CohortQueryBuilder(cic,null); + var builder = new CohortQueryBuilder(cic, null); Assert.AreEqual( CollapseWhitespace( string.Format( @@ -85,7 +88,8 @@ public void CohortGenerationDifferingTableValuedParametersTest() distinct MyAwesomeFunction.[Name] FROM - [" + TestDatabaseNames.Prefix+ @"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction + [" + TestDatabaseNames.Prefix + + @"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction INTERSECT @@ -94,25 +98,26 @@ public void CohortGenerationDifferingTableValuedParametersTest() distinct MyAwesomeFunction.[Name] FROM - [" + TestDatabaseNames.Prefix+@"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction + [" + TestDatabaseNames.Prefix + + @"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction ) -",cic.ID)), +", cic.ID)), CollapseWhitespace(builder.SQL)); //now override JUST @name - var param1 = new AnyTableSqlParameter(CatalogueRepository,config1, "DECLARE @name AS varchar(50);") - { - Value = "'lobster'" - }; + var param1 = new AnyTableSqlParameter(CatalogueRepository, config1, "DECLARE @name AS varchar(50);") + { + Value = "'lobster'" + }; param1.SaveToDatabase(); - var param2 = new AnyTableSqlParameter(CatalogueRepository,config2, "DECLARE @name AS varchar(50);") - { - Value = "'monkey'" - }; + var param2 = new AnyTableSqlParameter(CatalogueRepository, config2, "DECLARE @name AS varchar(50);") + { + Value = "'monkey'" + }; param2.SaveToDatabase(); - var builder2 = new CohortQueryBuilder(cic,null); + var builder2 = new CohortQueryBuilder(cic, null); Assert.AreEqual( CollapseWhitespace( @@ -132,7 +137,8 @@ public void CohortGenerationDifferingTableValuedParametersTest() distinct MyAwesomeFunction.[Name] FROM - [" + TestDatabaseNames.Prefix+ @"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction + [" + TestDatabaseNames.Prefix + + @"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction INTERSECT @@ -141,9 +147,10 @@ public void CohortGenerationDifferingTableValuedParametersTest() distinct MyAwesomeFunction.[Name] FROM - [" + TestDatabaseNames.Prefix+@"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name_2) AS MyAwesomeFunction + [" + TestDatabaseNames.Prefix + + @"ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name_2) AS MyAwesomeFunction ) -",cic.ID)), +", cic.ID)), CollapseWhitespace(builder2.SQL)); } finally @@ -151,7 +158,6 @@ public void CohortGenerationDifferingTableValuedParametersTest() cic.DeleteInDatabase(); config1.DeleteInDatabase(); config2.DeleteInDatabase(); - } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderWithCacheTests.cs b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderWithCacheTests.cs index 2664dd6874..ea1a9f1478 100644 --- a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderWithCacheTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortQueryBuilderWithCacheTests.cs @@ -22,7 +22,7 @@ public class CohortQueryBuilderWithCacheTests : CohortIdentificationTests { protected DiscoveredDatabase queryCacheDatabase; protected ExternalDatabaseServer externalDatabaseServer; - protected DatabaseColumnRequest _chiColumnSpecification = new("chi","varchar(10)"); + protected DatabaseColumnRequest _chiColumnSpecification = new("chi", "varchar(10)"); [OneTimeSetUp] protected override void OneTimeSetUp() @@ -39,25 +39,24 @@ protected override void OneTimeSetUp() var p = new QueryCachingPatcher(); executor.CreateAndPatchDatabase(p, new AcceptAllCheckNotifier()); - - externalDatabaseServer = new ExternalDatabaseServer(CatalogueRepository, "QueryCacheForUnitTests",p); + + externalDatabaseServer = new ExternalDatabaseServer(CatalogueRepository, "QueryCacheForUnitTests", p); externalDatabaseServer.SetProperties(queryCacheDatabase); } - + [Test] public void TestGettingAggregateJustFromConfig_DistinctCHISelect() { + var manager = new CachedAggregateConfigurationResultsManager(externalDatabaseServer); - var manager = new CachedAggregateConfigurationResultsManager( externalDatabaseServer); - cohortIdentificationConfiguration.QueryCachingServer_ID = externalDatabaseServer.ID; cohortIdentificationConfiguration.SaveToDatabase(); - + cohortIdentificationConfiguration.CreateRootContainerIfNotExists(); - cohortIdentificationConfiguration.RootCohortAggregateContainer.AddChild(aggregate1,0); + cohortIdentificationConfiguration.RootCohortAggregateContainer.AddChild(aggregate1, 0); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); try { Assert.AreEqual( @@ -68,15 +67,15 @@ public void TestGettingAggregateJustFromConfig_DistinctCHISelect() /*cic_{0}_UnitTestAggregate1*/ SELECT distinct - [" + TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM - ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); var server = queryCacheDatabase.Server; - using(var con = server.GetConnection()) + using (var con = server.GetConnection()) { con.Open(); @@ -88,13 +87,14 @@ public void TestGettingAggregateJustFromConfig_DistinctCHISelect() string.Format(@"/*cic_{0}_UnitTestAggregate1*/ SELECT distinct -[" +TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM -[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData]", cohortIdentificationConfiguration.ID), dt, _chiColumnSpecification, 30)); +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData]", cohortIdentificationConfiguration.ID), dt, + _chiColumnSpecification, 30)); } - var builderCached = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builderCached = new CohortQueryBuilder(cohortIdentificationConfiguration, null); Assert.AreEqual( CollapseWhitespace( @@ -102,18 +102,16 @@ public void TestGettingAggregateJustFromConfig_DistinctCHISelect() @" ( /*Cached:cic_{0}_UnitTestAggregate1*/ - select * from [" + queryCacheDatabase.GetRuntimeName() + "]..[IndexedExtractionIdentifierList_AggregateConfiguration" + aggregate1.ID + @"] + select * from [" + queryCacheDatabase.GetRuntimeName() + + "]..[IndexedExtractionIdentifierList_AggregateConfiguration" + aggregate1.ID + @"] ) -",cohortIdentificationConfiguration.ID)), +", cohortIdentificationConfiguration.ID)), CollapseWhitespace(builderCached.SQL)); - } finally { cohortIdentificationConfiguration.RootCohortAggregateContainer.RemoveChild(aggregate1); - } - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortSummaryQueryBuilderTests.cs b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortSummaryQueryBuilderTests.cs index 20a59cd507..caeab8701c 100644 --- a/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortSummaryQueryBuilderTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/QueryTests/CohortSummaryQueryBuilderTests.cs @@ -16,7 +16,7 @@ namespace Rdmp.Core.Tests.CohortCreation.QueryTests; -public class CohortSummaryQueryBuilderTests:DatabaseTests +public class CohortSummaryQueryBuilderTests : DatabaseTests { private Catalogue c; private CatalogueItem ci; @@ -29,7 +29,7 @@ public class CohortSummaryQueryBuilderTests:DatabaseTests private AggregateConfiguration acCohort; private AggregateConfiguration acDataset; private ExtractionInformation ei_Chi; - + private CohortIdentificationConfiguration cic; private ExtractionInformation ei_Year; @@ -51,7 +51,7 @@ protected override void SetUp() col = new ColumnInfo(CatalogueRepository, "mycol", "varchar(10)", t); col2 = new ColumnInfo(CatalogueRepository, "myOtherCol", "varchar(10)", t); - + acCohort = new AggregateConfiguration(CatalogueRepository, c, $"{CohortIdentificationConfiguration.CICPrefix}Agg1_Cohort"); acDataset = new AggregateConfiguration(CatalogueRepository, c, "Agg2_Dataset"); @@ -76,29 +76,38 @@ protected override void SetUp() cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic"); cic.CreateRootContainerIfNotExists(); - cic.RootCohortAggregateContainer.AddChild(acCohort,0); + cic.RootCohortAggregateContainer.AddChild(acCohort, 0); } + #region Constructor Arguments + [Test] public void ConstructorArguments_SameAggregateTwice() { - var ex = Assert.Throws(()=>new CohortSummaryQueryBuilder(acCohort,acCohort,null)); - Assert.AreEqual("Summary and Cohort should be different aggregates. Summary should be a graphable useful aggregate while cohort should return a list of private identifiers",ex.Message); + var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acCohort, acCohort, null)); + Assert.AreEqual( + "Summary and Cohort should be different aggregates. Summary should be a graphable useful aggregate while cohort should return a list of private identifiers", + ex.Message); } [Test] public void ConstructorArguments_Param1AccidentallyACohort() { - var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acCohort, acDataset,null)); - Assert.AreEqual("The first argument to constructor CohortSummaryQueryBuilder should be a basic AggregateConfiguration (i.e. not a cohort) but the argument you passed ('cic_Agg1_Cohort') was a cohort identification configuration aggregate", ex.Message); + var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acCohort, acDataset, null)); + Assert.AreEqual( + "The first argument to constructor CohortSummaryQueryBuilder should be a basic AggregateConfiguration (i.e. not a cohort) but the argument you passed ('cic_Agg1_Cohort') was a cohort identification configuration aggregate", + ex.Message); } + [Test] public void ConstructorArguments_Param2AccidentallyAnAggregate() { //change it in memory so it doesn't look like a cohort aggregate anymore acCohort.Name = "RegularAggregate"; - var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acDataset,acCohort,null)); - Assert.AreEqual("The second argument to constructor CohortSummaryQueryBuilder should be a cohort identification aggregate (i.e. have a single AggregateDimension marked IsExtractionIdentifier and have a name starting with cic_) but the argument you passed ('RegularAggregate') was NOT a cohort identification configuration aggregate", ex.Message); + var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acDataset, acCohort, null)); + Assert.AreEqual( + "The second argument to constructor CohortSummaryQueryBuilder should be a cohort identification aggregate (i.e. have a single AggregateDimension marked IsExtractionIdentifier and have a name starting with cic_) but the argument you passed ('RegularAggregate') was NOT a cohort identification configuration aggregate", + ex.Message); acCohort.RevertToDatabaseState(); } @@ -106,17 +115,20 @@ public void ConstructorArguments_Param2AccidentallyAnAggregate() public void ConstructorArguments_DifferentDatasets() { acCohort.Catalogue_ID = -999999; - var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acDataset, acCohort,null)); + var ex = Assert.Throws(() => new CohortSummaryQueryBuilder(acDataset, acCohort, null)); - Assert.IsTrue(ex.Message.StartsWith("Constructor arguments to CohortSummaryQueryBuilder must belong to the same dataset")); + Assert.IsTrue( + ex.Message.StartsWith( + "Constructor arguments to CohortSummaryQueryBuilder must belong to the same dataset")); acCohort.RevertToDatabaseState(); } [Test] public void ConstructorArguments_Normal() { - Assert.DoesNotThrow(() => new CohortSummaryQueryBuilder(acDataset, acCohort,null)); + Assert.DoesNotThrow(() => new CohortSummaryQueryBuilder(acDataset, acCohort, null)); } + #endregion @@ -140,9 +152,10 @@ order by [Test] public void QueryGeneration_WithLinkedCohort_WHERECHIIN() { - var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort,null); + var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort, null); - var ex = Assert.Throws(() => csqb.GetAdjustedAggregateBuilder(CohortSummaryAdjustment.WhereExtractionIdentifiersIn)); + var ex = Assert.Throws(() => + csqb.GetAdjustedAggregateBuilder(CohortSummaryAdjustment.WhereExtractionIdentifiersIn)); Assert.AreEqual("No Query Caching Server configured", ex.Message); } @@ -150,15 +163,16 @@ public void QueryGeneration_WithLinkedCohort_WHERECHIIN() [Test] public void QueryGeneration_Parameters_DifferentValues_WHERECHIIN() { - CreateParameters("'bob'","'fish'"); + CreateParameters("'bob'", "'fish'"); try { - var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort,null); + var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort, null); - var ex = Assert.Throws(() => csqb.GetAdjustedAggregateBuilder(CohortSummaryAdjustment.WhereExtractionIdentifiersIn)); + var ex = Assert.Throws(() => + csqb.GetAdjustedAggregateBuilder(CohortSummaryAdjustment.WhereExtractionIdentifiersIn)); - Assert.AreEqual("No Query Caching Server configured",ex.Message); + Assert.AreEqual("No Query Caching Server configured", ex.Message); } finally { @@ -167,11 +181,10 @@ public void QueryGeneration_Parameters_DifferentValues_WHERECHIIN() } - [Test] public void QueryGeneration_NoCohortWhereLogic() { - var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort,null); + var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort, null); var builder = csqb.GetAdjustedAggregateBuilder(CohortSummaryAdjustment.WhereRecordsIn); @@ -201,7 +214,7 @@ public void QueryGeneration_BothHaveWHEREContainerAndParameters() try { ((IDeleteable)parama1).DeleteInDatabase(); - var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort,null); + var csqb = new CohortSummaryQueryBuilder(acDataset, acCohort, null); var builder = csqb.GetAdjustedAggregateBuilder(CohortSummaryAdjustment.WhereRecordsIn); @@ -230,7 +243,6 @@ group by Year order by Year"), CollapseWhitespace(builder.SQL)); - } finally { @@ -238,6 +250,7 @@ order by DestroyParameters(); } } + private void DestroyParameters() { container1.GetFilters()[0].DeleteInDatabase(); @@ -247,7 +260,7 @@ private void DestroyParameters() container2.DeleteInDatabase(); } - private void CreateParameters(string param1Value,string param2Value) + private void CreateParameters(string param1Value, string param2Value) { container1 = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND); acDataset.RootFilterContainer_ID = container1.ID; @@ -281,6 +294,5 @@ private void CreateParameters(string param1Value,string param2Value) parama2 = filter2.GetAllParameters()[0]; parama2.Value = param2Value; parama2.SaveToDatabase(); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/QueryTests/JoinableCohortConfigurationTests.cs b/Rdmp.Core.Tests/CohortCreation/QueryTests/JoinableCohortConfigurationTests.cs index 01914e9db9..bce37f84a9 100644 --- a/Rdmp.Core.Tests/CohortCreation/QueryTests/JoinableCohortConfigurationTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/QueryTests/JoinableCohortConfigurationTests.cs @@ -36,7 +36,8 @@ public void CreateJoinable() JoinableCohortAggregateConfiguration joinable = null; try { - joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); + joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); Assert.AreEqual(joinable.CohortIdentificationConfiguration_ID, cohortIdentificationConfiguration.ID); Assert.AreEqual(joinable.AggregateConfiguration_ID, aggregate1.ID); @@ -50,10 +51,14 @@ public void CreateJoinable() [Test] public void CreateJoinable_IsAlreadyInAContainer() { - cohortIdentificationConfiguration.RootCohortAggregateContainer.AddChild(aggregate1,1); - - var ex = Assert.Throws(() => new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1)); - Assert.AreEqual("Cannot make aggregate UnitTestAggregate1 into a Joinable aggregate because it is already in a CohortAggregateContainer", ex.Message); + cohortIdentificationConfiguration.RootCohortAggregateContainer.AddChild(aggregate1, 1); + + var ex = Assert.Throws(() => + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1)); + Assert.AreEqual( + "Cannot make aggregate UnitTestAggregate1 into a Joinable aggregate because it is already in a CohortAggregateContainer", + ex.Message); cohortIdentificationConfiguration.RootCohortAggregateContainer.RemoveChild(aggregate1); } @@ -64,20 +69,27 @@ public void CreateJoinable_NoIsExtractionIdentifier() aggregate1.AggregateDimensions.First().DeleteInDatabase(); aggregate1.ClearAllInjections(); - var ex = Assert.Throws(()=>new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1)); - Assert.AreEqual("Cannot make aggregate UnitTestAggregate1 into a Joinable aggregate because it has 0 columns marked IsExtractionIdentifier", ex.Message); + var ex = Assert.Throws(() => + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1)); + Assert.AreEqual( + "Cannot make aggregate UnitTestAggregate1 into a Joinable aggregate because it has 0 columns marked IsExtractionIdentifier", + ex.Message); } [Test] public void CreateJoinable_AddTwice() { //delete the first dimension (chi) - var join1 = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); + var join1 = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); try { - if(CatalogueRepository is TableRepository) + if (CatalogueRepository is TableRepository) { - var ex = Assert.Throws(() => new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1)); + var ex = Assert.Throws(() => + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1)); Assert.IsTrue(ex.Message.Contains("ix_eachAggregateCanOnlyBeJoinableOnOneProject")); } } @@ -90,14 +102,15 @@ public void CreateJoinable_AddTwice() [Test] public void CreateUsers() { - JoinableCohortAggregateConfiguration joinable = null; + JoinableCohortAggregateConfiguration joinable = null; try { - joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); + joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); joinable.AddUser(aggregate2); Assert.IsTrue(joinable.Users.Length == 1); - Assert.AreEqual(aggregate2,joinable.Users[0].AggregateConfiguration); + Assert.AreEqual(aggregate2, joinable.Users[0].AggregateConfiguration); } finally { @@ -108,12 +121,16 @@ public void CreateUsers() [Test] public void CreateUsers_DuplicateUser() { - var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); + var joinable = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); try { joinable.AddUser(aggregate2); - var ex = Assert.Throws(()=>joinable.AddUser(aggregate2)); - Assert.AreEqual($"AggregateConfiguration 'UnitTestAggregate2' already uses 'Patient Index Table:cic_{cohortIdentificationConfiguration.ID}_UnitTestAggregate1'. Only one patient index table join is permitted.", ex.Message); + var ex = Assert.Throws(() => joinable.AddUser(aggregate2)); + Assert.AreEqual( + $"AggregateConfiguration 'UnitTestAggregate2' already uses 'Patient Index Table:cic_{cohortIdentificationConfiguration.ID}_UnitTestAggregate1'. Only one patient index table join is permitted.", + ex.Message); } finally { @@ -124,11 +141,14 @@ public void CreateUsers_DuplicateUser() [Test] public void CreateUsers_SelfReferrential() { - var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); + var joinable = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); try { - var ex = Assert.Throws(()=>joinable.AddUser(aggregate1)); - Assert.AreEqual("Cannot configure AggregateConfiguration UnitTestAggregate1 as a Join user to itself!", ex.Message); + var ex = Assert.Throws(() => joinable.AddUser(aggregate1)); + Assert.AreEqual("Cannot configure AggregateConfiguration UnitTestAggregate1 as a Join user to itself!", + ex.Message); } finally { @@ -139,12 +159,18 @@ public void CreateUsers_SelfReferrential() [Test] public void CreateUsers_ToAnyOtherJoinable() { - var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); - var joinable2 = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate2); + var joinable = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); + var joinable2 = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate2); try { var ex = Assert.Throws(() => joinable.AddUser(aggregate2)); - Assert.AreEqual("Cannot add user UnitTestAggregate2 because that AggregateConfiguration is itself a JoinableCohortAggregateConfiguration", ex.Message); + Assert.AreEqual( + "Cannot add user UnitTestAggregate2 because that AggregateConfiguration is itself a JoinableCohortAggregateConfiguration", + ex.Message); } finally { @@ -152,10 +178,13 @@ public void CreateUsers_ToAnyOtherJoinable() joinable2.DeleteInDatabase(); } } + [Test] public void CreateUsers_ToNoExtractionIdentifierTable() { - var joinable = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate1); + var joinable = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate1); aggregate2.AggregateDimensions.First().DeleteInDatabase(); aggregate2.ClearAllInjections(); @@ -163,7 +192,9 @@ public void CreateUsers_ToNoExtractionIdentifierTable() try { var ex = Assert.Throws(() => joinable.AddUser(aggregate2)); - Assert.AreEqual("Cannot configure AggregateConfiguration UnitTestAggregate2 as join user because it does not contain exactly 1 IsExtractionIdentifier dimension", ex.Message); + Assert.AreEqual( + "Cannot configure AggregateConfiguration UnitTestAggregate2 as join user because it does not contain exactly 1 IsExtractionIdentifier dimension", + ex.Message); } finally { @@ -175,20 +206,21 @@ public void CreateUsers_ToNoExtractionIdentifierTable() public void QueryBuilderTest() { //make aggregate 2 a joinable - var joinable2 = new JoinableCohortAggregateConfiguration(CatalogueRepository,cohortIdentificationConfiguration, aggregate2); + var joinable2 = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate2); joinable2.AddUser(aggregate1); - var builder = new CohortQueryBuilder(aggregate1, null,null); + var builder = new CohortQueryBuilder(aggregate1, null, null); Console.WriteLine(builder.SQL); try { - using (var con = (SqlConnection)Database.Server.GetConnection()) { con.Open(); using var dbReader = new SqlCommand(builder.SQL, con).ExecuteReader(); - + //can read at least one row Assert.IsTrue(dbReader.Read()); } @@ -201,19 +233,19 @@ public void QueryBuilderTest() @"/*cic_{1}_UnitTestAggregate1*/ SELECT distinct -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM -["+TestDatabaseNames.Prefix+ @"ScratchArea].[dbo].[BulkData] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] LEFT Join ( /*cic_{1}_UnitTestAggregate2*/ SELECT distinct - [" + TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM - ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] ){0} -on ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] = {0}.chi",expectedTableAlias,cohortIdentificationConfiguration.ID), builder.SQL); - +on [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] = {0}.chi", expectedTableAlias, + cohortIdentificationConfiguration.ID), builder.SQL); } finally { @@ -225,11 +257,14 @@ LEFT Join ( [Test] public void QueryBuilderTest_AdditionalColumn() { - var anotherCol = aggregate2.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(e => e.GetRuntimeName().Equals("dtCreated")); + var anotherCol = aggregate2.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(e => e.GetRuntimeName().Equals("dtCreated")); aggregate2.AddDimension(anotherCol); //make aggregate 2 a joinable - var joinable2 = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate2); + var joinable2 = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate2); joinable2.AddUser(aggregate1); var expectedTableAlias = $"ix{joinable2.ID}"; @@ -240,7 +275,10 @@ public void QueryBuilderTest_AdditionalColumn() var filter1 = new AggregateFilter(CatalogueRepository, "Within 1 year of event", filterContainer1); var filter2 = new AggregateFilter(CatalogueRepository, "DateAfter2001", filterContainer2); - filter1.WhereSQL = string.Format("ABS(DATEDIFF(year, {0}.dtCreated, ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].dtCreated)) <= 1",expectedTableAlias); + filter1.WhereSQL = + string.Format( + "ABS(DATEDIFF(year, {0}.dtCreated, [" + TestDatabaseNames.Prefix + + @"ScratchArea].[dbo].[BulkData].dtCreated)) <= 1", expectedTableAlias); filter1.SaveToDatabase(); filter2.WhereSQL = "dtCreated > '2001-01-01'"; @@ -252,12 +290,12 @@ public void QueryBuilderTest_AdditionalColumn() aggregate2.RootFilterContainer_ID = filterContainer2.ID; aggregate2.SaveToDatabase(); - var builder = new CohortQueryBuilder(aggregate1, null,null); + var builder = new CohortQueryBuilder(aggregate1, null, null); Console.WriteLine(builder.SQL); - + try { using (var con = (SqlConnection)Database.Server.GetConnection()) @@ -278,29 +316,29 @@ public void QueryBuilderTest_AdditionalColumn() @"/*cic_{1}_UnitTestAggregate1*/ SELECT distinct -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM -["+TestDatabaseNames.Prefix+ @"ScratchArea].[dbo].[BulkData] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] LEFT Join ( /*cic_{1}_UnitTestAggregate2*/ SELECT distinct - [" + TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi], ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[dtCreated] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi], [" + TestDatabaseNames.Prefix + + @"ScratchArea].[dbo].[BulkData].[dtCreated] FROM - ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] + [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] WHERE ( /*DateAfter2001*/ dtCreated > '2001-01-01' ) ){0} -on ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] = {0}.chi +on [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] = {0}.chi WHERE ( /*Within 1 year of event*/ -ABS(DATEDIFF(year, {0}.dtCreated, ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].dtCreated)) <= 1 -)", expectedTableAlias,cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); - +ABS(DATEDIFF(year, {0}.dtCreated, [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].dtCreated)) <= 1 +)", expectedTableAlias, cohortIdentificationConfiguration.ID)), CollapseWhitespace(builder.SQL)); } finally { @@ -310,7 +348,7 @@ SELECT distinct filterContainer1.DeleteInDatabase(); filterContainer2.DeleteInDatabase(); - + joinable2.Users[0].DeleteInDatabase(); joinable2.DeleteInDatabase(); } @@ -319,11 +357,14 @@ SELECT distinct [Test] public void QueryBuilderTest_JoinableCloning() { - var anotherCol = aggregate2.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(e => e.GetRuntimeName().Equals("dtCreated")); + var anotherCol = aggregate2.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(e => e.GetRuntimeName().Equals("dtCreated")); aggregate2.AddDimension(anotherCol); //make aggregate 2 a joinable - var joinable2 = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate2); + var joinable2 = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate2); joinable2.AddUser(aggregate1); var expectedTableAlias = $"ix{joinable2.ID}"; @@ -334,7 +375,10 @@ public void QueryBuilderTest_JoinableCloning() var filter1 = new AggregateFilter(CatalogueRepository, "Within 1 year of event", filterContainer1); var filter2 = new AggregateFilter(CatalogueRepository, "DateAfter2001", filterContainer2); - filter1.WhereSQL = string.Format("ABS(DATEDIFF(year, {0}.dtCreated, ["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].dtCreated)) <= 1", expectedTableAlias); + filter1.WhereSQL = + string.Format( + "ABS(DATEDIFF(year, {0}.dtCreated, [" + TestDatabaseNames.Prefix + + @"ScratchArea].[dbo].[BulkData].dtCreated)) <= 1", expectedTableAlias); filter1.SaveToDatabase(); filter2.WhereSQL = "dtCreated > '2001-01-01'"; @@ -347,48 +391,55 @@ public void QueryBuilderTest_JoinableCloning() aggregate2.SaveToDatabase(); //add the first aggregate to the configuration - rootcontainer.AddChild(aggregate1,1); + rootcontainer.AddChild(aggregate1, 1); - var globalParameter = new AnyTableSqlParameter(CatalogueRepository, cohortIdentificationConfiguration,"DECLARE @fish varchar(50)") - { - Comment = "Comments for the crazies", - Value = "'fishes'" - }; + var globalParameter = new AnyTableSqlParameter(CatalogueRepository, cohortIdentificationConfiguration, + "DECLARE @fish varchar(50)") + { + Comment = "Comments for the crazies", + Value = "'fishes'" + }; globalParameter.SaveToDatabase(); - var builder = new CohortQueryBuilder(cohortIdentificationConfiguration,null); + var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, null); try { var clone = cohortIdentificationConfiguration.CreateClone(new ThrowImmediatelyCheckNotifier()); - var cloneBuilder = new CohortQueryBuilder(clone,null); + var cloneBuilder = new CohortQueryBuilder(clone, null); var origSql = builder.SQL; var cloneOrigSql = cloneBuilder.SQL; - Console.WriteLine("//////////////////////////////////////////////VERBATIM//////////////////////////////////////////////"); + Console.WriteLine( + "//////////////////////////////////////////////VERBATIM//////////////////////////////////////////////"); Console.WriteLine(origSql); Console.WriteLine(cloneOrigSql); - Console.WriteLine("//////////////////////////////////////////////END VERBATIM//////////////////////////////////////////////"); + Console.WriteLine( + "//////////////////////////////////////////////END VERBATIM//////////////////////////////////////////////"); var builderSql = Regex.Replace(Regex.Replace(origSql, "cic_[0-9]+_", ""), "ix[0-9]+", "ix"); - var cloneBuilderSql = Regex.Replace(Regex.Replace(cloneOrigSql, "cic_[0-9]+_", ""), "ix[0-9]+", "ix").Replace("(Clone)", "");//get rid of explicit ix53 etc for the comparison + var cloneBuilderSql = Regex.Replace(Regex.Replace(cloneOrigSql, "cic_[0-9]+_", ""), "ix[0-9]+", "ix") + .Replace("(Clone)", ""); //get rid of explicit ix53 etc for the comparison - Console.WriteLine("//////////////////////////////////////////////TEST COMPARISON IS//////////////////////////////////////////////"); + Console.WriteLine( + "//////////////////////////////////////////////TEST COMPARISON IS//////////////////////////////////////////////"); Console.WriteLine(builderSql); Console.WriteLine(cloneBuilderSql); - Console.WriteLine("//////////////////////////////////////////////END COMPARISON//////////////////////////////////////////////"); + Console.WriteLine( + "//////////////////////////////////////////////END COMPARISON//////////////////////////////////////////////"); Assert.AreEqual(builderSql, cloneBuilderSql); ////////////////Cleanup Database////////////////////////////// //find the WHERE logic too - var containerClone = clone.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively()//get all the aggregates - .Union(clone.GetAllJoinables().Select(j=>j.AggregateConfiguration))//including the joinables - .Where(a => a.RootFilterContainer_ID != null)//that have WHERE sql - .Select(ag => ag.RootFilterContainer);//grab their containers so we can clean them SetUp + var containerClone = clone.RootCohortAggregateContainer + .GetAllAggregateConfigurationsRecursively() //get all the aggregates + .Union(clone.GetAllJoinables().Select(j => j.AggregateConfiguration)) //including the joinables + .Where(a => a.RootFilterContainer_ID != null) //that have WHERE sql + .Select(ag => ag.RootFilterContainer); //grab their containers so we can clean them SetUp ((IDeleteable)clone.GetAllParameters()[0]).DeleteInDatabase(); clone.DeleteInDatabase(); @@ -423,24 +474,27 @@ public void JoinablesWithCache() _queryCachingDatabase = To; //make aggregate 2 a joinable - var joinable2 = new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, aggregate2); + var joinable2 = + new JoinableCohortAggregateConfiguration(CatalogueRepository, cohortIdentificationConfiguration, + aggregate2); joinable2.AddUser(aggregate1); //make aggregate 2 have an additional column (dtCreated) - var anotherCol = aggregate2.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(e => e.GetRuntimeName().Equals("dtCreated")); + var anotherCol = aggregate2.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(e => e.GetRuntimeName().Equals("dtCreated")); aggregate2.AddDimension(anotherCol); //create a caching server var scripter = new MasterDatabaseScriptExecutor(_queryCachingDatabase); scripter.CreateAndPatchDatabase(new QueryCachingPatcher(), new AcceptAllCheckNotifier()); - var queryCachingDatabaseServer = new ExternalDatabaseServer(CatalogueRepository, queryCachingDatabaseName,null); + var queryCachingDatabaseServer = + new ExternalDatabaseServer(CatalogueRepository, queryCachingDatabaseName, null); queryCachingDatabaseServer.SetProperties(_queryCachingDatabase); - + try { - - var builderForCaching = new CohortQueryBuilder(aggregate2, null,null); + var builderForCaching = new CohortQueryBuilder(aggregate2, null, null); var cacheDt = new DataTable(); using (var con = (SqlConnection)Database.Server.GetConnection()) @@ -451,11 +505,12 @@ public void JoinablesWithCache() } var cacheManager = new CachedAggregateConfigurationResultsManager(queryCachingDatabaseServer); - cacheManager.CommitResults(new CacheCommitJoinableInceptionQuery(aggregate2, builderForCaching.SQL, cacheDt, null,30)); + cacheManager.CommitResults( + new CacheCommitJoinableInceptionQuery(aggregate2, builderForCaching.SQL, cacheDt, null, 30)); try { - var builder = new CohortQueryBuilder(aggregate1, null,null) + var builder = new CohortQueryBuilder(aggregate1, null, null) { //make the builder use the query cache we just set SetUp CacheServer = queryCachingDatabaseServer @@ -482,21 +537,20 @@ public void JoinablesWithCache() @"/*cic_{2}_UnitTestAggregate1*/ SELECT distinct -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData].[chi] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] FROM -["+TestDatabaseNames.Prefix+@"ScratchArea].[dbo].[BulkData] +[" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData] LEFT Join ( /*Cached:cic_{2}_UnitTestAggregate2*/ select * from [{3}]..[JoinableInceptionQuery_AggregateConfiguration{1}] ){0} on [" + TestDatabaseNames.Prefix + @"ScratchArea].[dbo].[BulkData].[chi] = {0}.chi", - expectedTableAlias, //{0} + expectedTableAlias, //{0} aggregate2.ID, //{1} - cohortIdentificationConfiguration.ID,//{2} + cohortIdentificationConfiguration.ID, //{2} queryCachingDatabaseName) //{3} ), CollapseWhitespace(builder.SQL)); - } finally { @@ -504,16 +558,10 @@ LEFT Join ( joinable2.DeleteInDatabase(); } } - finally + finally { - queryCachingDatabaseServer.DeleteInDatabase(); DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(queryCachingDatabaseName).Drop(); - } - - - - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CohortCreation/SimpleCohortIdentificationTests.cs b/Rdmp.Core.Tests/CohortCreation/SimpleCohortIdentificationTests.cs index 24802a700c..13cf973454 100644 --- a/Rdmp.Core.Tests/CohortCreation/SimpleCohortIdentificationTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/SimpleCohortIdentificationTests.cs @@ -11,18 +11,18 @@ namespace Rdmp.Core.Tests.CohortCreation; -public class SimpleCohortIdentificationTests:DatabaseTests +public class SimpleCohortIdentificationTests : DatabaseTests { [Test] public void CreateNewCohortIdentificationConfiguration_SaveAndReload() { var config = new CohortIdentificationConfiguration(CatalogueRepository, "franky"); - + try { Assert.IsTrue(config.Exists()); - Assert.AreEqual("franky",config.Name); - + Assert.AreEqual("franky", config.Name); + config.Description = "Hi there"; config.SaveToDatabase(); @@ -30,7 +30,7 @@ public void CreateNewCohortIdentificationConfiguration_SaveAndReload() var config2 = CatalogueRepository.GetObjectByID(config.ID); Assert.AreEqual("Hi there", config2.Description); } - finally + finally { config.DeleteInDatabase(); Assert.IsFalse(config.Exists()); @@ -40,11 +40,11 @@ public void CreateNewCohortIdentificationConfiguration_SaveAndReload() [Test] public void ContainerCreate() { - var container = new CohortAggregateContainer(CatalogueRepository,SetOperation.UNION); + var container = new CohortAggregateContainer(CatalogueRepository, SetOperation.UNION); try { - Assert.AreEqual(SetOperation.UNION,container.Operation); + Assert.AreEqual(SetOperation.UNION, container.Operation); container.Operation = SetOperation.INTERSECT; container.SaveToDatabase(); @@ -62,14 +62,14 @@ public void ContainerCreate() [Test] public void Container_Subcontainering() { - var container = new CohortAggregateContainer(CatalogueRepository,SetOperation.UNION); + var container = new CohortAggregateContainer(CatalogueRepository, SetOperation.UNION); - var container2 = new CohortAggregateContainer(CatalogueRepository,SetOperation.INTERSECT); + var container2 = new CohortAggregateContainer(CatalogueRepository, SetOperation.INTERSECT); try { Assert.AreEqual(0, container.GetSubContainers().Length); - + Assert.AreEqual(0, container.GetSubContainers().Length); //set container to parent diff --git a/Rdmp.Core.Tests/CommandExecution/AxisAndPivotCLITests.cs b/Rdmp.Core.Tests/CommandExecution/AxisAndPivotCLITests.cs index 04db53097f..05bccda8c9 100644 --- a/Rdmp.Core.Tests/CommandExecution/AxisAndPivotCLITests.cs +++ b/Rdmp.Core.Tests/CommandExecution/AxisAndPivotCLITests.cs @@ -18,10 +18,12 @@ public void SetPivot_DimensionNonExistant() { var ac = WhenIHaveA(); - var cmd = new ExecuteCommandSetPivot(GetMockActivator().Object, ac,"fff"); - var ex = Assert.Throws(()=>cmd.Execute()); - - Assert.AreEqual("Could not find AggregateDimension fff in Aggregate My graph so could not set it as a pivot dimension. Try adding the column to the aggregate first", ex.Message); + var cmd = new ExecuteCommandSetPivot(GetMockActivator().Object, ac, "fff"); + var ex = Assert.Throws(() => cmd.Execute()); + + Assert.AreEqual( + "Could not find AggregateDimension fff in Aggregate My graph so could not set it as a pivot dimension. Try adding the column to the aggregate first", + ex.Message); } [Test] @@ -29,8 +31,8 @@ public void SetPivot_Exists() { var ac = WhenIHaveA(); var dim = WhenIHaveA(); - - + + dim.AggregateConfiguration_ID = ac.ID; dim.Alias = "frogmarch"; @@ -57,9 +59,10 @@ public void SetPivot_ExistsButIsADate() dim.ColumnInfo.Data_type = "datetime"; var cmd = new ExecuteCommandSetPivot(GetMockActivator().Object, ac, "frogmarch"); - var ex = Assert.Throws(()=>cmd.Execute()); + var ex = Assert.Throws(() => cmd.Execute()); - Assert.AreEqual("AggregateDimension frogmarch is a Date so cannot set it as a Pivot for Aggregate My graph",ex.Message); + Assert.AreEqual("AggregateDimension frogmarch is a Date so cannot set it as a Pivot for Aggregate My graph", + ex.Message); } [Test] @@ -70,7 +73,9 @@ public void SetAxis_DimensionNonExistant() var cmd = new ExecuteCommandSetAxis(GetMockActivator().Object, ac, "fff"); var ex = Assert.Throws(() => cmd.Execute()); - Assert.AreEqual("Could not find AggregateDimension fff in Aggregate My graph so could not set it as an axis dimension. Try adding the column to the aggregate first", ex.Message); + Assert.AreEqual( + "Could not find AggregateDimension fff in Aggregate My graph so could not set it as an axis dimension. Try adding the column to the aggregate first", + ex.Message); } [Test] @@ -110,6 +115,7 @@ public void SetAxis_ExistsButIsNotADate() var cmd = new ExecuteCommandSetAxis(GetMockActivator().Object, ac, "frogmarch"); var ex = Assert.Throws(() => cmd.Execute()); - Assert.AreEqual("AggregateDimension frogmarch is not a Date so cannot set it as an axis for Aggregate My graph", ex.Message); + Assert.AreEqual("AggregateDimension frogmarch is not a Date so cannot set it as an axis for Aggregate My graph", + ex.Message); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/CommandCliTests.cs b/Rdmp.Core.Tests/CommandExecution/CommandCliTests.cs index 162a407214..e858f51bbe 100644 --- a/Rdmp.Core.Tests/CommandExecution/CommandCliTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/CommandCliTests.cs @@ -34,15 +34,15 @@ protected override void OneTimeSetUp() protected CommandInvoker GetInvoker() { - var invoker = new CommandInvoker(new ConsoleInputManager(RepositoryLocator,new ThrowImmediatelyCheckNotifier()) + var invoker = new CommandInvoker(new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }); - invoker.CommandImpossible +=(s,c)=> throw new Exception(c.Command.ReasonCommandImpossible); + invoker.CommandImpossible += (s, c) => throw new Exception(c.Command.ReasonCommandImpossible); return invoker; } - + protected Mock GetMockActivator() { var mock = new Mock(); diff --git a/Rdmp.Core.Tests/CommandExecution/CommandInvokerTests.cs b/Rdmp.Core.Tests/CommandExecution/CommandInvokerTests.cs index 127b2a4f5f..fccca1e382 100644 --- a/Rdmp.Core.Tests/CommandExecution/CommandInvokerTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/CommandInvokerTests.cs @@ -28,10 +28,10 @@ protected override void OneTimeSetUp() [Timeout(5000)] public void Test_ListSupportedCommands_NoPicker() { - var mgr = GetActivator(); + var mgr = GetActivator(); var invoker = new CommandInvoker(mgr); - - invoker.ExecuteCommand(typeof(ExecuteCommandListSupportedCommands),null); + + invoker.ExecuteCommand(typeof(ExecuteCommandListSupportedCommands), null); } [Test] @@ -43,8 +43,8 @@ public void Test_Delete_WithPicker() WhenIHaveA(); - var picker = new CommandLineObjectPicker(new[] {"Catalogue:*"}, mgr); - invoker.ExecuteCommand(typeof(ExecuteCommandDelete),picker); + var picker = new CommandLineObjectPicker(new[] { "Catalogue:*" }, mgr); + invoker.ExecuteCommand(typeof(ExecuteCommandDelete), picker); } [Test] @@ -56,24 +56,20 @@ public void Test_Generic_WithPicker() WhenIHaveA(); - invoker.ExecuteCommand(typeof(GenericTestCommand),GetPicker("Catalogue:*")); - invoker.ExecuteCommand(typeof(GenericTestCommand),GetPicker("Pipeline")); - invoker.ExecuteCommand(typeof(GenericTestCommand), + invoker.ExecuteCommand(typeof(GenericTestCommand), GetPicker("Catalogue:*")); + invoker.ExecuteCommand(typeof(GenericTestCommand), GetPicker("Pipeline")); + invoker.ExecuteCommand(typeof(GenericTestCommand), GetPicker( "DatabaseType:MicrosoftSqlServer:Name:imaging:Server=localhost\\sqlexpress;Database=master;Trusted_Connection=True;", "true")); - } - private CommandLineObjectPicker GetPicker(params string[] args) - { - return new CommandLineObjectPicker(args, GetActivator()); - } + private CommandLineObjectPicker GetPicker(params string[] args) => new(args, GetActivator()); private class GenericTestCommand : BasicCommandExecution { private readonly T _arg; - + public GenericTestCommand(T a) { _arg = a; @@ -87,11 +83,11 @@ public override void Execute() } } - private class GenericTestCommand : BasicCommandExecution + private class GenericTestCommand : BasicCommandExecution { private readonly T1 _a; private readonly T2 _b; - + public GenericTestCommand(T1 a, T2 b) { _a = a; diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddNewFilterContainerTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddNewFilterContainerTests.cs index 6b12b39311..17e77483b2 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddNewFilterContainerTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddNewFilterContainerTests.cs @@ -20,16 +20,17 @@ public void TestNormalCase() { var ac = WhenIHaveA(); var cmd = new ExecuteCommandAddNewFilterContainer(new ThrowImmediatelyActivator(RepositoryLocator), ac); - + Assert.IsNull(ac.RootFilterContainer_ID); - + Assert.IsNull(cmd.ReasonCommandImpossible); Assert.IsFalse(cmd.IsImpossible); cmd.Execute(); - + Assert.IsNotNull(ac.RootFilterContainer_ID); } + [Test] public void Impossible_BecauseAlreadyHasContainer() { @@ -43,6 +44,7 @@ public void Impossible_BecauseAlreadyHasContainer() Assert.AreEqual("There is already a root filter container on this object", cmd.ReasonCommandImpossible); Assert.IsTrue(cmd.IsImpossible); } + [Test] public void Impossible_BecauseAPI() { diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddPipelineComponentTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddPipelineComponentTests.cs index fd05e44237..b27c66e9a8 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddPipelineComponentTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAddPipelineComponentTests.cs @@ -27,8 +27,8 @@ public void TestCreatePipelineWithCommands() Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(DelimitedFlatFileDataFlowSource)); - Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(CleanStrings),"2"); - Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(ColumnSwapper),"1"); + Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(CleanStrings), "2"); + Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(ColumnSwapper), "1"); Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(ExecuteFullExtractionToDatabaseMSSql)); @@ -49,8 +49,6 @@ public void TestCreatePipelineWithCommands() Assert.IsNotNull(p.Destination); Assert.AreEqual(typeof(ExecuteFullExtractionToDatabaseMSSql), p.Destination.GetClassAsSystemType()); Assert.IsNotEmpty(p.Destination.GetAllArguments()); - - } [Test] @@ -61,10 +59,12 @@ public void TestCreatePipeline_TooManySources() Assert.IsNull(p.Source); Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(DelimitedFlatFileDataFlowSource)); - var ex = Assert.Throws(()=>Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(DelimitedFlatFileDataFlowSource))); + var ex = Assert.Throws(() => + Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(DelimitedFlatFileDataFlowSource))); - Assert.AreEqual("Pipeline 'My Pipeline' already has a source",ex.Message); + Assert.AreEqual("Pipeline 'My Pipeline' already has a source", ex.Message); } + [Test] public void TestCreatePipeline_TooManyDestinations() { @@ -73,7 +73,8 @@ public void TestCreatePipeline_TooManyDestinations() Assert.IsNull(p.Source); Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(ExecuteFullExtractionToDatabaseMSSql)); - var ex = Assert.Throws(() => Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(ExecuteFullExtractionToDatabaseMSSql))); + var ex = Assert.Throws(() => + Run("AddPipelineComponent", $"Pipeline:{p.ID}", nameof(ExecuteFullExtractionToDatabaseMSSql))); Assert.AreEqual("Pipeline 'My Pipeline' already has a destination", ex.Message); } diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAlterTableMakeDistinctTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAlterTableMakeDistinctTests.cs index 8acb1b39d9..1b19ce268f 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAlterTableMakeDistinctTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandAlterTableMakeDistinctTests.cs @@ -18,7 +18,6 @@ namespace Rdmp.Core.Tests.CommandExecution; internal class ExecuteCommandAlterTableMakeDistinctTests : DatabaseTests { - [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] [TestCase(DatabaseType.PostgreSql)] @@ -36,11 +35,12 @@ public void Test(DatabaseType dbType) var tbl = db.CreateTable("MyTable", dt); - Import(tbl, out var tblInfo,out _); + Import(tbl, out var tblInfo, out _); Assert.AreEqual(5, tbl.GetRowCount()); - var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; + var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) + { DisallowInput = true }; var cmd = new ExecuteCommandAlterTableMakeDistinct(activator, tblInfo, 700, true); @@ -49,12 +49,12 @@ public void Test(DatabaseType dbType) cmd.Execute(); Assert.AreEqual(2, tbl.GetRowCount()); - + tbl.CreatePrimaryKey(tbl.DiscoverColumn("fff")); cmd = new ExecuteCommandAlterTableMakeDistinct(activator, tblInfo, 700, true); - var ex = Assert.Throws(()=>cmd.Execute()); + var ex = Assert.Throws(() => cmd.Execute()); Assert.AreEqual("Table 'MyTable' has primary key columns so cannot contain duplication", ex.Message); } diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandConfirmLogsTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandConfirmLogsTests.cs index 5852a10895..46531505df 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandConfirmLogsTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandConfirmLogsTests.cs @@ -33,11 +33,11 @@ public void ConfirmLogs_NoEntries_Throws() lm.CreateNewLoggingTaskIfNotExists("GGG"); var cmd = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), lmd); - var ex = Assert.Throws(()=>cmd.Execute()); + var ex = Assert.Throws(() => cmd.Execute()); Assert.AreEqual("There are no log entries for MyLmd", ex.Message); - } + [TestCase(true)] [TestCase(false)] public void ConfirmLogs_HappyEntries_Passes(bool withinTime) @@ -53,14 +53,14 @@ public void ConfirmLogs_HappyEntries_Passes(bool withinTime) var lm = new LogManager(lmd.GetDistinctLoggingDatabase()); lm.CreateNewLoggingTaskIfNotExists("FFF"); var logEntry = lm.CreateDataLoadInfo("FFF", "pack o' cards", "going down gambling", null, true); - + // we mark it as completed successfully - this is a good, happy log entry logEntry.CloseAndMarkComplete(); var cmd = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), //within last 10 hours - lmd, withinTime ? "10:00:00":null); + lmd, withinTime ? "10:00:00" : null); Assert.DoesNotThrow(() => cmd.Execute()); } @@ -86,6 +86,7 @@ public void ConfirmLogs_SadEntry_BecauseNeverEnded_Throws() StringAssert.IsMatch("Latest logs for MyLmd .* indicate that it did not complete", ex.Message); } + [Test] public void ConfirmLogs_SadEntryWithEx_Throws() { @@ -106,14 +107,12 @@ public void ConfirmLogs_SadEntryWithEx_Throws() var ex = Assert.Throws(() => cmd.Execute()); StringAssert.IsMatch("Latest logs for MyLmd .* indicate that it failed", ex.Message); - } [Test] public void ConfirmLogs_NotWithinTime_Throws() { - var lmd = new LoadMetadata(CatalogueRepository, "MyLmd"); var cata = new Catalogue(CatalogueRepository, "myCata") { @@ -132,10 +131,11 @@ public void ConfirmLogs_NotWithinTime_Throws() Thread.Sleep(5000); // but we want this to have finished in the last second - var cmd = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), lmd,"00:00:01"); + var cmd = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), lmd, "00:00:01"); var ex = Assert.Throws(() => cmd.Execute()); - StringAssert.IsMatch("Latest logged activity for MyLmd is .*. This is older than the requested date threshold:.*", ex.Message); + StringAssert.IsMatch( + "Latest logged activity for MyLmd is .*. This is older than the requested date threshold:.*", ex.Message); } [Test] @@ -171,7 +171,8 @@ public void ConfirmLogs_With2CacheProgress_Throws() lm.CreateNewLoggingTaskIfNotExists(cp1.GetDistinctLoggingTask()); // create a log entry for cp1 only - var logEntry = lm.CreateDataLoadInfo(cp1.GetDistinctLoggingTask(), "pack o' cards", cp1.GetLoggingRunName(), null, true); + var logEntry = lm.CreateDataLoadInfo(cp1.GetDistinctLoggingTask(), "pack o' cards", cp1.GetLoggingRunName(), + null, true); // we mark it as completed successfully - this is a good, happy log entry logEntry.CloseAndMarkComplete(); @@ -181,7 +182,7 @@ public void ConfirmLogs_With2CacheProgress_Throws() Assert.DoesNotThrow(() => cmd1.Execute()); // The second cache has not logged any successes so should be unhappy - var cmd2 = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), cp2,null); + var cmd2 = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), cp2, null); var ex = Assert.Throws(() => cmd2.Execute()); Assert.AreEqual("There are no log entries for MyCoolCache", ex.Message); diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewDataLoadDirectoryTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewDataLoadDirectoryTests.cs index 877d12557b..323f6a89fb 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewDataLoadDirectoryTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewDataLoadDirectoryTests.cs @@ -16,13 +16,10 @@ internal class ExecuteCommandCreateNewDataLoadDirectoryTests : CommandCliTests public void TestCreateNewDataLoadDirectory_CreateDeepFolder_NoLmd() { var root = Path.Combine(TestContext.CurrentContext.WorkDirectory, "abc"); - if(Directory.Exists(root)) - { - Directory.Delete(root, true); - } + if (Directory.Exists(root)) Directory.Delete(root, true); var toCreate = Path.Combine(root, "def", "ghi"); - Run("CreateNewDataLoadDirectory","null", toCreate); + Run("CreateNewDataLoadDirectory", "null", toCreate); Assert.IsTrue(Directory.Exists(root)); } @@ -31,10 +28,7 @@ public void TestCreateNewDataLoadDirectory_CreateDeepFolder_NoLmd() public void TestCreateNewDataLoadDirectory_WithLoadMetadata() { var root = Path.Combine(TestContext.CurrentContext.WorkDirectory, "def"); - if (Directory.Exists(root)) - { - Directory.Delete(root, true); - } + if (Directory.Exists(root)) Directory.Delete(root, true); var lmd = WhenIHaveA(); Assert.IsNull(lmd.LocationOfFlatFiles); @@ -42,6 +36,6 @@ public void TestCreateNewDataLoadDirectory_WithLoadMetadata() Run("CreateNewDataLoadDirectory", $"LoadMetadata:{lmd.ID}", root); Assert.IsTrue(Directory.Exists(root)); - Assert.AreEqual(root,lmd.LocationOfFlatFiles); + Assert.AreEqual(root, lmd.LocationOfFlatFiles); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewFilterCliTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewFilterCliTests.cs index b614d51795..eb670da760 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewFilterCliTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandCreateNewFilterCliTests.cs @@ -25,11 +25,12 @@ public void TestNewFilterForAggregate() // has no container to start with (no filters) Assert.IsNull(ac.RootFilterContainer_ID); - Run("CreateNewFilter",$"{nameof(AggregateConfiguration)}:{ac.ID}"); + Run("CreateNewFilter", $"{nameof(AggregateConfiguration)}:{ac.ID}"); - Assert.IsNotNull(ac.RootFilterContainer_ID,"Should now have a container"); + Assert.IsNotNull(ac.RootFilterContainer_ID, "Should now have a container"); Assert.AreEqual(1, ac.RootFilterContainer.GetFilters().Length, "Expected a single new filter"); } + [Test] public void TestNewFilterForExtractionConfiguration() { @@ -42,6 +43,7 @@ public void TestNewFilterForExtractionConfiguration() Assert.IsNotNull(sds.RootFilterContainer_ID, "Should now have a container"); Assert.AreEqual(1, sds.RootFilterContainer.GetFilters().Length, "Expected a single new filter"); } + [Test] public void TestNewFilterForCatalogue() { diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandDeleteTestsCli.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandDeleteTestsCli.cs index 368d6e56ce..99b124c39c 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandDeleteTestsCli.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandDeleteTestsCli.cs @@ -18,7 +18,7 @@ public void TestDeletingACatalogue_NoneInDbIsFine() var prev = RepositoryLocator.CatalogueRepository.GetAllObjects(); Assert.IsEmpty(prev); - Assert.AreEqual(0,Run("delete","Catalogue:bob")); + Assert.AreEqual(0, Run("delete", "Catalogue:bob")); var now = RepositoryLocator.CatalogueRepository.GetAllObjects(); Assert.IsEmpty(now); @@ -33,6 +33,7 @@ public void TestDeletingACatalogue_DeleteBecauseMatches() Assert.AreEqual(0, Run("delete", "Catalogue:bob")); Assert.IsFalse(cata.Exists()); } + [Test] public void TestDeletingACatalogue_DoesNotMatchPattern() { @@ -40,10 +41,10 @@ public void TestDeletingACatalogue_DoesNotMatchPattern() cata.Name = "ffff"; Assert.AreEqual(0, Run("delete", "Catalogue:bob")); - + // should not have been deleted because name does not match what is sought to be deleted Assert.IsTrue(cata.Exists()); - + //cleanup cata.DeleteInDatabase(); } @@ -56,7 +57,7 @@ public void TestDeleteMany_ThrowsBecauseNotExpected() var c2 = WhenIHaveA(); // delete all catalogues - var ex = Assert.Throws(()=>Run("delete", "Catalogue")); + var ex = Assert.Throws(() => Run("delete", "Catalogue")); Assert.AreEqual(ex.Message, "Allow delete many is false but multiple objects were matched for deletion (Mycata,Mycata)"); @@ -64,29 +65,31 @@ public void TestDeleteMany_ThrowsBecauseNotExpected() c1.DeleteInDatabase(); c2.DeleteInDatabase(); } + [Test] public void TestDeleteMany_Allowed() { - // 2 catalogues var c1 = WhenIHaveA(); var c2 = WhenIHaveA(); // delete all catalogues - Assert.AreEqual(0,Run("delete", "Catalogue","true")); + Assert.AreEqual(0, Run("delete", "Catalogue", "true")); Assert.IsFalse(c1.Exists()); Assert.IsFalse(c2.Exists()); } + [Test] public void TestDeleteMany_BadParameterFormat() { var c1 = WhenIHaveA(); // delete all catalogues - var ex = Assert.Throws(()=> Run("delete", "Catalogue", "FLIBBLE!")); + var ex = Assert.Throws(() => Run("delete", "Catalogue", "FLIBBLE!")); - Assert.AreEqual("Expected parameter at index 1 to be a System.Boolean (for parameter 'deleteMany') but it was FLIBBLE!", + Assert.AreEqual( + "Expected parameter at index 1 to be a System.Boolean (for parameter 'deleteMany') but it was FLIBBLE!", ex.Message); c1.DeleteInDatabase(); diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandListTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandListTests.cs index faf23f2755..651676adfc 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandListTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandListTests.cs @@ -18,25 +18,27 @@ internal class TestsExecuteCommandList : CommandCliTests [Test] public void Test_ExecuteCommandList_NoCataloguesParsing() { - foreach(var cat in RepositoryLocator.CatalogueRepository.GetAllObjects()) + foreach (var cat in RepositoryLocator.CatalogueRepository.GetAllObjects()) cat.DeleteInDatabase(); - Assert.IsEmpty(RepositoryLocator.CatalogueRepository.GetAllObjects(),"Failed to clear CatalogueRepository"); + Assert.IsEmpty(RepositoryLocator.CatalogueRepository.GetAllObjects(), + "Failed to clear CatalogueRepository"); GetInvoker().ExecuteCommand(typeof(ExecuteCommandList), - new CommandLineObjectPicker(new string[]{ "Catalogue"}, GetActivator())); + new CommandLineObjectPicker(new string[] { "Catalogue" }, GetActivator())); } - + [Test] public void Test_ExecuteCommandList_OneCatalogueParsing() { var c = WhenIHaveA(); GetInvoker().ExecuteCommand(typeof(ExecuteCommandList), - new CommandLineObjectPicker(new string[]{ "Catalogue"}, GetActivator())); - + new CommandLineObjectPicker(new string[] { "Catalogue" }, GetActivator())); + c.DeleteInDatabase(); } + [Test] public void Test_ExecuteCommandList_OneCatalogue() { @@ -46,8 +48,8 @@ public void Test_ExecuteCommandList_OneCatalogue() var mock = GetMockActivator(); - var cmd = new ExecuteCommandList(mock.Object,new []{c}); - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + var cmd = new ExecuteCommandList(mock.Object, new[] { c }); + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandRefreshBrokenCohortsTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandRefreshBrokenCohortsTests.cs index 473a9cdc5f..e8a8bb5c19 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandRefreshBrokenCohortsTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandRefreshBrokenCohortsTests.cs @@ -14,9 +14,8 @@ namespace Rdmp.Core.Tests.CommandExecution; -internal class ExecuteCommandRefreshBrokenCohortsTests +internal class ExecuteCommandRefreshBrokenCohortsTests { - [Test] public void TestBrokenCohort() { @@ -41,11 +40,12 @@ public void TestBrokenCohort() var repoLocator = new RepositoryProvider(repo); - var activator = new ConsoleInputManager(repoLocator, new ThrowImmediatelyCheckNotifier()) { + var activator = new ConsoleInputManager(repoLocator, new ThrowImmediatelyCheckNotifier()) + { DisallowInput = true }; - Assert.AreEqual(1,((DataExportChildProvider)activator.CoreChildProvider).ForbidListedSources.Count); + Assert.AreEqual(1, ((DataExportChildProvider)activator.CoreChildProvider).ForbidListedSources.Count); var cmd = new ExecuteCommandRefreshBrokenCohorts(activator) { @@ -53,7 +53,7 @@ public void TestBrokenCohort() // and find it missing again NoPublish = true }; - + Assert.IsFalse(cmd.IsImpossible); cmd.Execute(); @@ -64,8 +64,8 @@ public void TestBrokenCohort() cmd = new ExecuteCommandRefreshBrokenCohorts(activator); Assert.IsTrue(cmd.IsImpossible); Assert.AreEqual("There are no broken ExternalCohortTable to clear status on", cmd.ReasonCommandImpossible); - - cmd = new ExecuteCommandRefreshBrokenCohorts(activator,ect); + + cmd = new ExecuteCommandRefreshBrokenCohorts(activator, ect); Assert.IsTrue(cmd.IsImpossible); Assert.AreEqual("'yarg' is not broken", cmd.ReasonCommandImpossible); } diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandReplacedByTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandReplacedByTests.cs index b47fc18639..2b7b3195e8 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandReplacedByTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandReplacedByTests.cs @@ -19,10 +19,10 @@ public void CommandImpossible_BecauseNotDeprecated() var c1 = WhenIHaveA(); var c2 = WhenIHaveA(); - var cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object,c1,c2); - + var cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object, c1, c2); + Assert.IsTrue(cmd.IsImpossible); - StringAssert.Contains("is not marked IsDeprecated",cmd.ReasonCommandImpossible); + StringAssert.Contains("is not marked IsDeprecated", cmd.ReasonCommandImpossible); } [Test] @@ -30,35 +30,36 @@ public void CommandImpossible_BecauseDifferentTypes() { var c1 = WhenIHaveA(); var ci1 = WhenIHaveA(); - + c1.IsDeprecated = true; c1.SaveToDatabase(); - var cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object,c1,ci1); - + var cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object, c1, ci1); + Assert.IsTrue(cmd.IsImpossible); - StringAssert.Contains("because it is a different object Type",cmd.ReasonCommandImpossible); + StringAssert.Contains("because it is a different object Type", cmd.ReasonCommandImpossible); } + [Test] public void CommandImpossible_Allowed() { var c1 = WhenIHaveA(); var c2 = WhenIHaveA(); - + c1.IsDeprecated = true; c1.SaveToDatabase(); - var cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object,c1,c2); - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + var cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object, c1, c2); + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); var replacement = RepositoryLocator.CatalogueRepository - .GetAllObjectsWhere("Name",ExtendedProperty.ReplacedBy) - .Single(r=>r.IsReferenceTo(c1)); + .GetAllObjectsWhere("Name", ExtendedProperty.ReplacedBy) + .Single(r => r.IsReferenceTo(c1)); Assert.IsTrue(replacement.IsReferenceTo(c1)); - Assert.AreEqual(c2.ID.ToString(),replacement.Value); + Assert.AreEqual(c2.ID.ToString(), replacement.Value); // running command multiple times shouldn't result in duplicate objects cmd.Execute(); @@ -66,16 +67,15 @@ public void CommandImpossible_Allowed() cmd.Execute(); cmd.Execute(); - Assert.AreEqual(1,RepositoryLocator.CatalogueRepository + Assert.AreEqual(1, RepositoryLocator.CatalogueRepository .GetAllObjectsWhere("Name", ExtendedProperty.ReplacedBy) - .Count(r=>r.IsReferenceTo(c1))); + .Count(r => r.IsReferenceTo(c1))); - cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object,c1,null); + cmd = new ExecuteCommandReplacedBy(GetMockActivator().Object, c1, null); cmd.Execute(); Assert.IsEmpty(RepositoryLocator.CatalogueRepository .GetAllObjectsWhere("Name", ExtendedProperty.ReplacedBy) - .Where(r=>r.IsReferenceTo(c1))); - + .Where(r => r.IsReferenceTo(c1))); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetArgumentTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetArgumentTests.cs index 97f880e42d..11a9139918 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetArgumentTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetArgumentTests.cs @@ -18,22 +18,24 @@ internal class ExecuteCommandSetArgumentTests : CommandCliTests [Test] public void TestSetArgument_WrongArgCount() { - var picker = new CommandLineObjectPicker(new []{"yyy" }, GetActivator()); - var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object,picker); + var picker = new CommandLineObjectPicker(new[] { "yyy" }, GetActivator()); + var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object, picker); Assert.IsTrue(cmd.IsImpossible); - Assert.AreEqual("Wrong number of parameters supplied to command, expected 3 but got 1",cmd.ReasonCommandImpossible); + Assert.AreEqual("Wrong number of parameters supplied to command, expected 3 but got 1", + cmd.ReasonCommandImpossible); } + [Test] public void TestSetArgument_NotAHost() { var c = WhenIHaveA(); - var picker = new CommandLineObjectPicker(new []{$"Catalogue:{c.ID}","fff","yyy" }, GetActivator()); - var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object,picker); + var picker = new CommandLineObjectPicker(new[] { $"Catalogue:{c.ID}", "fff", "yyy" }, GetActivator()); + var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object, picker); Assert.IsTrue(cmd.IsImpossible); - Assert.AreEqual("First parameter must be an IArgumentHost",cmd.ReasonCommandImpossible); + Assert.AreEqual("First parameter must be an IArgumentHost", cmd.ReasonCommandImpossible); } [Test] @@ -42,50 +44,51 @@ public void TestSetArgument_NoArgumentFound() var pt = WhenIHaveA(); - var picker = new CommandLineObjectPicker(new []{$"ProcessTask:{pt.ID}","fff","yyy" }, GetActivator()); - var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object,picker); + var picker = new CommandLineObjectPicker(new[] { $"ProcessTask:{pt.ID}", "fff", "yyy" }, GetActivator()); + var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object, picker); Assert.IsTrue(cmd.IsImpossible); - StringAssert.StartsWith("Could not find argument called 'fff' on ",cmd.ReasonCommandImpossible); + StringAssert.StartsWith("Could not find argument called 'fff' on ", cmd.ReasonCommandImpossible); } - + [Test] public void TestSetArgument_ArgumentWrongType() { var pta = WhenIHaveA(); var pt = pta.ProcessTask; - + pta.Name = "fff"; - + // Argument expects int but is given string value "yyy" pta.SetType(typeof(int)); - var picker = new CommandLineObjectPicker(new []{$"ProcessTask:{pt.ID}","fff","yyy" }, GetActivator()); - var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object,picker); + var picker = new CommandLineObjectPicker(new[] { $"ProcessTask:{pt.ID}", "fff", "yyy" }, GetActivator()); + var cmd = new ExecuteCommandSetArgument(GetMockActivator().Object, picker); Assert.IsTrue(cmd.IsImpossible); - StringAssert.StartsWith("Provided value 'yyy' does not match expected Type 'Int32' of ",cmd.ReasonCommandImpossible); + StringAssert.StartsWith("Provided value 'yyy' does not match expected Type 'Int32' of ", + cmd.ReasonCommandImpossible); } - + [Test] public void TestSetArgument_Int_Valid() { var pta = WhenIHaveA(); var pt = pta.ProcessTask; - + pta.Name = "fff"; pta.SetType(typeof(int)); Assert.IsNull(pta.Value); - var picker = new CommandLineObjectPicker(new []{$"ProcessTask:{pt.ID}","fff","5" }, GetActivator()); - - Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument),picker)); + var picker = new CommandLineObjectPicker(new[] { $"ProcessTask:{pt.ID}", "fff", "5" }, GetActivator()); + + Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument), picker)); - Assert.AreEqual(5,pta.GetValueAsSystemType()); + Assert.AreEqual(5, pta.GetValueAsSystemType()); } - + [Test] public void TestSetArgument_Catalogue_Valid() { @@ -95,18 +98,20 @@ public void TestSetArgument_Catalogue_Valid() var pta = WhenIHaveA(); var pt = pta.ProcessTask; - + pta.Name = "fff"; pta.SetType(typeof(Catalogue)); Assert.IsNull(pta.Value); - var picker = new CommandLineObjectPicker(new []{$"ProcessTask:{pt.ID}","fff",$"Catalogue:kapow splat" }, GetActivator()); - - Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument),picker)); + var picker = new CommandLineObjectPicker(new[] { $"ProcessTask:{pt.ID}", "fff", $"Catalogue:kapow splat" }, + GetActivator()); + + Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument), picker)); - Assert.AreEqual(cata,pta.GetValueAsSystemType()); + Assert.AreEqual(cata, pta.GetValueAsSystemType()); } + [Test] public void TestSetArgument_CatalogueArrayOf1_Valid() { @@ -118,18 +123,20 @@ public void TestSetArgument_CatalogueArrayOf1_Valid() //let's also test that PipelineComponentArgument also work (not just ProcessTaskArgument) var pca = WhenIHaveA(); var pc = pca.PipelineComponent; - + pca.Name = "ggg"; pca.SetType(typeof(Catalogue[])); Assert.IsNull(pca.Value); - var picker = new CommandLineObjectPicker(new []{$"PipelineComponent:{pc.ID}","ggg",$"Catalogue:lolzzzyy" }, GetActivator()); - - Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument),picker)); + var picker = new CommandLineObjectPicker(new[] { $"PipelineComponent:{pc.ID}", "ggg", $"Catalogue:lolzzzyy" }, + GetActivator()); + + Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument), picker)); Assert.Contains(cata1, (System.Collections.ICollection)pca.GetValueAsSystemType()); } + [Test] public void TestSetArgument_CatalogueArrayOf2_Valid() { @@ -144,19 +151,21 @@ public void TestSetArgument_CatalogueArrayOf2_Valid() //let's also test that PipelineComponentArgument also work (not just ProcessTaskArgument) var pca = WhenIHaveA(); var pc = pca.PipelineComponent; - + pca.Name = "ggg"; pca.SetType(typeof(Catalogue[])); Assert.IsNull(pca.Value); - var picker = new CommandLineObjectPicker(new []{$"PipelineComponent:{pc.ID}","ggg",$"Catalogue:kapow*" }, GetActivator()); - - Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument),picker)); + var picker = new CommandLineObjectPicker(new[] { $"PipelineComponent:{pc.ID}", "ggg", $"Catalogue:kapow*" }, + GetActivator()); + + Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument), picker)); Assert.Contains(cata1, (System.Collections.ICollection)pca.GetValueAsSystemType()); Assert.Contains(cata2, (System.Collections.ICollection)pca.GetValueAsSystemType()); } + [Test] public void TestSetArgument_CatalogueArray_SetToNull_Valid() { @@ -168,17 +177,18 @@ public void TestSetArgument_CatalogueArray_SetToNull_Valid() //let's also test that PipelineComponentArgument also work (not just ProcessTaskArgument) var pca = WhenIHaveA(); var pc = pca.PipelineComponent; - + pca.Name = "ggg"; pca.SetType(typeof(Catalogue[])); - pca.SetValue(new Catalogue[]{ cata1}); + pca.SetValue(new Catalogue[] { cata1 }); pca.SaveToDatabase(); - + Assert.Contains(cata1, (System.Collections.ICollection)pca.GetValueAsSystemType()); - var picker = new CommandLineObjectPicker(new []{$"PipelineComponent:{pc.ID}","ggg",$"Null" }, GetActivator()); - - Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument),picker)); + var picker = + new CommandLineObjectPicker(new[] { $"PipelineComponent:{pc.ID}", "ggg", $"Null" }, GetActivator()); + + Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetArgument), picker)); Assert.IsNull(pca.GetValueAsSystemType()); } diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtendedPropertyTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtendedPropertyTests.cs index 7efde66309..019fed5105 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtendedPropertyTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtendedPropertyTests.cs @@ -19,11 +19,12 @@ public void CommandImpossible_BecausePropertyDoesNotExist() { var c1 = WhenIHaveA(); - var cmd = new ExecuteCommandSetExtendedProperty(GetMockActivator().Object, new[] { c1 },"blarg","fff"); + var cmd = new ExecuteCommandSetExtendedProperty(GetMockActivator().Object, new[] { c1 }, "blarg", "fff"); Assert.IsTrue(cmd.IsImpossible); StringAssert.StartsWith("blarg is not a known property. Known properties are:", cmd.ReasonCommandImpossible); } + [Test] public void SetIsTemplate_OnMultipleObjects() { @@ -36,17 +37,17 @@ public void SetIsTemplate_OnMultipleObjects() Assert.IsEmpty( Repository.CatalogueRepository.GetExtendedProperties(ac2)); - var cmd = new ExecuteCommandSetExtendedProperty(GetMockActivator().Object, new[] { ac1,ac2 }, - ExtendedProperty.IsTemplate,"true"); + var cmd = new ExecuteCommandSetExtendedProperty(GetMockActivator().Object, new[] { ac1, ac2 }, + ExtendedProperty.IsTemplate, "true"); - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); var declaration1 = Repository.CatalogueRepository.GetExtendedProperties(ac1).Single(); var declaration2 = Repository.CatalogueRepository.GetExtendedProperties(ac2).Single(); - foreach(var dec in new[] { declaration1,declaration2}) + foreach (var dec in new[] { declaration1, declaration2 }) { Assert.AreEqual("IsTemplate", dec.Name); Assert.AreEqual("true", dec.Value); @@ -66,6 +67,5 @@ public void SetIsTemplate_OnMultipleObjects() Repository.CatalogueRepository.GetExtendedProperties(ac1)); Assert.IsEmpty( Repository.CatalogueRepository.GetExtendedProperties(ac2)); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtractionIdentifierTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtractionIdentifierTests.cs index 6205d12451..344265527f 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtractionIdentifierTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSetExtractionIdentifierTests.cs @@ -18,23 +18,25 @@ internal class ExecuteCommandSetExtractionIdentifierTests : CommandCliTests public void TestSetExtractionIdentifier_Catalogue() { var ei1 = WhenIHaveA(); - + ei1.Alias = "happyfun"; ei1.IsExtractionIdentifier = false; ei1.SaveToDatabase(); - var cmd = new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object,ei1.CatalogueItem.Catalogue,null,"happyfun"); + var cmd = new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, ei1.CatalogueItem.Catalogue, + null, "happyfun"); cmd.Execute(); Assert.IsTrue(ei1.IsExtractionIdentifier); } + [Test] public void TestSetExtractionIdentifier_Catalogue_PickOther() { var ei1 = WhenIHaveA(); var otherCol = new ColumnInfo(Repository, "Other", "varchar", ei1.ColumnInfo.TableInfo); - var otherCatItem = new CatalogueItem(Repository, ei1.CatalogueItem.Catalogue,"Other"); + var otherCatItem = new CatalogueItem(Repository, ei1.CatalogueItem.Catalogue, "Other"); var otherEi = new ExtractionInformation(Repository, otherCatItem, otherCol, "FFF"); ei1.Alias = "happyfun"; @@ -46,7 +48,8 @@ public void TestSetExtractionIdentifier_Catalogue_PickOther() Assert.IsFalse(otherEi.IsExtractionIdentifier); // by picking the second (FFF) we should switch - var cmd = new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, ei1.CatalogueItem.Catalogue, null, "FFF"); + var cmd = new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, ei1.CatalogueItem.Catalogue, + null, "FFF"); cmd.Execute(); // original should no longer be the extraction identifer @@ -55,6 +58,7 @@ public void TestSetExtractionIdentifier_Catalogue_PickOther() // and the one picked should now be the only one Assert.IsTrue(otherEi.IsExtractionIdentifier); } + [Test] public void TestSetExtractionIdentifier_Catalogue_ButColumnDoesNotExist() { @@ -64,8 +68,9 @@ public void TestSetExtractionIdentifier_Catalogue_ButColumnDoesNotExist() ei1.IsExtractionIdentifier = false; ei1.SaveToDatabase(); - var ex = Assert.Throws(()=> - new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, ei1.CatalogueItem.Catalogue, null, "trollolo") + var ex = Assert.Throws(() => + new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, ei1.CatalogueItem.Catalogue, null, + "trollolo") .Execute()); Assert.AreEqual("Could not find column(s) trollolo amongst available columns (happyfun)", ex.Message); } @@ -82,7 +87,7 @@ public void TestSetExtractionIdentifier_Configuration() var config = Repository.GetObjectByID(ec1.ExtractionConfiguration_ID); - var cmd = new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, + var cmd = new ExecuteCommandSetExtractionIdentifier(GetMockActivator().Object, ec1.CatalogueExtractionInformation.CatalogueItem.Catalogue, config , "happyfun"); diff --git a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSimilarTests.cs b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSimilarTests.cs index 85d1d60de9..486314c57c 100644 --- a/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSimilarTests.cs +++ b/Rdmp.Core.Tests/CommandExecution/ExecuteCommandSimilarTests.cs @@ -42,7 +42,6 @@ public void FindDifferent_ColumnInfosSame() c1.DeleteInDatabase(); c2.DeleteInDatabase(); - } [Test] @@ -62,6 +61,7 @@ public void FindDifferent_ColumnInfosDiffer_OnType() c1.DeleteInDatabase(); c2.DeleteInDatabase(); } + [Test] public void FindDifferent_ColumnInfosDiffer_OnCollation() { diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandAssociateCatalogueWithLoadMetadata.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandAssociateCatalogueWithLoadMetadata.cs index 43d6f15102..02b623e25e 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandAssociateCatalogueWithLoadMetadata.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandAssociateCatalogueWithLoadMetadata.cs @@ -14,25 +14,24 @@ namespace Rdmp.Core.Tests.CommandExecution; internal class TestExecuteCommandAssociateCatalogueWithLoadMetadata : CommandCliTests { - [Test] public void TestExecuteCommandAssociateCatalogueWithLoadMetadata_Simple() { - var cata1 = new Catalogue(RepositoryLocator.CatalogueRepository,"fff"); - var cata2 = new Catalogue(RepositoryLocator.CatalogueRepository,"bbb"); + var cata1 = new Catalogue(RepositoryLocator.CatalogueRepository, "fff"); + var cata2 = new Catalogue(RepositoryLocator.CatalogueRepository, "bbb"); Assert.IsNull(cata1.LoadMetadata); Assert.IsNull(cata2.LoadMetadata); - var lmd = new LoadMetadata(RepositoryLocator.CatalogueRepository,"mylmd"); + var lmd = new LoadMetadata(RepositoryLocator.CatalogueRepository, "mylmd"); GetInvoker().ExecuteCommand(typeof(ExecuteCommandAssociateCatalogueWithLoadMetadata), - new CommandLineObjectPicker(new[]{$"LoadMetadata:{lmd.ID}", "Catalogue:fff"}, GetActivator())); + new CommandLineObjectPicker(new[] { $"LoadMetadata:{lmd.ID}", "Catalogue:fff" }, GetActivator())); cata1.RevertToDatabaseState(); cata2.RevertToDatabaseState(); - Assert.AreEqual(lmd.ID,cata1.LoadMetadata_ID); + Assert.AreEqual(lmd.ID, cata1.LoadMetadata_ID); Assert.IsNull(cata2.LoadMetadata); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribe.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribe.cs index ac5d9bf387..fb114b168c 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribe.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribe.cs @@ -24,8 +24,8 @@ public void TestDescribeCatalogue() var c = WhenIHaveA(); c.Description = "fish"; - var describe = new ExecuteCommandDescribe(mock.Object,new []{c}); - Assert.IsFalse(describe.IsImpossible,describe.ReasonCommandImpossible); + var describe = new ExecuteCommandDescribe(mock.Object, new[] { c }); + Assert.IsFalse(describe.IsImpossible, describe.ReasonCommandImpossible); describe.Execute(); diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribeCommand.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribeCommand.cs index c28ba4a2f9..0f060b3134 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribeCommand.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandDescribeCommand.cs @@ -13,7 +13,6 @@ namespace Rdmp.Core.Tests.CommandExecution; internal class TestExecuteCommandDescribeCommand : CommandCliTests { - /// /// Asserts that the help text matches your text /// @@ -23,8 +22,9 @@ private void AssertHelpIs(string expectedHelp, Type forCommand) { var activator = GetMockActivator().Object; - var cmd = new ExecuteCommandDescribe(activator, new CommandLineObjectPicker(new []{forCommand.Name},activator)); - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + var cmd = new ExecuteCommandDescribe(activator, + new CommandLineObjectPicker(new[] { forCommand.Name }, activator)); + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); StringAssert.Contains(expectedHelp, cmd.HelpShown); @@ -36,42 +36,42 @@ public void Test_DescribeDeleteCommand() AssertHelpIs(@" Delete PARAMETERS: -deletables IDeleteable[] The object(s) you want to delete. If multiple you must set deleteMany to true", typeof(ExecuteCommandDelete)); +deletables IDeleteable[] The object(s) you want to delete. If multiple you must set deleteMany to true", + typeof(ExecuteCommandDelete)); } [Test] public void Test_ImportTableInfo_CommandHelp() { - AssertHelpIs( + AssertHelpIs( @" ImportTableInfo PARAMETERS: table DiscoveredTable The table or view you want to reference from RDMP. See PickTable for syntax createCatalogue Boolean True to create a Catalogue as well as a TableInfo" - ,typeof(ExecuteCommandImportTableInfo)); - + , typeof(ExecuteCommandImportTableInfo)); } [Test] public void Test_DescribeCommand_ExecuteCommandNewObject() { - AssertHelpIs( @" NewObject + AssertHelpIs(@" NewObject PARAMETERS: type The object to create e.g. Catalogue -args Dynamic list of values to satisfy the types constructor",typeof(ExecuteCommandNewObject)); +args Dynamic list of values to satisfy the types constructor", typeof(ExecuteCommandNewObject)); } [Test] public void Test_DescribeCommand_ExecuteCommandSetArgument() { - AssertHelpIs( @" SetArgument + AssertHelpIs(@" SetArgument PARAMETERS: component Module to set value on e.g. ProcessTask:1 argName Name of an argument to set on the component e.g. Retry argValue New value for argument e.g. Null, True, Catalogue:5 etc -",typeof(ExecuteCommandSetArgument)); +", typeof(ExecuteCommandSetArgument)); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportFilterContainerTree.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportFilterContainerTree.cs index 6062e108b2..a665de62cd 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportFilterContainerTree.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportFilterContainerTree.cs @@ -25,83 +25,82 @@ public void TestImportTree_FromCohortIdentificationConfiguration_ToSelectedDatas var cata = sds.ExtractableDataSet.Catalogue; - var cic = new CohortIdentificationConfiguration(Repository,"my cic"); + var cic = new CohortIdentificationConfiguration(Repository, "my cic"); cic.CreateRootContainerIfNotExists(); - var ac = new AggregateConfiguration(Repository,cata,"myagg"); + var ac = new AggregateConfiguration(Repository, cata, "myagg"); ac.CreateRootContainerIfNotExists(); - cic.RootCohortAggregateContainer.AddChild(ac,1); + cic.RootCohortAggregateContainer.AddChild(ac, 1); - var filterToImport = new AggregateFilter(Repository,"MyFilter"){WhereSQL = "true" }; + var filterToImport = new AggregateFilter(Repository, "MyFilter") { WhereSQL = "true" }; ac.RootFilterContainer.AddChild(filterToImport); - + //there should be no root container Assert.IsNull(sds.RootFilterContainer); //run the command - var mgr = new ConsoleInputManager(RepositoryLocator,new ThrowImmediatelyCheckNotifier()) + var mgr = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; - var cmd = new ExecuteCommandImportFilterContainerTree(mgr,sds,ac); - - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + var cmd = new ExecuteCommandImportFilterContainerTree(mgr, sds, ac); + + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); - + sds.ClearAllInjections(); Assert.IsNotNull(sds.RootFilterContainer); - Assert.AreEqual(1,sds.RootFilterContainer.GetFilters().Length); - Assert.AreEqual("MyFilter",sds.RootFilterContainer.GetFilters()[0].Name); - Assert.AreEqual("true",sds.RootFilterContainer.GetFilters()[0].WhereSQL); + Assert.AreEqual(1, sds.RootFilterContainer.GetFilters().Length); + Assert.AreEqual("MyFilter", sds.RootFilterContainer.GetFilters()[0].Name); + Assert.AreEqual("true", sds.RootFilterContainer.GetFilters()[0].WhereSQL); - Assert.AreNotEqual(filterToImport.GetType(),sds.RootFilterContainer.GetFilters()[0].GetType()); + Assert.AreNotEqual(filterToImport.GetType(), sds.RootFilterContainer.GetFilters()[0].GetType()); } [Test] public void TestImportTree_FromSelectedDatasets_ToCohortIdentificationConfiguration() { - // Import From Selected Dataset var sds = WhenIHaveA(); sds.CreateRootContainerIfNotExists(); - var filterToImport = new DeployedExtractionFilter(Repository,"MyFilter", (FilterContainer)sds.RootFilterContainer){WhereSQL = "true" }; + var filterToImport = + new DeployedExtractionFilter(Repository, "MyFilter", (FilterContainer)sds.RootFilterContainer) + { WhereSQL = "true" }; filterToImport.SaveToDatabase(); var cata = sds.ExtractableDataSet.Catalogue; // Into an Aggregate Configuration - var cic = new CohortIdentificationConfiguration(Repository,"my cic"); + var cic = new CohortIdentificationConfiguration(Repository, "my cic"); cic.CreateRootContainerIfNotExists(); - var ac = new AggregateConfiguration(Repository,cata,"myagg"); + var ac = new AggregateConfiguration(Repository, cata, "myagg"); + + cic.RootCohortAggregateContainer.AddChild(ac, 1); - cic.RootCohortAggregateContainer.AddChild(ac,1); - //there should be no root container Assert.IsNull(ac.RootFilterContainer); //run the command - var mgr = new ConsoleInputManager(RepositoryLocator,new ThrowImmediatelyCheckNotifier()) + var mgr = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; - var cmd = new ExecuteCommandImportFilterContainerTree(mgr,ac,sds); - - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + var cmd = new ExecuteCommandImportFilterContainerTree(mgr, ac, sds); + + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); - + ac.ClearAllInjections(); Assert.IsNotNull(ac.RootFilterContainer); - Assert.AreEqual(1,ac.RootFilterContainer.GetFilters().Length); - Assert.AreEqual("MyFilter",ac.RootFilterContainer.GetFilters()[0].Name); - Assert.AreEqual("true",ac.RootFilterContainer.GetFilters()[0].WhereSQL); - - Assert.AreNotEqual(filterToImport.GetType(),ac.RootFilterContainer.GetFilters()[0].GetType()); - + Assert.AreEqual(1, ac.RootFilterContainer.GetFilters().Length); + Assert.AreEqual("MyFilter", ac.RootFilterContainer.GetFilters()[0].Name); + Assert.AreEqual("true", ac.RootFilterContainer.GetFilters()[0].WhereSQL); + Assert.AreNotEqual(filterToImport.GetType(), ac.RootFilterContainer.GetFilters()[0].GetType()); } - + [Test] public void TestImportTree_FromCohortIdentificationConfiguration_ToSelectedDatasets_PreserveOperation() { @@ -109,14 +108,14 @@ public void TestImportTree_FromCohortIdentificationConfiguration_ToSelectedDatas var cata = sds.ExtractableDataSet.Catalogue; - var cic = new CohortIdentificationConfiguration(Repository,"my cic"); + var cic = new CohortIdentificationConfiguration(Repository, "my cic"); cic.CreateRootContainerIfNotExists(); - var ac = new AggregateConfiguration(Repository,cata,"myagg"); + var ac = new AggregateConfiguration(Repository, cata, "myagg"); ac.CreateRootContainerIfNotExists(); - cic.RootCohortAggregateContainer.AddChild(ac,1); + cic.RootCohortAggregateContainer.AddChild(ac, 1); - var filterToImport = new AggregateFilter(Repository,"MyFilter"){WhereSQL = "true" }; + var filterToImport = new AggregateFilter(Repository, "MyFilter") { WhereSQL = "true" }; var root = ac.RootFilterContainer; root.AddChild(filterToImport); root.Operation = FilterContainerOperation.OR; @@ -130,26 +129,23 @@ public void TestImportTree_FromCohortIdentificationConfiguration_ToSelectedDatas Assert.IsNull(sds.RootFilterContainer); //run the command - var mgr = new ConsoleInputManager(RepositoryLocator,new ThrowImmediatelyCheckNotifier()) + var mgr = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) { DisallowInput = true }; - var cmd = new ExecuteCommandImportFilterContainerTree(mgr,sds,ac); - - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + var cmd = new ExecuteCommandImportFilterContainerTree(mgr, sds, ac); + + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); - + sds.ClearAllInjections(); Assert.AreEqual(FilterContainerOperation.OR, sds.RootFilterContainer.Operation); Assert.IsNotNull(sds.RootFilterContainer); - Assert.AreEqual(1,sds.RootFilterContainer.GetFilters().Length); + Assert.AreEqual(1, sds.RootFilterContainer.GetFilters().Length); var subContainers = sds.RootFilterContainer.GetSubContainers(); Assert.AreEqual(2, subContainers.Length); - Assert.AreEqual(1, subContainers.Count(e=>e.Operation == FilterContainerOperation.AND)); + Assert.AreEqual(1, subContainers.Count(e => e.Operation == FilterContainerOperation.AND)); Assert.AreEqual(1, subContainers.Count(e => e.Operation == FilterContainerOperation.OR)); - - } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportTableInfo.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportTableInfo.cs index 67457763ed..410d05d1ed 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportTableInfo.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandImportTableInfo.cs @@ -16,31 +16,34 @@ internal class TestExecuteCommandImportTableInfo : CommandCliTests [Test] public void Test_ImportTableInfo_NoArguments() { - var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandImportTableInfo), new CommandLineObjectPicker(Array.Empty(), GetActivator()))); - StringAssert.StartsWith("Expected parameter at index 0 to be a FAnsi.Discovery.DiscoveredTable (for parameter 'table') but it was Missing",ex.Message); + StringAssert.StartsWith( + "Expected parameter at index 0 to be a FAnsi.Discovery.DiscoveredTable (for parameter 'table') but it was Missing", + ex.Message); } [Test] public void Test_ImportTableInfo_MalformedArgument() { var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandImportTableInfo), - new CommandLineObjectPicker(new string[]{ "MyTable"}, GetActivator()))); + new CommandLineObjectPicker(new string[] { "MyTable" }, GetActivator()))); - StringAssert.StartsWith("Expected parameter at index 0 to be a FAnsi.Discovery.DiscoveredTable (for parameter 'table') but it was MyTable",ex.Message); + StringAssert.StartsWith( + "Expected parameter at index 0 to be a FAnsi.Discovery.DiscoveredTable (for parameter 'table') but it was MyTable", + ex.Message); } [Test] public void Test_ImportTableInfo_NoTable() { - var tbl = "Table:MyTable:DatabaseType:MicrosoftSQLServer:Server=myServerAddress;Database=myDataBase;Trusted_Connection=True"; + var tbl = + "Table:MyTable:DatabaseType:MicrosoftSQLServer:Server=myServerAddress;Database=myDataBase;Trusted_Connection=True"; var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandImportTableInfo), - new CommandLineObjectPicker(new string[]{ tbl,"true"}, GetActivator()))); - - StringAssert.StartsWith("Could not reach server myServerAddress",ex.Message); - } + new CommandLineObjectPicker(new string[] { tbl, "true" }, GetActivator()))); + StringAssert.StartsWith("Could not reach server myServerAddress", ex.Message); + } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandNewObject.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandNewObject.cs index 5f34933a5c..1205cf0f7f 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandNewObject.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandNewObject.cs @@ -19,52 +19,53 @@ internal class TestExecuteCommandNewObject : CommandCliTests [Test] public void Test_NewObjectCommand_NoArguments() { - var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject), new CommandLineObjectPicker(Array.Empty(), GetActivator()))); - StringAssert.StartsWith("First parameter must be a Type",ex.Message); + StringAssert.StartsWith("First parameter must be a Type", ex.Message); } [Test] public void Test_NewObjectCommand_NonExistentTypeArgument() { - var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject), - new CommandLineObjectPicker(new[]{"Fissdlkfldfj"}, GetActivator()))); + var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject), + new CommandLineObjectPicker(new[] { "Fissdlkfldfj" }, GetActivator()))); - StringAssert.StartsWith("First parameter must be a Type",ex.Message); + StringAssert.StartsWith("First parameter must be a Type", ex.Message); } [Test] public void Test_NewObjectCommand_WrongTypeArgument() { - var picker = new CommandLineObjectPicker(new[] {"UnitTests"}, GetActivator()); - Assert.AreEqual(typeof(UnitTests),picker[0].Type); + var picker = new CommandLineObjectPicker(new[] { "UnitTests" }, GetActivator()); + Assert.AreEqual(typeof(UnitTests), picker[0].Type); - var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject),picker)); + var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject), picker)); - StringAssert.StartsWith("Type must be derived from DatabaseEntity",ex.Message); + StringAssert.StartsWith("Type must be derived from DatabaseEntity", ex.Message); } [Test] public void Test_NewObjectCommand_MissingNameArgument() { - var picker = new CommandLineObjectPicker(new[] {"Catalogue"}, GetActivator()); - Assert.AreEqual(typeof(Catalogue),picker[0].Type); + var picker = new CommandLineObjectPicker(new[] { "Catalogue" }, GetActivator()); + Assert.AreEqual(typeof(Catalogue), picker[0].Type); - var ex = Assert.Throws(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject),picker)); + var ex = Assert.Throws(() => + GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject), picker)); - StringAssert.StartsWith("Value needed for parameter 'name' (of type 'System.String')",ex.Message); + StringAssert.StartsWith("Value needed for parameter 'name' (of type 'System.String')", ex.Message); } [Test] public void Test_NewObjectCommand_Success() { - var picker = new CommandLineObjectPicker(new[] {"Catalogue","lolzeeeyeahyeah"}, GetActivator()); - Assert.AreEqual(typeof(Catalogue),picker[0].Type); + var picker = new CommandLineObjectPicker(new[] { "Catalogue", "lolzeeeyeahyeah" }, GetActivator()); + Assert.AreEqual(typeof(Catalogue), picker[0].Type); + + Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject), picker)); - Assert.DoesNotThrow(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandNewObject),picker)); - - Assert.Contains("lolzeeeyeahyeah",RepositoryLocator.CatalogueRepository.GetAllObjects().Select(c=>c.Name).ToArray()); + Assert.Contains("lolzeeeyeahyeah", + RepositoryLocator.CatalogueRepository.GetAllObjects().Select(c => c.Name).ToArray()); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSet.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSet.cs index 5aff358ad2..f878ddfe6f 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSet.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSet.cs @@ -19,12 +19,13 @@ public void Test_CatalogueDescription_Normal() { var cata = new Catalogue(Repository.CatalogueRepository, "Bob"); - GetInvoker().ExecuteCommand(typeof(ExecuteCommandSet),new CommandLineObjectPicker(new []{ - $"Catalogue:{cata.ID}","Description","Some long description"}, GetActivator())); + GetInvoker().ExecuteCommand(typeof(ExecuteCommandSet), new CommandLineObjectPicker(new[] + { + $"Catalogue:{cata.ID}", "Description", "Some long description" + }, GetActivator())); cata.RevertToDatabaseState(); - Assert.AreEqual("Some long description",cata.Description); - + Assert.AreEqual("Some long description", cata.Description); } [Test] @@ -36,12 +37,13 @@ public void Test_CatalogueDescription_Null() }; cata.SaveToDatabase(); - GetInvoker().ExecuteCommand(typeof(ExecuteCommandSet),new CommandLineObjectPicker(new []{ - $"Catalogue:{cata.ID}","Description","NULL"}, GetActivator())); + GetInvoker().ExecuteCommand(typeof(ExecuteCommandSet), new CommandLineObjectPicker(new[] + { + $"Catalogue:{cata.ID}", "Description", "NULL" + }, GetActivator())); cata.RevertToDatabaseState(); Assert.IsNull(cata.Description); - } [Test] @@ -62,13 +64,14 @@ public void TestExecuteCommandSet_SetArrayValueFromCLI() Assert.IsNull(pta.Value); Assert.IsNull(pta.GetValueAsSystemType()); - GetInvoker().ExecuteCommand(typeof(ExecuteCommandSet),new CommandLineObjectPicker(new []{"ProcessTaskArgument:TablesToIsolate" ,"Value",ids}, GetActivator())); + GetInvoker().ExecuteCommand(typeof(ExecuteCommandSet), + new CommandLineObjectPicker(new[] { "ProcessTaskArgument:TablesToIsolate", "Value", ids }, GetActivator())); - Assert.AreEqual(ids,pta.Value); + Assert.AreEqual(ids, pta.Value); - Assert.Contains(t1,(TableInfo[])pta.GetValueAsSystemType()); - Assert.Contains(t2,(TableInfo[])pta.GetValueAsSystemType()); - Assert.Contains(t3,(TableInfo[])pta.GetValueAsSystemType()); - Assert.Contains(t4,(TableInfo[])pta.GetValueAsSystemType()); + Assert.Contains(t1, (TableInfo[])pta.GetValueAsSystemType()); + Assert.Contains(t2, (TableInfo[])pta.GetValueAsSystemType()); + Assert.Contains(t3, (TableInfo[])pta.GetValueAsSystemType()); + Assert.Contains(t4, (TableInfo[])pta.GetValueAsSystemType()); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSetUserSetting.cs b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSetUserSetting.cs index 81f4885b72..e95324837e 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSetUserSetting.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestExecuteCommandSetUserSetting.cs @@ -19,14 +19,15 @@ public void Test_CatalogueDescription_Normal() { UserSettings.Wait5SecondsAfterStartupUI = false; - GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetUserSetting),new CommandLineObjectPicker(new []{ "Wait5SecondsAfterStartupUI", "true"}, GetActivator())); + GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetUserSetting), + new CommandLineObjectPicker(new[] { "Wait5SecondsAfterStartupUI", "true" }, GetActivator())); Assert.IsTrue(UserSettings.Wait5SecondsAfterStartupUI); - GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetUserSetting),new CommandLineObjectPicker(new []{ "Wait5SecondsAfterStartupUI", "false"}, GetActivator())); - - Assert.IsFalse(UserSettings.Wait5SecondsAfterStartupUI); + GetInvoker().ExecuteCommand(typeof(ExecuteCommandSetUserSetting), + new CommandLineObjectPicker(new[] { "Wait5SecondsAfterStartupUI", "false" }, GetActivator())); + Assert.IsFalse(UserSettings.Wait5SecondsAfterStartupUI); } [Test] @@ -34,7 +35,8 @@ public void TestSettingErrorCodeValue_InvalidValue() { var cmd = new ExecuteCommandSetUserSetting(GetActivator(), "R001", "foo"); Assert.IsTrue(cmd.IsImpossible); - Assert.AreEqual(cmd.ReasonCommandImpossible, "Invalid enum value. When setting an error code you must supply a value of one of :Success,Warning,Fail"); + Assert.AreEqual(cmd.ReasonCommandImpossible, + "Invalid enum value. When setting an error code you must supply a value of one of :Success,Warning,Fail"); } [Test] @@ -45,13 +47,13 @@ public void TestSettingErrorCodeValue_Success() Assert.AreNotEqual(CheckResult.Success, before); var cmd = new ExecuteCommandSetUserSetting(GetActivator(), "R001", "Success"); - Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible); + Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible); cmd.Execute(); var after = UserSettings.GetErrorReportingLevelFor(ErrorCodes.ExistingExtractionTableInDatabase); Assert.AreEqual(CheckResult.Success, after); //reset the original state of the system (the default) - UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExistingExtractionTableInDatabase,before); + UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExistingExtractionTableInDatabase, before); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandExecution/TestStartup.cs b/Rdmp.Core.Tests/CommandExecution/TestStartup.cs index 0967b6297f..965ed8acd8 100644 --- a/Rdmp.Core.Tests/CommandExecution/TestStartup.cs +++ b/Rdmp.Core.Tests/CommandExecution/TestStartup.cs @@ -17,8 +17,7 @@ internal class TestStartup : UnitTests [Test] public void TestStartupWithMemoryRepository() { - var s = new Rdmp.Core.Startup.Startup(new EnvironmentInfo(),RepositoryLocator); - Assert.DoesNotThrow(()=>s.DoStartup(new ThrowImmediatelyCheckNotifier())); + var s = new Rdmp.Core.Startup.Startup(new EnvironmentInfo(), RepositoryLocator); + Assert.DoesNotThrow(() => s.DoStartup(new ThrowImmediatelyCheckNotifier())); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/AbstractBaseRunnerTests.cs b/Rdmp.Core.Tests/CommandLine/AbstractBaseRunnerTests.cs index bd7662f9b9..6e48db0a31 100644 --- a/Rdmp.Core.Tests/CommandLine/AbstractBaseRunnerTests.cs +++ b/Rdmp.Core.Tests/CommandLine/AbstractBaseRunnerTests.cs @@ -26,7 +26,7 @@ public void SetupMef() { SetupMEF(); } - + [SetUp] public void CleanRemnants() { @@ -41,7 +41,7 @@ public void GetObjectFromCommandLineString_CatalogueByID() WhenIHaveA(); WhenIHaveA(); var r = new TestRunner(); - Assert.AreEqual(c, TestRunner.GetObjectFromCommandLineString(RepositoryLocator,c.ID.ToString())); + Assert.AreEqual(c, TestRunner.GetObjectFromCommandLineString(RepositoryLocator, c.ID.ToString())); } [Test] @@ -130,7 +130,8 @@ public void GetObjectsFromCommandLineString_CatalogueByID() WhenIHaveA(); var r = new TestRunner(); - var results = TestRunner.GetObjectsFromCommandLineString(RepositoryLocator,$"{c.ID},{c2.ID}").ToArray(); + var results = TestRunner.GetObjectsFromCommandLineString(RepositoryLocator, $"{c.ID},{c2.ID}") + .ToArray(); Assert.AreEqual(2, results.Length); Assert.AreSame(c, results[0]); @@ -147,33 +148,28 @@ public void GetObjectsFromCommandLineString_CatalogueByPattern() var c2 = WhenIHaveA(); c2.Name = "go hard"; c2.SaveToDatabase(); - + WhenIHaveA(); var r = new TestRunner(); - var results = TestRunner.GetObjectsFromCommandLineString(RepositoryLocator, "Catalogue:*go*").ToArray(); + var results = TestRunner.GetObjectsFromCommandLineString(RepositoryLocator, "Catalogue:*go*") + .ToArray(); Assert.AreEqual(2, results.Length); - Assert.Contains(c,results); + Assert.Contains(c, results); Assert.Contains(c2, results); } private class TestRunner : Runner { - public new static T GetObjectFromCommandLineString(IRDMPPlatformRepositoryServiceLocator locator, string arg) where T : IMapsDirectlyToDatabaseTable - { - return Runner.GetObjectFromCommandLineString(locator, arg); - } - - public new static IEnumerable GetObjectsFromCommandLineString(IRDMPPlatformRepositoryServiceLocator locator, string arg) where T : IMapsDirectlyToDatabaseTable - { - return Runner.GetObjectsFromCommandLineString(locator, arg); - } - - public override int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener, ICheckNotifier checkNotifier, GracefulCancellationToken token) - { - - return 0; - } + public new static T GetObjectFromCommandLineString(IRDMPPlatformRepositoryServiceLocator locator, string arg) + where T : IMapsDirectlyToDatabaseTable => Runner.GetObjectFromCommandLineString(locator, arg); + + public new static IEnumerable + GetObjectsFromCommandLineString(IRDMPPlatformRepositoryServiceLocator locator, string arg) + where T : IMapsDirectlyToDatabaseTable => Runner.GetObjectsFromCommandLineString(locator, arg); + + public override int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, + IDataLoadEventListener listener, ICheckNotifier checkNotifier, GracefulCancellationToken token) => 0; } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndCacheTest.cs b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndCacheTest.cs index 72054bc54a..b457e72d08 100644 --- a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndCacheTest.cs +++ b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndCacheTest.cs @@ -26,7 +26,6 @@ namespace Rdmp.Core.Tests.CommandLine.AutomationLoopTests; public class EndToEndCacheTest : DatabaseTests { - private Catalogue _cata; private LoadMetadata _lmd; private LoadProgress _lp; @@ -43,9 +42,11 @@ protected override void SetUp() RepositoryLocator.CatalogueRepository.MEF.AddTypeToCatalogForTesting(typeof(TestDataWriter)); RepositoryLocator.CatalogueRepository.MEF.AddTypeToCatalogForTesting(typeof(TestDataInventor)); - + _lmd = new LoadMetadata(CatalogueRepository, "Ive got a lovely bunch o' coconuts"); - _LoadDirectory = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), @"EndToEndCacheTest", true); + _LoadDirectory = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + @"EndToEndCacheTest", true); _lmd.LocationOfFlatFiles = _LoadDirectory.RootPath.FullName; _lmd.SaveToDatabase(); @@ -58,12 +59,13 @@ protected override void SetUp() _cata.SaveToDatabase(); _lp = new LoadProgress(CatalogueRepository, _lmd); - _cp = new CacheProgress(CatalogueRepository, _lp); - - _lp.OriginDate = new DateTime(2001,1,1); + _cp = new CacheProgress(CatalogueRepository, _lp); + + _lp.OriginDate = new DateTime(2001, 1, 1); _lp.SaveToDatabase(); - _testPipeline = new TestDataPipelineAssembler($"EndToEndCacheTestPipeline{Guid.NewGuid()}",CatalogueRepository); + _testPipeline = + new TestDataPipelineAssembler($"EndToEndCacheTestPipeline{Guid.NewGuid()}", CatalogueRepository); _testPipeline.ConfigureCacheProgressToUseThePipeline(_cp); _cp.CacheFillProgress = DateTime.Now.AddDays(-NumDaysToCache); @@ -93,7 +95,7 @@ public void FireItUpManually() var cacheFiles = _LoadDirectory.Cache.GetFiles().Select(fi => fi.Name).ToArray(); for (var i = -NumDaysToCache; i < 0; i++) { - var filename = $"{DateTime.Now.AddDays(i):yyyyMMdd}.csv"; + var filename = $"{DateTime.Now.AddDays(i):yyyyMMdd}.csv"; Assert.IsTrue(cacheFiles.Contains(filename), filename + " not found"); } } @@ -105,8 +107,10 @@ public void RunEndToEndCacheTest() { Assert.AreEqual(0, _LoadDirectory.Cache.GetFiles("*.csv").Length); - var auto = new CacheRunner(new CacheOptions {CacheProgress = _cp.ID.ToString(), Command = CommandLineActivity.run}); - auto.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(),new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); + var auto = new CacheRunner(new CacheOptions + { CacheProgress = _cp.ID.ToString(), Command = CommandLineActivity.run }); + auto.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), + new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); }); Assert.True(t.Wait(60000)); diff --git a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLECacheTest.cs b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLECacheTest.cs index b29b362bea..57d35daa51 100644 --- a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLECacheTest.cs +++ b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLECacheTest.cs @@ -17,7 +17,7 @@ namespace Rdmp.Core.Tests.CommandLine.AutomationLoopTests; -public class EndToEndDLECacheTest:TestsRequiringADle +public class EndToEndDLECacheTest : TestsRequiringADle { [Test] public void RunEndToEndDLECacheTest() @@ -29,16 +29,16 @@ public void RunEndToEndDLECacheTest() var lmd = TestLoadMetadata; - var lp = new LoadProgress(CatalogueRepository,lmd) + var lp = new LoadProgress(CatalogueRepository, lmd) { - DataLoadProgress = new DateTime(2001,1,1), + DataLoadProgress = new DateTime(2001, 1, 1), DefaultNumberOfDaysToLoadEachTime = 10 }; lp.SaveToDatabase(); var cp = new CacheProgress(CatalogueRepository, lp) { - CacheFillProgress = new DateTime(2001,1,11) //10 days available to load + CacheFillProgress = new DateTime(2001, 1, 11) //10 days available to load }; cp.SaveToDatabase(); @@ -48,42 +48,42 @@ public void RunEndToEndDLECacheTest() //setup the cache process task var pt = new ProcessTask(CatalogueRepository, lmd, LoadStage.GetFiles) { - Path = typeof (BasicCacheDataProvider).FullName, + Path = typeof(BasicCacheDataProvider).FullName, ProcessTaskType = ProcessTaskType.DataProvider }; pt.SaveToDatabase(); pt.CreateArgumentsForClassIfNotExists(); var attacher = lmd.ProcessTasks.Single(p => p.ProcessTaskType == ProcessTaskType.Attacher); - var patternArgument = (ProcessTaskArgument)attacher.GetAllArguments().Single(a => a.Name.Equals("FilePattern")); + var patternArgument = (ProcessTaskArgument)attacher.GetAllArguments().Single(a => a.Name.Equals("FilePattern")); patternArgument.SetValue("*.csv"); patternArgument.SaveToDatabase(); //take the forLoading file - var csvFile = CreateFileInForLoading("bob.csv",10,new Random(5000)); + var csvFile = CreateFileInForLoading("bob.csv", 10, new Random(5000)); //and move it to the cache and give it a date in the range we expect for the cached data - csvFile.MoveTo(Path.Combine(LoadDirectory.Cache.FullName,"2001-01-09.csv")); - + csvFile.MoveTo(Path.Combine(LoadDirectory.Cache.FullName, "2001-01-09.csv")); + RunDLE(timeoutInMilliseconds); - Assert.AreEqual(10,RowsNow - RowsBefore); + Assert.AreEqual(10, RowsNow - RowsBefore); Assert.AreEqual(0, LoadDirectory.Cache.GetFiles().Length); Assert.AreEqual(0, LoadDirectory.ForLoading.GetFiles().Length); Assert.AreEqual(1, LoadDirectory.ForArchiving.GetFiles().Length); var archiveFile = LoadDirectory.ForArchiving.GetFiles()[0]; - Assert.AreEqual(".zip",archiveFile.Extension); + Assert.AreEqual(".zip", archiveFile.Extension); //load progress should be updated to the largest date in the cache (2001-01-09) lp.RevertToDatabaseState(); - Assert.AreEqual(lp.DataLoadProgress, new DateTime(2001,01,09)); + Assert.AreEqual(lp.DataLoadProgress, new DateTime(2001, 01, 09)); cp.DeleteInDatabase(); lp.DeleteInDatabase(); - assembler.Destroy(); + assembler.Destroy(); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLETest.cs b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLETest.cs index 25dd31ab5a..0c36ecc140 100644 --- a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLETest.cs +++ b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/EndToEndDLETest.cs @@ -22,19 +22,19 @@ public class EndToEndDLETest : TestsRequiringADle public void RunEndToEndDLETest() { const int timeoutInMilliseconds = 120000; - CreateFileInForLoading("loadmeee.csv",500,new Random(500)); + CreateFileInForLoading("loadmeee.csv", 500, new Random(500)); RunDLE(timeoutInMilliseconds); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void TestDle_DodgyColumnNames(DatabaseType dbType) { var db = GetCleanedServer(dbType); - var tbl = db.CreateTable("Troll Select * Loll",new DatabaseColumnRequest[] + var tbl = db.CreateTable("Troll Select * Loll", new DatabaseColumnRequest[] { - new DatabaseColumnRequest("group by",new DatabaseTypeRequest(typeof(string),100)){IsPrimaryKey = true}, - new DatabaseColumnRequest(",,,,",new DatabaseTypeRequest(typeof(string))) + new("group by", new DatabaseTypeRequest(typeof(string), 100)) { IsPrimaryKey = true }, + new(",,,,", new DatabaseTypeRequest(typeof(string))) }); CreateFileInForLoading("Troll.csv", new string[] @@ -50,16 +50,16 @@ public void TestDle_DodgyColumnNames(DatabaseType dbType) }; lmd.SaveToDatabase(); - CreateFlatFileAttacher(lmd,"Troll.csv",cata.GetTableInfoList(false).Single()); + CreateFlatFileAttacher(lmd, "Troll.csv", cata.GetTableInfoList(false).Single()); cata.LoadMetadata_ID = lmd.ID; cata.SaveToDatabase(); - Assert.AreEqual(0,tbl.GetRowCount()); + Assert.AreEqual(0, tbl.GetRowCount()); - RunDLE(lmd,30000,true); + RunDLE(lmd, 30000, true); - Assert.AreEqual(1,tbl.GetRowCount()); - Assert.AreEqual("fishon",tbl.GetDataTable().Rows[0][",,,,"]); + Assert.AreEqual(1, tbl.GetRowCount()); + Assert.AreEqual("fishon", tbl.GetDataTable().Rows[0][",,,,"]); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/FictionalCache/Reading/TestDataCacheReader.cs b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/FictionalCache/Reading/TestDataCacheReader.cs index c3f3875f5c..fc07a17e9f 100644 --- a/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/FictionalCache/Reading/TestDataCacheReader.cs +++ b/Rdmp.Core.Tests/CommandLine/AutomationLoopTests/FictionalCache/Reading/TestDataCacheReader.cs @@ -38,17 +38,11 @@ public void Initialize(ILoadDirectory directory, DiscoveredDatabase dbInfo) throw new NotImplementedException(); } - public ExitCodeType Fetch(IDataLoadJob job, GracefulCancellationToken cancellationToken) - { + public ExitCodeType Fetch(IDataLoadJob job, GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); - } public CacheArchiveType CacheArchiveType { get; set; } public string CacheDateFormat { get; set; } public Type CacheLayoutType { get; set; } - public ILoadCachePathResolver CreateResolver(ILoadProgress loadProgress) - { - throw new NotImplementedException(); - } - + public ILoadCachePathResolver CreateResolver(ILoadProgress loadProgress) => throw new NotImplementedException(); } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/CommandLineObjectPickerTests.cs b/Rdmp.Core.Tests/CommandLine/CommandLineObjectPickerTests.cs index a192fdfe16..fa238e5f0a 100644 --- a/Rdmp.Core.Tests/CommandLine/CommandLineObjectPickerTests.cs +++ b/Rdmp.Core.Tests/CommandLine/CommandLineObjectPickerTests.cs @@ -18,7 +18,6 @@ namespace Rdmp.Core.Tests.CommandLine; internal class CommandLineObjectPickerTests : UnitTests { - [OneTimeSetUp] protected override void OneTimeSetUp() { @@ -32,10 +31,7 @@ protected override void SetUp() { base.SetUp(); - foreach(var c in Repository.GetAllObjects()) - { - c.DeleteInDatabase(); - } + foreach (var c in Repository.GetAllObjects()) c.DeleteInDatabase(); } @@ -43,9 +39,9 @@ protected override void SetUp() public void Test_RandomGarbage_GeneratesRawValueOnly() { var str = $"Shiver me timbers"; - var picker = new CommandLineObjectPicker(new []{str}, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { str }, GetActivator()); - Assert.AreEqual(str,picker[0].RawValue); + Assert.AreEqual(str, picker[0].RawValue); Assert.IsNull(picker[0].DatabaseEntities); Assert.IsNull(picker[0].Database); Assert.IsNull(picker[0].Table); @@ -55,17 +51,17 @@ public void Test_RandomGarbage_GeneratesRawValueOnly() [Test] public void Test_PickCatalogueByID_PickOne() { - var cata = WhenIHaveA(); + var cata = WhenIHaveA(); - var picker = new CommandLineObjectPicker(new []{$"Catalogue:{cata.ID}"}, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { $"Catalogue:{cata.ID}" }, GetActivator()); + + Assert.AreEqual(cata, picker[0].DatabaseEntities.Single()); - Assert.AreEqual(cata,picker[0].DatabaseEntities.Single()); - //specifying the same ID twice shouldn't return duplicate objects - picker = new CommandLineObjectPicker(new []{$"Catalogue:{cata.ID},{cata.ID}"}, GetActivator()); + picker = new CommandLineObjectPicker(new[] { $"Catalogue:{cata.ID},{cata.ID}" }, GetActivator()); - Assert.AreEqual(cata,picker[0].DatabaseEntities.Single()); + Assert.AreEqual(cata, picker[0].DatabaseEntities.Single()); } /// @@ -76,39 +72,39 @@ public void Test_PickCatalogueByID_PickOne() [TestCase("\r\n")] public void Test_PickerForWhitespace(string val) { - var picker = new CommandLineObjectPicker(new []{val }, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { val }, GetActivator()); + + Assert.AreEqual(1, picker.Length); - Assert.AreEqual(1,picker.Length); - Assert.IsNull(picker[0].Database); Assert.IsNull(picker[0].DatabaseEntities); Assert.IsFalse(picker[0].ExplicitNull); - Assert.AreEqual(val,picker[0].RawValue); + Assert.AreEqual(val, picker[0].RawValue); Assert.IsNull(picker[0].Type); - - Assert.AreEqual(val,picker[0].GetValueForParameterOfType(typeof(string))); + + Assert.AreEqual(val, picker[0].GetValueForParameterOfType(typeof(string))); Assert.IsTrue(picker.HasArgumentOfType(0, typeof(string))); } - + [Test] public void Test_PickCatalogueByID_PickTwo() { - var cata1 = WhenIHaveA(); - var cata2 = WhenIHaveA(); + var cata1 = WhenIHaveA(); + var cata2 = WhenIHaveA(); - var picker = new CommandLineObjectPicker(new []{$"Catalogue:{cata1.ID},{cata2.ID}"}, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { $"Catalogue:{cata1.ID},{cata2.ID}" }, GetActivator()); Assert.AreEqual(2, picker[0].DatabaseEntities.Count); - Assert.Contains(cata1,picker[0].DatabaseEntities); - Assert.Contains(cata2,picker[0].DatabaseEntities); + Assert.Contains(cata1, picker[0].DatabaseEntities); + Assert.Contains(cata2, picker[0].DatabaseEntities); } - + [Test] public void Test_PickCatalogueByName_PickTwo() { - var cata1 = WhenIHaveA(); - var cata2 = WhenIHaveA(); - var cata3 = WhenIHaveA(); + var cata1 = WhenIHaveA(); + var cata2 = WhenIHaveA(); + var cata3 = WhenIHaveA(); cata1.Name = "lolzy"; cata2.Name = "lolxy"; @@ -118,7 +114,7 @@ public void Test_PickCatalogueByName_PickTwo() cata2.SaveToDatabase(); cata3.SaveToDatabase(); - var picker = new CommandLineObjectPicker(new []{$"Catalogue:lol*"}, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { $"Catalogue:lol*" }, GetActivator()); Assert.AreEqual(2, picker[0].DatabaseEntities.Count); Assert.Contains(cata1, picker[0].DatabaseEntities); @@ -128,29 +124,30 @@ public void Test_PickCatalogueByName_PickTwo() [Test] public void TestPicker_TypeYieldsEmptyArrayOfObjects() { - foreach(var cat in RepositoryLocator.CatalogueRepository.GetAllObjects()) + foreach (var cat in RepositoryLocator.CatalogueRepository.GetAllObjects()) cat.DeleteInDatabase(); Assert.IsEmpty(RepositoryLocator.CatalogueRepository.GetAllObjects()); //when interpreting the string "Catalogue" for a command - var picker = new CommandLineObjectPicker(new []{"Catalogue" }, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { "Catalogue" }, GetActivator()); //we can pick it as either a Catalogue or a collection of all the Catalogues - Assert.AreEqual(typeof(Catalogue),picker.Arguments.Single().Type); + Assert.AreEqual(typeof(Catalogue), picker.Arguments.Single().Type); Assert.IsEmpty(picker.Arguments.Single().DatabaseEntities); //when interpretting as a Type we get Catalogue Assert.IsTrue(picker.Arguments.First().HasValueOfType(typeof(Type))); - Assert.AreEqual(typeof(Catalogue),picker.Arguments.Single().GetValueForParameterOfType(typeof(Type))); + Assert.AreEqual(typeof(Catalogue), picker.Arguments.Single().GetValueForParameterOfType(typeof(Type))); //if it is looking for an ienumerable of objects Assert.IsTrue(picker.Arguments.First().HasValueOfType(typeof(IMapsDirectlyToDatabaseTable[]))); - Assert.IsEmpty((IMapsDirectlyToDatabaseTable[])picker.Arguments.First().GetValueForParameterOfType(typeof(IMapsDirectlyToDatabaseTable[]))); + Assert.IsEmpty((IMapsDirectlyToDatabaseTable[])picker.Arguments.First() + .GetValueForParameterOfType(typeof(IMapsDirectlyToDatabaseTable[]))); Assert.IsTrue(picker.Arguments.First().HasValueOfType(typeof(Catalogue[]))); - Assert.IsEmpty(((Catalogue[])picker.Arguments.First().GetValueForParameterOfType(typeof(Catalogue[]))).ToArray()); - + Assert.IsEmpty( + ((Catalogue[])picker.Arguments.First().GetValueForParameterOfType(typeof(Catalogue[]))).ToArray()); } [TestCase(typeof(PickDatabase))] @@ -173,38 +170,40 @@ public void Pickers_ShouldAllHaveValidExamples_MatchingRegex(Type pickerType) var picker = (PickObjectBase)ObjectConstructor.Construct(pickerType, GetActivator(new RepositoryProvider(mem))); - Assert.IsNotEmpty(picker.Help,"No Help for picker {0}",picker); - Assert.IsNotEmpty(picker.Format,"No Format for picker {0}",picker); - Assert.IsNotNull(picker.Examples,"No Examples for picker {0}",picker); - Assert.IsNotEmpty(picker.Examples,"No Examples for picker {0}",picker); + Assert.IsNotEmpty(picker.Help, "No Help for picker {0}", picker); + Assert.IsNotEmpty(picker.Format, "No Format for picker {0}", picker); + Assert.IsNotNull(picker.Examples, "No Examples for picker {0}", picker); + Assert.IsNotEmpty(picker.Examples, "No Examples for picker {0}", picker); foreach (var example in picker.Examples) { //examples should be matched by the picker! - Assert.IsTrue(picker.IsMatch(example,0),"Example of picker '{0}' did not match the regex,listed example is '{1}'",picker,example); + Assert.IsTrue(picker.IsMatch(example, 0), + "Example of picker '{0}' did not match the regex,listed example is '{1}'", picker, example); var result = picker.Parse(example, 0); Assert.IsNotNull(result); } } - + [Test] public void PickTypeName() { - var picker = new CommandLineObjectPicker(new []{"Name"}, GetActivator()); - + var picker = new CommandLineObjectPicker(new[] { "Name" }, GetActivator()); + Assert.IsNull(picker[0].Type); - Assert.AreEqual("Name",picker[0].RawValue); + Assert.AreEqual("Name", picker[0].RawValue); } [TestCase("null")] [TestCase("NULL")] public void PickNull(string nullString) { - var picker = new CommandLineObjectPicker(new []{nullString}, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { nullString }, GetActivator()); Assert.IsTrue(picker[0].ExplicitNull); } + [Test] public void Test_PickCatalogueByName_WithShortCode() { @@ -266,6 +265,7 @@ public void Test_PickWithPropertyQuery_CatalogueItemsByCatalogue() Assert.Contains(ci2, picker[0].DatabaseEntities); Assert.IsFalse(picker[0].DatabaseEntities.Contains(ci3)); } + [Test] public void Test_PickWithPropertyQuery_CatalogueByFolder() { @@ -285,6 +285,7 @@ public void Test_PickWithPropertyQuery_CatalogueByFolder() Assert.Contains(c3, picker[0].DatabaseEntities); Assert.IsFalse(picker[0].DatabaseEntities.Contains(c2)); } + [Test] public void Test_PickWithPropertyQuery_PeriodicityNull() { @@ -295,15 +296,18 @@ public void Test_PickWithPropertyQuery_PeriodicityNull() c1.PivotCategory_ExtractionInformation_ID = 10; c2.PivotCategory_ExtractionInformation_ID = null; - var picker = new CommandLineObjectPicker(new[] { $"Catalogue?PivotCategory_ExtractionInformation_ID:null" }, GetActivator()); + var picker = new CommandLineObjectPicker(new[] { $"Catalogue?PivotCategory_ExtractionInformation_ID:null" }, + GetActivator()); Assert.AreEqual(1, picker[0].DatabaseEntities.Count); Assert.Contains(c2, picker[0].DatabaseEntities); } + [Test] public void Test_PickWithPropertyQuery_UnknownProperty() { - var ex = Assert.Throws(()=>new CommandLineObjectPicker(new[] { $"Catalogue?Blarg:null" }, GetActivator())); + var ex = Assert.Throws(() => + new CommandLineObjectPicker(new[] { $"Catalogue?Blarg:null" }, GetActivator())); Assert.AreEqual("Unknown property 'Blarg'. Did not exist on Type 'Catalogue'", ex.Message); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs b/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs index c2927014d1..5429060c0a 100644 --- a/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs +++ b/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs @@ -15,7 +15,7 @@ namespace Rdmp.Core.Tests.CommandLine; -internal class ExampleDatasetsCreationTests:DatabaseTests +internal class ExampleDatasetsCreationTests : DatabaseTests { /// /// Tests the creation of example datasets during first installation of RDMP or when running "rdmp.exe install [...] -e" from the CLI @@ -24,24 +24,25 @@ internal class ExampleDatasetsCreationTests:DatabaseTests public void Test_ExampleDatasetsCreation() { //Should be empty RDMP metadata database - Assert.AreEqual(0,CatalogueRepository.GetAllObjects().Length); - Assert.AreEqual(0,CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(0, CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(0, CatalogueRepository.GetAllObjects().Length); //create the pipelines var pipes = new CataloguePipelinesAndReferencesCreation(RepositoryLocator,null,null); - pipes.CreatePipelines(); + pipes.CreatePipelines(new PlatformDatabaseCreationOptions {}); //create all the stuff var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); - var creator = new ExampleDatasetsCreation(new ThrowImmediatelyActivator(RepositoryLocator),RepositoryLocator); - creator.Create(db,new ThrowImmediatelyCheckNotifier(),new PlatformDatabaseCreationOptions {Seed = 500,DropDatabases = true }); + var creator = new ExampleDatasetsCreation(new ThrowImmediatelyActivator(RepositoryLocator), RepositoryLocator); + creator.Create(db, new ThrowImmediatelyCheckNotifier(), + new PlatformDatabaseCreationOptions { Seed = 500, DropDatabases = true }); //should be at least 2 views (marked as view) var views = CatalogueRepository.GetAllObjects().Count(ti => ti.IsView); - Assert.GreaterOrEqual(views,2); + Assert.GreaterOrEqual(views, 2); //should have at least created some catalogues, graphs etc - Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects().Length,4); - Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects().Length,4); + Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects().Length, 4); + Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects().Length, 4); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/Interactive/ConsoleInputManagerTests.cs b/Rdmp.Core.Tests/CommandLine/Interactive/ConsoleInputManagerTests.cs index c44ef6883f..7c1e6e8a37 100644 --- a/Rdmp.Core.Tests/CommandLine/Interactive/ConsoleInputManagerTests.cs +++ b/Rdmp.Core.Tests/CommandLine/Interactive/ConsoleInputManagerTests.cs @@ -18,10 +18,10 @@ internal class ConsoleInputManagerTests : UnitTests public void TestDisallowInput() { var manager = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier()) - { - DisallowInput = true - }; + { + DisallowInput = true + }; - Assert.Throws(()=>manager.GetString(new DialogArgs { WindowTitle = "bob" }, null)); + Assert.Throws(() => manager.GetString(new DialogArgs { WindowTitle = "bob" }, null)); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommandLine/NewObjectPoolTests.cs b/Rdmp.Core.Tests/CommandLine/NewObjectPoolTests.cs index f0b3d9c7f7..42e159a280 100644 --- a/Rdmp.Core.Tests/CommandLine/NewObjectPoolTests.cs +++ b/Rdmp.Core.Tests/CommandLine/NewObjectPoolTests.cs @@ -20,7 +20,7 @@ public void TwoCataloguesWithSameName_NoSession() { SetupMEF(); - var cata1 = new Catalogue(Repository,"Hey"); + var cata1 = new Catalogue(Repository, "Hey"); // When there is only one object we can pick it by name var picker = new CommandLineObjectPicker(new string[] { "Catalogue:Hey" }, GetActivator()); @@ -38,7 +38,7 @@ public void TwoCataloguesWithSameName_WithSession() { SetupMEF(); - using(NewObjectPool.StartSession()) + using (NewObjectPool.StartSession()) { var cata1 = new Catalogue(Repository, "Hey"); diff --git a/Rdmp.Core.Tests/CommandLine/PickTableTests.cs b/Rdmp.Core.Tests/CommandLine/PickTableTests.cs index 8229d321fc..3b424bf03e 100644 --- a/Rdmp.Core.Tests/CommandLine/PickTableTests.cs +++ b/Rdmp.Core.Tests/CommandLine/PickTableTests.cs @@ -14,22 +14,24 @@ namespace Rdmp.Core.Tests.CommandLine; internal class PickTableTests : UnitTests { - [Test] public void TestPickTable() { var pick = new PickTable(); - var result = pick.Parse(@"Table:v_cool:Schema:dbo:IsView:True:DatabaseType:MicrosoftSQLServer:Name:MyDb:Server=localhost\sqlexpress;Trusted_Connection=True;",0); + var result = + pick.Parse( + @"Table:v_cool:Schema:dbo:IsView:True:DatabaseType:MicrosoftSQLServer:Name:MyDb:Server=localhost\sqlexpress;Trusted_Connection=True;", + 0); Assert.IsNotNull(result.Table); - - Assert.AreEqual(TableType.View,result.Table.TableType); - Assert.AreEqual("dbo",result.Table.Schema); - Assert.AreEqual("v_cool",result.Table.GetRuntimeName()); - Assert.AreEqual("MyDb",result.Table.Database.GetRuntimeName()); - Assert.AreEqual("localhost\\sqlexpress",result.Table.Database.Server.Name); - Assert.AreEqual(DatabaseType.MicrosoftSQLServer,result.Table.Database.Server.DatabaseType); + Assert.AreEqual(TableType.View, result.Table.TableType); + Assert.AreEqual("dbo", result.Table.Schema); + + Assert.AreEqual("v_cool", result.Table.GetRuntimeName()); + Assert.AreEqual("MyDb", result.Table.Database.GetRuntimeName()); + Assert.AreEqual("localhost\\sqlexpress", result.Table.Database.Server.Name); + Assert.AreEqual(DatabaseType.MicrosoftSQLServer, result.Table.Database.Server.DatabaseType); Assert.IsNull(result.Table.Database.Server.ExplicitPasswordIfAny); Assert.IsNull(result.Table.Database.Server.ExplicitUsernameIfAny); } diff --git a/Rdmp.Core.Tests/CommandLine/RdmpScriptTests.cs b/Rdmp.Core.Tests/CommandLine/RdmpScriptTests.cs index 814129adde..721f2a5dd0 100644 --- a/Rdmp.Core.Tests/CommandLine/RdmpScriptTests.cs +++ b/Rdmp.Core.Tests/CommandLine/RdmpScriptTests.cs @@ -18,42 +18,43 @@ namespace Rdmp.Core.Tests.CommandLine; internal class RdmpScriptTests : UnitTests { - [TestCase("NewObject Catalogue 'trog dor'","trog dor")] - [TestCase("NewObject Catalogue \"trog dor\"","trog dor")] - [TestCase("NewObject Catalogue \"'trog dor'\"","'trog dor'")] - [TestCase("NewObject Catalogue '\"trog dor\"'","\"trog dor\"")] - + [TestCase("NewObject Catalogue 'trog dor'", "trog dor")] + [TestCase("NewObject Catalogue \"trog dor\"", "trog dor")] + [TestCase("NewObject Catalogue \"'trog dor'\"", "'trog dor'")] + [TestCase("NewObject Catalogue '\"trog dor\"'", "\"trog dor\"")] public void RdmpScript_NewObject_Catalogue(string command, string expectedName) { - foreach(var c in RepositoryLocator.CatalogueRepository.GetAllObjects()) + foreach (var c in RepositoryLocator.CatalogueRepository.GetAllObjects()) c.DeleteInDatabase(); var runner = new ExecuteCommandRunner(new ExecuteCommandOptions { Script = new RdmpScript { - Commands = new[] {command} + Commands = new[] { command } } }); - + SetupMEF(); - var exitCode = runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); + var exitCode = runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), + new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); - Assert.AreEqual(0,exitCode); - Assert.AreEqual(1,RepositoryLocator.CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(0, exitCode); + Assert.AreEqual(1, RepositoryLocator.CatalogueRepository.GetAllObjects().Length); - Assert.AreEqual(expectedName,RepositoryLocator.CatalogueRepository.GetAllObjects().Single().Name); + Assert.AreEqual(expectedName, RepositoryLocator.CatalogueRepository.GetAllObjects().Single().Name); } - [TestCase("NewObject Catalogue 'fffff'","NewObject CatalogueItem Catalogue:*fff* 'bbbb'","bbbb")] - [TestCase("NewObject Catalogue '\"fff\"'","NewObject CatalogueItem 'Catalogue:\"fff\"' 'bbbb'","bbbb")] - [TestCase("NewObject Catalogue '\"ff ff\"'","NewObject CatalogueItem 'Catalogue:\"ff ff\"' 'bb bb'","bb bb")] - [TestCase("NewObject Catalogue '\"ff ff\"'","NewObject CatalogueItem 'Catalogue:\"ff ff\"' bb'bb","bb'bb")] - [TestCase("NewObject Catalogue '\"ff ff\"'","NewObject CatalogueItem 'Catalogue:\"ff ff\"' b\"b'bb'","b\"b'bb'")] - public void RdmpScript_NewObject_CatalogueItem(string cataCommand,string cataItemCommand, string expectedCataItemName) + [TestCase("NewObject Catalogue 'fffff'", "NewObject CatalogueItem Catalogue:*fff* 'bbbb'", "bbbb")] + [TestCase("NewObject Catalogue '\"fff\"'", "NewObject CatalogueItem 'Catalogue:\"fff\"' 'bbbb'", "bbbb")] + [TestCase("NewObject Catalogue '\"ff ff\"'", "NewObject CatalogueItem 'Catalogue:\"ff ff\"' 'bb bb'", "bb bb")] + [TestCase("NewObject Catalogue '\"ff ff\"'", "NewObject CatalogueItem 'Catalogue:\"ff ff\"' bb'bb", "bb'bb")] + [TestCase("NewObject Catalogue '\"ff ff\"'", "NewObject CatalogueItem 'Catalogue:\"ff ff\"' b\"b'bb'", "b\"b'bb'")] + public void RdmpScript_NewObject_CatalogueItem(string cataCommand, string cataItemCommand, + string expectedCataItemName) { - foreach(var c in RepositoryLocator.CatalogueRepository.GetAllObjects()) + foreach (var c in RepositoryLocator.CatalogueRepository.GetAllObjects()) c.DeleteInDatabase(); var runner = new ExecuteCommandRunner(new ExecuteCommandOptions @@ -67,34 +68,36 @@ public void RdmpScript_NewObject_CatalogueItem(string cataCommand,string cataIte } } }); - + SetupMEF(); - var exitCode = runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); + var exitCode = runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), + new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); - Assert.AreEqual(0,exitCode); - Assert.AreEqual(1,RepositoryLocator.CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(0, exitCode); + Assert.AreEqual(1, RepositoryLocator.CatalogueRepository.GetAllObjects().Length); var ci = RepositoryLocator.CatalogueRepository.GetAllObjects().Single().CatalogueItems.Single(); - Assert.AreEqual(expectedCataItemName,ci.Name); - + Assert.AreEqual(expectedCataItemName, ci.Name); } [Test] public void Test_SplitCommandLine() { - var vals = ExecuteCommandRunner.SplitCommandLine("NewObject CatalogueItem 'Catalogue:\"fff\"' 'bbbb'").ToArray(); - Assert.AreEqual("NewObject",vals[0]); - Assert.AreEqual("CatalogueItem",vals[1]); - Assert.AreEqual("Catalogue:\"fff\"",vals[2]); - Assert.AreEqual("bbbb",vals[3]); + var vals = ExecuteCommandRunner.SplitCommandLine("NewObject CatalogueItem 'Catalogue:\"fff\"' 'bbbb'") + .ToArray(); + Assert.AreEqual("NewObject", vals[0]); + Assert.AreEqual("CatalogueItem", vals[1]); + Assert.AreEqual("Catalogue:\"fff\"", vals[2]); + Assert.AreEqual("bbbb", vals[3]); } + [Test] public void Test_SplitCommandLine_QuotesInStrings() { var vals = ExecuteCommandRunner.SplitCommandLine("NewObject CatalogueItem bb\"'bb'").ToArray(); - Assert.AreEqual("NewObject",vals[0]); - Assert.AreEqual("CatalogueItem",vals[1]); - Assert.AreEqual("bb\"'bb'",vals[2]); + Assert.AreEqual("NewObject", vals[0]); + Assert.AreEqual("CatalogueItem", vals[1]); + Assert.AreEqual("bb\"'bb'", vals[2]); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/CommentStoreTests.cs b/Rdmp.Core.Tests/CommentStoreTests.cs index 148a6ac09f..8c56debef5 100644 --- a/Rdmp.Core.Tests/CommentStoreTests.cs +++ b/Rdmp.Core.Tests/CommentStoreTests.cs @@ -29,8 +29,7 @@ Does some stuff Assert.AreEqual( @"Does some stuff" - ,store["WindowFactory"]); - + , store["WindowFactory"]); } [Test] @@ -52,8 +51,7 @@ Does some stuff Assert.AreEqual( @"Does some stuff" - ,store["WindowFactory"]); - + , store["WindowFactory"]); } [Test] @@ -79,8 +77,7 @@ this is next para @"Does some stuff This is still one para this is next para" - ,store["WindowFactory"]); - + , store["WindowFactory"]); } @@ -99,7 +96,7 @@ public void Test_CommentStoreXmlDoc_EmptyElements() store.AddXmlDoc(null); //also shouldn't bomb but should be 0 store.AddXmlDoc(doc.FirstChild.FirstChild); - + Assert.IsEmpty(store); store.AddXmlDoc(doc.FirstChild); @@ -113,7 +110,7 @@ public void Test_CommentStoreXmlDoc_EmptyElements() store.AddXmlDoc(doc.FirstChild); Assert.IsEmpty(store); - + doc.LoadXml( @" a @@ -149,8 +146,7 @@ this is next para @"Does some stuff This is still one para this is next para" - ,store["WindowFactory"]); - + , store["WindowFactory"]); } @@ -180,7 +176,6 @@ got it? @"Does some stuff And some more stuff IObjectCollectionControl (for RDMPCollectionUI see WindowManager ). paragraph 2 got it?" - ,store["WindowFactory"]); - + , store["WindowFactory"]); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Anonymisation/ANOMigrationTests.cs b/Rdmp.Core.Tests/Curation/Anonymisation/ANOMigrationTests.cs index 3ce174d44a..a7eccdbd53 100644 --- a/Rdmp.Core.Tests/Curation/Anonymisation/ANOMigrationTests.cs +++ b/Rdmp.Core.Tests/Curation/Anonymisation/ANOMigrationTests.cs @@ -26,23 +26,26 @@ public class ANOMigrationTests : TestsRequiringANOStore private ANOTable _anoConditionTable; #region setup + [SetUp] protected override void SetUp() { base.SetUp(); var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); - + BlitzMainDataTables(); - + DeleteANOEndpoint(); - var remnantANO = CatalogueRepository.GetAllObjects().SingleOrDefault(a => a.TableName.Equals("ANOCondition")); + var remnantANO = CatalogueRepository.GetAllObjects() + .SingleOrDefault(a => a.TableName.Equals("ANOCondition")); remnantANO?.DeleteInDatabase(); //cleanup - foreach (var remnant in CatalogueRepository.GetAllObjects().Where(t => t.GetRuntimeName().Equals(TableName))) + foreach (var remnant in CatalogueRepository.GetAllObjects() + .Where(t => t.GetRuntimeName().Equals(TableName))) remnant.DeleteInDatabase(); const string sql = @" @@ -79,19 +82,19 @@ INSERT [ANOMigration] ([AdmissionDate], [DischargeDate], [Condition1], [Conditio using (var con = server.GetConnection()) { con.Open(); - server.GetCommand(sql,con).ExecuteNonQuery(); + server.GetCommand(sql, con).ExecuteNonQuery(); } var table = db.ExpectTable(TableName); var importer = new TableInfoImporter(CatalogueRepository, table); - importer.DoImport(out _tableInfo,out _columnInfos); + importer.DoImport(out _tableInfo, out _columnInfos); //Configure the structure of the ANO transform we want - identifiers should have 3 characters and 2 ints and end with _C - _anoConditionTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOCondition","C") - { - NumberOfCharactersToUseInAnonymousRepresentation = 3, - NumberOfIntegersToUseInAnonymousRepresentation = 2 - }; + _anoConditionTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOCondition", "C") + { + NumberOfCharactersToUseInAnonymousRepresentation = 3, + NumberOfIntegersToUseInAnonymousRepresentation = 2 + }; _anoConditionTable.SaveToDatabase(); _anoConditionTable.PushToANOServerAsNewTable("varchar(4)", new ThrowImmediatelyCheckNotifier()); } @@ -108,28 +111,35 @@ private void DeleteANOEndpoint() #endregion - - [Test,Order(1)] + + [Test] + [Order(1)] public void PKsAreCorrect() { - Assert.IsTrue(_columnInfos.Single(c=>c.GetRuntimeName().Equals("AdmissionDate")).IsPrimaryKey); + Assert.IsTrue(_columnInfos.Single(c => c.GetRuntimeName().Equals("AdmissionDate")).IsPrimaryKey); Assert.IsTrue(_columnInfos.Single(c => c.GetRuntimeName().Equals("Condition1")).IsPrimaryKey); Assert.IsTrue(_columnInfos.Single(c => c.GetRuntimeName().Equals("CHI")).IsPrimaryKey); } - [Test,Order(2)] + [Test] + [Order(2)] public void ConvertPrimaryKeyColumn() { //The table we created above should have a column called Condition2 in it, we will migrate this data to ANO land var condition = _columnInfos.Single(c => c.GetRuntimeName().Equals("Condition1")); var converter = new ColumnInfoToANOTableConverter(condition, _anoConditionTable); - var ex = Assert.Throws(()=>converter.ConvertFullColumnInfo(s => true, new ThrowImmediatelyCheckNotifier())); //say yes to everything it proposes + var ex = Assert.Throws(() => + converter.ConvertFullColumnInfo(s => true, + new ThrowImmediatelyCheckNotifier())); //say yes to everything it proposes - StringAssert.IsMatch(@"Could not perform transformation because column \[(.*)\]\.\[dbo\]\.\[.*\]\.\[Condition1\] is not droppable",ex.Message); + StringAssert.IsMatch( + @"Could not perform transformation because column \[(.*)\]\.\[dbo\]\.\[.*\]\.\[Condition1\] is not droppable", + ex.Message); } - [Test,Order(3)] + [Test] + [Order(3)] [TestCase("Condition2")] [TestCase("Condition3")] [TestCase("Condition4")] @@ -158,11 +168,11 @@ public void ConvertNonPrimaryKeyColumn(string conditionColumn) else rowsObjectFoundIn.Add(r[conditionColumn], new List(new[] {row})); } - + //The table we created above should have a column called Condition2 in it, we will migrate this data to ANO land ColumnInfo condition = _columnInfos.Single(c => c.GetRuntimeName().Equals(conditionColumn)); ColumnInfoToANOTableConverter converter = new ColumnInfoToANOTableConverter(condition, _anoConditionTable); - converter.ConvertFullColumnInfo((s) => true,new AcceptAllCheckNotifier()); //say yes to everything it proposes + converter.ConvertFullColumnInfo((s) => true,new AcceptAllCheckNotifier()); //say yes to everything it proposes //refresh the column infos ColumnInfo[] columnInfos = _tableInfo.ColumnInfos; @@ -185,7 +195,7 @@ public void ConvertNonPrimaryKeyColumn(string conditionColumn) DbCommand cmd = server.GetCommand("Select * from " + TableName, con); var r = cmd.ExecuteReader(); - + List objectsFound = new List(); while (r.Read()) diff --git a/Rdmp.Core.Tests/Curation/Anonymisation/ANOStoreFunctionalityTests.cs b/Rdmp.Core.Tests/Curation/Anonymisation/ANOStoreFunctionalityTests.cs index f170f1c89e..e13eeec805 100644 --- a/Rdmp.Core.Tests/Curation/Anonymisation/ANOStoreFunctionalityTests.cs +++ b/Rdmp.Core.Tests/Curation/Anonymisation/ANOStoreFunctionalityTests.cs @@ -13,7 +13,7 @@ namespace Rdmp.Core.Tests.Curation.Anonymisation; -public class ANOStoreFunctionalityTests:TestsRequiringFullAnonymisationSuite +public class ANOStoreFunctionalityTests : TestsRequiringFullAnonymisationSuite { [Test] public void CanAccessANODatabase_Directly() @@ -35,7 +35,8 @@ public void CanAccessANODatabase_Directly() [Test] public void CanAccessANODatabase_ViaExternalServerPointer() { - using (var connection = DataAccessPortal.ExpectServer(ANOStore_ExternalDatabaseServer, DataAccessContext.DataLoad).GetConnection()) + using (var connection = DataAccessPortal + .ExpectServer(ANOStore_ExternalDatabaseServer, DataAccessContext.DataLoad).GetConnection()) { connection.Open(); @@ -45,7 +46,7 @@ public void CanAccessANODatabase_ViaExternalServerPointer() var version = new Version(cmd.ExecuteScalar().ToString()); Assert.GreaterOrEqual(version, new Version("0.0.0.0")); } - + connection.Close(); } } @@ -69,7 +70,8 @@ public void CanAccessIdentifierDumpDatabase_Directly() [Test] public void CanAccessIdentifierDumpDatabase_ViaExternalServerPointer() { - using(var connection = DataAccessPortal.ExpectServer(IdentifierDump_ExternalDatabaseServer, DataAccessContext.DataLoad).GetConnection()) + using (var connection = DataAccessPortal + .ExpectServer(IdentifierDump_ExternalDatabaseServer, DataAccessContext.DataLoad).GetConnection()) { connection.Open(); @@ -78,7 +80,7 @@ public void CanAccessIdentifierDumpDatabase_ViaExternalServerPointer() var version = new Version(cmd.ExecuteScalar().ToString()); Assert.GreaterOrEqual(version, new Version("0.0.0.0")); } - + connection.Close(); } diff --git a/Rdmp.Core.Tests/Curation/Anonymisation/ANOTableTests.cs b/Rdmp.Core.Tests/Curation/Anonymisation/ANOTableTests.cs index 1bfc2b6bb1..1d7b0874e5 100644 --- a/Rdmp.Core.Tests/Curation/Anonymisation/ANOTableTests.cs +++ b/Rdmp.Core.Tests/Curation/Anonymisation/ANOTableTests.cs @@ -20,11 +20,12 @@ namespace Rdmp.Core.Tests.Curation.Anonymisation; -public class ANOTableTests:TestsRequiringANOStore +public class ANOTableTests : TestsRequiringANOStore { private Regex _anochiPattern = new(@"\d{10}_A"); #region Create New ANOTables + [Test] [TestCase("varchar(1)")] [TestCase("int")] @@ -32,15 +33,15 @@ public class ANOTableTests:TestsRequiringANOStore [TestCase("bit")] public void CreateAnANOTable_PushAs(string datatypeForPush) { - var anoTable = GetANOTable(); Assert.AreEqual("ANOMyTable", anoTable.TableName); - anoTable.NumberOfCharactersToUseInAnonymousRepresentation =20; + anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 20; anoTable.NumberOfIntegersToUseInAnonymousRepresentation = 20; anoTable.PushToANOServerAsNewTable(datatypeForPush, new ThrowImmediatelyCheckNotifier()); - var discoveredTable = ANOStore_Database.DiscoverTables(false).SingleOrDefault(t => t.GetRuntimeName().Equals("ANOMyTable")); - + var discoveredTable = ANOStore_Database.DiscoverTables(false) + .SingleOrDefault(t => t.GetRuntimeName().Equals("ANOMyTable")); + //server should have Assert.NotNull(discoveredTable); Assert.IsTrue(discoveredTable.Exists()); @@ -61,7 +62,7 @@ public void CreateAnANOTable_Revertable() anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 63; anoTable.RevertToDatabaseState(); - Assert.AreEqual(1,anoTable.NumberOfCharactersToUseInAnonymousRepresentation); + Assert.AreEqual(1, anoTable.NumberOfCharactersToUseInAnonymousRepresentation); anoTable.DeleteInDatabase(); } @@ -80,7 +81,8 @@ public void DuplicateSuffix_Throws() var anoTable = GetANOTable(); try { - var ex = Assert.Throws(()=>new ANOTable(CatalogueRepository, anoTable.Server, "DuplicateSuffix", anoTable.Suffix)); + var ex = Assert.Throws(() => + new ANOTable(CatalogueRepository, anoTable.Server, "DuplicateSuffix", anoTable.Suffix)); Assert.AreEqual("There is already another ANOTable with the suffix 'A'", ex.Message); } finally @@ -88,7 +90,7 @@ public void DuplicateSuffix_Throws() anoTable.DeleteInDatabase(); } } - + [Test] public void CreateAnANOTable_CharCountNegative() { @@ -97,15 +99,14 @@ public void CreateAnANOTable_CharCountNegative() { anoTable.NumberOfCharactersToUseInAnonymousRepresentation = -500; var ex = Assert.Throws(anoTable.SaveToDatabase); - Assert.AreEqual("NumberOfCharactersToUseInAnonymousRepresentation cannot be negative",ex.Message); + Assert.AreEqual("NumberOfCharactersToUseInAnonymousRepresentation cannot be negative", ex.Message); } finally { anoTable.DeleteInDatabase(); } - } - + [Test] public void CreateAnANOTable_IntCountNegative() { @@ -121,7 +122,6 @@ public void CreateAnANOTable_IntCountNegative() { anoTable.DeleteInDatabase(); } - } [Test] @@ -133,13 +133,14 @@ public void CreateAnANOTable_TotalCountZero() anoTable.NumberOfIntegersToUseInAnonymousRepresentation = 0; anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 0; var ex = Assert.Throws(anoTable.SaveToDatabase); - Assert.AreEqual("Anonymous representations must have at least 1 integer or character",ex.Message); + Assert.AreEqual("Anonymous representations must have at least 1 integer or character", ex.Message); } finally { anoTable.DeleteInDatabase(); } } + #endregion [Test] @@ -148,30 +149,30 @@ public void SubstituteANOIdentifiers_2CHINumbers() var anoTable = GetANOTable(); anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 0; anoTable.NumberOfIntegersToUseInAnonymousRepresentation = 10; - anoTable.PushToANOServerAsNewTable("varchar(10)",new ThrowImmediatelyCheckNotifier()); + anoTable.PushToANOServerAsNewTable("varchar(10)", new ThrowImmediatelyCheckNotifier()); var dt = new DataTable(); dt.Columns.Add("CHI"); dt.Columns.Add("ANOCHI"); - dt.Rows.Add("0101010101",DBNull.Value);//duplicates - dt.Rows.Add("0101010102",DBNull.Value); - dt.Rows.Add("0101010101",DBNull.Value);//duplicates + dt.Rows.Add("0101010101", DBNull.Value); //duplicates + dt.Rows.Add("0101010102", DBNull.Value); + dt.Rows.Add("0101010101", DBNull.Value); //duplicates var transformer = new ANOTransformer(anoTable, new ThrowImmediatelyDataLoadEventListener()); - transformer.Transform(dt,dt.Columns["CHI"],dt.Columns["ANOCHI"]); + transformer.Transform(dt, dt.Columns["CHI"], dt.Columns["ANOCHI"]); - Assert.IsTrue((string) dt.Rows[0][0] == "0101010101"); - Assert.IsTrue(_anochiPattern.IsMatch((string) dt.Rows[0][1]));//should be 10 digits and then _A - Assert.AreEqual(dt.Rows[0][1], dt.Rows[2][1]);//because of duplication these should both be the same + Assert.IsTrue((string)dt.Rows[0][0] == "0101010101"); + Assert.IsTrue(_anochiPattern.IsMatch((string)dt.Rows[0][1])); //should be 10 digits and then _A + Assert.AreEqual(dt.Rows[0][1], dt.Rows[2][1]); //because of duplication these should both be the same Console.WriteLine($"ANO identifiers created were:{dt.Rows[0][1]},{dt.Rows[1][1]}"); TruncateANOTable(anoTable); //now test previews - transformer.Transform(dt,dt.Columns["CHI"],dt.Columns["ANOCHI"], true); + transformer.Transform(dt, dt.Columns["CHI"], dt.Columns["ANOCHI"], true); var val1 = dt.Rows[0][1]; transformer.Transform(dt, dt.Columns["CHI"], dt.Columns["ANOCHI"], true); @@ -181,7 +182,7 @@ public void SubstituteANOIdentifiers_2CHINumbers() var val3 = dt.Rows[0][1]; //should always be different - Assert.AreNotEqual(val1,val2); + Assert.AreNotEqual(val1, val2); Assert.AreNotEqual(val1, val3); //now test repeatability @@ -193,18 +194,17 @@ public void SubstituteANOIdentifiers_2CHINumbers() transformer.Transform(dt, dt.Columns["CHI"], dt.Columns["ANOCHI"], false); var val6 = dt.Rows[0][1]; - Assert.AreEqual(val4,val5); + Assert.AreEqual(val4, val5); Assert.AreEqual(val4, val6); TruncateANOTable(anoTable); - + anoTable.DeleteInDatabase(); } [Test] public void SubstituteANOIdentifiers_PreviewWithoutPush() { - var anoTable = GetANOTable(); anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 0; anoTable.NumberOfIntegersToUseInAnonymousRepresentation = 10; @@ -221,8 +221,8 @@ public void SubstituteANOIdentifiers_PreviewWithoutPush() var transformer = new ANOTransformer(anoTable, new ThrowImmediatelyDataLoadEventListener()); transformer.Transform(dt, dt.Columns["CHI"], dt.Columns["ANOCHI"], true); - Assert.IsTrue(_anochiPattern.IsMatch((string)dt.Rows[0][1]));//should be 10 digits and then _A - + Assert.IsTrue(_anochiPattern.IsMatch((string)dt.Rows[0][1])); //should be 10 digits and then _A + //still not exist yet Assert.False(ANOtable.Exists()); @@ -258,15 +258,16 @@ public void SubstituteANOIdentifiers_BulkTest() var val = r.NextDouble() * 9999999999; val = Math.Round(val); var valAsString = val.ToString(); - + while (valAsString.Length < 10) valAsString = $"0{valAsString}"; if (!uniqueSourceSet.Contains(valAsString)) uniqueSourceSet.Add(valAsString); - dt.Rows.Add(valAsString, DBNull.Value);//duplicates + dt.Rows.Add(valAsString, DBNull.Value); //duplicates } + Console.WriteLine($"Time to allocate in C# memory:{sw.Elapsed}"); Console.WriteLine($"Allocated {dt.Rows.Count} identifiers ({uniqueSourceSet.Count} unique ones)"); @@ -302,16 +303,17 @@ public void SubstituteANOIdentifiers_BulkTest() var numberOfRows = Convert.ToInt32(cmd.ExecuteScalar()); //should be the same number of unique identifiers in memory as in the database - Assert.AreEqual(uniqueSet.Count,numberOfRows); + Assert.AreEqual(uniqueSet.Count, numberOfRows); Console.WriteLine($"Found {numberOfRows} unique ones"); var cmdNulls = server.GetCommand("select count(*) from ANOMyTable where ANOMyTable is null", con); var nulls = Convert.ToInt32(cmdNulls.ExecuteScalar()); - Assert.AreEqual(0,nulls); + Assert.AreEqual(0, nulls); Console.WriteLine($"Found {nulls} null ANO identifiers"); con.Close(); } + sw.Stop(); Console.WriteLine($"Time to evaluate results:{sw.Elapsed}"); TruncateANOTable(anoTable); diff --git a/Rdmp.Core.Tests/Curation/Anonymisation/ForwardEngineerANOCatalogueTwoTableTests.cs b/Rdmp.Core.Tests/Curation/Anonymisation/ForwardEngineerANOCatalogueTwoTableTests.cs index d5fedb1225..8984ab41b6 100644 --- a/Rdmp.Core.Tests/Curation/Anonymisation/ForwardEngineerANOCatalogueTwoTableTests.cs +++ b/Rdmp.Core.Tests/Curation/Anonymisation/ForwardEngineerANOCatalogueTwoTableTests.cs @@ -78,34 +78,34 @@ REFERENCES [dbo].[Tests] ([TestId]) using (var con = server.GetConnection()) { con.Open(); - UsefulStuff.ExecuteBatchNonQuery(sql,con); + UsefulStuff.ExecuteBatchNonQuery(sql, con); } var importer1 = new TableInfoImporter(CatalogueRepository, From.ExpectTable("Tests")); var importer2 = new TableInfoImporter(CatalogueRepository, From.ExpectTable("Results")); - importer1.DoImport(out t1,out c1); - + importer1.DoImport(out t1, out c1); + importer2.DoImport(out t2, out c2); var engineer1 = new ForwardEngineerCatalogue(t1, c1); var engineer2 = new ForwardEngineerCatalogue(t2, c2); - engineer1.ExecuteForwardEngineering(out cata1,out cataItems1,out eis1); + engineer1.ExecuteForwardEngineering(out cata1, out cataItems1, out eis1); engineer2.ExecuteForwardEngineering(out cata2, out cataItems2, out eis2); new JoinInfo(CatalogueRepository, c1.Single(e => e.GetRuntimeName().Equals("TestId")), c2.Single(e => e.GetRuntimeName().Equals("TestId")), - ExtractionJoinType.Left,null); + ExtractionJoinType.Left, null); _anoTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOTes", "T") - { - NumberOfCharactersToUseInAnonymousRepresentation = 10 - }; + { + NumberOfCharactersToUseInAnonymousRepresentation = 10 + }; _anoTable.SaveToDatabase(); - _anoTable.PushToANOServerAsNewTable("int",new ThrowImmediatelyCheckNotifier()); - + _anoTable.PushToANOServerAsNewTable("int", new ThrowImmediatelyCheckNotifier()); + _comboCata = new Catalogue(CatalogueRepository, "Combo Catalogue"); //pk @@ -120,7 +120,7 @@ REFERENCES [dbo].[Tests] ([TestId]) var colMeasure = c2.Single(c => c.GetRuntimeName().Equals("Measure")); ciMeasure.ColumnInfo_ID = colMeasure.ID; ciMeasure.SaveToDatabase(); - var eiMeasure = new ExtractionInformation(CatalogueRepository, ciMeasure,colMeasure, colMeasure.Name); + var eiMeasure = new ExtractionInformation(CatalogueRepository, ciMeasure, colMeasure, colMeasure.Name); //Date var ciDate = new CatalogueItem(CatalogueRepository, _comboCata, "Dat"); @@ -151,25 +151,27 @@ public void TestAnonymisingJoinKey() var engine1 = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, plan1); engine1.Execute(); - var plan1ExtractionInformationsAtDestination = engine1.NewCatalogue.GetAllExtractionInformation(ExtractionCategory.Any); + var plan1ExtractionInformationsAtDestination = + engine1.NewCatalogue.GetAllExtractionInformation(ExtractionCategory.Any); var ei1 = plan1ExtractionInformationsAtDestination.Single(e => e.GetRuntimeName().Equals("ANOTestId")); Assert.IsTrue(ei1.Exists()); //Now create a plan for the combo Catalogue which contains references to both tables (Tests and Results). Remember Tests has already been migrated as part of plan1 var plan2 = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, _comboCata); - + //tell it to skip table 1 (Tests) and only anonymise Results plan2.SkippedTables.Add(t1); plan2.TargetDatabase = _destinationDatabase; plan2.Check(new ThrowImmediatelyCheckNotifier()); //Run the anonymisation - var engine2 = new ForwardEngineerANOCatalogueEngine(RepositoryLocator,plan2); + var engine2 = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, plan2); engine2.Execute(); //Did it succesfully pick SetUp the correct ANO column - var plan2ExtractionInformationsAtDestination = engine2.NewCatalogue.GetAllExtractionInformation(ExtractionCategory.Any); + var plan2ExtractionInformationsAtDestination = + engine2.NewCatalogue.GetAllExtractionInformation(ExtractionCategory.Any); var ei2 = plan2ExtractionInformationsAtDestination.Single(e => e.GetRuntimeName().Equals("ANOTestId")); Assert.IsTrue(ei2.Exists()); @@ -183,14 +185,14 @@ public void TestAnonymisingJoinKey() con.Open(); var cmd = _destinationDatabase.Server.GetCommand(qb.SQL, con); - - Assert.DoesNotThrow(()=>cmd.ExecuteNonQuery()); + + Assert.DoesNotThrow(() => cmd.ExecuteNonQuery()); } Console.WriteLine($"Final migrated combo dataset SQL was:{qb.SQL}"); Assert.IsTrue(_comboCata.CatalogueItems.Any(ci => ci.Name.Equals("Measuree"))); - Assert.IsTrue(engine2.NewCatalogue.CatalogueItems.Any(ci => ci.Name.Equals("Measuree")),"ANO Catalogue did not respect the original CatalogueItem Name"); + Assert.IsTrue(engine2.NewCatalogue.CatalogueItems.Any(ci => ci.Name.Equals("Measuree")), + "ANO Catalogue did not respect the original CatalogueItem Name"); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Anonymisation/IdentifierDumpFunctionalityTests.cs b/Rdmp.Core.Tests/Curation/Anonymisation/IdentifierDumpFunctionalityTests.cs index 940d56ca36..8760bd17ca 100644 --- a/Rdmp.Core.Tests/Curation/Anonymisation/IdentifierDumpFunctionalityTests.cs +++ b/Rdmp.Core.Tests/Curation/Anonymisation/IdentifierDumpFunctionalityTests.cs @@ -20,7 +20,7 @@ namespace Rdmp.Core.Tests.Curation.Anonymisation; -public class IdentifierDumpFunctionalityTests:TestsRequiringFullAnonymisationSuite +public class IdentifierDumpFunctionalityTests : TestsRequiringFullAnonymisationSuite { private ITableInfo tableInfoCreated; private ColumnInfo[] columnInfosCreated; @@ -32,15 +32,16 @@ protected override void OneTimeSetUp() base.OneTimeSetUp(); Console.WriteLine("Setting SetUp bulk test data"); - _bulkData = new BulkTestsData(RepositoryLocator.CatalogueRepository, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); + _bulkData = new BulkTestsData(RepositoryLocator.CatalogueRepository, + GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); _bulkData.SetupTestData(); - + Console.WriteLine("Importing to Catalogue"); var tbl = _bulkData.Table; var importer = new TableInfoImporter(CatalogueRepository, tbl); - importer.DoImport(out tableInfoCreated,out columnInfosCreated); - + importer.DoImport(out tableInfoCreated, out columnInfosCreated); + Console.WriteLine($"Imported TableInfo {tableInfoCreated}"); Console.WriteLine( $"Imported ColumnInfos {string.Join(",", columnInfosCreated.Select(c => c.GetRuntimeName()))}"); @@ -60,6 +61,7 @@ protected override void OneTimeSetUp() #region tests that pass + [Test] public void DumpAllIdentifiersInTable_Passes() { @@ -83,7 +85,7 @@ public void DumpAllIdentifiersInTable_Passes() var dt = _bulkData.GetDataTable(1000); - Assert.AreEqual(1000,dt.Rows.Count); + Assert.AreEqual(1000, dt.Rows.Count); Assert.IsTrue(dt.Columns.Contains("surname")); //for checking the final ID table has the correct values in @@ -91,8 +93,8 @@ public void DumpAllIdentifiersInTable_Passes() { var chi = row["chi"].ToString(); - if(!chiToSurnameDictionary.ContainsKey(chi)) - chiToSurnameDictionary.Add(chi,new HashSet()); + if (!chiToSurnameDictionary.ContainsKey(chi)) + chiToSurnameDictionary.Add(chi, new HashSet()); chiToSurnameDictionary[chi].Add(row["surname"] as string); } @@ -112,19 +114,20 @@ public void DumpAllIdentifiersInTable_Passes() var cmd = server.GetCommand($"Select * from ID_{BulkTestsData.BulkDataTable}", con); var r = cmd.ExecuteReader(); - + //make sure the values in the ID table match the ones we originally had in the pipeline while (r.Read()) if (!chiToSurnameDictionary[r["chi"].ToString()].Any()) Assert.IsTrue(r["surname"] == DBNull.Value); else - Assert.IsTrue(chiToSurnameDictionary[r["chi"].ToString()].Contains(r["surname"] as string),"Dictionary did not contain expected surname:" + r["surname"]); + Assert.IsTrue(chiToSurnameDictionary[r["chi"].ToString()].Contains(r["surname"] as string), + "Dictionary did not contain expected surname:" + r["surname"]); r.Close(); //leave the identifier dump in the way we found it (empty) var tbl = IdentifierDump_Database.ExpectTable($"ID_{BulkTestsData.BulkDataTable}"); - if(tbl.Exists()) + if (tbl.Exists()) tbl.Drop(); tbl = IdentifierDump_Database.ExpectTable($"ID_{BulkTestsData.BulkDataTable}_Archive"); @@ -136,34 +139,33 @@ public void DumpAllIdentifiersInTable_Passes() finally { preDiscardedColumn1.DeleteInDatabase(); - tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it + tableInfoCreated.IdentifierDumpServer_ID = null; //reset it back to how it was when we found it tableInfoCreated.SaveToDatabase(); } - } - #endregion #region tests that throw + [Test] public void DumpAllIdentifiersInTable_UnexpectedColumnFoundInIdentifierDumpTable() { var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "surname") - { - Destination = DiscardedColumnDestination.StoreInIdentifiersDump, - SqlDataType = "varchar(20)" - }; + { + Destination = DiscardedColumnDestination.StoreInIdentifiersDump, + SqlDataType = "varchar(20)" + }; preDiscardedColumn1.SaveToDatabase(); var preDiscardedColumn2 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "forename") - { - Destination = DiscardedColumnDestination.StoreInIdentifiersDump, - SqlDataType = "varchar(50)" - }; + { + Destination = DiscardedColumnDestination.StoreInIdentifiersDump, + SqlDataType = "varchar(50)" + }; preDiscardedColumn2.SaveToDatabase(); - + //give it the correct server tableInfoCreated.IdentifierDumpServer_ID = IdentifierDump_ExternalDatabaseServer.ID; tableInfoCreated.SaveToDatabase(); @@ -175,9 +177,9 @@ public void DumpAllIdentifiersInTable_UnexpectedColumnFoundInIdentifierDumpTable Assert.IsTrue(tableInDump.Exists(), "ID table did not exist"); - var columnsInDump = tableInDump.DiscoverColumns().Select(c=>c.GetRuntimeName()).ToArray(); + var columnsInDump = tableInDump.DiscoverColumns().Select(c => c.GetRuntimeName()).ToArray(); //works and creates table on server - Assert.Contains("hic_validFrom",columnsInDump); + Assert.Contains("hic_validFrom", columnsInDump); Assert.Contains("forename", columnsInDump); Assert.Contains("chi", columnsInDump); Assert.Contains("surname", columnsInDump); @@ -195,8 +197,10 @@ public void DumpAllIdentifiersInTable_UnexpectedColumnFoundInIdentifierDumpTable try { - var ex = Assert.Throws(()=>dumper2.Check(thrower)); - Assert.AreEqual("Column forename was found in the IdentifierDump table ID_BulkData but was not one of the primary keys or a PreLoadDiscardedColumn",ex.Message); + var ex = Assert.Throws(() => dumper2.Check(thrower)); + Assert.AreEqual( + "Column forename was found in the IdentifierDump table ID_BulkData but was not one of the primary keys or a PreLoadDiscardedColumn", + ex.Message); } finally { @@ -215,11 +219,9 @@ public void DumpAllIdentifiersInTable_UnexpectedColumnFoundInIdentifierDumpTable } preDiscardedColumn1.DeleteInDatabase(); - tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it + tableInfoCreated.IdentifierDumpServer_ID = null; //reset it back to how it was when we found it tableInfoCreated.SaveToDatabase(); - } - } [Test] @@ -240,13 +242,15 @@ public void IdentifierDumperCheckFails_StagingNotCalled() try { dumper.Check(new AcceptAllCheckNotifier()); - var ex = Assert.Throws(()=>dumper.DumpAllIdentifiersInTable(_bulkData.GetDataTable(10))); - Assert.AreEqual("IdentifierDumper STAGING insert (ID_BulkData_STAGING) failed, make sure you have called CreateSTAGINGTable() before trying to Dump identifiers (also you should call DropStagging() when you are done)",ex.Message); + var ex = Assert.Throws(() => dumper.DumpAllIdentifiersInTable(_bulkData.GetDataTable(10))); + Assert.AreEqual( + "IdentifierDumper STAGING insert (ID_BulkData_STAGING) failed, make sure you have called CreateSTAGINGTable() before trying to Dump identifiers (also you should call DropStagging() when you are done)", + ex.Message); } finally { preDiscardedColumn1.DeleteInDatabase(); - tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it + tableInfoCreated.IdentifierDumpServer_ID = null; //reset it back to how it was when we found it tableInfoCreated.SaveToDatabase(); } } @@ -255,10 +259,10 @@ public void IdentifierDumperCheckFails_StagingNotCalled() public void IdentifierDumperCheckFails_NoTableExists() { var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "forename") - { - Destination = DiscardedColumnDestination.StoreInIdentifiersDump, - SqlDataType = "varchar(50)" - }; + { + Destination = DiscardedColumnDestination.StoreInIdentifiersDump, + SqlDataType = "varchar(50)" + }; preDiscardedColumn1.SaveToDatabase(); //give it the correct server @@ -269,7 +273,7 @@ public void IdentifierDumperCheckFails_NoTableExists() .ExpectDatabase(IdentifierDump_ExternalDatabaseServer, DataAccessContext.InternalDataProcessing) .ExpectTable("ID_BulkData"); - if(existingTable.Exists()) + if (existingTable.Exists()) existingTable.Drop(); var dumper = new IdentifierDumper(tableInfoCreated); @@ -279,15 +283,15 @@ public void IdentifierDumperCheckFails_NoTableExists() var notifier = new ToMemoryCheckNotifier(new AcceptAllCheckNotifier()); dumper.Check(notifier); - Assert.IsTrue(notifier.Messages.Any(m=> - m.Result == CheckResult.Warning + Assert.IsTrue(notifier.Messages.Any(m => + m.Result == CheckResult.Warning && m.Message.Contains("Table ID_BulkData was not found"))); } finally { preDiscardedColumn1.DeleteInDatabase(); - tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it + tableInfoCreated.IdentifierDumpServer_ID = null; //reset it back to how it was when we found it tableInfoCreated.SaveToDatabase(); } } @@ -295,13 +299,14 @@ public void IdentifierDumperCheckFails_NoTableExists() [Test] public void IdentifierDumperCheckFails_ServerIsNotADumpServer() { - var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "NationalSecurityNumber") + var preDiscardedColumn1 = + new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "NationalSecurityNumber") { Destination = DiscardedColumnDestination.StoreInIdentifiersDump, SqlDataType = "varchar(10)" }; preDiscardedColumn1.SaveToDatabase(); - + //give it the WRONG server tableInfoCreated.IdentifierDumpServer_ID = ANOStore_ExternalDatabaseServer.ID; tableInfoCreated.SaveToDatabase(); @@ -314,31 +319,34 @@ public void IdentifierDumperCheckFails_ServerIsNotADumpServer() } catch (Exception ex) { - Assert.IsTrue(ex.Message.StartsWith("Exception occurred when trying to find stored procedure sp_createIdentifierDump")); + Assert.IsTrue( + ex.Message.StartsWith( + "Exception occurred when trying to find stored procedure sp_createIdentifierDump")); Assert.IsTrue(ex.InnerException.Message.StartsWith("Connected successfully to server")); - Assert.IsTrue(ex.InnerException.Message.EndsWith(" but did not find the stored procedure sp_createIdentifierDump in the database (Possibly the ExternalDatabaseServer is not an IdentifierDump database?)")); + Assert.IsTrue(ex.InnerException.Message.EndsWith( + " but did not find the stored procedure sp_createIdentifierDump in the database (Possibly the ExternalDatabaseServer is not an IdentifierDump database?)")); } finally { preDiscardedColumn1.DeleteInDatabase(); - tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it + tableInfoCreated.IdentifierDumpServer_ID = null; //reset it back to how it was when we found it tableInfoCreated.SaveToDatabase(); } - } [Test] public void IdentifierDumperCheckFails_NoTableOnServerRejectChange() { - var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "NationalSecurityNumber"); + var preDiscardedColumn1 = + new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "NationalSecurityNumber"); try { preDiscardedColumn1.Destination = DiscardedColumnDestination.StoreInIdentifiersDump; preDiscardedColumn1.SqlDataType = "varchar(10)"; preDiscardedColumn1.SaveToDatabase(); - var ex = Assert.Throws(()=> new IdentifierDumper(tableInfoCreated)); - StringAssert.Contains("does not have a listed IdentifierDump ExternalDatabaseServer",ex.Message); + var ex = Assert.Throws(() => new IdentifierDumper(tableInfoCreated)); + StringAssert.Contains("does not have a listed IdentifierDump ExternalDatabaseServer", ex.Message); } finally { @@ -350,10 +358,10 @@ public void IdentifierDumperCheckFails_NoTableOnServerRejectChange() public void IdentifierDumperCheckFails_LieAboutDatatype() { var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "forename") - { - Destination = DiscardedColumnDestination.StoreInIdentifiersDump, - SqlDataType = "varchar(50)" - }; + { + Destination = DiscardedColumnDestination.StoreInIdentifiersDump, + SqlDataType = "varchar(50)" + }; preDiscardedColumn1.SaveToDatabase(); try { @@ -362,28 +370,28 @@ public void IdentifierDumperCheckFails_LieAboutDatatype() tableInfoCreated.SaveToDatabase(); var dumper = new IdentifierDumper(tableInfoCreated); - + //table doesnt exist yet it should work dumper.Check(new AcceptAllCheckNotifier()); - + //now it is varbinary preDiscardedColumn1.SqlDataType = "varbinary(200)"; preDiscardedColumn1.SaveToDatabase(); - + //get a new dumper because we have changed the pre load discarded column dumper = new IdentifierDumper(tableInfoCreated); //table doesnt exist yet it should work - var ex = Assert.Throws(()=>dumper.Check(new ThrowImmediatelyCheckNotifier())); + var ex = Assert.Throws(() => dumper.Check(new ThrowImmediatelyCheckNotifier())); - Assert.IsTrue(ex.Message.Contains("has data type varbinary(200) in the Catalogue but appears as varchar(50) in the actual IdentifierDump")); + Assert.IsTrue(ex.Message.Contains( + "has data type varbinary(200) in the Catalogue but appears as varchar(50) in the actual IdentifierDump")); } finally { preDiscardedColumn1.DeleteInDatabase(); - tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it + tableInfoCreated.IdentifierDumpServer_ID = null; //reset it back to how it was when we found it tableInfoCreated.SaveToDatabase(); } - } #endregion diff --git a/Rdmp.Core.Tests/Curation/CrossPlatformParameterTests/BasicParameterUseTests.cs b/Rdmp.Core.Tests/Curation/CrossPlatformParameterTests/BasicParameterUseTests.cs index 8abcb8a244..c5b7e43b34 100644 --- a/Rdmp.Core.Tests/Curation/CrossPlatformParameterTests/BasicParameterUseTests.cs +++ b/Rdmp.Core.Tests/Curation/CrossPlatformParameterTests/BasicParameterUseTests.cs @@ -21,7 +21,7 @@ namespace Rdmp.Core.Tests.Curation.CrossPlatformParameterTests; -public class BasicParameterUseTests:DatabaseTests +public class BasicParameterUseTests : DatabaseTests { [Test] [TestCase(DatabaseType.MySql)] @@ -48,9 +48,9 @@ public void Test_DatabaseTypeQueryWithParameter_IntParameter(DatabaseType dbType { ///////////////////////UPLOAD THE DataTable TO THE DESTINATION//////////////////////////////////////////// var uploader = new DataTableUploadDestination(); - uploader.PreInitialize(db,new ThrowImmediatelyDataLoadJob()); + uploader.PreInitialize(db, new ThrowImmediatelyDataLoadJob()); uploader.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); - uploader.Dispose(new ThrowImmediatelyDataLoadJob(),null ); + uploader.Dispose(new ThrowImmediatelyDataLoadJob(), null); var tbl = db.ExpectTable(tableName); @@ -65,25 +65,26 @@ public void Test_DatabaseTypeQueryWithParameter_IntParameter(DatabaseType dbType //create an extraction filter var extractionInformation = ei.Single(); var filter = new ExtractionFilter(CatalogueRepository, "Filter by numbers", extractionInformation) - { - WhereSQL = $"{extractionInformation.SelectSQL} = @n" - }; + { + WhereSQL = $"{extractionInformation.SelectSQL} = @n" + }; filter.SaveToDatabase(); //create the parameters for filter (no globals, masters or scope adjacent parameters) - new ParameterCreator(filter.GetFilterFactory(), null, null).CreateAll(filter,null); + new ParameterCreator(filter.GetFilterFactory(), null, null).CreateAll(filter, null); var p = filter.GetAllParameters().Single(); - Assert.AreEqual("@n",p.ParameterName); + Assert.AreEqual("@n", p.ParameterName); p.ParameterSQL = p.ParameterSQL.Replace("varchar(50)", "int"); //make it int p.Value = "20"; p.SaveToDatabase(); var qb = new QueryBuilder(null, null); qb.AddColumn(extractionInformation); - qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null, new[] { filter }, FilterContainerOperation.AND); - - using(var con = db.Server.GetConnection()) + qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null, + new[] { filter }, FilterContainerOperation.AND); + + using (var con = db.Server.GetConnection()) { con.Open(); diff --git a/Rdmp.Core.Tests/Curation/DublinCoreTests.cs b/Rdmp.Core.Tests/Curation/DublinCoreTests.cs index 4e610f7648..8a750423d5 100644 --- a/Rdmp.Core.Tests/Curation/DublinCoreTests.cs +++ b/Rdmp.Core.Tests/Curation/DublinCoreTests.cs @@ -21,21 +21,23 @@ public void TestWritingDocument() { var def = new DublinCoreDefinition { - Title = "ssssshh", - Alternative = "O'Rly", + Title = "ssssshh", + Alternative = "O'Rly", Description = "Description of stuff", Format = "text/html", Identifier = new Uri("http://foo.com"), Publisher = "University of Dundee", IsPartOf = new Uri("http://foo2.com"), - Modified = new DateTime(2001,1,1), + Modified = new DateTime(2001, 1, 1), Subject = "Interesting, PayAttention, HighPriority, Omg" }; var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "dublinTest.xml")); - using(var fw = f.OpenWrite()) + using (var fw = f.OpenWrite()) + { def.WriteXml(fw); + } var contents = File.ReadAllText(f.FullName); StringAssert.Contains(def.Title, contents); @@ -62,8 +64,6 @@ public void TestWritingDocument() Assert.AreEqual(def.Modified, def2.Modified); Assert.AreEqual(def.IsPartOf.ToString(), def2.IsPartOf.ToString()); Assert.AreEqual(def.Identifier.ToString(), def2.Identifier.ToString()); - - } [Test] @@ -125,7 +125,7 @@ UKOLN est un centre national d'expertise dans la gestion de l'information "; var fi = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "dublinTestReading.xml")); - File.WriteAllText(fi.FullName,xml); + File.WriteAllText(fi.FullName, xml); var doc = XDocument.Load(fi.FullName); @@ -133,8 +133,9 @@ UKOLN est un centre national d'expertise dans la gestion de l'information def.LoadFrom(doc.Root); - Assert.IsTrue(DatabaseTests.AreBasicallyEquals("UKOLN",def.Title)); - Assert.IsTrue(DatabaseTests.AreBasicallyEquals("UK Office for Library and Information Networking", def.Alternative)); + Assert.IsTrue(DatabaseTests.AreBasicallyEquals("UKOLN", def.Title)); + Assert.IsTrue(DatabaseTests.AreBasicallyEquals("UK Office for Library and Information Networking", + def.Alternative)); Assert.IsTrue(DatabaseTests.AreBasicallyEquals(@"national centre, network information support, library community, awareness, research, information services,public library networking, bibliographic management, distributed @@ -149,7 +150,7 @@ UKOLN est un centre national d'expertise dans la gestion de l'information Assert.IsTrue(DatabaseTests.AreBasicallyEquals("UKOLN, University of Bath", def.Publisher)); StringAssert.AreEqualIgnoringCase("http://www.bath.ac.uk/", def.IsPartOf.AbsoluteUri); StringAssert.AreEqualIgnoringCase("http://www.ukoln.ac.uk/", def.Identifier.AbsoluteUri); - Assert.IsTrue(DatabaseTests.AreBasicallyEquals(new DateTime(2001,07,18),def.Modified)); + Assert.IsTrue(DatabaseTests.AreBasicallyEquals(new DateTime(2001, 07, 18), def.Modified)); } /// @@ -160,21 +161,23 @@ public void Test_DublinCore_WriteReadFile_NetCore() { var def1 = new DublinCoreDefinition { - Title = "ssssshh", - Alternative = "O'Rly", + Title = "ssssshh", + Alternative = "O'Rly", Description = "Description of stuff", Format = "text/html", Identifier = new Uri("http://foo.com"), Publisher = "University of Dundee", IsPartOf = new Uri("http://foo2.com"), - Modified = new DateTime(2001,1,1), + Modified = new DateTime(2001, 1, 1), Subject = "Interesting, PayAttention, HighPriority, Omg" }; var fi = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "dublin.xml")); - using(var outStream = fi.OpenWrite()) + using (var outStream = fi.OpenWrite()) + { def1.WriteXml(outStream); + } using (var inStream = fi.OpenRead()) { diff --git a/Rdmp.Core.Tests/Curation/ExtendedPropertyTests.cs b/Rdmp.Core.Tests/Curation/ExtendedPropertyTests.cs index b066468cee..b710ccbdd6 100644 --- a/Rdmp.Core.Tests/Curation/ExtendedPropertyTests.cs +++ b/Rdmp.Core.Tests/Curation/ExtendedPropertyTests.cs @@ -15,26 +15,25 @@ internal class ExtendedPropertyTests : DatabaseTests [Test] public void ExtendedProperty_Catalogue() { - var cata = new Catalogue(CatalogueRepository,"My cata"); - var prop = new ExtendedProperty(CatalogueRepository,cata,"Fish",5); + var cata = new Catalogue(CatalogueRepository, "My cata"); + var prop = new ExtendedProperty(CatalogueRepository, cata, "Fish", 5); - Assert.AreEqual(5,prop.GetValueAsSystemType()); + Assert.AreEqual(5, prop.GetValueAsSystemType()); Assert.IsTrue(prop.IsReferenceTo(cata)); prop.SetValue(10); prop.SaveToDatabase(); - - Assert.AreEqual(10,prop.GetValueAsSystemType()); + + Assert.AreEqual(10, prop.GetValueAsSystemType()); Assert.IsTrue(prop.IsReferenceTo(cata)); prop.RevertToDatabaseState(); - Assert.AreEqual(10,prop.GetValueAsSystemType()); + Assert.AreEqual(10, prop.GetValueAsSystemType()); Assert.IsTrue(prop.IsReferenceTo(cata)); var prop2 = CatalogueRepository.GetObjectByID(prop.ID); - Assert.AreEqual(10,prop.GetValueAsSystemType()); + Assert.AreEqual(10, prop.GetValueAsSystemType()); Assert.IsTrue(prop.IsReferenceTo(cata)); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/ImportTests/GatherAndShareTests.cs b/Rdmp.Core.Tests/Curation/ImportTests/GatherAndShareTests.cs index 9cfe61ef89..916cf99535 100644 --- a/Rdmp.Core.Tests/Curation/ImportTests/GatherAndShareTests.cs +++ b/Rdmp.Core.Tests/Curation/ImportTests/GatherAndShareTests.cs @@ -22,49 +22,53 @@ namespace Rdmp.Core.Tests.Curation.ImportTests; -public class GatherAndShareTests:DatabaseTests +public class GatherAndShareTests : DatabaseTests { [Test] public void Test_SerializeObject_ShareAttribute() { - var d = new Dictionary(); + var d = new Dictionary(); - var json = JsonConvertExtensions.SerializeObject(d,RepositoryLocator); - var obj = (Dictionary)JsonConvertExtensions.DeserializeObject(json, typeof(Dictionary),RepositoryLocator); + var json = JsonConvertExtensions.SerializeObject(d, RepositoryLocator); + var obj = (Dictionary)JsonConvertExtensions.DeserializeObject(json, + typeof(Dictionary), RepositoryLocator); - Assert.AreEqual(0,obj.Count); + Assert.AreEqual(0, obj.Count); //now add a key - d.Add(new RelationshipAttribute(typeof(string),RelationshipType.SharedObject,"fff"),Guid.Empty); - - json = JsonConvertExtensions.SerializeObject(d,RepositoryLocator); - obj = (Dictionary)JsonConvertExtensions.DeserializeObject(json, typeof(Dictionary),RepositoryLocator); + d.Add(new RelationshipAttribute(typeof(string), RelationshipType.SharedObject, "fff"), Guid.Empty); - Assert.AreEqual(1,obj.Count); + json = JsonConvertExtensions.SerializeObject(d, RepositoryLocator); + obj = (Dictionary)JsonConvertExtensions.DeserializeObject(json, + typeof(Dictionary), RepositoryLocator); + + Assert.AreEqual(1, obj.Count); } [TestCase(true)] [TestCase(false)] public void GatherAndShare_ANOTable_Test(bool goViaJson) { - var anoserver = new ExternalDatabaseServer(CatalogueRepository, "MyGatherAndShareTestANOServer", new ANOStorePatcher()); + var anoserver = + new ExternalDatabaseServer(CatalogueRepository, "MyGatherAndShareTestANOServer", new ANOStorePatcher()); var anoTable = new ANOTable(CatalogueRepository, anoserver, "ANOMagad", "N"); - Assert.AreEqual(anoTable.Server_ID,anoserver.ID); + Assert.AreEqual(anoTable.Server_ID, anoserver.ID); var g = new Gatherer(RepositoryLocator); Assert.IsTrue(g.CanGatherDependencies(anoTable)); var gObj = Gatherer.GatherDependencies(anoTable); - + //root should be the server - Assert.AreEqual(gObj.Object,anoserver); + Assert.AreEqual(gObj.Object, anoserver); Assert.AreEqual(gObj.Children.Single().Object, anoTable); //get the sharing definitions var shareManager = new ShareManager(RepositoryLocator); - var defParent = gObj.ToShareDefinition(shareManager,new List()); - var defChild = gObj.Children.Single().ToShareDefinition(shareManager, new List(new []{defParent})); + var defParent = gObj.ToShareDefinition(shareManager, new List()); + var defChild = gObj.Children.Single() + .ToShareDefinition(shareManager, new List(new[] { defParent })); //make it look like we never had it in the first place shareManager.GetNewOrExistingExportFor(anoserver).DeleteInDatabase(); @@ -72,17 +76,19 @@ public void GatherAndShare_ANOTable_Test(bool goViaJson) anoTable.DeleteInDatabase(); anoserver.DeleteInDatabase(); - if(goViaJson) + if (goViaJson) { - var sParent = JsonConvertExtensions.SerializeObject(defParent,RepositoryLocator); + var sParent = JsonConvertExtensions.SerializeObject(defParent, RepositoryLocator); var sChild = JsonConvertExtensions.SerializeObject(defChild, RepositoryLocator); - defParent = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sParent, typeof(ShareDefinition),RepositoryLocator); - defChild = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sChild, typeof(ShareDefinition), RepositoryLocator); + defParent = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sParent, typeof(ShareDefinition), + RepositoryLocator); + defChild = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sChild, typeof(ShareDefinition), + RepositoryLocator); } var anoserverAfter = new ExternalDatabaseServer(shareManager, defParent); - + Assert.IsTrue(anoserverAfter.Exists()); //new instance @@ -103,7 +109,8 @@ public void GatherAndShare_ANOTable_Test(bool goViaJson) Assert.AreNotEqual(anoTableAfter.Server_ID, anoTable.Server_ID); //same properties - Assert.AreEqual(anoTableAfter.NumberOfCharactersToUseInAnonymousRepresentation, anoTable.NumberOfCharactersToUseInAnonymousRepresentation); + Assert.AreEqual(anoTableAfter.NumberOfCharactersToUseInAnonymousRepresentation, + anoTable.NumberOfCharactersToUseInAnonymousRepresentation); Assert.AreEqual(anoTableAfter.Suffix, anoTable.Suffix); //change a property and save it @@ -116,7 +123,7 @@ public void GatherAndShare_ANOTable_Test(bool goViaJson) Assert.AreEqual(anoTableAfter.ID, anoTableAfter2.ID); Assert.AreEqual("N", anoTableAfter2.Suffix); - + anoTableAfter.DeleteInDatabase(); anoserverAfter.DeleteInDatabase(); @@ -129,11 +136,11 @@ public void GatherAndShare_Plugin_Test() { var f1 = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, $"Imaginary1{PackPluginRunner.PluginPackageSuffix}")); - File.WriteAllBytes(f1.FullName,new byte[]{0x1,0x2}); + File.WriteAllBytes(f1.FullName, new byte[] { 0x1, 0x2 }); - var plugin = new Core.Curation.Data.Plugin(CatalogueRepository,new FileInfo( - $"Imaginary{PackPluginRunner.PluginPackageSuffix}"),new Version(1,1,1),new Version(1,1,1)); - var lma1 = new LoadModuleAssembly(CatalogueRepository,f1,plugin); + var plugin = new Core.Curation.Data.Plugin(CatalogueRepository, new FileInfo( + $"Imaginary{PackPluginRunner.PluginPackageSuffix}"), new Version(1, 1, 1), new Version(1, 1, 1)); + var lma1 = new LoadModuleAssembly(CatalogueRepository, f1, plugin); Assert.AreEqual(lma1.Plugin_ID, plugin.ID); @@ -144,7 +151,7 @@ public void GatherAndShare_Plugin_Test() //root should be the server Assert.AreEqual(gObj.Object, plugin); - Assert.IsTrue(gObj.Children.Any(d=>d.Object.Equals(lma1))); + Assert.IsTrue(gObj.Children.Any(d => d.Object.Equals(lma1))); } @@ -196,7 +203,7 @@ public void GatherAndShare_Catalogue_Test(bool goViaJson) shareDefinition.Select(s => JsonConvertExtensions.SerializeObject(s, RepositoryLocator)).ToList(); shareDefinition = json.Select( - j => JsonConvertExtensions.DeserializeObject(j, typeof (ShareDefinition), RepositoryLocator)) + j => JsonConvertExtensions.DeserializeObject(j, typeof(ShareDefinition), RepositoryLocator)) .Cast() .ToList(); } @@ -207,7 +214,7 @@ public void GatherAndShare_Catalogue_Test(bool goViaJson) cata.LoadMetadata_ID = null; cata.Periodicity = Catalogue.CataloguePeriodicity.Unknown; cata.SaveToDatabase(); - + lmd.DeleteInDatabase(); //import the saved copy @@ -229,11 +236,11 @@ public void GatherAndShare_Catalogue_Test(bool goViaJson) cata.SaveToDatabase(); //test importing the Catalogue properties only - ShareManager.ImportPropertiesOnly(cata,shareDefinition[0]); - + ShareManager.ImportPropertiesOnly(cata, shareDefinition[0]); + //import the defined properties but not name - Assert.AreEqual("fishfish",cata.Name); - Assert.AreEqual(Catalogue.CataloguePeriodicity.BiMonthly,cata.Periodicity); //reset this though + Assert.AreEqual("fishfish", cata.Name); + Assert.AreEqual(Catalogue.CataloguePeriodicity.BiMonthly, cata.Periodicity); //reset this though Assert.IsNull(cata.LoadMetadata_ID); cata.SaveToDatabase(); @@ -247,9 +254,9 @@ public void GatherAndShare_Catalogue_Test(bool goViaJson) //import the saved copy var newObjects = shareManager.ImportSharedObject(shareDefinition).ToArray(); - Assert.AreEqual("Cata", ((Catalogue) newObjects[0]).Name); - Assert.AreEqual("Ci1", ((CatalogueItem) newObjects[1]).Name); - Assert.AreEqual("Ci2", ((CatalogueItem) newObjects[2]).Name); + Assert.AreEqual("Cata", ((Catalogue)newObjects[0]).Name); + Assert.AreEqual("Ci1", ((CatalogueItem)newObjects[1]).Name); + Assert.AreEqual("Ci2", ((CatalogueItem)newObjects[2]).Name); } [Test] @@ -280,26 +287,27 @@ public void GatherAndShare_ExtractionFilter_Test() }; //Give the filter a parameter @a just to make things interesting - var declaration = filter.GetQuerySyntaxHelper().GetParameterDeclaration("@a", new DatabaseTypeRequest(typeof (string), 1)); + var declaration = filter.GetQuerySyntaxHelper() + .GetParameterDeclaration("@a", new DatabaseTypeRequest(typeof(string), 1)); var param = filter.GetFilterFactory().CreateNewParameter(filter, declaration); //Also create a 'known good value' set i.e. recommended value for the parameter to achive some goal (you can have multiple of these - this will not be shared) var set = new ExtractionFilterParameterSet(CatalogueRepository, filter, "Fife"); - var val = new ExtractionFilterParameterSetValue(CatalogueRepository, set, (ExtractionFilterParameter) param) - { - Value = "'FISH'" - }; + var val = new ExtractionFilterParameterSetValue(CatalogueRepository, set, (ExtractionFilterParameter)param) + { + Value = "'FISH'" + }; //Gather the dependencies (this is what we are testing) var gatherer = new Gatherer(RepositoryLocator); - + Assert.IsTrue(gatherer.CanGatherDependencies(filter)); var gathered = Gatherer.GatherDependencies(filter); //gatherer should have gathered the filter and the parameter (but not the ExtractionFilterParameterSet sets) - Assert.AreEqual(1,gathered.Children.Count); - Assert.AreEqual(param,gathered.Children[0].Object); - + Assert.AreEqual(1, gathered.Children.Count); + Assert.AreEqual(param, gathered.Children[0].Object); + //Cleanup val.DeleteInDatabase(); set.DeleteInDatabase(); diff --git a/Rdmp.Core.Tests/Curation/ImportTests/PluginClassTests.cs b/Rdmp.Core.Tests/Curation/ImportTests/PluginClassTests.cs index d4c779b568..e6630e7524 100644 --- a/Rdmp.Core.Tests/Curation/ImportTests/PluginClassTests.cs +++ b/Rdmp.Core.Tests/Curation/ImportTests/PluginClassTests.cs @@ -18,7 +18,7 @@ namespace Rdmp.Core.Tests.Curation.ImportTests; -public class PluginClassTests:UnitTests +public class PluginClassTests : UnitTests { [OneTimeSetUp] protected override void OneTimeSetUp() @@ -53,10 +53,10 @@ public void Catalogue_returns_latest_compatible_plugin() lma1.Plugin.RdmpVersion = new Version(version); //the version of Rdmp.Core targetted lma1.Plugin.PluginVersion = new Version(1, 1, 1, 1); //the version of the plugin lma1.Plugin.SaveToDatabase(); - + lma2.Plugin.Name = "MyPlugin"; - lma2.Plugin.RdmpVersion = new Version(version);//the version of Rdmp.Core targetted (same as above) - lma2.Plugin.PluginVersion = new Version(1, 1, 1, 2);//the version of the plugin (higher) + lma2.Plugin.RdmpVersion = new Version(version); //the version of Rdmp.Core targetted (same as above) + lma2.Plugin.PluginVersion = new Version(1, 1, 1, 2); //the version of the plugin (higher) lma2.SaveToDatabase(); var plugins = Repository.PluginManager.GetCompatiblePlugins(); @@ -80,7 +80,7 @@ public void TestPlugin_OrphanImport_Sharing() $"Blah3.{PackPluginRunner.PluginPackageSuffix}")); File.WriteAllBytes(fi3.FullName, new byte[] { 0x3, 0x4 }); - var p = new Core.Curation.Data.Plugin(Repository, fi,new Version(1,1,1),new Version(1,1,1,1)); + var p = new Core.Curation.Data.Plugin(Repository, fi, new Version(1, 1, 1), new Version(1, 1, 1, 1)); var lma = new LoadModuleAssembly(Repository, fi2, p); var lma2 = new LoadModuleAssembly(Repository, fi3, p); @@ -104,11 +104,11 @@ public void TestPlugin_OrphanImport_Sharing() Assert.AreEqual(3, Repository.GetAllObjects().Length); - lma2 = (LoadModuleAssembly) created[2]; + lma2 = (LoadModuleAssembly)created[2]; //now delete lma2 only lma2.DeleteInDatabase(); - + Assert.AreEqual(2, Repository.GetAllObjects().Length); //import them @@ -118,14 +118,14 @@ public void TestPlugin_OrphanImport_Sharing() Assert.AreEqual(3, created2.Count()); } - [TestCase("Rdmp.1.2.3.nupkg","Rdmp")] - [TestCase("Rdmp.Dicom.1.2.3.nupkg","Rdmp.Dicom")] - [TestCase("Rdmp.Dicom.nupkg","Rdmp.Dicom")] - [TestCase("Rdmp.Dicom","Rdmp.Dicom")] + [TestCase("Rdmp.1.2.3.nupkg", "Rdmp")] + [TestCase("Rdmp.Dicom.1.2.3.nupkg", "Rdmp.Dicom")] + [TestCase("Rdmp.Dicom.nupkg", "Rdmp.Dicom")] + [TestCase("Rdmp.Dicom", "Rdmp.Dicom")] public void Test_Plugin_ShortName(string fullname, string expected) { var p = WhenIHaveA(); p.Name = fullname; - Assert.AreEqual(expected,p.GetShortName()); + Assert.AreEqual(expected, p.GetShortName()); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/ImportTests/ShareLoadMetadataTests.cs b/Rdmp.Core.Tests/Curation/ImportTests/ShareLoadMetadataTests.cs index 98534577e5..7fbe412539 100644 --- a/Rdmp.Core.Tests/Curation/ImportTests/ShareLoadMetadataTests.cs +++ b/Rdmp.Core.Tests/Curation/ImportTests/ShareLoadMetadataTests.cs @@ -31,9 +31,9 @@ public void GatherAndShare_LoadMetadata_EmptyLoadMetadata() var lmd = new LoadMetadata(Repository, "MyLmd"); var lmd2 = ShareToNewRepository(lmd); - + //different repos so not identical - Assert.IsFalse(ReferenceEquals(lmd,lmd2)); + Assert.IsFalse(ReferenceEquals(lmd, lmd2)); Assert.AreEqual(lmd.Name, lmd2.Name); } @@ -48,13 +48,13 @@ public void GatherAndShare_LoadMetadata_WithCatalogue() var cata2 = lmd2.GetAllCatalogues().Single(); //different repos so not identical - Assert.IsFalse(ReferenceEquals(lmd1,lmd2)); - Assert.IsFalse(ReferenceEquals(cata1,cata2)); + Assert.IsFalse(ReferenceEquals(lmd1, lmd2)); + Assert.IsFalse(ReferenceEquals(cata1, cata2)); Assert.AreEqual(lmd1.Name, lmd2.Name); Assert.AreEqual(cata1.Name, cata2.Name); } - + /// /// Tests sharing a basic process task load metadata /// @@ -63,20 +63,20 @@ public void GatherAndShare_LoadMetadata_WithProcessTask() { //create an object LoadMetadata lmd1; - var lmd2 = ShareToNewRepository(lmd1=WhenIHaveA().ProcessTask.LoadMetadata); + var lmd2 = ShareToNewRepository(lmd1 = WhenIHaveA().ProcessTask.LoadMetadata); var pt1 = lmd1.ProcessTasks.Single(); var pt2 = lmd2.ProcessTasks.Single(); - + //different repos so not identical - Assert.IsFalse(ReferenceEquals(lmd1,lmd2)); - AssertAreEqual(lmd1,lmd2); - - Assert.IsFalse(ReferenceEquals(pt1,pt2)); - AssertAreEqual(pt1,pt2); - - Assert.IsFalse(ReferenceEquals(pt1.ProcessTaskArguments.Single(),pt2.ProcessTaskArguments.Single())); - AssertAreEqual(pt1.ProcessTaskArguments.Single(),pt2.ProcessTaskArguments.Single()); + Assert.IsFalse(ReferenceEquals(lmd1, lmd2)); + AssertAreEqual(lmd1, lmd2); + + Assert.IsFalse(ReferenceEquals(pt1, pt2)); + AssertAreEqual(pt1, pt2); + + Assert.IsFalse(ReferenceEquals(pt1.ProcessTaskArguments.Single(), pt2.ProcessTaskArguments.Single())); + AssertAreEqual(pt1.ProcessTaskArguments.Single(), pt2.ProcessTaskArguments.Single()); } /// @@ -105,26 +105,26 @@ public void GatherAndShare_LoadMetadata_WithRealProcessTask() var lmd2 = ShareToNewRepository(lmd1); - + //different repos so not identical - Assert.IsFalse(ReferenceEquals(lmd1,lmd2)); - AssertAreEqual(lmd1,lmd2); + Assert.IsFalse(ReferenceEquals(lmd1, lmd2)); + AssertAreEqual(lmd1, lmd2); var pt2 = lmd2.ProcessTasks.Single(); - Assert.IsFalse(ReferenceEquals(pt1,pt2)); - AssertAreEqual(pt1,pt2); + Assert.IsFalse(ReferenceEquals(pt1, pt2)); + AssertAreEqual(pt1, pt2); - AssertAreEqual(pt1.GetAllArguments(),pt2.GetAllArguments()); + AssertAreEqual(pt1.GetAllArguments(), pt2.GetAllArguments()); var f = new RuntimeTaskFactory(Repository); - var stg = Mock.Of(x => x.LoadStage==LoadStage.Mounting); + var stg = Mock.Of(x => x.LoadStage == LoadStage.Mounting); f.Create(pt1, stg); } - + /// /// Tests sharing a with a which has a reference argument (to /// another object in the database. @@ -139,7 +139,7 @@ public void GatherAndShare_LoadMetadata_WithReferenceProcessTaskArgument() SetupMEF(); var f = new RuntimeTaskFactory(Repository); var stg = Mock.Of(x => - x.LoadStage==LoadStage.Mounting && + x.LoadStage == LoadStage.Mounting && x.DbInfo == new DiscoveredServer(new SqlConnectionStringBuilder()).ExpectDatabase("d")); //create a single process task for the load @@ -158,7 +158,7 @@ public void GatherAndShare_LoadMetadata_WithReferenceProcessTaskArgument() pta.SaveToDatabase(); //check that reflection can assemble the master ProcessTask - var t = (MutilateDataTablesRuntimeTask) f.Create(pt1, stg); + var t = (MutilateDataTablesRuntimeTask)f.Create(pt1, stg); Assert.IsNotNull(((SafePrimaryKeyCollisionResolverMutilation)t.MEFPluginClassInstance).ColumnToResolveOn); //share to the second repository (which won't have that ColumnInfo) @@ -169,23 +169,22 @@ public void GatherAndShare_LoadMetadata_WithReferenceProcessTaskArgument() lmd2.CatalogueRepository.MEF = MEF; //when we create the shared instance it should not have a valid value for ColumnInfo (since it wasn't - and shouldn't be shared) - var t2 = (MutilateDataTablesRuntimeTask) f2.Create(lmd2.ProcessTasks.Single(), stg); + var t2 = (MutilateDataTablesRuntimeTask)f2.Create(lmd2.ProcessTasks.Single(), stg); Assert.IsNull(((SafePrimaryKeyCollisionResolverMutilation)t2.MEFPluginClassInstance).ColumnToResolveOn); - } private LoadMetadata ShareToNewRepository(LoadMetadata lmd) { var gatherer = new Gatherer(RepositoryLocator); - + Assert.IsTrue(gatherer.CanGatherDependencies(lmd)); var rootObj = gatherer.GatherDependencies(lmd); - var sm = new ShareManager(RepositoryLocator,null); + var sm = new ShareManager(RepositoryLocator, null); var shareDefinition = rootObj.ToShareDefinitionWithChildren(sm); var repo2 = new MemoryDataExportRepository(); - var sm2 = new ShareManager(new RepositoryProvider(repo2)); + var sm2 = new ShareManager(new RepositoryProvider(repo2)); return sm2.ImportSharedObject(shareDefinition).OfType().Single(); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/ImportTests/TestImportingAnObject.cs b/Rdmp.Core.Tests/Curation/ImportTests/TestImportingAnObject.cs index f57b202181..71275b231d 100644 --- a/Rdmp.Core.Tests/Curation/ImportTests/TestImportingAnObject.cs +++ b/Rdmp.Core.Tests/Curation/ImportTests/TestImportingAnObject.cs @@ -39,9 +39,9 @@ public void TestSharingAPluginIgnoringCollisions() var p = new Plugin(CatalogueRepository, fi); var lma = new LoadModuleAssembly(CatalogueRepository, fi, p); - + var n = new SharedPluginImporter(p); - + //reject the reuse of an existing one var p2 = n.Import(RepositoryLocator, new ThrowImmediatelyCheckNotifier()); @@ -76,7 +76,7 @@ public void TestSharingAPluginReplaceBinary() newDll.Add("SoftwareVersion", "2.5.0.1"); var n = new SharedPluginImporter(new ShareDefinition(p), new[] { new ShareDefinition(newDll) }); - + //accept that it is an update var p2 = n.Import(RepositoryLocator, new AcceptAllCheckNotifier()); @@ -111,9 +111,9 @@ public void TestSharingAPluginReplaceDllBinary(bool fiddleIds) //edit the binary data to represent a new version of the dll that should be imported lmaStateless.Properties["Dll"] = new byte[] { 0, 1, 0, 1 }; - + var n = new SharedPluginImporter(pStateless,new []{lmaStateless}); - + //accept that it is an update var p2 = n.Import(RepositoryLocator, new AcceptAllCheckNotifier()); diff --git a/Rdmp.Core.Tests/Curation/Integration/AllKeywordsDescribedTest.cs b/Rdmp.Core.Tests/Curation/Integration/AllKeywordsDescribedTest.cs index 0d4049b3a7..9dca71becd 100644 --- a/Rdmp.Core.Tests/Curation/Integration/AllKeywordsDescribedTest.cs +++ b/Rdmp.Core.Tests/Curation/Integration/AllKeywordsDescribedTest.cs @@ -17,9 +17,8 @@ namespace Rdmp.Core.Tests.Curation.Integration; [TestFixture] -public class AllKeywordsDescribedTest :DatabaseTests +public class AllKeywordsDescribedTest : DatabaseTests { - [OneTimeSetUp] protected override void OneTimeSetUp() { @@ -36,21 +35,23 @@ public void AllTablesDescribed() var problems = new List(); - var databaseTypes = typeof(Catalogue).Assembly.GetTypes().Where(t => typeof(IMapsDirectlyToDatabaseTable).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract && !t.Name.StartsWith("Spontaneous") && !t.Name.Contains("Proxy")).ToArray(); - + var databaseTypes = typeof(Catalogue).Assembly.GetTypes().Where(t => + typeof(IMapsDirectlyToDatabaseTable).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract && + !t.Name.StartsWith("Spontaneous") && !t.Name.Contains("Proxy")).ToArray(); + foreach (var type in databaseTypes) { - var docs = CatalogueRepository.CommentStore[type.Name]??CatalogueRepository.CommentStore[$"I{type.Name}"]; - - if(string.IsNullOrWhiteSpace(docs)) + var docs = CatalogueRepository.CommentStore[type.Name] ?? CatalogueRepository.CommentStore[$"I{type.Name}"]; + + if (string.IsNullOrWhiteSpace(docs)) problems.Add( $"Type {type.Name} does not have an entry in the help dictionary (maybe the class doesn't have documentation? - try adding /// style comments to the class)"); - } + foreach (var problem in problems) Console.WriteLine($"Fatal Problem:{problem}"); - Assert.AreEqual(0,problems.Count); + Assert.AreEqual(0, problems.Count); } [Test] @@ -67,11 +68,9 @@ public void AllForeignKeysDescribed() var problems = new List(); foreach (var fkName in allKeys) - { if (!CatalogueRepository.CommentStore.ContainsKey(fkName)) problems.Add($"{fkName} is a foreign Key (which does not CASCADE) but does not have any HelpText"); - } - + foreach (var problem in problems) Console.WriteLine($"Fatal Problem:{problem}"); @@ -92,16 +91,13 @@ public void AllUserIndexesDescribed() var problems = new List(); foreach (var idx in allIndexes) - { if (!CatalogueRepository.CommentStore.ContainsKey(idx)) problems.Add($"{idx} is an index but does not have any HelpText"); - } - + foreach (var problem in problems) Console.WriteLine($"Fatal Problem:{problem}"); - Assert.AreEqual(0,problems.Count,@"Add a description for each of these to KeywordHelp.txt"); - + Assert.AreEqual(0, problems.Count, @"Add a description for each of these to KeywordHelp.txt"); } private static IEnumerable GetForeignKeys(DiscoveredServer server) @@ -109,7 +105,8 @@ private static IEnumerable GetForeignKeys(DiscoveredServer server) using (var con = server.GetConnection()) { con.Open(); - var r = server.GetCommand(@"select name from sys.foreign_keys where delete_referential_action = 0", con).ExecuteReader(); + var r = server.GetCommand(@"select name from sys.foreign_keys where delete_referential_action = 0", con) + .ExecuteReader(); while (r.Read()) yield return (string)r["name"]; diff --git a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ArgumentTypeTests.cs b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ArgumentTypeTests.cs index 86850949fe..1dd3935153 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ArgumentTypeTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ArgumentTypeTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.ArgumentTests; -public class ArgumentTypeTests:UnitTests +public class ArgumentTypeTests : UnitTests { [OneTimeSetUp] protected override void OneTimeSetUp() @@ -23,22 +23,23 @@ protected override void OneTimeSetUp() SetupMEF(); } - private object[] _expectedAnswers = { + private object[] _expectedAnswers = + { 5, new CultureInfo("en-us"), CultureInfo.CurrentCulture }; - - [TestCase(typeof(int),"5",0)] - [TestCase(typeof(CultureInfo),"en-us",1)] + + [TestCase(typeof(int), "5", 0)] + [TestCase(typeof(CultureInfo), "en-us", 1)] public void Test_Type_WithStringValue(Type t, string val, int expectedAnswerIdx) { var arg = WhenIHaveA(); - + arg.SetType(t); arg.Value = val; - Assert.AreEqual(_expectedAnswers[expectedAnswerIdx],arg.GetValueAsSystemType()); + Assert.AreEqual(_expectedAnswers[expectedAnswerIdx], arg.GetValueAsSystemType()); } [Test] @@ -46,14 +47,13 @@ public void TestClassDemandingDouble_CreateArgumentsForClassIfNotExists() { var args = WhenIHaveA().CreateArgumentsForClassIfNotExists(); - Assert.AreEqual(1.0,args.Single().GetValueAsSystemType()); - Assert.AreEqual("1",args.Single().Value); - + Assert.AreEqual(1.0, args.Single().GetValueAsSystemType()); + Assert.AreEqual("1", args.Single().Value); } private class TestClassDemandingDouble { - [DemandsInitialization("some field",defaultValue:1)] + [DemandsInitialization("some field", defaultValue: 1)] public double MyVar { get; set; } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskArgumentTests.cs b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskArgumentTests.cs index 2a9cdfef82..f07a002dc0 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskArgumentTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskArgumentTests.cs @@ -19,7 +19,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.ArgumentTests; -public class ProcessTaskArgumentTests:DatabaseTests +public class ProcessTaskArgumentTests : DatabaseTests { [Test] [TestCase(true)] @@ -28,7 +28,8 @@ public void TypeOfTableInfo(bool declareAsInterface) { var tableInfoName = $"TableInfoFor_{new StackTrace().GetFrame(0).GetMethod().Name}"; - var toCleanup = CatalogueRepository.GetAllObjects().SingleOrDefault(t => t.Name.Equals(tableInfoName)); + var toCleanup = CatalogueRepository.GetAllObjects() + .SingleOrDefault(t => t.Name.Equals(tableInfoName)); toCleanup?.DeleteInDatabase(); @@ -49,12 +50,12 @@ public void TypeOfTableInfo(bool declareAsInterface) var newInstanceOfPTA = CatalogueRepository.GetObjectByID(pta.ID); - Assert.AreEqual(newInstanceOfPTA.Value,pta.Value); + Assert.AreEqual(newInstanceOfPTA.Value, pta.Value); - var t1 = (TableInfo) pta.GetValueAsSystemType(); + var t1 = (TableInfo)pta.GetValueAsSystemType(); var t2 = (TableInfo)newInstanceOfPTA.GetValueAsSystemType(); - Assert.AreEqual(t1.ID,t2.ID); + Assert.AreEqual(t1.ID, t2.ID); } finally { @@ -66,6 +67,7 @@ public void TypeOfTableInfo(bool declareAsInterface) loadMetadata.DeleteInDatabase(); } } + [Test] public void TypeOfPreLoadDiscardedColumn() { @@ -73,10 +75,11 @@ public void TypeOfPreLoadDiscardedColumn() var tableInfoName = $"TableInfoFor_{methodName}"; var preLoadDiscardedColumnName = $"PreLoadDiscardedColumnFor_{methodName}"; - var toCleanup = CatalogueRepository.GetAllObjects().SingleOrDefault(t => t.Name.Equals(tableInfoName)); + var toCleanup = CatalogueRepository.GetAllObjects() + .SingleOrDefault(t => t.Name.Equals(tableInfoName)); var toCleanupCol = CatalogueRepository.GetAllObjects() .SingleOrDefault(c => c.RuntimeColumnName.Equals(preLoadDiscardedColumnName)); - + //must delete pre load discarded first toCleanupCol?.DeleteInDatabase(); @@ -93,7 +96,8 @@ public void TypeOfPreLoadDiscardedColumn() var tableInfo = new TableInfo(CatalogueRepository, tableInfoName); - var preloadDiscardedColumn = new PreLoadDiscardedColumn(CatalogueRepository, tableInfo, preLoadDiscardedColumnName); + var preloadDiscardedColumn = + new PreLoadDiscardedColumn(CatalogueRepository, tableInfo, preLoadDiscardedColumnName); try { pta.SetValue(preloadDiscardedColumn); @@ -124,7 +128,8 @@ public void TableInfoType_FetchAfterDelete_ReturnsNull() { var tableInfoName = $"TableInfoFor_{new StackTrace().GetFrame(0).GetMethod().Name}"; - var toCleanup = CatalogueRepository.GetAllObjects().SingleOrDefault(t => t.Name.Equals(tableInfoName)); + var toCleanup = CatalogueRepository.GetAllObjects() + .SingleOrDefault(t => t.Name.Equals(tableInfoName)); toCleanup?.DeleteInDatabase(); @@ -165,7 +170,8 @@ public void LieToProcessTaskArgumentAboutWhatTypeIs_Throws() { var tableInfoName = $"TableInfoFor_{new StackTrace().GetFrame(0).GetMethod().Name}"; - var toCleanup = CatalogueRepository.GetAllObjects().SingleOrDefault(t => t.Name.Equals(tableInfoName)); + var toCleanup = CatalogueRepository.GetAllObjects() + .SingleOrDefault(t => t.Name.Equals(tableInfoName)); toCleanup?.DeleteInDatabase(); @@ -181,9 +187,10 @@ public void LieToProcessTaskArgumentAboutWhatTypeIs_Throws() //tell it that we are going to give it a PreLoadDiscardedColumn pta.SetType(typeof(PreLoadDiscardedColumn)); //then surprise! heres a TableInfo! - var ex = Assert.Throws(()=>pta.SetValue(tableInfo)); - StringAssert.Contains("has an incompatible Type specified (Rdmp.Core.Curation.Data.DataLoad.PreLoadDiscardedColumn)",ex.Message); - + var ex = Assert.Throws(() => pta.SetValue(tableInfo)); + StringAssert.Contains( + "has an incompatible Type specified (Rdmp.Core.Curation.Data.DataLoad.PreLoadDiscardedColumn)", + ex.Message); } finally { @@ -192,7 +199,6 @@ public void LieToProcessTaskArgumentAboutWhatTypeIs_Throws() } finally { - lmd.DeleteInDatabase(); } } @@ -238,8 +244,7 @@ public void TestEncryptedPasswordHostArgumentType() [Test] public void TestArgumentCreation() { - - var lmd = new LoadMetadata(CatalogueRepository,"TestArgumentCreation"); + var lmd = new LoadMetadata(CatalogueRepository, "TestArgumentCreation"); var pt = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustRaw); pt.CreateArgumentsForClassIfNotExists(); try @@ -249,9 +254,8 @@ public void TestArgumentCreation() Assert.AreEqual("MyBool", arg.Name); Assert.AreEqual("System.Boolean", arg.Type); Assert.AreEqual("Fishes", arg.Description); - Assert.AreEqual("True",arg.Value); + Assert.AreEqual("True", arg.Value); Assert.AreEqual(true, arg.GetValueAsSystemType()); - } finally { @@ -264,7 +268,7 @@ public void TestArgumentCreation() public void TestNestedDemandsGetPutIntoDatabaseAndCanBeBroughtBack() { var pipe = new Pipeline(CatalogueRepository, "NestedPipe"); - var pc = new PipelineComponent(CatalogueRepository, pipe, typeof (BasicDataReleaseDestination), -1, + var pc = new PipelineComponent(CatalogueRepository, pipe, typeof(BasicDataReleaseDestination), -1, "Coconuts"); pipe.DestinationPipelineComponent_ID = pc.ID; pipe.SaveToDatabase(); @@ -272,7 +276,8 @@ public void TestNestedDemandsGetPutIntoDatabaseAndCanBeBroughtBack() //some of the DemandsInitialization on BasicDataReleaseDestination should be nested var f = new ArgumentFactory(); Assert.True( - ArgumentFactory.GetRequiredProperties(typeof(BasicDataReleaseDestination)).Any(r => r.ParentPropertyInfo != null)); + ArgumentFactory.GetRequiredProperties(typeof(BasicDataReleaseDestination)) + .Any(r => r.ParentPropertyInfo != null)); //new pc should have no arguments Assert.That(pc.GetAllArguments(), Is.Empty); @@ -289,7 +294,7 @@ public void TestNestedDemandsGetPutIntoDatabaseAndCanBeBroughtBack() var useCase = ReleaseUseCase.DesignTime(); - var factory = new DataFlowPipelineEngineFactory(useCase,RepositoryLocator.CatalogueRepository.MEF); + var factory = new DataFlowPipelineEngineFactory(useCase, RepositoryLocator.CatalogueRepository.MEF); var destInstance = DataFlowPipelineEngineFactory.CreateDestinationIfExists(pipe); Assert.AreEqual(true, ((BasicDataReleaseDestination)destInstance).ReleaseSettings.DeleteFilesOnSuccess); @@ -304,7 +309,7 @@ public void TestArgumentWithTypeThatIsEnum() "c"); var arg = new PipelineComponentArgument(CatalogueRepository, pc); - + try { arg.SetType(typeof(ExitCodeType)); @@ -335,21 +340,21 @@ public void TestArgumentWithTypeThatIsInterface(bool useInterfaceDeclaration) var arg = new PipelineComponentArgument(CatalogueRepository, pc); - var server = new ExternalDatabaseServer(CatalogueRepository, "fish",null); + var server = new ExternalDatabaseServer(CatalogueRepository, "fish", null); try { - arg.SetType(useInterfaceDeclaration ? typeof (IExternalDatabaseServer) : typeof (ExternalDatabaseServer)); + arg.SetType(useInterfaceDeclaration ? typeof(IExternalDatabaseServer) : typeof(ExternalDatabaseServer)); arg.SetValue(server); //should have set Value string to the ID of the object - Assert.AreEqual(arg.Value,server.ID.ToString()); + Assert.AreEqual(arg.Value, server.ID.ToString()); arg.SaveToDatabase(); //but as system Type should return the server - Assert.AreEqual(arg.GetValueAsSystemType(),server); + Assert.AreEqual(arg.GetValueAsSystemType(), server); } finally { @@ -371,7 +376,7 @@ public void TestArgumentThatIsDictionary() { Name = "MyNames" }; - arg.SetType(typeof(Dictionary)); + arg.SetType(typeof(Dictionary)); arg.SaveToDatabase(); Assert.AreEqual(typeof(Dictionary), arg.GetConcreteSystemType()); @@ -389,8 +394,8 @@ public void TestArgumentThatIsDictionary() arg.SaveToDatabase(); - var val2 = (Dictionary) arg.GetValueAsSystemType(); - Assert.AreEqual(2,val2.Count); + var val2 = (Dictionary)arg.GetValueAsSystemType(); + Assert.AreEqual(2, val2.Count); Assert.AreEqual("Fish", val2[ti1]); Assert.AreEqual("Fish", val2[ti2]); } @@ -399,5 +404,4 @@ public void TestArgumentThatIsDictionary() pipe.DeleteInDatabase(); } } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskTests.cs b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskTests.cs index 81fb1c3591..7008c4ff89 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/ProcessTaskTests.cs @@ -13,7 +13,6 @@ namespace Rdmp.Core.Tests.Curation.Integration.ArgumentTests; public class ProcessTaskTests : DatabaseTests { - [Test] public void CloneProcessTask_ToSameLoadMetadataWithoutArguments() { @@ -28,7 +27,7 @@ public void CloneProcessTask_ToSameLoadMetadataWithoutArguments() { processTask1.SaveToDatabase(); - var clone = processTask1.CloneToNewLoadMetadataStage(test,LoadStage.GetFiles); + var clone = processTask1.CloneToNewLoadMetadataStage(test, LoadStage.GetFiles); Assert.AreNotSame(clone.ID, processTask1.ID); Assert.IsFalse(clone.ID == processTask1.ID); @@ -37,17 +36,17 @@ public void CloneProcessTask_ToSameLoadMetadataWithoutArguments() clone = CatalogueRepository.GetObjectByID(clone.ID); Assert.IsFalse(orig.ID == clone.ID); - Assert.AreEqual(LoadStage.AdjustRaw,orig.LoadStage); + Assert.AreEqual(LoadStage.AdjustRaw, orig.LoadStage); Assert.AreEqual(LoadStage.GetFiles, clone.LoadStage); - Assert.AreEqual(orig.Order,clone.Order); + Assert.AreEqual(orig.Order, clone.Order); Assert.AreEqual(orig.Path, clone.Path); Assert.AreEqual(orig.ProcessTaskType, clone.ProcessTaskType); Assert.AreEqual(orig.LoadMetadata_ID, clone.LoadMetadata_ID); clone.DeleteInDatabase(); } - finally + finally { processTask1.DeleteInDatabase(); test.DeleteInDatabase(); @@ -60,9 +59,9 @@ public void CloneProcessTask_ToNewLoadMetadataWithArguments() //setup parents var parent1 = new LoadMetadata(CatalogueRepository); var parent2 = new LoadMetadata(CatalogueRepository); - + //make sure we didn't magically create the same ID somehow - Assert.AreNotEqual(parent1.ID,parent2.ID); + Assert.AreNotEqual(parent1.ID, parent2.ID); //setup things to clone in parent1 var processTask1 = new ProcessTask(CatalogueRepository, parent1, LoadStage.AdjustRaw); @@ -70,14 +69,14 @@ public void CloneProcessTask_ToNewLoadMetadataWithArguments() { Name = "TestArg" }; - arg.SetType(typeof (string)); + arg.SetType(typeof(string)); arg.SetValue("TestValue"); arg.SaveToDatabase(); processTask1.Name = "Franky"; processTask1.Order = 999; processTask1.SaveToDatabase(); - + try { //clone to parent 2 @@ -89,14 +88,14 @@ public void CloneProcessTask_ToNewLoadMetadataWithArguments() //get fresh copy out of database to ensure it is still there var orig = CatalogueRepository.GetObjectByID(processTask1.ID); clone = CatalogueRepository.GetObjectByID(clone.ID); - + //ids must have changed Assert.IsFalse(orig.ID == clone.ID); //load stages must be correct per what we requested Assert.AreEqual(LoadStage.AdjustRaw, orig.LoadStage); Assert.AreEqual(LoadStage.GetFiles, clone.LoadStage); - + //all regular values must have been cloned successfully Assert.AreEqual(orig.Order, clone.Order); Assert.AreEqual(orig.Path, clone.Path); @@ -108,14 +107,14 @@ public void CloneProcessTask_ToNewLoadMetadataWithArguments() //////////////////////////////////////////////////////////////////CHECK CLONAGE OF ARGUMENTS //////////////////////////////////////////////////////////// - var clonearg = clone.ProcessTaskArguments.SingleOrDefault(); + var clonearg = clone.ProcessTaskArguments.SingleOrDefault(); Assert.NotNull(clonearg); - Assert.AreNotEqual(clonearg.ID,arg.ID); - Assert.AreEqual(clonearg.GetType(),arg.GetType()); - Assert.AreEqual(clonearg.Name,arg.Name); - Assert.AreEqual(clonearg.Value,arg.Value); - + Assert.AreNotEqual(clonearg.ID, arg.ID); + Assert.AreEqual(clonearg.GetType(), arg.GetType()); + Assert.AreEqual(clonearg.Name, arg.Name); + Assert.AreEqual(clonearg.Value, arg.Value); + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// clone.DeleteInDatabase(); } diff --git a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/TestArgumentedClass.cs b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/TestArgumentedClass.cs index b840df8105..b38d416a2e 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/TestArgumentedClass.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ArgumentTests/TestArgumentedClass.cs @@ -10,6 +10,6 @@ namespace Rdmp.Core.Tests.Curation.Integration.ArgumentTests; public class TestArgumentedClass { - [DemandsInitialization("Fishes", DemandType.Unspecified,true)] + [DemandsInitialization("Fishes", DemandType.Unspecified, true)] public bool MyBool { get; set; } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/BundledLookupTableTests.cs b/Rdmp.Core.Tests/Curation/Integration/BundledLookupTableTests.cs index a2ea38a818..cc1d94d16d 100644 --- a/Rdmp.Core.Tests/Curation/Integration/BundledLookupTableTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/BundledLookupTableTests.cs @@ -19,11 +19,12 @@ public class BundledLookupTableTests : UnitTests public void TestLookupGetDataTableFetchSql() { var l = WhenIHaveA(); - var t =l.PrimaryKey.TableInfo; + var t = l.PrimaryKey.TableInfo; var bundle = new BundledLookupTable(t); Assert.AreEqual("select * from [MyDb]..[ChildTable]", bundle.GetDataTableFetchSql()); } + [Test] public void TestLookupGetDataTableFetchSql_WithCatalogue() { @@ -31,7 +32,7 @@ public void TestLookupGetDataTableFetchSql_WithCatalogue() var t = l.PrimaryKey.TableInfo; var engineer = new ForwardEngineerCatalogue(t, t.ColumnInfos); - engineer.ExecuteForwardEngineering(out var cata,out _, out var eis); + engineer.ExecuteForwardEngineering(out var cata, out _, out var eis); var bundle = new BundledLookupTable(t); Assert.AreEqual(@" @@ -63,6 +64,8 @@ public void TestLookupGetDataTableFetchSql_WithCatalogue() // so now there are no columns at all that are extractable var ex = Assert.Throws(() => bundle.GetDataTableFetchSql()); - Assert.AreEqual("Lookup table 'ChildTable' has a Catalogue defined 'ChildTable' but it has no Core extractable columns", ex.Message); + Assert.AreEqual( + "Lookup table 'ChildTable' has a Catalogue defined 'ChildTable' but it has no Core extractable columns", + ex.Message); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/CatalogueCheckTests.cs b/Rdmp.Core.Tests/Curation/Integration/CatalogueCheckTests.cs index 5e2351cacc..ab614dac65 100644 --- a/Rdmp.Core.Tests/Curation/Integration/CatalogueCheckTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/CatalogueCheckTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class CatalogueCheckTests:DatabaseTests +public class CatalogueCheckTests : DatabaseTests { [Test] public void CatalogueCheck_DodgyName() @@ -25,7 +25,7 @@ public void CatalogueCheck_DodgyName() Name = @"c:\bob.txt#" }; - var ex = Assert.Throws(()=>cata.Check(new ThrowImmediatelyCheckNotifier())); + var ex = Assert.Throws(() => cata.Check(new ThrowImmediatelyCheckNotifier())); Assert.IsTrue(ex.Message.Contains("The following invalid characters were found:'\\','.','#'")); cata.DeleteInDatabase(); @@ -41,14 +41,14 @@ public void CatalogueCheck_FetchData(DatabaseType databaseType) dt.Rows.Add("Peter"); var database = GetCleanedServer(databaseType); - var tbl = database.CreateTable("CatalogueCheck_CanReadText",dt); + var tbl = database.CreateTable("CatalogueCheck_CanReadText", dt); var cata = Import(tbl); //shouldn't be any errors var tomemory = new ToMemoryCheckNotifier(); cata.Check(tomemory); - Assert.AreEqual(CheckResult.Success,tomemory.GetWorst()); + Assert.AreEqual(CheckResult.Success, tomemory.GetWorst()); //delete all the records in the table tbl.Truncate(); @@ -64,7 +64,5 @@ public void CatalogueCheck_FetchData(DatabaseType databaseType) //now it should fail checks Assert.AreEqual(CheckResult.Fail, tomemory.GetWorst()); - - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/CatalogueItemTests.cs b/Rdmp.Core.Tests/Curation/Integration/CatalogueItemTests.cs index c39c751e8b..c0c3f2d43a 100644 --- a/Rdmp.Core.Tests/Curation/Integration/CatalogueItemTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/CatalogueItemTests.cs @@ -12,11 +12,9 @@ namespace Rdmp.Core.Tests.Curation.Integration; internal class CatalogueItemTests : DatabaseTests { - [Test] public void constructor_newTestCatalogueItem_pass() { - var parent = new Catalogue(CatalogueRepository, "GROG"); var child1 = new CatalogueItem(CatalogueRepository, parent, "GROG_ITEM1"); @@ -26,7 +24,7 @@ public void constructor_newTestCatalogueItem_pass() Assert.IsTrue(child2.Catalogue_ID == parent.ID); Assert.IsTrue(child1.ID != child2.ID); - + child1.DeleteInDatabase(); child2.DeleteInDatabase(); parent.DeleteInDatabase(); @@ -36,12 +34,11 @@ public void constructor_newTestCatalogueItem_pass() [Test] public void TestSettingColumnInfoToNull() { - var parent = new Catalogue(CatalogueRepository, "GROG"); var child1 = new CatalogueItem(CatalogueRepository, parent, "GROG_ITEM1"); child1.SetColumnInfo(null); - + Assert.IsNull(child1.ColumnInfo_ID); child1.DeleteInDatabase(); parent.DeleteInDatabase(); @@ -57,7 +54,7 @@ public void GetAllCatalogueItemsForCatalogueID_NewCatalogue_pass() var children = parent.CatalogueItems; - Assert.AreEqual(children.Length,2); + Assert.AreEqual(children.Length, 2); Assert.IsTrue(children[0].ID == child1.ID || children[1].ID == child1.ID); Assert.IsTrue(children[0].ID == child2.ID || children[1].ID == child2.ID); Assert.IsTrue(children[0].ID != children[1].ID); @@ -106,7 +103,7 @@ public void update_changeAllPropertiesOfCatalogueItem_passes() [Test] public void clone_CloneCatalogueItemWithIDIntoCatalogue_passes() { - var parent = new Catalogue(CatalogueRepository,"KONGOR"); + var parent = new Catalogue(CatalogueRepository, "KONGOR"); var parent2 = new Catalogue(CatalogueRepository, "KONGOR2"); var child = new CatalogueItem(CatalogueRepository, parent, "KONGOR_SUPERKING") @@ -142,14 +139,13 @@ public void clone_CloneCatalogueItemWithIDIntoCatalogue_passes() Assert.AreEqual(cloneChild.Statistical_cons, child.Statistical_cons); Assert.AreEqual(cloneChild.Topic, child.Topic); } - finally + finally { cloneChild?.DeleteInDatabase(); child.DeleteInDatabase(); parent.DeleteInDatabase(); parent2.DeleteInDatabase(); - } } @@ -157,18 +153,15 @@ public void clone_CloneCatalogueItemWithIDIntoCatalogue_passes() [TestCase(false)] public void TestDeleting_CascadesToExtractionInformations(bool makeOrphanFirst) { - var c = new Catalogue(CatalogueRepository,"My new cata"); + var c = new Catalogue(CatalogueRepository, "My new cata"); var ci = new CatalogueItem(CatalogueRepository, c, "myci"); var t = new TableInfo(CatalogueRepository, "myt"); var col = new ColumnInfo(CatalogueRepository, "mycol", "varchar(10)", t); - var ei = new ExtractionInformation(CatalogueRepository, ci, col,"fff"); + var ei = new ExtractionInformation(CatalogueRepository, ci, col, "fff"); - if(makeOrphanFirst) - { - col.DeleteInDatabase(); - } + if (makeOrphanFirst) col.DeleteInDatabase(); c.DeleteInDatabase(); @@ -177,7 +170,6 @@ public void TestDeleting_CascadesToExtractionInformations(bool makeOrphanFirst) Assert.IsFalse(ei.Exists()); Assert.IsTrue(t.Exists()); - Assert.AreEqual(!makeOrphanFirst,col.Exists()); - + Assert.AreEqual(!makeOrphanFirst, col.Exists()); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/CatalogueTests.cs b/Rdmp.Core.Tests/Curation/Integration/CatalogueTests.cs index 9ef3046934..3c6e79564b 100644 --- a/Rdmp.Core.Tests/Curation/Integration/CatalogueTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/CatalogueTests.cs @@ -29,8 +29,8 @@ public void Test_GetObjects_Catalogue() [Test] public void SettingPropertyViaRelationshipDoesntSave_NoticeHowYouHaveToCacheThePropertyCatalogueToSetIt() { - var c = new Catalogue(Repository,"frank"); - var ci = new CatalogueItem(Repository,c,"bob"); + var c = new Catalogue(Repository, "frank"); + var ci = new CatalogueItem(Repository, c, "bob"); var cata = ci.Catalogue; @@ -41,12 +41,12 @@ public void SettingPropertyViaRelationshipDoesntSave_NoticeHowYouHaveToCacheTheP //now thanks to lazy this works... but it's ambiguous (it works if the property is referenced via IInjectKnown) ci.Catalogue.Name = "fish"; ci.Catalogue.SaveToDatabase(); - Assert.AreEqual("fish",ci.Catalogue.Name); + Assert.AreEqual("fish", ci.Catalogue.Name); c.DeleteInDatabase(); } - - + + [Test] public void update_changeNameOfCatalogue_passes() { @@ -58,25 +58,21 @@ public void update_changeNameOfCatalogue_passes() var catas = Repository.GetAllObjects().ToArray(); foreach (var catalogue in catas) - { if (catalogue.ID == expectedID) { catalogue.Name = "fish"; catalogue.SaveToDatabase(); } - } //find it again and see if its name has changed - then delete it so we don't polute the db var catasAfter = Repository.GetAllObjects().ToArray(); foreach (var catalogue in catasAfter) - { if (catalogue.ID == expectedID) { Assert.AreEqual(catalogue.Name, "fish"); catalogue.DeleteInDatabase(); } - } } [Test] @@ -90,7 +86,6 @@ public void update_changeAllProperties_pass() var catas = Repository.GetAllObjects().ToArray(); foreach (var catalogue in catas) - { if (catalogue.ID == expectedID) { catalogue.Access_options = "backwards,frontwards"; @@ -109,7 +104,7 @@ public void update_changeAllProperties_pass() catalogue.Background_summary = "£50 preferred"; catalogue.Periodicity = Catalogue.CataloguePeriodicity.Monthly; catalogue.Query_tool_URL = new Uri("http://querier.html"); - catalogue.Source_URL = new Uri("http://blackholeSun.html"); + catalogue.Source_URL = new Uri("http://blackholeSun.html"); catalogue.Time_coverage = "comprehensive"; catalogue.Search_keywords = "excitement,fishmongery"; catalogue.Type = Catalogue.CatalogueType.ResearchStudy; @@ -129,56 +124,52 @@ public void update_changeAllProperties_pass() catalogue.SaveToDatabase(); } - } - //find it again and see if it has changed - then delete it so we don't polute the db var catasAfter = Repository.GetAllObjects().ToArray(); foreach (var catalogue in catasAfter) - { if (catalogue.ID == expectedID) { - Assert.AreEqual(catalogue.Access_options , "backwards,frontwards"); - Assert.AreEqual(catalogue.API_access_URL , new Uri("http://API.html")); - Assert.AreEqual(catalogue.Acronym , "abc"); - Assert.AreEqual(catalogue.Attribution_citation , "belongs to dave"); - Assert.AreEqual(catalogue.Browse_URL , new Uri("http://browse.html")); - Assert.AreEqual(catalogue.Bulk_Download_URL , new Uri("http://bulk.html")); - Assert.AreEqual(catalogue.Contact_details , "thomasnind"); + Assert.AreEqual(catalogue.Access_options, "backwards,frontwards"); + Assert.AreEqual(catalogue.API_access_URL, new Uri("http://API.html")); + Assert.AreEqual(catalogue.Acronym, "abc"); + Assert.AreEqual(catalogue.Attribution_citation, "belongs to dave"); + Assert.AreEqual(catalogue.Browse_URL, new Uri("http://browse.html")); + Assert.AreEqual(catalogue.Bulk_Download_URL, new Uri("http://bulk.html")); + Assert.AreEqual(catalogue.Contact_details, "thomasnind"); Assert.AreEqual(catalogue.Geographical_coverage, "fullspectrum"); Assert.AreEqual(catalogue.Resource_owner, "blackhole"); - Assert.AreEqual(catalogue.Description , "exciting stuff of great excitement"); - Assert.AreEqual(catalogue.Detail_Page_URL , new Uri("http://detail.html")); - Assert.AreEqual(catalogue.Last_revision_date , DateTime.Parse("01/01/01")); - Assert.AreEqual(catalogue.Name , "kaptainshield"); + Assert.AreEqual(catalogue.Description, "exciting stuff of great excitement"); + Assert.AreEqual(catalogue.Detail_Page_URL, new Uri("http://detail.html")); + Assert.AreEqual(catalogue.Last_revision_date, DateTime.Parse("01/01/01")); + Assert.AreEqual(catalogue.Name, "kaptainshield"); Assert.AreEqual(catalogue.Background_summary, "£50 preferred"); - Assert.AreEqual(catalogue.Periodicity , Catalogue.CataloguePeriodicity.Monthly); - Assert.AreEqual(catalogue.Query_tool_URL , new Uri("http://querier.html")); - Assert.AreEqual(catalogue.Source_URL , new Uri("http://blackholeSun.html")); - Assert.AreEqual(catalogue.Time_coverage , "comprehensive"); + Assert.AreEqual(catalogue.Periodicity, Catalogue.CataloguePeriodicity.Monthly); + Assert.AreEqual(catalogue.Query_tool_URL, new Uri("http://querier.html")); + Assert.AreEqual(catalogue.Source_URL, new Uri("http://blackholeSun.html")); + Assert.AreEqual(catalogue.Time_coverage, "comprehensive"); Assert.AreEqual(catalogue.Search_keywords, "excitement,fishmongery"); - Assert.AreEqual(catalogue.Type , Catalogue.CatalogueType.ResearchStudy); - Assert.AreEqual(catalogue.Update_freq , "Every darmn second!"); - Assert.AreEqual(catalogue.Update_sched , "periodically on request"); - - - Assert.AreEqual(catalogue.Country_of_origin , "United Kingdom"); - Assert.AreEqual(catalogue.Data_standards , "Highly Standardised"); - Assert.AreEqual(catalogue.Administrative_contact_address , "Candyland"); - Assert.AreEqual(catalogue.Administrative_contact_email , "big@brother.com"); - Assert.AreEqual(catalogue.Administrative_contact_name , "Uncle Sam"); - Assert.AreEqual(catalogue.Administrative_contact_telephone , "12345 67890"); - Assert.AreEqual(catalogue.Explicit_consent , true); - Assert.AreEqual(catalogue.Ethics_approver , "Tayside Supernatural Department"); - Assert.AreEqual(catalogue.Source_of_data_collection , "Invented by Unit Test"); + Assert.AreEqual(catalogue.Type, Catalogue.CatalogueType.ResearchStudy); + Assert.AreEqual(catalogue.Update_freq, "Every darmn second!"); + Assert.AreEqual(catalogue.Update_sched, "periodically on request"); + + + Assert.AreEqual(catalogue.Country_of_origin, "United Kingdom"); + Assert.AreEqual(catalogue.Data_standards, "Highly Standardised"); + Assert.AreEqual(catalogue.Administrative_contact_address, "Candyland"); + Assert.AreEqual(catalogue.Administrative_contact_email, "big@brother.com"); + Assert.AreEqual(catalogue.Administrative_contact_name, "Uncle Sam"); + Assert.AreEqual(catalogue.Administrative_contact_telephone, "12345 67890"); + Assert.AreEqual(catalogue.Explicit_consent, true); + Assert.AreEqual(catalogue.Ethics_approver, "Tayside Supernatural Department"); + Assert.AreEqual(catalogue.Source_of_data_collection, "Invented by Unit Test"); Assert.AreEqual(catalogue.SubjectNumbers, "100,000,000"); catalogue.DeleteInDatabase(); } - } } [Test] @@ -199,13 +190,11 @@ public void create_blankConstructorCatalogue_createsNewInDatabase() var numberDeleted = 0; foreach (var cata in catasAfter) - { if (cata.ID == expectedID) { cata.DeleteInDatabase(); numberDeleted++; } - } Assert.AreEqual(numberDeleted, 1); } @@ -223,7 +212,7 @@ public void GetCatalogueWithID_validID_pass() Assert.NotNull(c); Assert.True(c.Name == "TEST"); - + c.DeleteInDatabase(); } @@ -244,7 +233,7 @@ public void TestGetTablesAndLookupTables() //2 columns come from table 1 var t1 = new TableInfo(Repository, "Table1"); - var t1_c1 = new ColumnInfo(Repository, "Col1","varchar(10)",t1); + var t1_c1 = new ColumnInfo(Repository, "Col1", "varchar(10)", t1); var t1_c2 = new ColumnInfo(Repository, "Col2", "int", t1); //2 columns come from table 2 @@ -259,42 +248,42 @@ public void TestGetTablesAndLookupTables() //wire SetUp virtual columns to underlying columns ci1.SetColumnInfo(t1_c1); - ci2.SetColumnInfo( t1_c2); - ci3.SetColumnInfo( t2_c1); - ci4.SetColumnInfo( t2_c2); - ci5.SetColumnInfo( t3_c1); - ci6.SetColumnInfo( t3_c2); + ci2.SetColumnInfo(t1_c2); + ci3.SetColumnInfo(t2_c1); + ci4.SetColumnInfo(t2_c2); + ci5.SetColumnInfo(t3_c1); + ci6.SetColumnInfo(t3_c2); //configure the lookup relationship - var lookup = new Lookup(Repository, t3_c1, t1_c2, t3_c2,ExtractionJoinType.Left, ""); + var lookup = new Lookup(Repository, t3_c1, t1_c2, t3_c2, ExtractionJoinType.Left, ""); try { var allTables = cata.GetTableInfoList(true).ToArray(); - Assert.Contains(t1,allTables); + Assert.Contains(t1, allTables); Assert.Contains(t2, allTables); Assert.Contains(t3, allTables); var normalTablesOnly = cata.GetTableInfoList(false).ToArray(); - Assert.AreEqual(2,normalTablesOnly.Length); - Assert.Contains(t1,normalTablesOnly); + Assert.AreEqual(2, normalTablesOnly.Length); + Assert.Contains(t1, normalTablesOnly); Assert.Contains(t2, normalTablesOnly); var lookupTablesOnly = cata.GetLookupTableInfoList(); - Assert.AreEqual(1,lookupTablesOnly.Length); - Assert.Contains(t3,lookupTablesOnly); + Assert.AreEqual(1, lookupTablesOnly.Length); + Assert.Contains(t3, lookupTablesOnly); cata.GetTableInfos(out var normalTables, out var lookupTables); - Assert.AreEqual(2,normalTables.Count); + Assert.AreEqual(2, normalTables.Count); Assert.AreEqual(1, lookupTables.Count); - Assert.Contains(t1,normalTables); + Assert.Contains(t1, normalTables); Assert.Contains(t2, normalTables); - Assert.Contains(t3,lookupTables); + Assert.Contains(t3, lookupTables); } finally { lookup.DeleteInDatabase(); - + t1.DeleteInDatabase(); t2.DeleteInDatabase(); t3.DeleteInDatabase(); @@ -309,17 +298,18 @@ public void CatalogueFolder_DefaultIsRoot() var c = new Catalogue(Repository, "bob"); try { - Assert.AreEqual("\\",c.Folder); + Assert.AreEqual("\\", c.Folder); } finally { c.DeleteInDatabase(); } } + [Test] public void CatalogueFolder_ChangeAndSave() { - var c = new Catalogue(Repository, "bob"); + var c = new Catalogue(Repository, "bob"); try { c.Folder = "\\Research\\Important"; @@ -342,8 +332,8 @@ public void CatalogueFolder_CannotSetToNonRoot() var c = new Catalogue(Repository, "bob"); try { - var ex = Assert.Throws(()=>c.Folder = "fish"); - Assert.AreEqual(@"All catalogue paths must start with \. Invalid path was:fish",ex.Message); + var ex = Assert.Throws(() => c.Folder = "fish"); + Assert.AreEqual(@"All catalogue paths must start with \. Invalid path was:fish", ex.Message); } finally { @@ -357,15 +347,17 @@ public void CatalogueFolder_CannotSetToNull() var c = new Catalogue(Repository, "bob"); try { - var ex = Assert.Throws(()=>c.Folder = null); - Assert.AreEqual(@"An attempt was made to set Catalogue Folder to null, every Catalogue must have a folder, set it to \ if you want the root", ex.Message); + var ex = Assert.Throws(() => c.Folder = null); + Assert.AreEqual( + @"An attempt was made to set Catalogue Folder to null, every Catalogue must have a folder, set it to \ if you want the root", + ex.Message); } finally { c.DeleteInDatabase(); } } - + [Test] public void CatalogueFolder_CannotHaveDoubleSlashes() { @@ -373,8 +365,9 @@ public void CatalogueFolder_CannotHaveDoubleSlashes() try { //notice the @ symbol that makes the double slashes actual double slashes - common error we might make and what this test is designed to prevent - var ex = Assert.Throws(()=>c.Folder = @"\\bob\\"); - Assert.AreEqual(@"Catalogue paths cannot contain double slashes '\\', Invalid path was:\\bob\\", ex.Message); + var ex = Assert.Throws(() => c.Folder = @"\\bob\\"); + Assert.AreEqual(@"Catalogue paths cannot contain double slashes '\\', Invalid path was:\\bob\\", + ex.Message); } finally { @@ -385,16 +378,15 @@ public void CatalogueFolder_CannotHaveDoubleSlashes() [Test] public void RelatedCatalogueTest_NoCatalogues() { - var t = new TableInfo(Repository,"MyTable"); + var t = new TableInfo(Repository, "MyTable"); try { - Assert.AreEqual(0,t.GetAllRelatedCatalogues().Length); + Assert.AreEqual(0, t.GetAllRelatedCatalogues().Length); } finally { t.DeleteInDatabase(); } - } [Test] @@ -403,10 +395,10 @@ public void RelatedCatalogueTest_NoCatalogues() public void RelatedCatalogueTest_OneCatalogue(bool createExtractionInformation) { var t = new TableInfo(Repository, "MyTable"); - var c = new ColumnInfo(Repository,"MyCol","varchar(10)",t); + var c = new ColumnInfo(Repository, "MyCol", "varchar(10)", t); - var cata = new Catalogue(Repository,"MyCata"); - var ci = new CatalogueItem(Repository,cata,"MyCataItem"); + var cata = new Catalogue(Repository, "MyCata"); + var ci = new CatalogueItem(Repository, cata, "MyCataItem"); try { @@ -417,7 +409,7 @@ public void RelatedCatalogueTest_OneCatalogue(bool createExtractionInformation) var catas = t.GetAllRelatedCatalogues(); Assert.AreEqual(1, catas.Length); - Assert.AreEqual(cata,catas[0]); + Assert.AreEqual(cata, catas[0]); } finally { @@ -458,11 +450,9 @@ public void RelatedCatalogueTest_TwoCatalogues_TwoColumnsEach(bool createExtract ci1_2.SetColumnInfo(c2); ci2_1.SetColumnInfo(c2); ci2_2.SetColumnInfo(c1); - } - var catas = t.GetAllRelatedCatalogues(); Assert.AreEqual(2, catas.Length); Assert.IsTrue(catas.Contains(cata1)); @@ -474,14 +464,13 @@ public void RelatedCatalogueTest_TwoCatalogues_TwoColumnsEach(bool createExtract cata2.DeleteInDatabase(); t.DeleteInDatabase(); } - } - [TestCase("\\","\\")] + [TestCase("\\", "\\")] [TestCase("\\fish", "fish")] [TestCase("\\fish\\dog\\cat", "cat")] - public void TestTreeNode_FullName_CleanPaths(string fullName,string expectedName) + public void TestTreeNode_FullName_CleanPaths(string fullName, string expectedName) { var r1 = WhenIHaveA(); r1.Folder = fullName; @@ -489,11 +478,8 @@ public void TestTreeNode_FullName_CleanPaths(string fullName,string expectedName var tree = FolderHelper.BuildFolderTree(new[] { r1 }); var bottomFolder = tree; - - while(bottomFolder.ChildFolders.Any()) - { - bottomFolder = bottomFolder.ChildFolders.Single(); - } + + while (bottomFolder.ChildFolders.Any()) bottomFolder = bottomFolder.ChildFolders.Single(); Assert.AreEqual(expectedName, bottomFolder.Name); Assert.AreEqual(fullName, bottomFolder.FullName); @@ -527,7 +513,7 @@ public void TestBuildFolderTree() var objects = new IHasFolder[] { - r1,r2,cat,fun,morefun + r1, r2, cat, fun, morefun }; @@ -561,7 +547,7 @@ public void TestBuildFolderTree_MiddleBranches() var objects = new IHasFolder[] { - cata1,cata2 + cata1, cata2 }; var tree = FolderHelper.BuildFolderTree(objects); diff --git a/Rdmp.Core.Tests/Curation/Integration/ColumnInfoTests.cs b/Rdmp.Core.Tests/Curation/Integration/ColumnInfoTests.cs index 1778e1412b..bf34a0f17f 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ColumnInfoTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ColumnInfoTests.cs @@ -15,14 +15,11 @@ namespace Rdmp.Core.Tests.Curation.Integration; internal class ColumnInfoTests : DatabaseTests { - - - [Test] public void CreateNewColumnInfoInDatabase_NewColumns_NewColumnsAreEqualAfterSave() { TableInfo parent = null; - ColumnInfo child=null; + ColumnInfo child = null; try { @@ -43,28 +40,24 @@ public void CreateNewColumnInfoInDatabase_NewColumns_NewColumnsAreEqualAfterSave Assert.AreEqual(child.Description, childAfter.Description); Assert.AreEqual(child.Status, childAfter.Status); Assert.AreEqual(child.RegexPattern, childAfter.RegexPattern); - Assert.AreEqual(child.ValidationRules, childAfter.ValidationRules); - + Assert.AreEqual(child.ValidationRules, childAfter.ValidationRules); } - finally + finally { child.DeleteInDatabase(); parent.DeleteInDatabase(); } - - } [Test] public void GetAllColumnInfos_moreThan1_pass() { - var parent = new TableInfo(CatalogueRepository, "Slalom"); try { - var ci = new ColumnInfo(CatalogueRepository, "MyAwesomeColumn","varchar(1000)", parent); - + var ci = new ColumnInfo(CatalogueRepository, "MyAwesomeColumn", "varchar(1000)", parent); + try { Assert.IsTrue(CatalogueRepository.GetAllObjectsWithParent(parent).Length == 1); @@ -84,13 +77,14 @@ public void GetAllColumnInfos_moreThan1_pass() public void CreateNewColumnInfoInDatabase_valid_pass() { var parent = new TableInfo(CatalogueRepository, "Lazors"); - var columnInfo = new ColumnInfo(CatalogueRepository, "Lazor Reflection Vol","varchar(1000)",parent); + var columnInfo = new ColumnInfo(CatalogueRepository, "Lazor Reflection Vol", "varchar(1000)", parent); Assert.NotNull(columnInfo); columnInfo.DeleteInDatabase(); - var ex = Assert.Throws(() => CatalogueRepository.GetObjectByID(columnInfo.ID)); + var ex = Assert.Throws(() => + CatalogueRepository.GetObjectByID(columnInfo.ID)); Assert.IsTrue(ex.Message.StartsWith($"Could not find ColumnInfo with ID {columnInfo.ID}"), ex.Message); parent.DeleteInDatabase(); @@ -100,7 +94,7 @@ public void CreateNewColumnInfoInDatabase_valid_pass() public void update_changeAllProperties_pass() { var parent = new TableInfo(CatalogueRepository, "Rokkits"); - var column = new ColumnInfo(CatalogueRepository, "ExplosiveVol","varchar(1000)", parent) + var column = new ColumnInfo(CatalogueRepository, "ExplosiveVol", "varchar(1000)", parent) { Digitisation_specs = "Highly digitizable", Format = "Jpeg", @@ -124,7 +118,7 @@ public void update_changeAllProperties_pass() } [Test] - public void Test_GetRAWStageTypeWhenPreLoadDiscardedDilution() + public void Test_GetRAWStageTypeWhenPreLoadDiscardedDilution() { var parent = new TableInfo(CatalogueRepository, "Rokkits"); var column = new ColumnInfo(CatalogueRepository, "MyCol", "varchar(4)", parent); @@ -142,6 +136,5 @@ public void Test_GetRAWStageTypeWhenPreLoadDiscardedDilution() discard.DeleteInDatabase(); parent.DeleteInDatabase(); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/CommitInProgressTests.cs b/Rdmp.Core.Tests/Curation/Integration/CommitInProgressTests.cs index 00134f056b..8124d572f0 100644 --- a/Rdmp.Core.Tests/Curation/Integration/CommitInProgressTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/CommitInProgressTests.cs @@ -27,8 +27,8 @@ public void CommitInProgress_CatalogueModify() c.SaveToDatabase(); var activator = new ThrowImmediatelyActivator(RepositoryLocator); - - Assert.IsNull(start.TryFinish(activator),"No changes made to Catalogue so expected no commit"); + + Assert.IsNull(start.TryFinish(activator), "No changes made to Catalogue so expected no commit"); c.Name = "abadaba"; c.IsDeprecated = true; @@ -51,10 +51,10 @@ public void CommitInProgress_TestCancellation() { var c = new Catalogue(CatalogueRepository, "Hey"); - Assert.AreEqual(ChangeDescription.NoChanges,c.HasLocalChanges().Evaluation, + Assert.AreEqual(ChangeDescription.NoChanges, c.HasLocalChanges().Evaluation, "We just created this Catalogue, how can db copy be different?!"); - var start = new CommitInProgress(RepositoryLocator, new CommitInProgressSettings(c) + var start = new CommitInProgress(RepositoryLocator, new CommitInProgressSettings(c) { UseTransactions = true }); diff --git a/Rdmp.Core.Tests/Curation/Integration/ComprehensiveQueryPerformanceCounterTests.cs b/Rdmp.Core.Tests/Curation/Integration/ComprehensiveQueryPerformanceCounterTests.cs index 24824b8a18..ef637d7f68 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ComprehensiveQueryPerformanceCounterTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ComprehensiveQueryPerformanceCounterTests.cs @@ -21,20 +21,19 @@ public void TestPerformance() if (TestDatabaseSettings.UseFileSystemRepo) Assert.Inconclusive("No queries are run when using file back repository"); - var pCounter = new ComprehensiveQueryPerformanceCounter(); + var pCounter = new ComprehensiveQueryPerformanceCounter(); //enable performance counting DatabaseCommandHelper.PerformanceCounter = pCounter; try { - //send some queries - var cata = new Catalogue(CatalogueRepository, "Fish"); + var cata = new Catalogue(CatalogueRepository, "Fish"); Assert.IsTrue(cata.Name.Equals("Fish")); var commands = pCounter.DictionaryOfQueries.Values.ToArray(); Assert.IsTrue(commands.Any(c => c.QueryText.Contains("SELECT * FROM [Catalogue] WHERE ID="))); - + cata.DeleteInDatabase(); } finally diff --git a/Rdmp.Core.Tests/Curation/Integration/CredentialsTests.cs b/Rdmp.Core.Tests/Curation/Integration/CredentialsTests.cs index dbb28a0a36..ed1d188bab 100644 --- a/Rdmp.Core.Tests/Curation/Integration/CredentialsTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/CredentialsTests.cs @@ -23,7 +23,6 @@ protected override void OneTimeSetUp() base.OneTimeSetUp(); foreach (var table in CatalogueRepository.GetAllObjects()) - { if (table.Name.Equals("GetCredentialsFromATableInfo") || table.Name.Equals("Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt1") @@ -41,19 +40,13 @@ protected override void OneTimeSetUp() table.Name.Equals("Tableinfo1") ) table.DeleteInDatabase(); - } foreach (var cred in CatalogueRepository.GetAllObjects()) - { - if(cred.Name.Equals("bob") - || - cred.Name.Equals("Test") - ) + if (cred.Name.Equals("bob") + || + cred.Name.Equals("Test") + ) cred.DeleteInDatabase(); - } - - - } [Test] @@ -84,9 +77,10 @@ public void CreateNewCredentialsThenGetByUsernamePasswordCombo() newCredentials.SaveToDatabase(); - var newCopy = CatalogueRepository.GetAllObjects().SingleOrDefault(c=>c.Username == "myusername"); + var newCopy = CatalogueRepository.GetAllObjects() + .SingleOrDefault(c => c.Username == "myusername"); Assert.IsNotNull(newCopy); - + try { Assert.NotNull(newCopy); @@ -98,7 +92,6 @@ public void CreateNewCredentialsThenGetByUsernamePasswordCombo() finally { newCredentials.DeleteInDatabase(); - } } @@ -120,10 +113,8 @@ public void TestThe_Any_EnumValue_CannotRequestAnyCredentials() tableInfo.SaveToDatabase(); //attempt to request ANY credentials - var ex = Assert.Throws(()=> tableInfo.GetCredentialsIfExists(DataAccessContext.Any)); - Assert.AreEqual("You cannot ask for any credentials, you must supply a usage context.",ex.Message); - - + var ex = Assert.Throws(() => tableInfo.GetCredentialsIfExists(DataAccessContext.Any)); + Assert.AreEqual("You cannot ask for any credentials, you must supply a usage context.", ex.Message); } finally { @@ -131,6 +122,7 @@ public void TestThe_Any_EnumValue_CannotRequestAnyCredentials() creds.DeleteInDatabase(); } } + [Test] public void TestThe_Any_EnumValue() { @@ -145,7 +137,7 @@ public void TestThe_Any_EnumValue() { creds.Name = "Test"; creds.SaveToDatabase(); - + //now create the association as Any tableInfo.SetCredentials(creds, DataAccessContext.Any); @@ -156,7 +148,6 @@ public void TestThe_Any_EnumValue() Assert.NotNull(creds2); creds2 = tableInfo.GetCredentialsIfExists(DataAccessContext.DataLoad); Assert.NotNull(creds2); - } finally { @@ -176,7 +167,7 @@ public void Test_Any_PrioritisingTheMoreAppropriateCredential() var creds = new DataAccessCredentials(CatalogueRepository); var creds2 = new DataAccessCredentials(CatalogueRepository); - + try { creds.Name = "Test"; @@ -185,10 +176,9 @@ public void Test_Any_PrioritisingTheMoreAppropriateCredential() //now create the association as Any tableInfo.SetCredentials(creds, DataAccessContext.DataLoad); tableInfo.SetCredentials(creds2, DataAccessContext.Any); - - - Assert.AreEqual(creds, tableInfo.GetCredentialsIfExists(DataAccessContext.DataLoad)); + + Assert.AreEqual(creds, tableInfo.GetCredentialsIfExists(DataAccessContext.DataLoad)); } finally { @@ -216,10 +206,9 @@ public void SaveAndReloadCredentials() Assert.AreEqual(originalCredentials.Password, newCopy.Password); //test overridden Equals - Assert.AreEqual(originalCredentials,newCopy); + Assert.AreEqual(originalCredentials, newCopy); originalCredentials.Password = "fish"; - Assert.AreEqual(originalCredentials, newCopy);//they are still equal because IDs are the same - + Assert.AreEqual(originalCredentials, newCopy); //they are still equal because IDs are the same } finally { @@ -230,7 +219,6 @@ public void SaveAndReloadCredentials() [Test] public void GetCredentialsFromATableInfo() { - var tableInfo = new TableInfo(CatalogueRepository, "GetCredentialsFromATableInfo") { Name = "My Exciting Table" @@ -246,7 +234,8 @@ public void GetCredentialsFromATableInfo() tableInfo.SaveToDatabase(); //Go via TableInfo and get credentials - var creds2 = (DataAccessCredentials)tableInfo.GetCredentialsIfExists(DataAccessContext.InternalDataProcessing); + var creds2 = + (DataAccessCredentials)tableInfo.GetCredentialsIfExists(DataAccessContext.InternalDataProcessing); Assert.AreEqual(creds2.Name, creds.Name); } finally @@ -266,33 +255,33 @@ public void Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt_ThrowsT try { - - tableInfo1.SetCredentials(creds,DataAccessContext.InternalDataProcessing); + tableInfo1.SetCredentials(creds, DataAccessContext.InternalDataProcessing); tableInfo2.SetCredentials(creds, DataAccessContext.InternalDataProcessing); tableInfo1.SaveToDatabase(); tableInfo2.SaveToDatabase(); - var ex = Assert.Throws(creds.DeleteInDatabase);//the bit that fails (because tables are there) - Assert.AreEqual("Cannot delete credentials bob because it is in use by one or more TableInfo objects(Dependency1,Dependency2)",ex.Message); + var ex = Assert.Throws(creds + .DeleteInDatabase); //the bit that fails (because tables are there) + Assert.AreEqual( + "Cannot delete credentials bob because it is in use by one or more TableInfo objects(Dependency1,Dependency2)", + ex.Message); } finally { - tableInfo1.DeleteInDatabase();//will work - tableInfo2.DeleteInDatabase();//will work - creds.DeleteInDatabase();//will work + tableInfo1.DeleteInDatabase(); //will work + tableInfo2.DeleteInDatabase(); //will work + creds.DeleteInDatabase(); //will work } - - - } [Test] public void GetAllUsersOfACredential() { - //Get all TableInfos that share this credential - var tableInfo1 = new TableInfo(CatalogueRepository, "Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt1"); - var tableInfo2 = new TableInfo(CatalogueRepository, "Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt2"); + var tableInfo1 = new TableInfo(CatalogueRepository, + "Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt1"); + var tableInfo2 = new TableInfo(CatalogueRepository, + "Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt2"); var creds = new DataAccessCredentials(CatalogueRepository, "bob"); tableInfo1.SetCredentials(creds, DataAccessContext.InternalDataProcessing); @@ -301,10 +290,11 @@ public void GetAllUsersOfACredential() tableInfo2.SaveToDatabase(); - var TablesThatUseCredential = creds.GetAllTableInfosThatUseThis()[DataAccessContext.InternalDataProcessing].ToArray(); + var TablesThatUseCredential = + creds.GetAllTableInfosThatUseThis()[DataAccessContext.InternalDataProcessing].ToArray(); Assert.Contains(tableInfo1, TablesThatUseCredential); - Assert.Contains(tableInfo2, TablesThatUseCredential); + Assert.Contains(tableInfo2, TablesThatUseCredential); tableInfo1.DeleteInDatabase(); tableInfo2.DeleteInDatabase(); @@ -314,10 +304,12 @@ public void GetAllUsersOfACredential() [Test] public void GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride() { - var c = new Catalogue(CatalogueRepository, "GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride"); - var ci = new CatalogueItem(CatalogueRepository, c,"GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride"); + var c = new Catalogue(CatalogueRepository, + "GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride"); + var ci = new CatalogueItem(CatalogueRepository, c, + "GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride"); var t = new TableInfo(CatalogueRepository, "Test"); - var col = new ColumnInfo(CatalogueRepository, "[mydatabase].[dbo].test.col","varchar(10)", t); + var col = new ColumnInfo(CatalogueRepository, "[mydatabase].[dbo].test.col", "varchar(10)", t); var extractionInformation = new ExtractionInformation(CatalogueRepository, ci, col, col.Name); @@ -326,14 +318,14 @@ public void GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOve { t.Server = "myserver"; t.Database = "mydatabase"; - + cred = new DataAccessCredentials(CatalogueRepository, "bob") { Username = "bob", Password = "pass" }; - Assert.AreNotEqual("pass",cred.Password); + Assert.AreNotEqual("pass", cred.Password); Assert.AreEqual("pass", cred.GetDecryptedPassword()); @@ -341,22 +333,20 @@ public void GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOve t.SetCredentials(cred, DataAccessContext.InternalDataProcessing); t.SaveToDatabase(); - var constr = (SqlConnectionStringBuilder)c.GetDistinctLiveDatabaseServer(DataAccessContext.InternalDataProcessing,false).Builder; - Assert.AreEqual("myserver",constr.DataSource); + var constr = + (SqlConnectionStringBuilder)c + .GetDistinctLiveDatabaseServer(DataAccessContext.InternalDataProcessing, false).Builder; + Assert.AreEqual("myserver", constr.DataSource); Assert.False(constr.IntegratedSecurity); Assert.AreEqual("bob", constr.UserID); Assert.AreEqual("pass", constr.Password); - - } - finally + finally { t.DeleteInDatabase(); cred?.DeleteInDatabase(); - c.DeleteInDatabase();//no need to delete ci because of cascades - + c.DeleteInDatabase(); //no need to delete ci because of cascades } - } [Test] @@ -372,8 +362,8 @@ public void Test_BlankPasswords() var manager = new TableInfoCredentialsManager(CatalogueTableRepository); - Assert.AreEqual(creds,manager.GetCredentialByUsernameAndPasswordIfExists("Root",null)); - Assert.AreEqual(creds,manager.GetCredentialByUsernameAndPasswordIfExists("Root","")); + Assert.AreEqual(creds, manager.GetCredentialByUsernameAndPasswordIfExists("Root", null)); + Assert.AreEqual(creds, manager.GetCredentialByUsernameAndPasswordIfExists("Root", "")); } [Test] @@ -386,11 +376,12 @@ public void Test_NoDuplicatePasswords() //if there is a username then we need to associate it with the TableInfo we just created var credentialsFactory = new DataAccessCredentialsFactory(CatalogueRepository); - var cred = credentialsFactory.Create(t1, "blarg", "flarg",DataAccessContext.Any); + var cred = credentialsFactory.Create(t1, "blarg", "flarg", DataAccessContext.Any); var cred2 = credentialsFactory.Create(t2, "blarg", "flarg", DataAccessContext.Any); Assert.AreEqual(credCount + 1, CatalogueRepository.GetAllObjects().Length); - - Assert.AreEqual(cred, cred2, $"Expected {nameof(DataAccessCredentialsFactory)} to reuse existing credentials for both tables as they have the same username/password - e.g. bulk insert"); + + Assert.AreEqual(cred, cred2, + $"Expected {nameof(DataAccessCredentialsFactory)} to reuse existing credentials for both tables as they have the same username/password - e.g. bulk insert"); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/CrossDatabaseTriggerTests.cs b/Rdmp.Core.Tests/Curation/Integration/CrossDatabaseTriggerTests.cs index 8331cfe35f..9430e838a2 100644 --- a/Rdmp.Core.Tests/Curation/Integration/CrossDatabaseTriggerTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/CrossDatabaseTriggerTests.cs @@ -28,21 +28,21 @@ public void TriggerImplementationTest(DatabaseType type) var db = GetCleanedServer(type); var tbl = db.CreateTable("MyTable", new[] { - new DatabaseColumnRequest("name", new DatabaseTypeRequest(typeof (string), 30),false), - new DatabaseColumnRequest("bubbles", new DatabaseTypeRequest(typeof (int))) + new DatabaseColumnRequest("name", new DatabaseTypeRequest(typeof(string), 30), false), + new DatabaseColumnRequest("bubbles", new DatabaseTypeRequest(typeof(int))) }); var factory = new TriggerImplementerFactory(type); var implementer = factory.Create(tbl); - - Assert.AreEqual(TriggerStatus.Missing,implementer.GetTriggerStatus()); - Assert.AreEqual(2,tbl.DiscoverColumns().Length); + Assert.AreEqual(TriggerStatus.Missing, implementer.GetTriggerStatus()); + + Assert.AreEqual(2, tbl.DiscoverColumns().Length); implementer = factory.Create(tbl); //no primary keys - Assert.Throws(()=>implementer.CreateTrigger(new ThrowImmediatelyCheckNotifier())); + Assert.Throws(() => implementer.CreateTrigger(new ThrowImmediatelyCheckNotifier())); tbl.CreatePrimaryKey(tbl.DiscoverColumn("name")); @@ -59,25 +59,33 @@ public void TriggerImplementationTest(DatabaseType type) Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("name"))); Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("bubbles"))); - Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("hic_dataLoadrunID",StringComparison.CurrentCultureIgnoreCase))); - Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("hic_validFrom",StringComparison.CurrentCultureIgnoreCase))); - Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("hic_validTo",StringComparison.CurrentCultureIgnoreCase))); - Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("hic_userID",StringComparison.CurrentCultureIgnoreCase))); + Assert.AreEqual(1, + archiveTable.DiscoverColumns().Count(c => + c.GetRuntimeName().Equals("hic_dataLoadrunID", StringComparison.CurrentCultureIgnoreCase))); + Assert.AreEqual(1, + archiveTable.DiscoverColumns().Count(c => + c.GetRuntimeName().Equals("hic_validFrom", StringComparison.CurrentCultureIgnoreCase))); + Assert.AreEqual(1, + archiveTable.DiscoverColumns().Count(c => + c.GetRuntimeName().Equals("hic_validTo", StringComparison.CurrentCultureIgnoreCase))); + Assert.AreEqual(1, + archiveTable.DiscoverColumns().Count(c => + c.GetRuntimeName().Equals("hic_userID", StringComparison.CurrentCultureIgnoreCase))); Assert.AreEqual(1, archiveTable.DiscoverColumns().Count(c => c.GetRuntimeName().Equals("hic_status"))); - + //is the trigger now existing Assert.AreEqual(TriggerStatus.Enabled, implementer.GetTriggerStatus()); //does it function as expected - using(var con = tbl.Database.Server.GetConnection()) + using (var con = tbl.Database.Server.GetConnection()) { con.Open(); var cmd = tbl.Database.Server.GetCommand( - $"INSERT INTO {tbl.GetRuntimeName()}(name,bubbles) VALUES('bob',1)",con); + $"INSERT INTO {tbl.GetRuntimeName()}(name,bubbles) VALUES('bob',1)", con); cmd.ExecuteNonQuery(); - Assert.AreEqual(1,tbl.GetRowCount()); - Assert.AreEqual(0,archiveTable.GetRowCount()); + Assert.AreEqual(1, tbl.GetRowCount()); + Assert.AreEqual(0, archiveTable.GetRowCount()); cmd = tbl.Database.Server.GetCommand($"UPDATE {tbl.GetRuntimeName()} set bubbles=2", con); cmd.ExecuteNonQuery(); @@ -88,16 +96,17 @@ public void TriggerImplementationTest(DatabaseType type) var archive = archiveTable.GetDataTable(); var dr = archive.Rows.Cast().Single(); - Assert.AreEqual(((DateTime)dr["hic_validTo"]).Date,DateTime.Now.Date); + Assert.AreEqual(((DateTime)dr["hic_validTo"]).Date, DateTime.Now.Date); } - + //do the strict check too - Assert.IsTrue(implementer.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); + Assert.IsTrue(implementer.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); - tbl.AddColumn("amagad",new DatabaseTypeRequest(typeof(float),null,new DecimalSize(2,2)),true,30); + tbl.AddColumn("amagad", new DatabaseTypeRequest(typeof(float), null, new DecimalSize(2, 2)), true, 30); implementer = factory.Create(tbl); - Assert.Throws(() => implementer.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); + Assert.Throws(() => + implementer.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); archiveTable.AddColumn("amagad", new DatabaseTypeRequest(typeof(float), null, new DecimalSize(2, 2)), true, 30); @@ -106,7 +115,7 @@ public void TriggerImplementationTest(DatabaseType type) Assert.IsTrue(implementer.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); - + //does it function as expected using (var con = tbl.Database.Server.GetConnection()) { @@ -125,11 +134,11 @@ public void TriggerImplementationTest(DatabaseType type) Assert.AreEqual(3, archiveTable.GetRowCount()); var archive = archiveTable.GetDataTable(); - Assert.AreEqual(1,archive.Rows.Cast().Count(r=>Equals(r["amagad"],(decimal)1.00))); + Assert.AreEqual(1, archive.Rows.Cast().Count(r => Equals(r["amagad"], (decimal)1.00))); Assert.AreEqual(2, archive.Rows.Cast().Count(r => r["amagad"] == DBNull.Value)); } - implementer.DropTrigger(out var problems, out string worked); + implementer.DropTrigger(out var problems, out var worked); Assert.IsTrue(string.IsNullOrEmpty(problems)); diff --git a/Rdmp.Core.Tests/Curation/Integration/DataAccess/SuperMultiThreadedVolumeAccess.cs b/Rdmp.Core.Tests/Curation/Integration/DataAccess/SuperMultiThreadedVolumeAccess.cs index 7d7f821c62..1885eb88f0 100644 --- a/Rdmp.Core.Tests/Curation/Integration/DataAccess/SuperMultiThreadedVolumeAccess.cs +++ b/Rdmp.Core.Tests/Curation/Integration/DataAccess/SuperMultiThreadedVolumeAccess.cs @@ -19,9 +19,8 @@ namespace Rdmp.Core.Tests.Curation.Integration.DataAccess; -public class SuperMultiThreadedVolumeAccess:DatabaseTests +public class SuperMultiThreadedVolumeAccess : DatabaseTests { - [OneTimeSetUp] protected override void SetUp() { @@ -36,7 +35,7 @@ var catalogue in .Where(c => c.Name.StartsWith("SuperMultiThreadedTestCatalogue"))) catalogue.DeleteInDatabase(); - DatabaseCommandHelper.GlobalTimeout=timeoutBefore; + DatabaseCommandHelper.GlobalTimeout = timeoutBefore; } [OneTimeTearDown] @@ -55,7 +54,7 @@ var catalogue in [TestCase(false)] public void SingleThreadedBulkCatalogueCreation(bool useTransactions) { - IManagedConnection c= null; + IManagedConnection c = null; if (CatalogueRepository is not TableRepository && useTransactions) @@ -85,9 +84,6 @@ public void SingleThreadedBulkCatalogueCreation(bool useTransactions) if (useTransactions) CatalogueTableRepository.EndTransactedConnection(false); } - - - } [Test] @@ -139,10 +135,10 @@ private void FireMultiThreaded(Action method, int numberToFire, bool useTr for (var i = 0; i < numberToFire; i++) { var i1 = i; - ts.Add(new Thread(() => { + ts.Add(new Thread(() => + { try { - method(useTransactions && i1 == 0); } catch (Exception ex) @@ -154,10 +150,10 @@ private void FireMultiThreaded(Action method, int numberToFire, bool useTr foreach (var thread in ts) thread.Start(); - - while(ts.Any(t=>t.IsAlive)) - ts.FirstOrDefault(t=>t.IsAlive)?.Join(100); - + + while (ts.Any(t => t.IsAlive)) + ts.FirstOrDefault(t => t.IsAlive)?.Join(100); + Assert.IsEmpty(exes); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/DataAccess/TestDataAccess.cs b/Rdmp.Core.Tests/Curation/Integration/DataAccess/TestDataAccess.cs index 9786b6cdf2..2c0e66a276 100644 --- a/Rdmp.Core.Tests/Curation/Integration/DataAccess/TestDataAccess.cs +++ b/Rdmp.Core.Tests/Curation/Integration/DataAccess/TestDataAccess.cs @@ -24,9 +24,8 @@ namespace Rdmp.Core.Tests.Curation.Integration.DataAccess; -public class TestDataAccess:DatabaseTests +public class TestDataAccess : DatabaseTests { - #region Distinct Connection String (from Collection tests - Failing) [Test] @@ -34,14 +33,15 @@ public void TestDistinctCredentials_PasswordMismatch() { var testPoints = new List { - new TestAccessPoint("frank", "bob", "username", "mypas"), - new TestAccessPoint("frank", "bob", "username", "mydifferentPass") + new("frank", "bob", "username", "mypas"), + new("frank", "bob", "username", "mydifferentPass") }; //call this - var ex = Assert.Throws(()=>DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true)); - StringAssert.Contains("collection could not agree on a single Password",ex.Message); - + var ex = Assert.Throws(() => + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, + true)); + StringAssert.Contains("collection could not agree on a single Password", ex.Message); } [Test] @@ -49,14 +49,15 @@ public void TestDistinctCredentials_UsernamePasswordAreNull() { var testPoints = new List { - new TestAccessPoint("frank", "bob", null, null), - new TestAccessPoint("frank", "bob", "username", "mydifferentPass") + new("frank", "bob", null, null), + new("frank", "bob", "username", "mydifferentPass") }; //call this - var ex = Assert.Throws(()=>DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true)); - StringAssert.Contains("collection could not agree whether to use Credentials",ex.Message); - + var ex = Assert.Throws(() => + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, + true)); + StringAssert.Contains("collection could not agree whether to use Credentials", ex.Message); } [Test] @@ -64,15 +65,16 @@ public void TestDistinctCredentials_UsernameMismatch() { var testPoints = new List { - new TestAccessPoint("frank", "bob", "usernameasdasd", "mydifferentpass"), - new TestAccessPoint("frank", "bob", "username", "mydifferentPass") + new("frank", "bob", "usernameasdasd", "mydifferentpass"), + new("frank", "bob", "username", "mydifferentPass") }; //call this - var ex = Assert.Throws(()=>DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true)); - StringAssert.Contains("collection could not agree on a single Username",ex.Message); - + var ex = Assert.Throws(() => + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, + true)); + StringAssert.Contains("collection could not agree on a single Username", ex.Message); } @@ -81,11 +83,12 @@ public void TestDistinctCredentials_ServerMixedCapitalization_Allowed() { var testPoints = new List { - new TestAccessPoint("frank", "bob", null, null), - new TestAccessPoint("FRANK", "bob", null, null) + new("frank", "bob", null, null), + new("FRANK", "bob", null, null) }; - var server = DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true); + var server = + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true); Assert.AreEqual("frank", server.Name); } @@ -94,13 +97,18 @@ public void TestDistinctCredentials_DatabaseMixedCapitalization_NotAllowed() { var testPoints = new List { - new TestAccessPoint("frank", "bob", null, null), - new TestAccessPoint("frank", "BOB", null, null) + new("frank", "bob", null, null), + new("frank", "BOB", null, null) }; - var ex = Assert.Throws(() => DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true)); - StringAssert.Contains("All data access points must be into the same database, access points 'frankbob' and 'frankBOB' are into different databases", ex.Message); + var ex = Assert.Throws(() => + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, + true)); + StringAssert.Contains( + "All data access points must be into the same database, access points 'frankbob' and 'frankBOB' are into different databases", + ex.Message); } + #endregion #region Distinct Connection String (from Collection tests - Passing) @@ -110,11 +118,12 @@ public void TestDistinctCredentials_WrappedDatabaseName() { var testPoints = new List { - new TestAccessPoint("frank", "[bob's Database]", "username", "mypas"), - new TestAccessPoint("frank", "bob's Database", "username", "mypas") + new("frank", "[bob's Database]", "username", "mypas"), + new("frank", "bob's Database", "username", "mypas") }; //call this - var result = DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true); + var result = + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true); //test result Assert.AreEqual("bob's Database", result.Builder["Initial Catalog"]); @@ -125,17 +134,18 @@ public void TestDistinctCredentials_PasswordMatch() { var testPoints = new List { - new TestAccessPoint("frank", "bob", "username", "mypas"), - new TestAccessPoint("frank", "bob", "username", "mypas") + new("frank", "bob", "username", "mypas"), + new("frank", "bob", "username", "mypas") }; //call this - var result = DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true); + var result = + DataAccessPortal.ExpectDistinctServer(testPoints.ToArray(), DataAccessContext.InternalDataProcessing, true); //test result Assert.AreEqual("mypas", result.Builder["Password"]); - } + #endregion [Test] @@ -153,7 +163,7 @@ public void AsyncTest() foreach (var t in threads) t.Start(); - while(threads.Any(t=>t.ThreadState != ThreadState.Stopped)) + while (threads.Any(t => t.ThreadState != ThreadState.Stopped)) Thread.Sleep(100); for (var index = 0; index < asyncExceptions.Count; index++) @@ -162,6 +172,7 @@ public void AsyncTest() var asyncException = asyncExceptions[index]; Console.WriteLine(ExceptionHelper.ExceptionToListOfInnerMessages(asyncException, true)); } + Assert.IsEmpty(asyncExceptions); } @@ -192,10 +203,12 @@ private void MessWithCatalogue() [Test] public void TestGettingConnectionStrings() { - foreach (var tbl in CatalogueRepository.GetAllObjects().Where(table => table.Name.ToLower().Equals("bob"))) + foreach (var tbl in CatalogueRepository.GetAllObjects() + .Where(table => table.Name.ToLower().Equals("bob"))) tbl.DeleteInDatabase(); - foreach (var c in CatalogueRepository.GetAllObjects().Where(cred=>cred.Name.ToLower().Equals("bob"))) + foreach (var c in CatalogueRepository.GetAllObjects() + .Where(cred => cred.Name.ToLower().Equals("bob"))) c.DeleteInDatabase(); //test it with TableInfos @@ -241,17 +254,15 @@ public void TestGettingConnectionStrings() linker.BreakAllLinksBetween(creds, t); creds.DeleteInDatabase(); } - } finally { t.DeleteInDatabase(); - } } - internal class TestAccessPoint:IDataAccessPoint,IDataAccessCredentials + internal class TestAccessPoint : IDataAccessPoint, IDataAccessCredentials { public string Server { get; set; } public string Database { get; set; } @@ -277,20 +288,11 @@ public IDataAccessCredentials GetCredentialsIfExists(DataAccessContext context) } - public string GetDecryptedPassword() - { - return Password?? ""; - } + public string GetDecryptedPassword() => Password ?? ""; - public override string ToString() - { - return Server + Database; - } + public override string ToString() => Server + Database; - public IQuerySyntaxHelper GetQuerySyntaxHelper() - { - return MicrosoftQuerySyntaxHelper.Instance; - } + public IQuerySyntaxHelper GetQuerySyntaxHelper() => MicrosoftQuerySyntaxHelper.Instance; public bool DiscoverExistence(DataAccessContext context, out string reason) { @@ -298,6 +300,4 @@ public bool DiscoverExistence(DataAccessContext context, out string reason) return false; } } - - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/Dependencies/DependencyTests.cs b/Rdmp.Core.Tests/Curation/Integration/Dependencies/DependencyTests.cs index 040b9007e7..eb17a931b2 100644 --- a/Rdmp.Core.Tests/Curation/Integration/Dependencies/DependencyTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/Dependencies/DependencyTests.cs @@ -25,12 +25,12 @@ public void ExtractionInformationTriangle() try { //col depends on tr - Assert.Contains(t,col.GetObjectsThisDependsOn()); - Assert.Contains(col,t.GetObjectsDependingOnThis()); + Assert.Contains(t, col.GetObjectsThisDependsOn()); + Assert.Contains(col, t.GetObjectsDependingOnThis()); //catalogue depends on catalogue items existing (slightly counter intuitive but think of it as data flow out of technical low level data through transforms into datasets - and then into researchers and research projects) - Assert.Contains(cat,ci.GetObjectsDependingOnThis()); - Assert.Contains(ci,cat.GetObjectsThisDependsOn()); + Assert.Contains(cat, ci.GetObjectsDependingOnThis()); + Assert.Contains(ci, cat.GetObjectsThisDependsOn()); //catalogue item should not be relying on anything currently (no link to underlying technical data) Assert.IsNull(ci.GetObjectsThisDependsOn()); @@ -38,7 +38,6 @@ public void ExtractionInformationTriangle() //now they are associated so the ci should be dependent on the col ci.SetColumnInfo(col); Assert.Contains(col, ci.GetObjectsDependingOnThis()); - } finally { diff --git a/Rdmp.Core.Tests/Curation/Integration/DitaExtractorTests.cs b/Rdmp.Core.Tests/Curation/Integration/DitaExtractorTests.cs index 6c5012f748..8a8a33af42 100644 --- a/Rdmp.Core.Tests/Curation/Integration/DitaExtractorTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/DitaExtractorTests.cs @@ -38,13 +38,12 @@ protected override void OneTimeSetUp() //delete all catalogues with duplicate names var catalogues = CatalogueRepository.GetAllObjects().ToArray(); - foreach (var cata in catalogues.GroupBy(c=>c.Name).Where(g=>g.Count()>1).SelectMany(y => y)) - { + foreach (var cata in catalogues.GroupBy(c => c.Name).Where(g => g.Count() > 1).SelectMany(y => y)) cata.DeleteInDatabase(); - } //make sure all Catalogues have acronyms, if they don't then assign them a super random one - foreach (var cata in CatalogueRepository.GetAllObjects().Where(c=>string.IsNullOrWhiteSpace(c.Acronym))) + foreach (var cata in CatalogueRepository.GetAllObjects() + .Where(c => string.IsNullOrWhiteSpace(c.Acronym))) { cata.Acronym = $"RANDOMACRONYM_{random.Next(10000)}"; cata.SaveToDatabase(); @@ -55,7 +54,7 @@ protected override void OneTimeSetUp() _setupException = e; } } - + [SetUp] protected override void SetUp() { @@ -75,14 +74,17 @@ public void DitaExtractorConstructor_ExtractTestCatalogue_FilesExist() var testDir = _directoryHelper.Directory; //get rid of any old copies lying around - var oldCatalogueVersion = CatalogueRepository.GetAllObjects().SingleOrDefault(c => c.Name.Equals("DitaExtractorConstructor_ExtractTestCatalogue_FilesExist")); + var oldCatalogueVersion = CatalogueRepository.GetAllObjects() + .SingleOrDefault(c => c.Name.Equals("DitaExtractorConstructor_ExtractTestCatalogue_FilesExist")); oldCatalogueVersion?.DeleteInDatabase(); - var ditaTestCatalogue = new Catalogue(CatalogueRepository, "DitaExtractorConstructor_ExtractTestCatalogue_FilesExist") + var ditaTestCatalogue = + new Catalogue(CatalogueRepository, "DitaExtractorConstructor_ExtractTestCatalogue_FilesExist") { Acronym = "DITA_TEST", - Description = $"Test catalogue for the unit test DitaExtractorConstructor_ExtractTestCatalogue_FilesExist in file {typeof(DitaExtractorTests).FullName}.cs" - };//name of Catalogue + Description = + $"Test catalogue for the unit test DitaExtractorConstructor_ExtractTestCatalogue_FilesExist in file {typeof(DitaExtractorTests).FullName}.cs" + }; //name of Catalogue ditaTestCatalogue.SaveToDatabase(); @@ -99,12 +101,13 @@ public void DitaExtractorConstructor_ExtractTestCatalogue_FilesExist() Assert.IsTrue(File.Exists(Path.Combine(testDir.FullName, "dataset.dita"))); //make sure the catalogue we created is there - var ditaCatalogueAsDotDitaFile = new FileInfo(Path.Combine(testDir.FullName, "ditaextractorconstructor_extracttestcatalogue_filesexist.dita"));//name of Dita file (for the Catalogue we just created) + var ditaCatalogueAsDotDitaFile = new FileInfo(Path.Combine(testDir.FullName, + "ditaextractorconstructor_extracttestcatalogue_filesexist.dita")); //name of Dita file (for the Catalogue we just created) Assert.IsTrue(ditaCatalogueAsDotDitaFile.Exists); - Assert.IsTrue(File.ReadAllText(ditaCatalogueAsDotDitaFile.FullName).Contains(ditaTestCatalogue.Description)); - + Assert.IsTrue(File.ReadAllText(ditaCatalogueAsDotDitaFile.FullName) + .Contains(ditaTestCatalogue.Description)); } - finally + finally { ditaTestCatalogue.DeleteInDatabase(); foreach (var file in testDir.GetFiles()) @@ -129,22 +132,20 @@ public void CreateCatalogueWithNoAcronym_CrashesDITAExtractor() try { var extractor = new DitaCatalogueExtractor(CatalogueRepository, testDir); - var ex = Assert.Throws(()=>extractor.Extract(new ThrowImmediatelyDataLoadEventListener())); - Assert.AreEqual("Dita Extraction requires that each catalogue have a unique Acronym, the catalogue UnitTestCatalogue is missing an Acronym",ex.Message); - + var ex = Assert.Throws(() => extractor.Extract(new ThrowImmediatelyDataLoadEventListener())); + Assert.AreEqual( + "Dita Extraction requires that each catalogue have a unique Acronym, the catalogue UnitTestCatalogue is missing an Acronym", + ex.Message); } finally { myNewCatalogue.DeleteInDatabase(); } - } finally { foreach (var file in testDir.GetFiles()) file.Delete(); } - } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/EncryptionTests.cs b/Rdmp.Core.Tests/Curation/Integration/EncryptionTests.cs index 184ca1da83..f6b7e1421f 100644 --- a/Rdmp.Core.Tests/Curation/Integration/EncryptionTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/EncryptionTests.cs @@ -19,7 +19,6 @@ public class EncryptionTests : DatabaseTests [Test] public void EncryptAndThenDecryptString() { - var encrypter = CatalogueRepository.EncryptionManager.GetEncrypter(); var toEncrypt = "Amagad"; @@ -27,20 +26,19 @@ public void EncryptAndThenDecryptString() Console.WriteLine($"Encrypted password was:{encrytpedBinaryString}"); Assert.AreNotEqual(toEncrypt, encrytpedBinaryString); - Assert.AreEqual(toEncrypt,encrypter.Decrypt(encrytpedBinaryString)); + Assert.AreEqual(toEncrypt, encrypter.Decrypt(encrytpedBinaryString)); } [Test] public void CheckIfThingsAreEncryptedOrNot() { - var encrypter = CatalogueRepository.EncryptionManager.GetEncrypter(); var toEncrypt = "Amagad"; var encrytpedBinaryString = encrypter.Encrypt(toEncrypt); Console.WriteLine($"Encrypted password was:{encrytpedBinaryString}"); - + Assert.True(encrypter.IsStringEncrypted(encrytpedBinaryString)); Assert.False(encrypter.IsStringEncrypted(toEncrypt)); } @@ -50,7 +48,8 @@ public void CheckIfThingsAreEncryptedOrNot() public void MultiEncryptingShouldntBreakIt() { //cleanup - foreach (var c in CatalogueRepository.GetAllObjects().Where(c => c.Name.Equals("frankieFran"))) + foreach (var c in CatalogueRepository.GetAllObjects() + .Where(c => c.Name.Equals("frankieFran"))) c.DeleteInDatabase(); var creds = new DataAccessCredentials(CatalogueRepository, "frankieFran"); @@ -58,10 +57,10 @@ public void MultiEncryptingShouldntBreakIt() { //as soon as you set a password it should be encrypted by the credentials class in memory creds.Password = "fish"; - + Assert.AreNotEqual("fish", creds.Password); Assert.AreEqual("fish", creds.GetDecryptedPassword()); //but we should still be able to decrypt it - + //set the password to the encrypted password creds.Password = creds.Password; @@ -80,7 +79,8 @@ public void MultiEncryptingShouldntBreakIt() public void DataAccessCredentialsEncryption() { //cleanup - foreach (var c in CatalogueRepository.GetAllObjects().Where(c => c.Name.Equals("frankieFran"))) + foreach (var c in CatalogueRepository.GetAllObjects() + .Where(c => c.Name.Equals("frankieFran"))) c.DeleteInDatabase(); var creds = new DataAccessCredentials(CatalogueRepository, "frankieFran"); @@ -88,32 +88,35 @@ public void DataAccessCredentialsEncryption() { //as soon as you set a password it should be encrypted by the credentials class in memory creds.Password = "fish"; - Assert.AreNotEqual("fish",creds.Password); - Assert.AreEqual("fish", creds.GetDecryptedPassword());//but we should still be able to decrypt it - + Assert.AreNotEqual("fish", creds.Password); + Assert.AreEqual("fish", creds.GetDecryptedPassword()); //but we should still be able to decrypt it + //save it creds.SaveToDatabase(); using (var con = CatalogueTableRepository.GetConnection()) { string value; - using(var cmd = DatabaseCommandHelper.GetCommand("Select Password from DataAccessCredentials where Name='frankieFran'", con.Connection, con.Transaction)) - value = (string) cmd.ExecuteScalar(); + using (var cmd = DatabaseCommandHelper.GetCommand( + "Select Password from DataAccessCredentials where Name='frankieFran'", con.Connection, + con.Transaction)) + { + value = (string)cmd.ExecuteScalar(); + } //ensure password in database is encrypted - Assert.AreNotEqual("fish",value); - Assert.AreEqual(creds.Password,value);//does value in database match value in memory (encrypted) + Assert.AreNotEqual("fish", value); + Assert.AreEqual(creds.Password, value); //does value in database match value in memory (encrypted) } //get a new copy out of the database var newCopy = CatalogueRepository.GetObjectByID(creds.ID); - Assert.AreEqual(creds.Password,newCopy.Password);//passwords should match - Assert.AreNotEqual("fish",creds.Password);//neither should be fish + Assert.AreEqual(creds.Password, newCopy.Password); //passwords should match + Assert.AreNotEqual("fish", creds.Password); //neither should be fish Assert.AreNotEqual("fish", newCopy.Password); - + //both should decrypt to the same value (fish - Assert.AreEqual("fish",creds.GetDecryptedPassword()); + Assert.AreEqual("fish", creds.GetDecryptedPassword()); Assert.AreEqual("fish", newCopy.GetDecryptedPassword()); - } finally { @@ -128,7 +131,8 @@ public void DataAccessCredentialsEncryption() public void TestFreakyPasswordValues(string freakyPassword) { //cleanup - foreach (var c in CatalogueRepository.GetAllObjects().Where(c => c.Name.Equals("frankieFran"))) + foreach (var c in CatalogueRepository.GetAllObjects() + .Where(c => c.Name.Equals("frankieFran"))) c.DeleteInDatabase(); var creds = new DataAccessCredentials(CatalogueRepository, "frankieFran"); @@ -137,31 +141,34 @@ public void TestFreakyPasswordValues(string freakyPassword) //as soon as you set a password it should be encrypted by the credentials class in memory creds.Password = freakyPassword; Assert.AreNotEqual(freakyPassword, creds.Password); - Assert.AreEqual(freakyPassword, creds.GetDecryptedPassword());//but we should still be able to decrypt it + Assert.AreEqual(freakyPassword, creds.GetDecryptedPassword()); //but we should still be able to decrypt it //save it creds.SaveToDatabase(); using (var con = CatalogueTableRepository.GetConnection()) { string value; - using(var cmd = DatabaseCommandHelper.GetCommand("Select Password from DataAccessCredentials where Name='frankieFran'", con.Connection, con.Transaction)) - value = (string) cmd.ExecuteScalar(); + using (var cmd = DatabaseCommandHelper.GetCommand( + "Select Password from DataAccessCredentials where Name='frankieFran'", con.Connection, + con.Transaction)) + { + value = (string)cmd.ExecuteScalar(); + } //ensure password in database is encrypted Assert.AreNotEqual(freakyPassword, value); - Assert.AreEqual(creds.Password, value);//does value in database match value in memory (encrypted) + Assert.AreEqual(creds.Password, value); //does value in database match value in memory (encrypted) } //get a new copy out of the database var newCopy = CatalogueRepository.GetObjectByID(creds.ID); - Assert.AreEqual(creds.Password, newCopy.Password);//passwords should match - Assert.AreNotEqual(freakyPassword, creds.Password);//neither should be fish + Assert.AreEqual(creds.Password, newCopy.Password); //passwords should match + Assert.AreNotEqual(freakyPassword, creds.Password); //neither should be fish Assert.AreNotEqual(freakyPassword, newCopy.Password); //both should decrypt to the same value (fish Assert.AreEqual(freakyPassword, creds.GetDecryptedPassword()); Assert.AreEqual(freakyPassword, newCopy.GetDecryptedPassword()); - } finally { @@ -174,7 +181,8 @@ public void TestFreakyPasswordValues(string freakyPassword) public void MigrationOfOldPasswordsTest() { //cleanup - foreach (var c in CatalogueRepository.GetAllObjects().Where(c => c.Name.Equals("frankieFran"))) + foreach (var c in CatalogueRepository.GetAllObjects() + .Where(c => c.Name.Equals("frankieFran"))) c.DeleteInDatabase(); //create a new credentials @@ -185,15 +193,17 @@ public void MigrationOfOldPasswordsTest() using (var con = CatalogueTableRepository.GetConnection()) { using (var cmd = DatabaseCommandHelper.GetCommand( - "UPDATE DataAccessCredentials set Password = 'fish' where Name='frankieFran'", con.Connection, + "UPDATE DataAccessCredentials set Password = 'fish' where Name='frankieFran'", + con.Connection, con.Transaction)) + { Assert.AreEqual(1, cmd.ExecuteNonQuery()); - + } } var newCopy = CatalogueRepository.GetObjectByID(creds.ID); - - Assert.AreEqual("fish",newCopy.GetDecryptedPassword()); + + Assert.AreEqual("fish", newCopy.GetDecryptedPassword()); Assert.AreNotEqual("fish", newCopy.Password); } finally @@ -205,15 +215,18 @@ public void MigrationOfOldPasswordsTest() [Test] public void PasswordTooLong() { - if(RepositoryLocator.CatalogueRepository.EncryptionManager is PasswordEncryptionKeyLocation em && !string.IsNullOrWhiteSpace(em.GetKeyFileLocation())) - Assert.Inconclusive("Could not run test because there is already an encryption key set up. Likely one that handles very long passwords"); + if (RepositoryLocator.CatalogueRepository.EncryptionManager is PasswordEncryptionKeyLocation em && + !string.IsNullOrWhiteSpace(em.GetKeyFileLocation())) + Assert.Inconclusive( + "Could not run test because there is already an encryption key set up. Likely one that handles very long passwords"); var password = "a"; for (var i = 0; i < 200; i++) password += "a"; var ex = Assert.Throws(() => TestFreakyPasswordValues(password)); - Assert.AreEqual("The free text Value supplied to this class was too long to be encrypted (Length of string was 201)", ex.Message); + Assert.AreEqual( + "The free text Value supplied to this class was too long to be encrypted (Length of string was 201)", + ex.Message); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ExtractionFilterTests.cs b/Rdmp.Core.Tests/Curation/Integration/ExtractionFilterTests.cs index a75a57cf80..97dbf9cf24 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ExtractionFilterTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ExtractionFilterTests.cs @@ -17,8 +17,9 @@ public class ExtractionFilterTests : DatabaseTests public void TestExtractionFilterDeleting_WhenItHas_ExtractionFilterParameterSet_DirectlyFails() { var filter = GetFilterWithParameterSet(); - var ex = Assert.Throws(()=>filter.DeleteInDatabase()); - Assert.AreEqual("Cannot delete 'Age' because there are one or more ExtractionFilterParameterSet declared on it", ex.Message); + var ex = Assert.Throws(() => filter.DeleteInDatabase()); + Assert.AreEqual("Cannot delete 'Age' because there are one or more ExtractionFilterParameterSet declared on it", + ex.Message); } private ExtractionFilter GetFilterWithParameterSet() @@ -38,7 +39,7 @@ private ExtractionFilter GetFilterWithParameterSet() var paramSet = new ExtractionFilterParameterSet(CatalogueRepository, filter, "Old"); paramSet.CreateNewValueEntries(); - + return filter; } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationTests.cs b/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationTests.cs index 7f5c08b0a9..043f06bace 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationTests.cs @@ -40,7 +40,6 @@ protected override void SetUp() //create a link between catalogue item lazor and velocity column cataItem.SetColumnInfo(columnInfo); - } [Test] @@ -55,7 +54,6 @@ public void BasicIDsAreCorrect() [Test] public void test_creating_ExtractionFilter() { - ExtractionInformation extractInfo = null; ExtractionFilter filterFastThings = null; ExtractionFilterParameter parameter = null; @@ -63,7 +61,8 @@ public void test_creating_ExtractionFilter() try { //define extraction information - extractInfo = new ExtractionInformation(CatalogueRepository, cataItem, columnInfo, "ROUND(VelocityOfMatter,2) VelocityOfMatterRounded"); + extractInfo = new ExtractionInformation(CatalogueRepository, cataItem, columnInfo, + "ROUND(VelocityOfMatter,2) VelocityOfMatterRounded"); //define filter and parameter filterFastThings = new ExtractionFilter(CatalogueRepository, "FastThings", extractInfo) @@ -77,16 +76,17 @@ public void test_creating_ExtractionFilter() parameter = new ExtractionFilterParameter(CatalogueRepository, "DECLARE @X INT", filterFastThings); Assert.IsNotNull(parameter); - Assert.AreEqual(parameter.ParameterName ,"@X"); + Assert.AreEqual(parameter.ParameterName, "@X"); parameter.Value = "500"; parameter.SaveToDatabase(); var afterSave = CatalogueRepository.GetObjectByID(parameter.ID); - Assert.AreEqual(afterSave.Value ,"500"); + Assert.AreEqual(afterSave.Value, "500"); - var filterFastThings_NewCopyFromDB = CatalogueRepository.GetObjectByID(filterFastThings.ID); + var filterFastThings_NewCopyFromDB = + CatalogueRepository.GetObjectByID(filterFastThings.ID); Assert.AreEqual(filterFastThings.ID, filterFastThings_NewCopyFromDB.ID); Assert.AreEqual(filterFastThings.Description, filterFastThings_NewCopyFromDB.Description); @@ -102,21 +102,15 @@ public void test_creating_ExtractionFilter() extractInfo?.DeleteInDatabase(); } - - - } [Test] public void test_creating_ExtractionInformation() { - - - ExtractionInformation extractInfo =null; + ExtractionInformation extractInfo = null; try { - //define extraction information //change some values and then save it extractInfo = new ExtractionInformation(CatalogueRepository, cataItem, columnInfo, "dave") @@ -125,9 +119,9 @@ public void test_creating_ExtractionInformation() ExtractionCategory = ExtractionCategory.Supplemental }; extractInfo.SaveToDatabase(); - + //confirm the insert worked - Assert.AreEqual(extractInfo.SelectSQL,"dave"); + Assert.AreEqual(extractInfo.SelectSQL, "dave"); //fetch the extraction information via the linked CatalogueItem - ColumnInfo pair (i.e. we are testing the alternate route to fetch ExtractionInformation - by ID or by colum/item pair) var extractInfo2_CameFromLinker = cataItem.ExtractionInformation; @@ -135,14 +129,12 @@ public void test_creating_ExtractionInformation() Assert.AreEqual(extractInfo.SelectSQL, extractInfo2_CameFromLinker.SelectSQL); //make sure it saves properly - Assert.AreEqual(extractInfo2_CameFromLinker.Order,123 ); - Assert.AreEqual( extractInfo2_CameFromLinker.ExtractionCategory,ExtractionCategory.Supplemental); - + Assert.AreEqual(extractInfo2_CameFromLinker.Order, 123); + Assert.AreEqual(extractInfo2_CameFromLinker.ExtractionCategory, ExtractionCategory.Supplemental); } finally { extractInfo?.DeleteInDatabase(); - } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationUnitTests.cs b/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationUnitTests.cs index a48388efc3..31cdf00bf7 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationUnitTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ExtractionInformationUnitTests.cs @@ -26,15 +26,15 @@ public void NewExtractionInformation_OrderShouldBeContiguous(int? explicitOrder) ei.Order = explicitOrder.Value; ei.SaveToDatabase(); } - - Assert.AreEqual(explicitOrder ?? 1,ei.Order); + + Assert.AreEqual(explicitOrder ?? 1, ei.Order); // Newly created ones should have the right Order to not collide var cata = ei.CatalogueItem.Catalogue; var cataItem = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "ci"); var ei2 = new ExtractionInformation(RepositoryLocator.CatalogueRepository, cataItem, ei.ColumnInfo, "fff"); - Assert.AreEqual((explicitOrder ?? 1) + 1,ei2.Order); + Assert.AreEqual((explicitOrder ?? 1) + 1, ei2.Order); } [Test] @@ -48,16 +48,16 @@ public void NewExtractionInformation_OrderShouldBeContiguous_ManyCalls() var cataItem2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "ci"); var ei2 = new ExtractionInformation(RepositoryLocator.CatalogueRepository, cataItem2, ei1.ColumnInfo, "fff"); - Assert.AreEqual(2,ei2.Order); + Assert.AreEqual(2, ei2.Order); var cataItem3 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "ci"); var ei3 = new ExtractionInformation(RepositoryLocator.CatalogueRepository, cataItem3, ei1.ColumnInfo, "fff"); - Assert.AreEqual(3,ei3.Order); + Assert.AreEqual(3, ei3.Order); var cataItem4 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "ci"); var ei4 = new ExtractionInformation(RepositoryLocator.CatalogueRepository, cataItem4, ei1.ColumnInfo, "fff"); - Assert.AreEqual(4,ei4.Order); + Assert.AreEqual(4, ei4.Order); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/FilterImporterTests.cs b/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/FilterImporterTests.cs index 698b214a17..447c5ecc6a 100644 --- a/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/FilterImporterTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/FilterImporterTests.cs @@ -19,46 +19,45 @@ namespace Rdmp.Core.Tests.Curation.Integration.FilterImportingTests; [Category("Unit")] public class FilterImporterTests : UnitTests { - [Test] public void FilterCreated_NewFilterGetsSameName() { //Thing we will be cloning - var master = Mock.Of(x => - x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && + var master = Mock.Of(x => + x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && x.Name == "Space Odyssey"); //The factory will return this value - var constructed = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var constructed = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); //The factory Mock var factory = new Mock(); factory.Setup(m => m.CreateNewFilter("Space Odyssey")).Returns(constructed); //The thing we are testing - var filterCreator = new FilterImporter(factory.Object,null); - + var filterCreator = new FilterImporter(factory.Object, null); + //The method we are testing - filterCreator.ImportFilter(WhenIHaveA(),master,null); + filterCreator.ImportFilter(WhenIHaveA(), master, null); //Did the factory mock get ordered to create a filter called "Space Odyssey"? - factory.Verify(f=>f.CreateNewFilter(It.IsAny()),Times.Once); + factory.Verify(f => f.CreateNewFilter(It.IsAny()), Times.Once); } [Test] public void FilterCreated_CopyBecauseExistsAlready() { //The thing we will be importing - var master = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var master = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); master.Name = "Space Odyssey"; //An existing IFilter that is in the scope that is being imported into (e.g. a data extract configuration) - var existing = Mock.Of(f=> + var existing = Mock.Of(f => f.Name == "Space Odyssey" && - f.GetAllParameters()==Array.Empty());// has no parameters + f.GetAllParameters() == Array.Empty()); // has no parameters //The factory will return this value - var constructed = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var constructed = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); //The factory Mock var factory = new Mock(); @@ -68,7 +67,7 @@ public void FilterCreated_CopyBecauseExistsAlready() var filterCreator = new FilterImporter(factory.Object, null); //The method we are testing - filterCreator.ImportFilter(WhenIHaveA(), master,new []{existing}); + filterCreator.ImportFilter(WhenIHaveA(), master, new[] { existing }); //Did the factory mock get ordered to create a filter called "Copy of Space Odyssey" (because there was already one called "Space Odyssey" in the same scope) factory.Verify(); @@ -77,69 +76,73 @@ public void FilterCreated_CopyBecauseExistsAlready() [Test] public void FilterCreated_Parameters() { - var master = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var master = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); master.Name = "Space Odyssey"; master.WhereSQL = "@hall = 'active'"; - var constructed = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var constructed = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); var constructedParameter = Mock.Of(); var factory = new Mock(); factory.Setup(m => m.CreateNewFilter("Space Odyssey")).Returns(constructed); - factory.Setup(m => m.CreateNewParameter(constructed, "DECLARE @hall AS varchar(50);")).Returns(constructedParameter); + factory.Setup(m => m.CreateNewParameter(constructed, "DECLARE @hall AS varchar(50);")) + .Returns(constructedParameter); var filterCreator = new FilterImporter(factory.Object, null); //Returns constructed filterCreator.ImportFilter(WhenIHaveA(), master, null); - - factory.Verify(m => m.CreateNewFilter("Space Odyssey"),Times.Once); - factory.Verify(m=>m.CreateNewParameter(constructed, "DECLARE @hall AS varchar(50);"), Times.Once); + + factory.Verify(m => m.CreateNewFilter("Space Odyssey"), Times.Once); + factory.Verify(m => m.CreateNewParameter(constructed, "DECLARE @hall AS varchar(50);"), Times.Once); } + [Test] public void FilterCreated_ParametersWithMasterExplicitTyping() { //The filter we are cloning var master = Mock.Of(x => - x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance && - x.Name == "Space Odyssey" && + x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && + x.Name == "Space Odyssey" && x.WhereSQL == "@hall = 'active'"); //The existing parameter declared on the filter we are cloning var masterParameter = Mock.Of( x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && - x.ParameterName=="@hall" && + x.ParameterName == "@hall" && x.Comment == "SomeComment" && x.Value == "500" && x.ParameterSQL == "DECLARE @hall AS int" ); - Mock.Get(master).Setup(m=> m.GetAllParameters()).Returns(new[] {masterParameter}); + Mock.Get(master).Setup(m => m.GetAllParameters()).Returns(new[] { masterParameter }); //We expect that the filter we are cloning will be asked what its parameters are once (and we tell them the param above) //The return values for our Mock factory - var constructed = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var constructed = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); var constructedParameter = Mock.Of(); constructedParameter.ParameterSQL = "DECLARE @hall AS int"; //The mock factory will return the above instances for the new cloned objects - var factory = Mock.Of( m=> - m.CreateNewFilter("Space Odyssey")==constructed && - m.CreateNewParameter(constructed, "DECLARE @hall AS int")==constructedParameter ); + var factory = Mock.Of(m => + m.CreateNewFilter("Space Odyssey") == constructed && + m.CreateNewParameter(constructed, "DECLARE @hall AS int") == constructedParameter); //The thing we are actually testing var filterCreator = new FilterImporter(factory, null); - filterCreator.ImportFilter(WhenIHaveA(), master, null);//Import it brah - + filterCreator.ImportFilter(WhenIHaveA(), master, null); //Import it brah + //Master filter should have been asked what its parameters are Mock.Get(master).Verify(); //factory should have been asked to create a new filter called "Space Odyssey" and a parameter with a declaration that matches the master filter SQL (i.e. 'AS int') - Mock.Get(factory).Verify(m=>m.CreateNewFilter("Space Odyssey"),Times.Once); + Mock.Get(factory).Verify(m => m.CreateNewFilter("Space Odyssey"), Times.Once); //The master filter parameters should have been copied to the child Assert.AreEqual(constructedParameter.Comment, masterParameter.Comment); - Assert.AreEqual(constructedParameter.ParameterSQL, masterParameter.ParameterSQL); //We actually manually set this above because that's the contract with "CreateNewParameter" + Assert.AreEqual(constructedParameter.ParameterSQL, + masterParameter + .ParameterSQL); //We actually manually set this above because that's the contract with "CreateNewParameter" Assert.AreEqual(constructedParameter.Value, masterParameter.Value); } @@ -147,49 +150,51 @@ public void FilterCreated_ParametersWithMasterExplicitTyping() public void FilterCreated_ParametersRenamingDueToExistingParameterInScopeWithSameName() { //The filter we are cloning - var master = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var master = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); master.Name = "Space Odyssey"; master.WhereSQL = "@hall = 'active'"; //An existing parameter that is in the scope that is being imported into - var existingParameter = Mock.Of(x => x.ParameterName=="@hall"); + var existingParameter = Mock.Of(x => x.ParameterName == "@hall"); //The filter to which the above existing parameter belongs - var existing = Mock.Of(x => - x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance&& - x.GetAllParameters()==new[] { existingParameter }); + var existing = Mock.Of(x => + x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && + x.GetAllParameters() == new[] { existingParameter }); existing.Name = "Space Odyssey"; //The return value for our Mock factory - var constructed = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var constructed = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); var constructedParameter = Mock.Of(); //The mocked factory var factory = new Mock(); factory.Setup(m => m.CreateNewFilter("Copy of Space Odyssey")).Returns(constructed); - factory.Setup(m => m.CreateNewParameter(constructed,"DECLARE @hall2 AS varchar(50);")).Returns(constructedParameter); + factory.Setup(m => m.CreateNewParameter(constructed, "DECLARE @hall2 AS varchar(50);")) + .Returns(constructedParameter); //The thing we are testing var filterCreator = new FilterImporter(factory.Object, null); - filterCreator.ImportFilter(WhenIHaveA(), master, new []{existing}); + filterCreator.ImportFilter(WhenIHaveA(), master, new[] { existing }); //Existing filter in the scope should have been asked what its parameters are - Mock.Get(existing).Verify(x=>x.GetAllParameters(),Times.Once); + Mock.Get(existing).Verify(x => x.GetAllParameters(), Times.Once); //The factory should have been asked to create a filter called "Copy of Space Odyssey" and a parameter "@hall2" (because @hall already exists in the import into scope) factory.Verify(); } [Test] - public void FilterCreated_ParametersRenamingDueToExistingParameterInScopeWithSameName_MasterContainsMasterParameter() + public void + FilterCreated_ParametersRenamingDueToExistingParameterInScopeWithSameName_MasterContainsMasterParameter() { //The filter we are cloning - var master = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var master = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); master.Name = "Space Odyssey"; master.WhereSQL = "@hall = 'active'"; //The existing parameter declared on the filter we are cloning - var masterParameter = Mock.Of(p => p.ParameterName=="@hall"); + var masterParameter = Mock.Of(p => p.ParameterName == "@hall"); masterParameter.Comment = "SomeComment"; masterParameter.Value = "500"; masterParameter.ParameterSQL = "DECLARE @hall AS int"; @@ -198,16 +203,16 @@ public void FilterCreated_ParametersRenamingDueToExistingParameterInScopeWithSam Mock.Get(master).Setup(m => m.GetAllParameters()).Returns(new[] { masterParameter }); //An existing parameter that is in the scope that is being imported into - var existingParameter = Mock.Of(x => x.ParameterName=="@hall"); + var existingParameter = Mock.Of(x => x.ParameterName == "@hall"); //The filter to which the above existing parameter belongs - var existing = Mock.Of(x => - x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance && - x.GetAllParameters()==new[] { existingParameter }); + var existing = Mock.Of(x => + x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && + x.GetAllParameters() == new[] { existingParameter }); existing.Name = "Space Odyssey"; //The return value for our Mock factory - var constructed = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var constructed = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); var constructedParameter = Mock.Of(); //The mocked factory @@ -219,10 +224,10 @@ public void FilterCreated_ParametersRenamingDueToExistingParameterInScopeWithSam var filterCreator = new FilterImporter(factory.Object, null); filterCreator.ImportFilter(WhenIHaveA(), master, new[] { existing }); - Assert.AreEqual("@hall2 = 'active'",constructed.WhereSQL); + Assert.AreEqual("@hall2 = 'active'", constructed.WhereSQL); //Master filter should have been asked what its parameters are - Mock.Get(master).Verify(m => m.GetAllParameters(),Times.Once); + Mock.Get(master).Verify(m => m.GetAllParameters(), Times.Once); //Existing filter in the scope should have been asked what its parameters are Mock.Get(existing).Verify(); diff --git a/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/ParameterCreatorTests.cs b/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/ParameterCreatorTests.cs index d45d718c96..73162db477 100644 --- a/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/ParameterCreatorTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/FilterImportingTests/ParameterCreatorTests.cs @@ -20,86 +20,89 @@ public class ParameterCreatorTests [Test] public void NoParametersTest_CreateNotCalled() { - var f = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); var factory = new Mock(); - factory.Verify(m => m.CreateNewParameter(It.IsAny(), It.IsAny()),Times.Never); + factory.Verify(m => m.CreateNewParameter(It.IsAny(), It.IsAny()), Times.Never); var creator = new ParameterCreator(factory.Object, Array.Empty(), null); - creator.CreateAll(f,null); + creator.CreateAll(f, null); factory.Verify(); } - + [Test] public void SingleParameterTest_NullReturnFromConstruct_Throws() { - var f = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); f.WhereSQL = "@bob = 'bob'"; - var factory = Mock.Of(m => m.CreateNewParameter(f,"DECLARE @bob AS varchar(50);")==null); + var factory = Mock.Of(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);") == null); var creator = new ParameterCreator(factory, null, null); - var ex = Assert.Throws(()=>creator.CreateAll(f,null)); + var ex = Assert.Throws(() => creator.CreateAll(f, null)); Assert.IsTrue(ex.Message.StartsWith("Parameter construction method returned null")); } - + [Test] public void SingleParameterTest_OneParameter_CreateCalled() { - var p = new Mock();//save should be called because there is no VAlue on the parameter + var p = new Mock(); //save should be called because there is no VAlue on the parameter p.Setup(m => m.SaveToDatabase()); - var f = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); f.WhereSQL = "@bob = 'bob'"; var factory = new Mock(); - factory.Setup(m => m.CreateNewParameter(f,"DECLARE @bob AS varchar(50);")).Returns(p.Object); + factory.Setup(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);")).Returns(p.Object); var creator = new ParameterCreator(factory.Object, null, null); - creator.CreateAll(f,null); + creator.CreateAll(f, null); - p.Verify(m => m.SaveToDatabase(),Times.Once); + p.Verify(m => m.SaveToDatabase(), Times.Once); p.Verify(); - factory.Verify(m => m.CreateNewParameter(f,"DECLARE @bob AS varchar(50);"),Times.Once); + factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);"), Times.Once); } + [Test] public void SingleParameterTest_ParameterAlreadyExists_CreateNotCalled() { - var p = new Mock();//save should be called because there is no VAlue on the parameter + var p = new Mock(); //save should be called because there is no VAlue on the parameter p.Setup(m => m.SaveToDatabase()); - var existingParameter = Mock.Of(x => - x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance && - x.ParameterName=="@bob" + var existingParameter = Mock.Of(x => + x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && + x.ParameterName == "@bob" ); var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance && - x.WhereSQL == "@bob = 'bob'" && - x.GetAllParameters() == new[] {existingParameter}); + x.WhereSQL == "@bob = 'bob'" && + x.GetAllParameters() == new[] { existingParameter }); var factory = new Mock(); var creator = new ParameterCreator(factory.Object, null, null); - creator.CreateAll(f,null); creator.CreateAll(f, null); - creator.CreateAll(f, null);//no matter how many times we call create it shouldn't make more because there is already one + creator.CreateAll(f, null); + creator.CreateAll(f, + null); //no matter how many times we call create it shouldn't make more because there is already one - p.Verify(m=> m.SaveToDatabase(),Times.Never); - factory.Verify(m=> m.CreateNewParameter(f, It.IsAny()),Times.Never); //should never be called because the filter already has + p.Verify(m => m.SaveToDatabase(), Times.Never); + factory.Verify(m => m.CreateNewParameter(f, It.IsAny()), + Times.Never); //should never be called because the filter already has } - + [Test] public void SingleParameterTest_GlobalOverrides_CreateNotCalled() { - var f = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); f.WhereSQL = "@bob = 'bob'"; - var global = Mock.Of(x=>x.ParameterName=="@bob"); + var global = Mock.Of(x => x.ParameterName == "@bob"); var factory = new Mock(); factory @@ -107,7 +110,7 @@ public void SingleParameterTest_GlobalOverrides_CreateNotCalled() .Throws(); var creator = new ParameterCreator(factory.Object, new[] { global }, null); - creator.CreateAll(f,null); + creator.CreateAll(f, null); factory.Verify(); } @@ -115,19 +118,19 @@ public void SingleParameterTest_GlobalOverrides_CreateNotCalled() [Test] public void SingleParameterTest_GlobalButNotSameName_CreateCalled() { - var f = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); f.WhereSQL = "@bob = 'bob'"; - var global = Mock.Of(x => x.ParameterName=="@bob"); + var global = Mock.Of(x => x.ParameterName == "@bob"); var factory = new Mock(); - factory.Setup(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);")).Returns(Mock.Of); + factory.Setup(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);")) + .Returns(Mock.Of); var creator = new ParameterCreator(factory.Object, null, null); - creator.CreateAll(f,null); - - factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);"),Times.Once); + creator.CreateAll(f, null); + factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);"), Times.Once); } @@ -138,12 +141,12 @@ public void SingleParameterTest_Template_TemplateValuesUsed() var pstub = Mock.Of(); //The filter that requires that the parameters be created - var f = Mock.Of(x => x.GetQuerySyntaxHelper()==MicrosoftQuerySyntaxHelper.Instance); + var f = Mock.Of(x => x.GetQuerySyntaxHelper() == MicrosoftQuerySyntaxHelper.Instance); f.WhereSQL = "@bob = 'bob'"; //The template which is an existing known about parameter from the master filter that is being duplicated. This template will be spotted and used to make the new parameter match the cloned filter's one - var template = Mock.Of(x => x.ParameterName=="@bob"); - + var template = Mock.Of(x => x.ParameterName == "@bob"); + template.ParameterSQL = "DECLARE @bob AS int"; template.Value = "5"; template.Comment = "fish"; @@ -151,21 +154,23 @@ public void SingleParameterTest_Template_TemplateValuesUsed() var factory = new Mock(); factory.Setup(m => m.CreateNewParameter(f, "DECLARE @bob AS int")).Returns(pstub); - var creator = new ParameterCreator(factory.Object, null, new []{template}); - creator.CreateAll(f,null); + var creator = new ParameterCreator(factory.Object, null, new[] { template }); + creator.CreateAll(f, null); Assert.AreEqual("5", pstub.Value); - Assert.AreEqual("fish", pstub.Comment); + Assert.AreEqual("fish", pstub.Comment); - factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS int"),Times.Once); + factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS int"), Times.Once); } [TestCase("[MyTable].[MyCol] = @name", "@name", "@name2", "[MyTable].[MyCol] = @name2")] [TestCase("[Col]=@name OR [Col]=@name2", "@name", "@chtulhu", "[Col]=@chtulhu OR [Col]=@name2")] [TestCase("([MyTable].[MyCol] = @name) OR ...", "@name", "@name2", "([MyTable].[MyCol] = @name2) OR ...")] - [TestCase("[MyTable].[MyCol] = @name2", "@name", "@cthulhu", "[MyTable].[MyCol] = @name2")]//No match since it is a substring + [TestCase("[MyTable].[MyCol] = @name2", "@name", "@cthulhu", + "[MyTable].[MyCol] = @name2")] //No match since it is a substring [TestCase("[MyTable].[MyCol] = @name_2", "@name", "@cthulhu", "[MyTable].[MyCol] = @name_2")] - [TestCase("[MyTable].[MyCol] = @name@@coconuts", "@name", "@cthulhu", "[MyTable].[MyCol] = @name@@coconuts")]//No match since @ is a legit word to use in a parameter name making @name@coconuts legal name for a + [TestCase("[MyTable].[MyCol] = @name@@coconuts", "@name", "@cthulhu", + "[MyTable].[MyCol] = @name@@coconuts")] //No match since @ is a legit word to use in a parameter name making @name@coconuts legal name for a [TestCase("@a=a", "@a", "@b", "@b=a")] [TestCase(@"a=@a OR @@ -175,7 +180,7 @@ public void SingleParameterTest_Template_TemplateValuesUsed() public void ReplaceParametersSQL(string haystack, string needle, string replacement, string expectedOutput) { var output = ParameterCreator.RenameParameterInSQL(haystack, needle, replacement); - Assert.AreEqual(expectedOutput,output); + Assert.AreEqual(expectedOutput, output); } [Test] @@ -208,6 +213,6 @@ [test]..[prescribing].[approved_name] LIKE @drugName2_2 [test]..[prescribing].[approved_name] LIKE @drugName3_2"; - Assert.AreEqual(expectedoutput,newString); + Assert.AreEqual(expectedoutput, newString); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ForwardEngineerANOCatalogueTests.cs b/Rdmp.Core.Tests/Curation/Integration/ForwardEngineerANOCatalogueTests.cs index bee7e326af..6d441b3610 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ForwardEngineerANOCatalogueTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ForwardEngineerANOCatalogueTests.cs @@ -34,7 +34,7 @@ protected override void SetUp() BlitzMainDataTables(); - if(ANOStore_Database.Exists()) + if (ANOStore_Database.Exists()) DeleteTables(ANOStore_Database); } @@ -52,9 +52,9 @@ public void PlanManagementTest() bulk.ImportAsCatalogue(); var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, bulk.catalogue) - { - TargetDatabase = db - }; + { + TargetDatabase = db + }; //no operations are as yet configured Assert.DoesNotThrow(() => planManager.Check(new ThrowImmediatelyCheckNotifier())); @@ -62,7 +62,7 @@ public void PlanManagementTest() //create a table with the same name in the endpoint database to confirm that that's a problem db.CreateTable(bulk.tableInfo.GetRuntimeName(), new DatabaseColumnRequest[] { - new DatabaseColumnRequest("fish", "varchar(100)") + new("fish", "varchar(100)") }); //throws because table already exists @@ -84,10 +84,8 @@ public void PlanManagementTest() { planManager.GetPlanForColumnInfo(chi).Plan = Plan.Drop; planManager.GetPlanForColumnInfo(chi).Check(new ThrowImmediatelyCheckNotifier()); - } - - ,"Should not be able to drop primary key column"); + , "Should not be able to drop primary key column"); db.Drop(); } @@ -106,10 +104,10 @@ public void CreateANOVersionTest() bulk.SetupTestData(); bulk.ImportAsCatalogue(); - var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator,bulk.catalogue) - { - TargetDatabase = db - }; + var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, bulk.catalogue) + { + TargetDatabase = db + }; //setup test rules for migrator CreateMigrationRules(planManager, bulk); @@ -145,11 +143,11 @@ public void CreateANOVersionTest_IntIdentity() //Create this table in the scratch database var tbl = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer).CreateTable("MyTable", new[] { - new DatabaseColumnRequest("id", "int identity(1,1)", false) {IsPrimaryKey = true}, - new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof (string), 10), false) + new DatabaseColumnRequest("id", "int identity(1,1)", false) { IsPrimaryKey = true }, + new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 10), false) }); - var cata = Import(tbl,out var ti, out var cols); + var cata = Import(tbl, out var ti, out var cols); var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, cata) { @@ -171,10 +169,10 @@ public void CreateANOVersionTest_IntIdentity() Assert.IsTrue(anoCatalogue.Exists()); //should only be one (the id column - Assert.AreEqual(1,anoCatalogue.CatalogueItems.Length); + Assert.AreEqual(1, anoCatalogue.CatalogueItems.Length); var idColInAnoDatabase = anoCatalogue.CatalogueItems[0].ColumnInfo; Assert.AreEqual("int", idColInAnoDatabase.Data_type); - + db.Drop(); var exports = CatalogueRepository.GetAllObjects().Length; @@ -185,13 +183,13 @@ public void CreateANOVersionTest_IntIdentity() } - [Test] - [TestCase(false,false)] + [TestCase(false, false)] [TestCase(false, true)] - [TestCase(true,false)] - [TestCase(true,true)] - public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSkippedTable,bool putPlanThroughSerialization) + [TestCase(true, false)] + [TestCase(true, true)] + public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSkippedTable, + bool putPlanThroughSerialization) { var dbFrom = From; var dbTo = To; @@ -211,7 +209,7 @@ public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSk new DatabaseColumnRequest("Vertebrae", "varchar(25)") }; - var tblFromNeck = dbFrom.CreateTable("Necks",cols); + var tblFromNeck = dbFrom.CreateTable("Necks", cols); //Necks table already exists in the destination so will be skipped for migration but still needs to be imported var tblToNeck = dbTo.CreateTable("Necks", cols); @@ -221,9 +219,9 @@ public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSk var i2 = new TableInfoImporter(CatalogueRepository, tblFromNeck); i2.DoImport(out var fromNeckTableInfo, out var fromNeckColumnInfo); - + //Table already exists but does the in Catalogue reference exist? - if(tableInfoAlreadyExistsForSkippedTable) + if (tableInfoAlreadyExistsForSkippedTable) { var i3 = new TableInfoImporter(CatalogueRepository, tblToNeck); i3.DoImport(out var toNecksTableInfo, out var toNecksColumnInfo); @@ -246,17 +244,19 @@ public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSk //setup ANOTable on head var anoTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOSkullColor", "C") - { - NumberOfCharactersToUseInAnonymousRepresentation = 10 - }; + { + NumberOfCharactersToUseInAnonymousRepresentation = 10 + }; anoTable.SaveToDatabase(); - anoTable.PushToANOServerAsNewTable("varchar(10)",new ThrowImmediatelyCheckNotifier()); + anoTable.PushToANOServerAsNewTable("varchar(10)", new ThrowImmediatelyCheckNotifier()); //////////////////The actual test!///////////////// - var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator,cata); + var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, cata); //ano the table SkullColor - var scPlan = planManager.GetPlanForColumnInfo(fromHeadsColumnInfo.Single(col => col.GetRuntimeName().Equals("SkullColor"))); + var scPlan = + planManager.GetPlanForColumnInfo( + fromHeadsColumnInfo.Single(col => col.GetRuntimeName().Equals("SkullColor"))); scPlan.ANOTable = anoTable; scPlan.Plan = Plan.ANO; @@ -264,14 +264,16 @@ public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSk { var asString = JsonConvertExtensions.SerializeObject(planManager, RepositoryLocator); - planManager = (ForwardEngineerANOCataloguePlanManager)JsonConvertExtensions.DeserializeObject( asString, typeof(ForwardEngineerANOCataloguePlanManager), RepositoryLocator); + planManager = (ForwardEngineerANOCataloguePlanManager)JsonConvertExtensions.DeserializeObject(asString, + typeof(ForwardEngineerANOCataloguePlanManager), RepositoryLocator); } - + //not part of serialization planManager.TargetDatabase = dbTo; - planManager.SkippedTables.Add(fromNeckTableInfo);//skip the necks table because it already exists (ColumnInfos may or may not exist but physical table definetly does) + planManager.SkippedTables + .Add(fromNeckTableInfo); //skip the necks table because it already exists (ColumnInfos may or may not exist but physical table definetly does) - var engine = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, planManager); + var engine = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, planManager); if (!tableInfoAlreadyExistsForSkippedTable) { @@ -297,7 +299,9 @@ public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSk //these columns should all exist Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("SkullColor"))); Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("SpineColor"))); - Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("Vertebrae"))); //actually there will be 2 copies of this one from Necks one from Heads + Assert.IsTrue(newCataItems.Any(ci => + ci.ExtractionInformation.SelectSQL + .Contains("Vertebrae"))); //actually there will be 2 copies of this one from Necks one from Heads //new ColumnInfo should have a reference to the anotable Assert.IsTrue(newCataItems.Single(ci => ci.Name.Equals("ANOSkullColor")).ColumnInfo.ANOTable_ID == anoTable.ID); @@ -306,7 +310,7 @@ public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSk var newSpineColorColumnInfo = newCataItems.Single(ci => ci.Name.Equals("ANOSkullColor")).ColumnInfo; //table info already existed, make sure the new CatalogueItems point to the same columninfos / table infos - Assert.IsTrue(newCataItems.Select(ci=>ci.ColumnInfo).Contains(newSpineColorColumnInfo)); + Assert.IsTrue(newCataItems.Select(ci => ci.ColumnInfo).Contains(newSpineColorColumnInfo)); } [Test] @@ -325,13 +329,13 @@ public void CreateANOVersionTest_LookupsAndExtractionInformations() //Create a lookup table on the server var lookupTbl = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer).CreateTable("z_sexLookup", new[] { - new DatabaseColumnRequest("Code", "varchar(1)"){IsPrimaryKey = true}, - new DatabaseColumnRequest("hb_Code", "varchar(1)"){IsPrimaryKey = true}, + new DatabaseColumnRequest("Code", "varchar(1)") { IsPrimaryKey = true }, + new DatabaseColumnRequest("hb_Code", "varchar(1)") { IsPrimaryKey = true }, new DatabaseColumnRequest("Description", "varchar(100)") }); //import a reference to the table - var importer = new TableInfoImporter(CatalogueRepository,lookupTbl); + var importer = new TableInfoImporter(CatalogueRepository, lookupTbl); importer.DoImport(out var lookupTableInfo, out var lookupColumnInfos); //Create a Lookup reference @@ -358,7 +362,7 @@ public void CreateANOVersionTest_LookupsAndExtractionInformations() var ciComboCol = new CatalogueItem(CatalogueRepository, bulk.catalogue, "ComboColumn"); var colForename = bulk.columnInfos.Single(c => c.GetRuntimeName() == "forename"); - var colSurname = bulk.columnInfos.Single(c => c.GetRuntimeName() == "surname"); + var colSurname = bulk.columnInfos.Single(c => c.GetRuntimeName() == "surname"); var eiComboCol = new ExtractionInformation(CatalogueRepository, ciComboCol, colForename, $"{colForename} + ' ' + {colSurname}") @@ -367,58 +371,63 @@ public void CreateANOVersionTest_LookupsAndExtractionInformations() }; eiComboCol.SaveToDatabase(); - var eiDataLoadRunId = bulk.extractionInformations.Single(ei => ei.GetRuntimeName().Equals(SpecialFieldNames.DataLoadRunID)); + var eiDataLoadRunId = + bulk.extractionInformations.Single(ei => ei.GetRuntimeName().Equals(SpecialFieldNames.DataLoadRunID)); eiDataLoadRunId.DeleteInDatabase(); - var lookup = new Lookup(CatalogueRepository, lookupColumnInfos[2], ciSex.ColumnInfo, lookupColumnInfos[0],ExtractionJoinType.Left, null); + var lookup = new Lookup(CatalogueRepository, lookupColumnInfos[2], ciSex.ColumnInfo, lookupColumnInfos[0], + ExtractionJoinType.Left, null); //now let's make it worse, let's assume the sex code changes per healthboard therefore the join to the lookup requires both fields sex and hb_extract - var compositeLookup = new LookupCompositeJoinInfo(CatalogueRepository, lookup, ciHb.ColumnInfo, lookupColumnInfos[1]); + var compositeLookup = + new LookupCompositeJoinInfo(CatalogueRepository, lookup, ciHb.ColumnInfo, lookupColumnInfos[1]); //now let's make the _Desc field in the original Catalogue var orderToInsertDescriptionFieldAt = ciSex.ExtractionInformation.Order; //bump everyone down 1 - foreach (var toBumpDown in bulk.catalogue.CatalogueItems.Select(ci=>ci.ExtractionInformation).Where(e =>e != null && e.Order > orderToInsertDescriptionFieldAt)) + foreach (var toBumpDown in bulk.catalogue.CatalogueItems.Select(ci => ci.ExtractionInformation) + .Where(e => e != null && e.Order > orderToInsertDescriptionFieldAt)) { toBumpDown.Order++; toBumpDown.SaveToDatabase(); } var ciDescription = new CatalogueItem(CatalogueRepository, bulk.catalogue, "Sex_Desc"); - var eiDescription = new ExtractionInformation(CatalogueRepository, ciDescription, lookupColumnInfos[2],lookupColumnInfos[2].Name) - { - Alias = "Sex_Desc", - Order = orderToInsertDescriptionFieldAt +1, - ExtractionCategory = ExtractionCategory.Supplemental - }; + var eiDescription = new ExtractionInformation(CatalogueRepository, ciDescription, lookupColumnInfos[2], + lookupColumnInfos[2].Name) + { + Alias = "Sex_Desc", + Order = orderToInsertDescriptionFieldAt + 1, + ExtractionCategory = ExtractionCategory.Supplemental + }; eiDescription.SaveToDatabase(); bulk.catalogue.ClearAllInjections(); //check it worked - var qb = new QueryBuilder(null,null); + var qb = new QueryBuilder(null, null); qb.AddColumnRange(bulk.catalogue.GetAllExtractionInformation(ExtractionCategory.Any)); - + //The query builder should be able to succesfully create SQL Console.WriteLine(qb.SQL); - + //there should be 2 tables involved in the query [z_sexLookup] and [BulkData] - Assert.AreEqual(2,qb.TablesUsedInQuery.Count); + Assert.AreEqual(2, qb.TablesUsedInQuery.Count); //the query builder should have identified the lookup - Assert.AreEqual(lookup,qb.GetDistinctRequiredLookups().Single()); + Assert.AreEqual(lookup, qb.GetDistinctRequiredLookups().Single()); //////////////////////////////////////////////////////////////////////////////////////The Actual Bit Being Tested//////////////////////////////////////////////////// - var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator,bulk.catalogue) - { - TargetDatabase = db - }; + var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, bulk.catalogue) + { + TargetDatabase = db + }; //setup test rules for migrator CreateMigrationRules(planManager, bulk); - + //rules should pass checks Assert.DoesNotThrow(() => planManager.Check(new ThrowImmediatelyCheckNotifier())); @@ -430,22 +439,31 @@ public void CreateANOVersionTest_LookupsAndExtractionInformations() Assert.IsTrue(anoCatalogue.Exists()); //The new Catalogue should have the same number of ExtractionInformations - var eiSource = bulk.catalogue.GetAllExtractionInformation(ExtractionCategory.Any).OrderBy(ei=>ei.Order).ToArray(); - var eiDestination = anoCatalogue.GetAllExtractionInformation(ExtractionCategory.Any).OrderBy(ei=>ei.Order).ToArray(); - - Assert.AreEqual(eiSource.Length,eiDestination.Length,"Both the new and the ANO catalogue should have the same number of ExtractionInformations (extractable columns)"); + var eiSource = bulk.catalogue.GetAllExtractionInformation(ExtractionCategory.Any).OrderBy(ei => ei.Order) + .ToArray(); + var eiDestination = anoCatalogue.GetAllExtractionInformation(ExtractionCategory.Any).OrderBy(ei => ei.Order) + .ToArray(); + + Assert.AreEqual(eiSource.Length, eiDestination.Length, + "Both the new and the ANO catalogue should have the same number of ExtractionInformations (extractable columns)"); for (var i = 0; i < eiSource.Length; i++) { - Assert.AreEqual(eiSource[i].Order , eiDestination[i].Order,"ExtractionInformations in the source and destination Catalogue should have the same order"); + Assert.AreEqual(eiSource[i].Order, eiDestination[i].Order, + "ExtractionInformations in the source and destination Catalogue should have the same order"); Assert.AreEqual(eiSource[i].GetRuntimeName(), - eiDestination[i].GetRuntimeName().Replace("ANO",""), "ExtractionInformations in the source and destination Catalogue should have the same names (excluding ANO prefix)"); - - Assert.AreEqual(eiSource[i].ExtractionCategory, eiDestination[i].ExtractionCategory, "Old / New ANO ExtractionInformations did not match on ExtractionCategory"); - Assert.AreEqual(eiSource[i].IsExtractionIdentifier, eiDestination[i].IsExtractionIdentifier, "Old / New ANO ExtractionInformations did not match on IsExtractionIdentifier"); - Assert.AreEqual(eiSource[i].HashOnDataRelease, eiDestination[i].HashOnDataRelease, "Old / New ANO ExtractionInformations did not match on HashOnDataRelease"); - Assert.AreEqual(eiSource[i].IsPrimaryKey, eiDestination[i].IsPrimaryKey, "Old / New ANO ExtractionInformations did not match on IsPrimaryKey"); + eiDestination[i].GetRuntimeName().Replace("ANO", ""), + "ExtractionInformations in the source and destination Catalogue should have the same names (excluding ANO prefix)"); + + Assert.AreEqual(eiSource[i].ExtractionCategory, eiDestination[i].ExtractionCategory, + "Old / New ANO ExtractionInformations did not match on ExtractionCategory"); + Assert.AreEqual(eiSource[i].IsExtractionIdentifier, eiDestination[i].IsExtractionIdentifier, + "Old / New ANO ExtractionInformations did not match on IsExtractionIdentifier"); + Assert.AreEqual(eiSource[i].HashOnDataRelease, eiDestination[i].HashOnDataRelease, + "Old / New ANO ExtractionInformations did not match on HashOnDataRelease"); + Assert.AreEqual(eiSource[i].IsPrimaryKey, eiDestination[i].IsPrimaryKey, + "Old / New ANO ExtractionInformations did not match on IsPrimaryKey"); } //check it worked @@ -455,25 +473,34 @@ public void CreateANOVersionTest_LookupsAndExtractionInformations() //The query builder should be able to succesfully create SQL Console.WriteLine(qbdestination.SQL); - var anoEiPostcode = anoCatalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(ei => ei.GetRuntimeName().Equals("MyMutilatedColumn")); - + var anoEiPostcode = anoCatalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(ei => ei.GetRuntimeName().Equals("MyMutilatedColumn")); + //The transform on postcode should have been refactored to the new table name and preserve the scalar function LEFT... - Assert.AreEqual($"LEFT(10,{anoEiPostcode.ColumnInfo.TableInfo.GetFullyQualifiedName()}.[current_postcode])",anoEiPostcode.SelectSQL); + Assert.AreEqual($"LEFT(10,{anoEiPostcode.ColumnInfo.TableInfo.GetFullyQualifiedName()}.[current_postcode])", + anoEiPostcode.SelectSQL); - var anoEiComboCol = anoCatalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(ei => ei.GetRuntimeName().Equals("ComboColumn")); + var anoEiComboCol = anoCatalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(ei => ei.GetRuntimeName().Equals("ComboColumn")); //The transform on postcode should have been refactored to the new table name and preserve the scalar function LEFT... - Assert.AreEqual(string.Format("{0}.[forename] + ' ' + {0}.[surname]", anoEiPostcode.ColumnInfo.TableInfo.GetFullyQualifiedName()), anoEiComboCol.SelectSQL); + Assert.AreEqual( + string.Format("{0}.[forename] + ' ' + {0}.[surname]", + anoEiPostcode.ColumnInfo.TableInfo.GetFullyQualifiedName()), anoEiComboCol.SelectSQL); //there should be 2 tables involved in the query [z_sexLookup] and [BulkData] Assert.AreEqual(2, qbdestination.TablesUsedInQuery.Count); //the query builder should have identified the lookup but it should be the new one not the old one - Assert.AreEqual(1, qbdestination.GetDistinctRequiredLookups().Count(), "New query builder for ano catalogue did not correctly identify that there was a Lookup"); - Assert.AreNotEqual(lookup, qbdestination.GetDistinctRequiredLookups().Single(), "New query builder for ano catalogue identified the OLD Lookup!"); - - Assert.AreEqual(1, qbdestination.GetDistinctRequiredLookups().Single().GetSupplementalJoins().Count(),"The new Lookup did not have the composite join key (sex/hb_extract)"); - Assert.AreNotEqual(compositeLookup, qbdestination.GetDistinctRequiredLookups().Single().GetSupplementalJoins(), "New query builder for ano catalogue identified the OLD LookupCompositeJoinInfo!"); + Assert.AreEqual(1, qbdestination.GetDistinctRequiredLookups().Count(), + "New query builder for ano catalogue did not correctly identify that there was a Lookup"); + Assert.AreNotEqual(lookup, qbdestination.GetDistinctRequiredLookups().Single(), + "New query builder for ano catalogue identified the OLD Lookup!"); + + Assert.AreEqual(1, qbdestination.GetDistinctRequiredLookups().Single().GetSupplementalJoins().Count(), + "The new Lookup did not have the composite join key (sex/hb_extract)"); + Assert.AreNotEqual(compositeLookup, qbdestination.GetDistinctRequiredLookups().Single().GetSupplementalJoins(), + "New query builder for ano catalogue identified the OLD LookupCompositeJoinInfo!"); db.Drop(); @@ -482,8 +509,6 @@ public void CreateANOVersionTest_LookupsAndExtractionInformations() Assert.AreEqual(exports, imports); Assert.IsTrue(exports > 0); - - } @@ -492,12 +517,12 @@ private void CreateMigrationRules(ForwardEngineerANOCataloguePlanManager planMan var chi = bulk.GetColumnInfo("chi"); var anoChi = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOCHI", "C") - { - NumberOfIntegersToUseInAnonymousRepresentation = 9, - NumberOfCharactersToUseInAnonymousRepresentation = 1 - }; + { + NumberOfIntegersToUseInAnonymousRepresentation = 9, + NumberOfCharactersToUseInAnonymousRepresentation = 1 + }; anoChi.SaveToDatabase(); - anoChi.PushToANOServerAsNewTable(chi.Data_type,new ThrowImmediatelyCheckNotifier()); + anoChi.PushToANOServerAsNewTable(chi.Data_type, new ThrowImmediatelyCheckNotifier()); planManager.GetPlanForColumnInfo(chi).Plan = Plan.ANO; planManager.GetPlanForColumnInfo(chi).ANOTable = anoChi; diff --git a/Rdmp.Core.Tests/Curation/Integration/GetDatabaseDiagramBinaryTest.cs b/Rdmp.Core.Tests/Curation/Integration/GetDatabaseDiagramBinaryTest.cs index 11093b8ffb..059496d0ef 100644 --- a/Rdmp.Core.Tests/Curation/Integration/GetDatabaseDiagramBinaryTest.cs +++ b/Rdmp.Core.Tests/Curation/Integration/GetDatabaseDiagramBinaryTest.cs @@ -12,26 +12,26 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class GetDatabaseDiagramBinaryTest:DatabaseTests +public class GetDatabaseDiagramBinaryTest : DatabaseTests { [Test] public void GetBinaryText() { using (var con = CatalogueTableRepository.GetConnection()) { - using(var cmd = DatabaseCommandHelper.GetCommand( - "SELECT definition FROM sysdiagrams where name = 'Catalogue_Data_Diagram' ", - con.Connection, con.Transaction)) + using (var cmd = DatabaseCommandHelper.GetCommand( + "SELECT definition FROM sysdiagrams where name = 'Catalogue_Data_Diagram' ", + con.Connection, con.Transaction)) using (var reader = cmd.ExecuteReader()) { //The system diagram exists Assert.IsTrue(reader.Read()); - var bytes = (byte[]) reader[0]; + var bytes = (byte[])reader[0]; var bytesAsString = ByteArrayToString(bytes); - + Console.WriteLine(bytesAsString); - Assert.Greater(bytesAsString.Length,100000); + Assert.Greater(bytesAsString.Length, 100000); } } } diff --git a/Rdmp.Core.Tests/Curation/Integration/GovernanceTests.cs b/Rdmp.Core.Tests/Curation/Integration/GovernanceTests.cs index 8347bcc0b9..ed483ef02d 100644 --- a/Rdmp.Core.Tests/Curation/Integration/GovernanceTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/GovernanceTests.cs @@ -18,7 +18,7 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class GovernanceTests:DatabaseTests +public class GovernanceTests : DatabaseTests { [OneTimeTearDown] protected void OneTimeTearDown() @@ -41,8 +41,9 @@ public void TestCreatingGovernance_StartsAtToday() var gov = GetGov(); Assert.NotNull(gov); - Assert.AreEqual(gov.StartDate,DateTime.Now.Date); + Assert.AreEqual(gov.StartDate, DateTime.Now.Date); } + [Test] public void TestCreatingGovernance_ChangeName() { @@ -52,20 +53,19 @@ public void TestCreatingGovernance_ChangeName() var gov = GetGov(); gov.Name = "Fish"; var freshCopy = CatalogueRepository.GetObjectByID(gov.ID); - + //local change not applied yet - Assert.AreNotEqual(gov.Name,freshCopy.Name); - + Assert.AreNotEqual(gov.Name, freshCopy.Name); + //comitted change to database gov.SaveToDatabase(); - + //notice that this fresh copy is still desynced - Assert.AreNotEqual(gov.Name,freshCopy.Name); - + Assert.AreNotEqual(gov.Name, freshCopy.Name); + //sync it freshCopy = CatalogueRepository.GetObjectByID(gov.ID); - Assert.AreEqual(gov.Name ,freshCopy.Name); - + Assert.AreEqual(gov.Name, freshCopy.Name); } [Test] @@ -79,12 +79,13 @@ public void TestCreatingGovernance_CannotHaveSameNames() gov2.Name = "HiDuplicate"; - if(CatalogueRepository is TableRepository) + if (CatalogueRepository is TableRepository) { var ex = Assert.Throws(gov2.SaveToDatabase); - StringAssert.StartsWith("Cannot insert duplicate key row in object 'dbo.GovernancePeriod' with unique index 'idxGovernancePeriodNameMustBeUnique'. The duplicate key value is (HiDuplicate)", ex.Message); + StringAssert.StartsWith( + "Cannot insert duplicate key row in object 'dbo.GovernancePeriod' with unique index 'idxGovernancePeriodNameMustBeUnique'. The duplicate key value is (HiDuplicate)", + ex.Message); } - } [Test] @@ -97,7 +98,9 @@ public void Checkability_ExpiresBeforeStarts() gov.Check(new ThrowImmediatelyCheckNotifier()); gov.EndDate = DateTime.MinValue; - var ex = Assert.Throws(()=>gov.Check(new ThrowImmediatelyCheckNotifier()));//no longer valid - notice there is no SaveToDatabase because we can shouldnt be going back to db anyway + var ex = Assert.Throws(() => + gov.Check( + new ThrowImmediatelyCheckNotifier())); //no longer valid - notice there is no SaveToDatabase because we can shouldnt be going back to db anyway Assert.AreEqual("GovernancePeriod TestExpiryBeforeStarting expires before it begins!", ex.Message); } @@ -108,16 +111,15 @@ public void Checkability_NoExpiryDateWarning() gov.Name = "NeverExpires"; //valid to start with - var ex = Assert.Throws(()=>gov.Check(new ThrowImmediatelyCheckNotifier {ThrowOnWarning = true})); - Assert.AreEqual("There is no end date for GovernancePeriod NeverExpires",ex.Message); - + var ex = Assert.Throws(() => gov.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); + Assert.AreEqual("There is no end date for GovernancePeriod NeverExpires", ex.Message); } [TestCase(true)] [TestCase(false)] public void GovernsCatalogue(bool memoryRepository) { - var repo = memoryRepository ? (ICatalogueRepository) new MemoryCatalogueRepository() : CatalogueRepository; + var repo = memoryRepository ? (ICatalogueRepository)new MemoryCatalogueRepository() : CatalogueRepository; var gov = GetGov(repo); var c = new Catalogue(repo, "GovernedCatalogue"); @@ -132,7 +134,7 @@ public void GovernsCatalogue(bool memoryRepository) var governedCatalogue = allCatalogues[0]; Assert.AreEqual(governedCatalogue, c); //we now govern C } - finally + finally { gov.DeleteGovernanceRelationshipTo(c); Assert.AreEqual(gov.GovernedCatalogues.Count(), 0); //we govern c nevermore! @@ -147,16 +149,18 @@ public void GovernsSameCatalogueTwice() var c = new Catalogue(CatalogueRepository, "GovernedCatalogue"); var gov = GetGov(); - Assert.AreEqual(gov.GovernedCatalogues.Count(), 0);//should be no governanced catalogues for this governancer yet + Assert.AreEqual(gov.GovernedCatalogues.Count(), + 0); //should be no governanced catalogues for this governancer yet gov.CreateGovernanceRelationshipTo(c); - gov.CreateGovernanceRelationshipTo(c); + gov.CreateGovernanceRelationshipTo(c); } private List toCleanup = new(); + private GovernancePeriod GetGov(ICatalogueRepository repo = null) { - var gov = new GovernancePeriod(repo??CatalogueRepository); + var gov = new GovernancePeriod(repo ?? CatalogueRepository); toCleanup.Add(gov); return gov; diff --git a/Rdmp.Core.Tests/Curation/Integration/HangingConnectionTest.cs b/Rdmp.Core.Tests/Curation/Integration/HangingConnectionTest.cs index c6d65c9a3c..f473c42e75 100644 --- a/Rdmp.Core.Tests/Curation/Integration/HangingConnectionTest.cs +++ b/Rdmp.Core.Tests/Curation/Integration/HangingConnectionTest.cs @@ -13,7 +13,7 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class HangingConnectionTest:DatabaseTests +public class HangingConnectionTest : DatabaseTests { private string testDbName = "HangingConnectionTest"; @@ -26,7 +26,7 @@ public void TestConnection(bool explicitClose) //drop it if it existed if (DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(testDbName).Exists()) DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(testDbName).Drop(); - + DiscoveredServerICanCreateRandomDatabasesAndTablesOn.CreateDatabase(testDbName); Thread.Sleep(500); @@ -42,27 +42,31 @@ public void TestConnection(bool explicitClose) //we are currently connected so this should throw Assert.Throws(ThrowIfDatabaseLock); - } + Thread.Sleep(500); if (explicitClose) { SqlConnection.ClearAllPools(); Thread.Sleep(500); - Assert.DoesNotThrow(ThrowIfDatabaseLock);//in this case we told .net to clear the pools which leaves the server free of locks/hanging connections + Assert.DoesNotThrow( + ThrowIfDatabaseLock); //in this case we told .net to clear the pools which leaves the server free of locks/hanging connections } else { - Assert.Throws(ThrowIfDatabaseLock);//despite us closing the connection and using the 'using' block .net still keeps a connection in sleep state to the server >< + Assert.Throws( + ThrowIfDatabaseLock); //despite us closing the connection and using the 'using' block .net still keeps a connection in sleep state to the server >< } - + db.Drop(); } private void ThrowIfDatabaseLock() { - var serverCopy = new DiscoveredServer(new SqlConnectionStringBuilder(DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Builder.ConnectionString)); + var serverCopy = + new DiscoveredServer(new SqlConnectionStringBuilder(DiscoveredServerICanCreateRandomDatabasesAndTablesOn + .Builder.ConnectionString)); serverCopy.ChangeDatabase("master"); using (var con = serverCopy.GetConnection()) { @@ -75,9 +79,7 @@ private void ThrowIfDatabaseLock() r.GetValues(vals); throw new Exception( $"Someone is locking {testDbName}:{Environment.NewLine}{string.Join(",", vals)}"); - } } - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/LinkerTests.cs b/Rdmp.Core.Tests/Curation/Integration/LinkerTests.cs index fe94a01571..3d2ad7e441 100644 --- a/Rdmp.Core.Tests/Curation/Integration/LinkerTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/LinkerTests.cs @@ -29,25 +29,21 @@ public void AddSameLinkTwice() //now you can add as many links as you want, it just skips them lazor.SetColumnInfo(velocityColumn); - Assert.AreEqual(lazor.ColumnInfo,velocityColumn); - + Assert.AreEqual(lazor.ColumnInfo, velocityColumn); } finally { lazor.DeleteInDatabase(); //delete child predator.DeleteInDatabase(); //delete parent - - velocityColumn.DeleteInDatabase();//delete child - highEnergyTable.DeleteInDatabase();//delete parent + + velocityColumn.DeleteInDatabase(); //delete child + highEnergyTable.DeleteInDatabase(); //delete parent } - - } [Test] public void AddLinkBetween_createNewLink_pass() { - ///////////////Create the things that we are going to create relationships between ///////////////// var predator = new Catalogue(CatalogueRepository, "Predator"); var lazor = new CatalogueItem(CatalogueRepository, predator, "QuadlzorVelocity"); @@ -66,13 +62,14 @@ public void AddLinkBetween_createNewLink_pass() //create a link between catalogue item lazor and velocity column lazor.SetColumnInfo(velocityColumn); Assert.IsTrue(lazor.ColumnInfo.ID == velocityColumn.ID); - + ////////////////cleanup ---- Delete everything that we created -------- ////////////// - velocityColumn.DeleteInDatabase(); //delete causes CASCADE: CatalogueItem no longer associated with ColumnInfo because ColumnInfo died - + velocityColumn + .DeleteInDatabase(); //delete causes CASCADE: CatalogueItem no longer associated with ColumnInfo because ColumnInfo died + lazor.RevertToDatabaseState(); - Assert.IsNull(lazor.ColumnInfo);//involves a database query so won't actually invalidate the below + Assert.IsNull(lazor.ColumnInfo); //involves a database query so won't actually invalidate the below predator.DeleteInDatabase(); diff --git a/Rdmp.Core.Tests/Curation/Integration/LoadMetadataTests.cs b/Rdmp.Core.Tests/Curation/Integration/LoadMetadataTests.cs index 579b9b2859..0170ad4a4c 100644 --- a/Rdmp.Core.Tests/Curation/Integration/LoadMetadataTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/LoadMetadataTests.cs @@ -24,7 +24,6 @@ public void CreateNewAndGetBackFromDatabase() try { - loadMetadata.LocationOfFlatFiles = TestContext.CurrentContext.TestDirectory; loadMetadata.SaveToDatabase(); @@ -49,13 +48,13 @@ public void Test_IgnoreTrigger_GetSet() loadMetadata.SaveToDatabase(); Assert.IsFalse(loadMetadata.IgnoreTrigger); loadMetadata.SaveToDatabase(); - + loadMetadata.IgnoreTrigger = true; Assert.IsTrue(loadMetadata.IgnoreTrigger); loadMetadata.RevertToDatabaseState(); Assert.IsFalse(loadMetadata.IgnoreTrigger); - + loadMetadata.IgnoreTrigger = true; Assert.IsTrue(loadMetadata.IgnoreTrigger); loadMetadata.SaveToDatabase(); @@ -78,16 +77,17 @@ public void TestPreExecutionChecker_TablesDontExist() var lmd = RdmpMockFactory.Mock_LoadMetadataLoadingTable(tbl); var checker = new PreExecutionChecker(lmd, new HICDatabaseConfiguration(db.Server)); - var ex = Assert.Throws(()=>checker.Check(new ThrowImmediatelyCheckNotifier())); + var ex = Assert.Throws(() => checker.Check(new ThrowImmediatelyCheckNotifier())); StringAssert.IsMatch("Table '.*Imaginary.*' does not exist", ex.Message); } + [Test] public void TestPreExecutionChecker_TableIsTableValuedFunction() { var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); var f = new TestableTableValuedFunction(); - f.Create(db,CatalogueRepository); + f.Create(db, CatalogueRepository); var tbl = f.TableInfoCreated.Discover(DataAccessContext.DataLoad); Assert.IsTrue(tbl.Exists()); diff --git a/Rdmp.Core.Tests/Curation/Integration/LoadProgressTest.cs b/Rdmp.Core.Tests/Curation/Integration/LoadProgressTest.cs index ec82e0dc53..90a810658f 100644 --- a/Rdmp.Core.Tests/Curation/Integration/LoadProgressTest.cs +++ b/Rdmp.Core.Tests/Curation/Integration/LoadProgressTest.cs @@ -42,10 +42,10 @@ public void LoadProgress_Equals() var progress = new LoadProgress(CatalogueRepository, loadMetadata); var progressCopy = CatalogueRepository.GetObjectByID(progress.ID); - + progressCopy.Name = "fish"; - progressCopy.OriginDate = new DateTime(2001,01,01); - + progressCopy.OriginDate = new DateTime(2001, 01, 01); + try { //values are different @@ -57,7 +57,6 @@ public void LoadProgress_Equals() //therefore objects are the same Assert.IsTrue(progressCopy.Equals(progress)); - } finally { diff --git a/Rdmp.Core.Tests/Curation/Integration/LoadProgressUnitTests.cs b/Rdmp.Core.Tests/Curation/Integration/LoadProgressUnitTests.cs index c1952914a6..5bb5b1c398 100644 --- a/Rdmp.Core.Tests/Curation/Integration/LoadProgressUnitTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/LoadProgressUnitTests.cs @@ -28,7 +28,7 @@ public void LoadProgress_Checks_BadDates() //Bad Origin Date lp.OriginDate = DateTime.Now.AddDays(1); - Assert.Throws(()=>lp.Check(new ThrowImmediatelyCheckNotifier())); + Assert.Throws(() => lp.Check(new ThrowImmediatelyCheckNotifier())); //Back to normal lp.RevertToDatabaseState(); @@ -36,15 +36,15 @@ public void LoadProgress_Checks_BadDates() //Bad ProgressDate lp.DataLoadProgress = DateTime.Now.AddDays(1); - Assert.Throws(()=>lp.Check(new ThrowImmediatelyCheckNotifier())); - + Assert.Throws(() => lp.Check(new ThrowImmediatelyCheckNotifier())); + //Back to normal lp.RevertToDatabaseState(); lp.Check(new ThrowImmediatelyCheckNotifier()); // valid progress (1 year) - lp.OriginDate = new DateTime(2001,1,1); - lp.DataLoadProgress = new DateTime(2002,1,1); + lp.OriginDate = new DateTime(2001, 1, 1); + lp.DataLoadProgress = new DateTime(2002, 1, 1); lp.Check(new ThrowImmediatelyCheckNotifier()); } @@ -53,32 +53,33 @@ public void LoadProgress_JobFactory_NoDates() { var lp = WhenIHaveA(); - - lp.OriginDate = new DateTime(2001,1,1); - + lp.OriginDate = new DateTime(2001, 1, 1); + // We are fully up-to-date lp.DataLoadProgress = DateTime.Now; - + lp.Check(new ThrowImmediatelyCheckNotifier()); - var stratFactory = new JobDateGenerationStrategyFactory(new AnyAvailableLoadProgressSelectionStrategy(lp.LoadMetadata)); - var strat = stratFactory.Create(lp,new ThrowImmediatelyDataLoadEventListener()); + var stratFactory = + new JobDateGenerationStrategyFactory(new AnyAvailableLoadProgressSelectionStrategy(lp.LoadMetadata)); + var strat = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener()); - var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.WorkDirectory),"LoadProgress_JobFactory_NoDates",true); + var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.WorkDirectory), + "LoadProgress_JobFactory_NoDates", true); var lmd = lp.LoadMetadata; lmd.LocationOfFlatFiles = dir.RootPath.FullName; - - foreach(var cata in lmd.GetAllCatalogues()) + + foreach (var cata in lmd.GetAllCatalogues()) { cata.LoggingDataTask = "ff"; cata.SaveToDatabase(); } - + lmd.SaveToDatabase(); - var jobFactory = new SingleScheduledJobFactory(lp,strat,999,lp.LoadMetadata,null); + var jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null); var job = jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null); Assert.IsNull(job); @@ -86,11 +87,11 @@ public void LoadProgress_JobFactory_NoDates() // We have 1 day to load (date is the last fully loaded date) lp.DataLoadProgress = DateTime.Now.AddDays(-2); lp.SaveToDatabase(); - - strat = stratFactory.Create(lp,new ThrowImmediatelyDataLoadEventListener()); - jobFactory = new SingleScheduledJobFactory(lp,strat,999,lp.LoadMetadata,null); - job = jobFactory.Create(RepositoryLocator,new ThrowImmediatelyDataLoadEventListener(),null); - Assert.AreEqual(1,((ScheduledDataLoadJob)job).DatesToRetrieve.Count); + strat = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener()); + jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null); + + job = jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null); + Assert.AreEqual(1, ((ScheduledDataLoadJob)job).DatesToRetrieve.Count); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/LookupTest.cs b/Rdmp.Core.Tests/Curation/Integration/LookupTest.cs index 4bdc626bcf..2bf4f24330 100644 --- a/Rdmp.Core.Tests/Curation/Integration/LookupTest.cs +++ b/Rdmp.Core.Tests/Curation/Integration/LookupTest.cs @@ -23,46 +23,45 @@ namespace Rdmp.Core.Tests.Curation.Integration; public class LookupTest : DatabaseTests { - [Test] public void Test_MultipleLookupReferences() { BlitzMainDataTables(); - var tiHeader = new TableInfo(CatalogueRepository,"Head"); - var tiHeader_Code = new ColumnInfo(CatalogueRepository,"code","",tiHeader); + var tiHeader = new TableInfo(CatalogueRepository, "Head"); + var tiHeader_Code = new ColumnInfo(CatalogueRepository, "code", "", tiHeader); + + var tiLookup = new TableInfo(CatalogueRepository, "z_HeadLookup"); + var tiLookup_Code = new ColumnInfo(CatalogueRepository, "code", "", tiLookup); + var tiLookup_Desc = new ColumnInfo(CatalogueRepository, "desc", "", tiLookup); - var tiLookup = new TableInfo(CatalogueRepository,"z_HeadLookup"); - var tiLookup_Code = new ColumnInfo(CatalogueRepository,"code","",tiLookup); - var tiLookup_Desc = new ColumnInfo(CatalogueRepository,"desc","",tiLookup); + var lookup = new Lookup(CatalogueRepository, tiLookup_Desc, tiHeader_Code, tiLookup_Code, + ExtractionJoinType.Left, null); - var lookup = new Lookup(CatalogueRepository,tiLookup_Desc,tiHeader_Code,tiLookup_Code,ExtractionJoinType.Left,null); + var cata1 = new Catalogue(CatalogueRepository, "Catalogue1"); + var cata2 = new Catalogue(CatalogueRepository, "Catalogue2"); - var cata1 = new Catalogue(CatalogueRepository,"Catalogue1"); - var cata2 = new Catalogue(CatalogueRepository,"Catalogue2"); + var cata1_code = new CatalogueItem(CatalogueRepository, cata1, "code"); + var cata1_desc = new CatalogueItem(CatalogueRepository, cata1, "desc"); + new ExtractionInformation(CatalogueRepository, cata1_code, tiHeader_Code, "[tbl]..[code]"); + new ExtractionInformation(CatalogueRepository, cata1_desc, tiLookup_Desc, "[lookup]..[desc]"); - var cata1_code = new CatalogueItem(CatalogueRepository,cata1,"code"); - var cata1_desc = new CatalogueItem(CatalogueRepository,cata1,"desc"); - new ExtractionInformation(CatalogueRepository,cata1_code,tiHeader_Code,"[tbl]..[code]"); - new ExtractionInformation(CatalogueRepository,cata1_desc,tiLookup_Desc,"[lookup]..[desc]"); + var cata2_code = new CatalogueItem(CatalogueRepository, cata2, "code"); + var cata2_desc = new CatalogueItem(CatalogueRepository, cata2, "desc"); + new ExtractionInformation(CatalogueRepository, cata2_code, tiHeader_Code, "[tbl]..[code]"); + new ExtractionInformation(CatalogueRepository, cata2_desc, tiLookup_Desc, "[lookup]..[desc]"); - var cata2_code = new CatalogueItem(CatalogueRepository,cata2,"code"); - var cata2_desc = new CatalogueItem(CatalogueRepository,cata2,"desc"); - new ExtractionInformation(CatalogueRepository,cata2_code,tiHeader_Code,"[tbl]..[code]"); - new ExtractionInformation(CatalogueRepository,cata2_desc,tiLookup_Desc,"[lookup]..[desc]"); - - new CatalogueChildProvider(CatalogueRepository,null, new ThrowImmediatelyCheckNotifier {ThrowOnWarning=true},null); - + new CatalogueChildProvider(CatalogueRepository, null, + new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }, null); } [Test] public void CreateLookup_linkWithSelfThrowsException() { - - TableInfo parent=null; - ColumnInfo child=null; - ColumnInfo child2=null; - ColumnInfo child3=null; + TableInfo parent = null; + ColumnInfo child = null; + ColumnInfo child2 = null; + ColumnInfo child3 = null; try { @@ -71,16 +70,43 @@ public void CreateLookup_linkWithSelfThrowsException() child2 = new ColumnInfo(CatalogueRepository, "unit_test_CreateLookup", "int", parent); child3 = new ColumnInfo(CatalogueRepository, "unit_test_CreateLookup", "int", parent); - Assert.Throws(()=>new Lookup(CatalogueRepository, child, child2, child3, ExtractionJoinType.Left, null)); + Assert.Throws(() => + new Lookup(CatalogueRepository, child, child2, child3, ExtractionJoinType.Left, null)); } - finally + finally { //cleanup - try{child.DeleteInDatabase();}catch (Exception){} - try{child2.DeleteInDatabase();}catch (Exception){} - try{child3.DeleteInDatabase();}catch (Exception){} - try{parent.DeleteInDatabase();}catch (Exception){} - + try + { + child.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + child2.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + child3.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + parent.DeleteInDatabase(); + } + catch (Exception) + { + } } } @@ -88,7 +114,7 @@ public void CreateLookup_linkWithSelfThrowsException() [TestCase(false)] public void CreateLookup_linkWithOtherTable(bool memoryRepo) { - var repo = memoryRepo? (ICatalogueRepository)new MemoryCatalogueRepository():CatalogueRepository; + var repo = memoryRepo ? (ICatalogueRepository)new MemoryCatalogueRepository() : CatalogueRepository; TableInfo parent = null; TableInfo parent2 = null; @@ -120,20 +146,51 @@ public void CreateLookup_linkWithOtherTable(bool memoryRepo) finally { //cleanup - try { child.DeleteInDatabase(); }catch (Exception) { } - try { child2.DeleteInDatabase(); }catch (Exception) { } - try { child3.DeleteInDatabase(); }catch (Exception) { } - try { parent.DeleteInDatabase(); }catch (Exception) { } - try { parent2.DeleteInDatabase(); }catch (Exception) { } - + try + { + child.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + child2.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + child3.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + parent.DeleteInDatabase(); + } + catch (Exception) + { + } + + try + { + parent2.DeleteInDatabase(); + } + catch (Exception) + { + } } } [Test] public void CompositeLookupTest() { - - TableInfo fkTable = null; TableInfo pkTable = null; ColumnInfo desc = null; @@ -144,11 +201,10 @@ public void CompositeLookupTest() ColumnInfo pk2 = null; Lookup lookup = null; - LookupCompositeJoinInfo composite=null; + LookupCompositeJoinInfo composite = null; try { - //table 1 - the dataset table, it has 2 foreign keys e.g. TestCode, Healthboard fkTable = new TableInfo(CatalogueRepository, "UnitTest_Biochemistry"); fk = new ColumnInfo(CatalogueRepository, "UnitTest_BCTestCode", "int", fkTable); @@ -174,7 +230,7 @@ public void CompositeLookupTest() composite = new LookupCompositeJoinInfo(CatalogueRepository, lookup, fk2, pk2); Assert.AreEqual(composite.OriginalLookup_ID, lookup.ID); - + Assert.AreEqual(composite.PrimaryKey.ID, pk2.ID); Assert.AreEqual(composite.PrimaryKey_ID, pk2.ID); Assert.AreEqual(composite.PrimaryKey.Name, pk2.Name); @@ -184,7 +240,7 @@ public void CompositeLookupTest() Assert.AreEqual(composite.ForeignKey.Name, fk2.Name); //get a fresh copy out of memory now that we have created the Lookup composite key, confirm the integrity of that relationship - Assert.AreEqual(lookup.GetSupplementalJoins().Count() , 1); + Assert.AreEqual(lookup.GetSupplementalJoins().Count(), 1); Assert.AreEqual(lookup.GetSupplementalJoins().Cast().First().ID, composite.ID); composite.DeleteInDatabase(); @@ -207,9 +263,9 @@ public void CompositeLookupTest() desc?.DeleteInDatabase(); fk?.DeleteInDatabase(); pk?.DeleteInDatabase(); - fk2?.DeleteInDatabase(); + fk2?.DeleteInDatabase(); pk2?.DeleteInDatabase(); - fkTable?.DeleteInDatabase(); + fkTable?.DeleteInDatabase(); pkTable?.DeleteInDatabase(); } } @@ -218,7 +274,6 @@ public void CompositeLookupTest() [Test] public void CompositeLookupTest_SQL() { - //this only works for MSSQL Servers if (CatalogueTableRepository.DiscoveredServer.DatabaseType != DatabaseType.MicrosoftSQLServer) Assert.Ignore("This test only targets Microsft SQL Servers"); @@ -237,7 +292,6 @@ public void CompositeLookupTest_SQL() try { - //table 1 - the dataset table, it has 2 foreign keys e.g. TestCode, Healthboard fkTable = new TableInfo(CatalogueRepository, "UnitTest_Biochemistry"); fk = new ColumnInfo(CatalogueRepository, "UnitTest_BCTestCode", "int", fkTable); @@ -252,14 +306,16 @@ public void CompositeLookupTest_SQL() var joinSQL = JoinHelper.GetJoinSQL(lookup); - Assert.AreEqual(joinSQL,"UnitTest_Biochemistry Left JOIN UnitTest_BiochemistryLookup ON UnitTest_BCTestCode = UnitTest_TestCode"); + Assert.AreEqual(joinSQL, + "UnitTest_Biochemistry Left JOIN UnitTest_BiochemistryLookup ON UnitTest_BCTestCode = UnitTest_TestCode"); //Create the composite lookup composite = new LookupCompositeJoinInfo(CatalogueRepository, lookup, fk2, pk2); var joinSQL_AfterAddingCompositeKey = JoinHelper.GetJoinSQL(lookup); - Assert.AreEqual(joinSQL_AfterAddingCompositeKey, "UnitTest_Biochemistry Left JOIN UnitTest_BiochemistryLookup ON UnitTest_BCTestCode = UnitTest_TestCode AND UnitTest_BCHealthBoard = UnitTest_Healthboard"); + Assert.AreEqual(joinSQL_AfterAddingCompositeKey, + "UnitTest_Biochemistry Left JOIN UnitTest_BiochemistryLookup ON UnitTest_BCTestCode = UnitTest_TestCode AND UnitTest_BCHealthBoard = UnitTest_Healthboard"); } catch (Exception ex) { @@ -287,7 +343,6 @@ public void CompositeLookupTest_SQL() [Test] public void LookupTest_CustomSql() { - //this only works for MSSQL Servers if (CatalogueTableRepository.DiscoveredServer.DatabaseType != DatabaseType.MicrosoftSQLServer) Assert.Ignore("This test only targets Microsft SQL Servers"); @@ -305,7 +360,6 @@ public void LookupTest_CustomSql() try { - //table 1 - the dataset table, it has 2 foreign keys e.g. TestCode, Healthboard fkTable = new TableInfo(CatalogueRepository, "UnitTest_Biochemistry"); fk = new ColumnInfo(CatalogueRepository, "One", "int", fkTable); @@ -384,12 +438,17 @@ public void TestLookupCommand(LookupTestCase testCase) var lookupCata = Import(lookuptbl); - var fkEi = mainCata.GetAllExtractionInformation(ExtractionCategory.Any).Single(n => n.GetRuntimeName() == "SendingLocation"); - var fk = mainCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "SendingLocation"); - var pk = lookupCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "LocationCode"); + var fkEi = mainCata.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(n => n.GetRuntimeName() == "SendingLocation"); + var fk = mainCata.GetTableInfoList(false).Single().ColumnInfos + .Single(n => n.GetRuntimeName() == "SendingLocation"); + var pk = lookupCata.GetTableInfoList(false).Single().ColumnInfos + .Single(n => n.GetRuntimeName() == "LocationCode"); - var descLine1 = lookupCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "Line1"); - var descLine2 = lookupCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "Line2"); + var descLine1 = lookupCata.GetTableInfoList(false).Single().ColumnInfos + .Single(n => n.GetRuntimeName() == "Line1"); + var descLine2 = lookupCata.GetTableInfoList(false).Single().ColumnInfos + .Single(n => n.GetRuntimeName() == "Line2"); ExecuteCommandCreateLookup cmd = null; @@ -398,14 +457,14 @@ public void TestLookupCommand(LookupTestCase testCase) switch (testCase) { case LookupTestCase.SingleKeySingleDescriptionNoVirtualColumn: - cmd = new ExecuteCommandCreateLookup(CatalogueRepository, fkEi, descLine1, pk,null, false); + cmd = new ExecuteCommandCreateLookup(CatalogueRepository, fkEi, descLine1, pk, null, false); cmd.Execute(); //sql should not have changed because we didn't create an new ExtractionInformation virtual column Assert.AreEqual(sqlBefore, GetSql(mainCata)); break; case LookupTestCase.SingleKeySingleDescription: - cmd = new ExecuteCommandCreateLookup(CatalogueRepository, fkEi, descLine1, pk,null, true); + cmd = new ExecuteCommandCreateLookup(CatalogueRepository, fkEi, descLine1, pk, null, true); cmd.Execute(); //should have the lookup join and the virtual column _Desc @@ -416,7 +475,7 @@ public void TestLookupCommand(LookupTestCase testCase) default: throw new ArgumentOutOfRangeException(nameof(testCase)); } - + foreach (var d in CatalogueRepository.GetAllObjects()) d.DeleteInDatabase(); foreach (var d in CatalogueRepository.GetAllObjects()) diff --git a/Rdmp.Core.Tests/Curation/Integration/MEFCheckerTests.cs b/Rdmp.Core.Tests/Curation/Integration/MEFCheckerTests.cs index 949da262d4..a05cb7eb90 100644 --- a/Rdmp.Core.Tests/Curation/Integration/MEFCheckerTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/MEFCheckerTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class MEFCheckerTests:UnitTests +public class MEFCheckerTests : UnitTests { [OneTimeSetUp] protected override void OneTimeSetUp() @@ -27,21 +27,24 @@ protected override void OneTimeSetUp() [Test] public void FindClass_WrongCase_FoundAnyway() { - Assert.AreEqual(typeof(Catalogue),Repository.MEF.GetType("catalogue")); + Assert.AreEqual(typeof(Catalogue), Repository.MEF.GetType("catalogue")); } [Test] public void FindClass_EmptyString() { var m = new MEFChecker(Repository.MEF, "", s => Assert.Fail()); - var ex = Assert.Throws(()=>m.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("MEFChecker was asked to check for the existence of an Export class but the _classToFind string was empty",ex.Message); + var ex = Assert.Throws(() => m.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual( + "MEFChecker was asked to check for the existence of an Export class but the _classToFind string was empty", + ex.Message); } [Test] public void FindClass_CorrectNamespace() { - var m = new MEFChecker(Repository.MEF, "Rdmp.Core.DataLoad.Modules.Attachers.AnySeparatorFileAttacher", s => Assert.Fail()); + var m = new MEFChecker(Repository.MEF, "Rdmp.Core.DataLoad.Modules.Attachers.AnySeparatorFileAttacher", + s => Assert.Fail()); m.Check(new ThrowImmediatelyCheckNotifier()); } @@ -58,20 +61,22 @@ public void FindClass_WrongNamespace() public void FindClass_NonExistant() { var m = new MEFChecker(Repository.MEF, "CatalogueLibrary.UncleSam", s => Assert.Fail()); - var ex = Assert.Throws(()=>m.Check(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains("Could not find MEF class called CatalogueLibrary.UncleSam in LoadModuleAssembly.GetAllTypes() and couldn't even find any with the same basic name",ex.Message); + var ex = Assert.Throws(() => m.Check(new ThrowImmediatelyCheckNotifier())); + StringAssert.Contains( + "Could not find MEF class called CatalogueLibrary.UncleSam in LoadModuleAssembly.GetAllTypes() and couldn't even find any with the same basic name", + ex.Message); } [Test] public void DllFileDuplication_Ignored() { // Setup 2 directories that will contain duplicate copies of the same dll - var badDir1 = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"Bad1")); + var badDir1 = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bad1")); var badDir2 = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bad2")); - + if (badDir1.Exists) badDir1.Delete(true); - + badDir1.Create(); if (badDir2.Exists) @@ -79,23 +84,19 @@ public void DllFileDuplication_Ignored() badDir2.Create(); - var dllToCopy = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"Rdmp.Core.dll")); + var dllToCopy = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Rdmp.Core.dll")); // copy the dll to both folders - File.Copy(dllToCopy.FullName, Path.Combine(badDir1.FullName,"Rdmp.Core.dll")); + File.Copy(dllToCopy.FullName, Path.Combine(badDir1.FullName, "Rdmp.Core.dll")); File.Copy(dllToCopy.FullName, Path.Combine(badDir2.FullName, "Rdmp.Core.dll")); var tomem = new ToMemoryCheckNotifier(); - var sdc = new SafeDirectoryCatalog(tomem, badDir1.FullName,badDir2.FullName); + var sdc = new SafeDirectoryCatalog(tomem, badDir1.FullName, badDir2.FullName); + + Assert.AreEqual(sdc.DuplicateDllsIgnored, 1); - Assert.AreEqual(sdc .DuplicateDllsIgnored, 1); - badDir1.Delete(true); badDir2.Delete(true); - } - - - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/MementoTests.cs b/Rdmp.Core.Tests/Curation/Integration/MementoTests.cs index 8f15ae29de..7998386c7d 100644 --- a/Rdmp.Core.Tests/Curation/Integration/MementoTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/MementoTests.cs @@ -16,12 +16,12 @@ public class MementoTests : DatabaseTests [Test] public void FakeMemento_Catalogue_Modify() { - var c = new Catalogue(CatalogueRepository,"Hey"); + var c = new Catalogue(CatalogueRepository, "Hey"); var g = Guid.NewGuid(); var commit = new Commit(CatalogueRepository, g, "Breaking stuff!"); - var mem = new Memento(CatalogueRepository,commit,MementoType.Modify,c,"yar","blerg"); + var mem = new Memento(CatalogueRepository, commit, MementoType.Modify, c, "yar", "blerg"); mem.SaveToDatabase(); mem.BeforeYaml = "haha"; @@ -36,7 +36,7 @@ public void FakeMemento_Catalogue_Modify() Assert.AreEqual("yar", mem2.BeforeYaml); Assert.AreEqual(MementoType.Modify, mem2.Type); Assert.AreEqual(Environment.UserName, mem2.Commit.Username); - Assert.AreEqual(c, mem2.GetReferencedObject(RepositoryLocator)); + Assert.AreEqual(c, mem2.GetReferencedObject(RepositoryLocator)); } @@ -51,7 +51,7 @@ public void FakeMemento_Catalogue_Add() var mem = new Memento(CatalogueRepository, commit, MementoType.Add, c, null, "blerg"); mem.SaveToDatabase(); - foreach(var check in new[] { mem, CatalogueRepository.GetObjectByID(mem.ID) }) + foreach (var check in new[] { mem, CatalogueRepository.GetObjectByID(mem.ID) }) { Assert.IsNull(check.BeforeYaml); Assert.AreEqual(g, new Guid(check.Commit.Transaction)); diff --git a/Rdmp.Core.Tests/Curation/Integration/MetadataLoggingConfigurationChecksTests.cs b/Rdmp.Core.Tests/Curation/Integration/MetadataLoggingConfigurationChecksTests.cs index d0ae1ca227..e5ecbfce88 100644 --- a/Rdmp.Core.Tests/Curation/Integration/MetadataLoggingConfigurationChecksTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/MetadataLoggingConfigurationChecksTests.cs @@ -25,13 +25,14 @@ public void Test_NoLoggingTask() var cata2 = WhenIHaveA(); cata2.LoadMetadata_ID = lmd.ID; - Assert.AreEqual(2,lmd.GetAllCatalogues().Count()); + Assert.AreEqual(2, lmd.GetAllCatalogues().Count()); var checks = new MetadataLoggingConfigurationChecks(lmd); var toMem = new ToMemoryCheckNotifier(); checks.Check(toMem); - AssertFailWithFix("Catalogues Mycata,Mycata do not have a logging task specified","Create a new Logging Task called 'MyLoad'?",toMem); + AssertFailWithFix("Catalogues Mycata,Mycata do not have a logging task specified", + "Create a new Logging Task called 'MyLoad'?", toMem); } [Test] @@ -41,16 +42,16 @@ public void Test_MismatchedLoggingTask() var cata1 = lmd.GetAllCatalogues().Single(); var cata2 = WhenIHaveA(); cata2.LoadMetadata_ID = lmd.ID; - + cata1.LoggingDataTask = "OMG YEAGH"; - Assert.AreEqual(2,lmd.GetAllCatalogues().Count()); + Assert.AreEqual(2, lmd.GetAllCatalogues().Count()); var checks = new MetadataLoggingConfigurationChecks(lmd); var toMem = new ToMemoryCheckNotifier(); checks.Check(toMem); - AssertFailWithFix("Some catalogues have NULL LoggingDataTasks","Set task to OMG YEAGH",toMem); + AssertFailWithFix("Some catalogues have NULL LoggingDataTasks", "Set task to OMG YEAGH", toMem); } [Test] @@ -60,20 +61,21 @@ public void Test_MissingLoggingServer() var cata1 = lmd.GetAllCatalogues().Single(); var cata2 = WhenIHaveA(); cata2.LoadMetadata_ID = lmd.ID; - + cata1.LoggingDataTask = "OMG YEAGH"; cata1.LiveLoggingServer_ID = 2; cata2.LoggingDataTask = "OMG YEAGH"; cata2.LiveLoggingServer_ID = null; - Assert.AreEqual(2,lmd.GetAllCatalogues().Count()); + Assert.AreEqual(2, lmd.GetAllCatalogues().Count()); var checks = new MetadataLoggingConfigurationChecks(lmd); var toMem = new ToMemoryCheckNotifier(); checks.Check(toMem); - AssertFailWithFix("Some catalogues have NULL LiveLoggingServer_ID","Set LiveLoggingServer_ID to 2",toMem); + AssertFailWithFix("Some catalogues have NULL LiveLoggingServer_ID", "Set LiveLoggingServer_ID to 2", toMem); } + [Test] public void Test_MissingLoggingServer_UseDefault() { @@ -86,28 +88,30 @@ public void Test_MissingLoggingServer_UseDefault() eds.SaveToDatabase(); cata2.LoadMetadata_ID = lmd.ID; - + cata1.LoggingDataTask = "OMG YEAGH"; cata1.LiveLoggingServer_ID = null; cata2.LoggingDataTask = "OMG YEAGH"; cata2.LiveLoggingServer_ID = null; var defaults = RepositoryLocator.CatalogueRepository; - defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID,eds); + defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, eds); - Assert.AreEqual(2,lmd.GetAllCatalogues().Count()); + Assert.AreEqual(2, lmd.GetAllCatalogues().Count()); var checks = new MetadataLoggingConfigurationChecks(lmd); var toMem = new ToMemoryCheckNotifier(); checks.Check(toMem); - AssertFailWithFix("Some catalogues have NULL LiveLoggingServer_ID",$"Set LiveLoggingServer_ID to 'My Logging Server' (the default)",toMem); + AssertFailWithFix("Some catalogues have NULL LiveLoggingServer_ID", + $"Set LiveLoggingServer_ID to 'My Logging Server' (the default)", toMem); } + private static void AssertFailWithFix(string expectedMessage, string expectedFix, ToMemoryCheckNotifier toMem) { var msg = toMem.Messages.First(m => m.Result == CheckResult.Fail); - Assert.AreEqual(expectedMessage,msg.Message,"Expected error message was wrong"); - Assert.AreEqual(expectedFix,msg.ProposedFix,"Expected proposed fix was wrong"); + Assert.AreEqual(expectedMessage, msg.Message, "Expected error message was wrong"); + Assert.AreEqual(expectedFix, msg.ProposedFix, "Expected proposed fix was wrong"); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/MySqlTriggerImplementerTests.cs b/Rdmp.Core.Tests/Curation/Integration/MySqlTriggerImplementerTests.cs index 03fef8bf2b..5163722df7 100644 --- a/Rdmp.Core.Tests/Curation/Integration/MySqlTriggerImplementerTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/MySqlTriggerImplementerTests.cs @@ -11,13 +11,13 @@ namespace Rdmp.Core.Tests.Curation.Integration; public class MySqlTriggerImplementerTests { - [TestCase("4.0",true)] - [TestCase("5.1",true)] - [TestCase("8.5",false)] - [TestCase("5.5.64-MariaDB",true)] - [TestCase("10.5.64-MariaDB",false)] + [TestCase("4.0", true)] + [TestCase("5.1", true)] + [TestCase("8.5", false)] + [TestCase("5.5.64-MariaDB", true)] + [TestCase("10.5.64-MariaDB", false)] public void TestOldNew(string versionString, bool expectToUseOldMethod) { - Assert.AreEqual(expectToUseOldMethod,MySqlTriggerImplementer.UseOldDateTimeDefaultMethod(versionString)); + Assert.AreEqual(expectToUseOldMethod, MySqlTriggerImplementer.UseOldDateTimeDefaultMethod(versionString)); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/BetweenCatalogueAndDataExportObscureDependencyFinderTests.cs b/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/BetweenCatalogueAndDataExportObscureDependencyFinderTests.cs index e38821a51f..95ed91b40c 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/BetweenCatalogueAndDataExportObscureDependencyFinderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/BetweenCatalogueAndDataExportObscureDependencyFinderTests.cs @@ -24,25 +24,27 @@ public void PreventDeletingCatalogueBecauseOfLinkedDatasetTest() var cata = new Catalogue(CatalogueRepository, "MyCata"); //catalogue exists in isolation so is deletable - Assert.DoesNotThrow(()=>obscura.ThrowIfDeleteDisallowed(cata)); + Assert.DoesNotThrow(() => obscura.ThrowIfDeleteDisallowed(cata)); //there is a new dataset which is linked to Catalogue - var dataset = new ExtractableDataSet(DataExportRepository,cata); + var dataset = new ExtractableDataSet(DataExportRepository, cata); //and suddenly we cannot delete the catalogue var ex = Assert.Throws(() => obscura.ThrowIfDeleteDisallowed(cata)); - Assert.IsTrue(ex.Message.Contains("Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); + Assert.IsTrue(ex.Message.Contains( + "Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); //also if we try to force through a delete it should behave in identical manner var ex2 = Assert.Throws(cata.DeleteInDatabase); - Assert.IsTrue(ex2.Message.Contains("Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); + Assert.IsTrue(ex2.Message.Contains( + "Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); //now we delete the linked dataset dataset.DeleteInDatabase(); //and because there is now no longer a dataset dependency on the catalogue we can delete it Assert.DoesNotThrow(() => obscura.ThrowIfDeleteDisallowed(cata)); - + //and the delete works too cata.DeleteInDatabase(); @@ -54,17 +56,18 @@ public void PreventDeletingCatalogueBecauseOfLinkedDatasetTest() [Test] public void AllowDeletingWhenDataExportManagerIsNotSet() { - var noDataExportManagerExists = new LinkedRepositoryProvider(CatalogueTableRepository.ConnectionString,null); + var noDataExportManagerExists = new LinkedRepositoryProvider(CatalogueTableRepository.ConnectionString, null); var obscura1 = new BetweenCatalogueAndDataExportObscureDependencyFinder(RepositoryLocator); var obscura2 = new BetweenCatalogueAndDataExportObscureDependencyFinder(noDataExportManagerExists); var cata = new Catalogue(CatalogueRepository, "MyCata"); - var dataset = new ExtractableDataSet(DataExportRepository,cata); + var dataset = new ExtractableDataSet(DataExportRepository, cata); //we cannot delete it because there is a dependency var ex = Assert.Throws(() => obscura1.ThrowIfDeleteDisallowed(cata)); - Assert.IsTrue(ex.Message.Contains("Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); + Assert.IsTrue(ex.Message.Contains( + "Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); //the second finder simulates when the repository locator doesn't have a record of the data export repository so it is unable to check it so it will let you delete it just fine Assert.DoesNotThrow(() => obscura2.ThrowIfDeleteDisallowed(cata)); @@ -72,6 +75,5 @@ public void AllowDeletingWhenDataExportManagerIsNotSet() //now delete them in the correct order dataset.DeleteInDatabase(); cata.DeleteInDatabase(); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ObjectSharingObscureDependencyFinderTests.cs b/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ObjectSharingObscureDependencyFinderTests.cs index a7d38a5810..483fe2d7d9 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ObjectSharingObscureDependencyFinderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ObjectSharingObscureDependencyFinderTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.ObscureDependencyTests; -public class ObjectSharingObscureDependencyFinderTests: DatabaseTests +public class ObjectSharingObscureDependencyFinderTests : DatabaseTests { private ShareManager _share; @@ -28,10 +28,10 @@ protected override void SetUp() [Test] public void TestPruning() { - var c = new Catalogue(CatalogueRepository,"Catapault"); + var c = new Catalogue(CatalogueRepository, "Catapault"); var ci = new CatalogueItem(CatalogueRepository, c, "string"); - var c2 = new Catalogue(CatalogueRepository,"Catapault (Import)"); + var c2 = new Catalogue(CatalogueRepository, "Catapault (Import)"); var ci2 = new CatalogueItem(CatalogueRepository, c2, "string (Import)"); Assert.AreEqual(CatalogueRepository.GetAllObjects().Length, 0); @@ -40,10 +40,12 @@ public void TestPruning() _share.GetImportAs(ec.SharingUID, c2); _share.GetImportAs(eci.SharingUID, ci2); - + Assert.AreEqual(2, CatalogueRepository.GetAllObjects().Length); Assert.AreEqual(2, CatalogueRepository.GetAllObjects().Length); - Assert.AreEqual(2, CatalogueRepository.GetAllObjects().Length);//successive calls shouldhn't generate extra entries since they are same obj + Assert.AreEqual(2, + CatalogueRepository.GetAllObjects() + .Length); //successive calls shouldhn't generate extra entries since they are same obj Assert.AreEqual(2, CatalogueRepository.GetAllObjects().Length); //cannot delete the shared object @@ -62,7 +64,7 @@ public void TestPruning() public void CannotDeleteSharedObjectTest() { //create a test catalogue - var c = new Catalogue(CatalogueRepository,"blah"); + var c = new Catalogue(CatalogueRepository, "blah"); Assert.IsFalse(_share.IsExportedObject(c)); diff --git a/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ValidationXMLObscureDependencyFinderTests.cs b/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ValidationXMLObscureDependencyFinderTests.cs index 041ddfbdf1..5adad9d0a1 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ValidationXMLObscureDependencyFinderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ObscureDependencyTests/ValidationXMLObscureDependencyFinderTests.cs @@ -21,20 +21,20 @@ namespace Rdmp.Core.Tests.Curation.Integration.ObscureDependencyTests; -public class ValidationXMLObscureDependencyFinderTests: DatabaseTests +public class ValidationXMLObscureDependencyFinderTests : DatabaseTests { [Test] public void TestGettingTheUsualSuspects() { - var finder = new ValidationXMLObscureDependencyFinder( RepositoryLocator); - + var finder = new ValidationXMLObscureDependencyFinder(RepositoryLocator); + //forces call to initialize finder.ThrowIfDeleteDisallowed(null); //this guy should be a usual suspect! Assert.IsTrue(finder.TheUsualSuspects.Any(s => s.Type == typeof(ReferentialIntegrityConstraint))); - var testXML = + var testXML = @" @@ -56,12 +56,12 @@ public void TestGettingTheUsualSuspects() { var pattern = string.Format(suspect.Pattern, 10029); - kaizerSoze = Regex.IsMatch(testXML, pattern,RegexOptions.Singleline); + kaizerSoze = Regex.IsMatch(testXML, pattern, RegexOptions.Singleline); if (kaizerSoze) break; } - + Assert.IsTrue(kaizerSoze); } @@ -84,14 +84,15 @@ public void DeleteAReferencedValidationXML() //we expect the validation XML to find the reference var finder = new ValidationXMLObscureDependencyFinder(RepositoryLocator); - + //and explode Assert.Throws(() => finder.ThrowIfDeleteDisallowed(l2ColumnInfo)); - - Assert.AreEqual(0,finder.CataloguesWithBrokenValidationXml.Count); + + Assert.AreEqual(0, finder.CataloguesWithBrokenValidationXml.Count); //now clear the validation XML - testData.catalogue.ValidatorXML = testData.catalogue.ValidatorXML.Insert(100,"I've got a lovely bunch of coconuts!"); + testData.catalogue.ValidatorXML = + testData.catalogue.ValidatorXML.Insert(100, "I've got a lovely bunch of coconuts!"); testData.catalogue.SaveToDatabase(); //column info should be deleteable but only because we got ourselves onto the forbidlist @@ -109,11 +110,11 @@ public void DeleteAReferencedValidationXML() testData.DeleteCatalogue(); } } - + [Test] public void Test_DeleteAColumnInfoThatIsReferenced() { - var startup = new Startup.Startup(new EnvironmentInfo(),RepositoryLocator); + var startup = new Startup.Startup(new EnvironmentInfo(), RepositoryLocator); startup.DoStartup(new IgnoreAllErrorsCheckNotifier()); var testData = SetupTestData(out var l2ColumnInfo); @@ -121,7 +122,7 @@ public void Test_DeleteAColumnInfoThatIsReferenced() try { //should fail because of the validation constraint being dependent on it - Assert.Throws(()=>l2ColumnInfo.DeleteInDatabase()); + Assert.Throws(() => l2ColumnInfo.DeleteInDatabase()); } finally { @@ -135,19 +136,19 @@ public void Test_DeleteAColumnInfoThatIsReferenced() [Test] public void TestRunningSetupMultipleTimes() { - - var startup = new Startup.Startup(new EnvironmentInfo(),RepositoryLocator); + var startup = new Startup.Startup(new EnvironmentInfo(), RepositoryLocator); try { startup.DoStartup(new IgnoreAllErrorsCheckNotifier()); } catch (InvalidPatchException patchException) { - throw new Exception($"Problem in patch {patchException.ScriptName}",patchException); + throw new Exception($"Problem in patch {patchException.ScriptName}", patchException); } + //there should be all the obscure dependencies we need done with only the first call to this function var numberAfterFirstRun = - ((CatalogueObscureDependencyFinder) CatalogueRepository.ObscureDependencyFinder) + ((CatalogueObscureDependencyFinder)CatalogueRepository.ObscureDependencyFinder) .OtherDependencyFinders.Count; startup.DoStartup(new IgnoreAllErrorsCheckNotifier()); @@ -156,10 +157,8 @@ public void TestRunningSetupMultipleTimes() //there should not be any replication! and doubling SetUp! Assert.AreEqual(numberAfterFirstRun, - ((CatalogueObscureDependencyFinder) CatalogueRepository.ObscureDependencyFinder) + ((CatalogueObscureDependencyFinder)CatalogueRepository.ObscureDependencyFinder) .OtherDependencyFinders.Count); - - } #region setup test data with some validation rule @@ -196,5 +195,6 @@ private BulkTestsData SetupTestData(out ColumnInfo l2ColumnInfo) return testData; } + #endregion } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/PasswordEncryptionKeyLocationTests.cs b/Rdmp.Core.Tests/Curation/Integration/PasswordEncryptionKeyLocationTests.cs index 0f7a08ea73..d1b1f1559b 100644 --- a/Rdmp.Core.Tests/Curation/Integration/PasswordEncryptionKeyLocationTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/PasswordEncryptionKeyLocationTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class PasswordEncryptionKeyLocationTests:DatabaseTests +public class PasswordEncryptionKeyLocationTests : DatabaseTests { [SetUp] protected override void SetUp() @@ -23,7 +23,7 @@ protected override void SetUp() var keyLocation = new PasswordEncryptionKeyLocation(CatalogueRepository); - if(keyLocation.GetKeyFileLocation() != null) + if (keyLocation.GetKeyFileLocation() != null) Assert.Inconclusive(); } @@ -37,14 +37,13 @@ public void NoKeyFileToStartWith() var e = Assert.Throws(keyLocation.DeleteKey); Assert.AreEqual("Cannot delete key because there is no key file configured", e.Message); - } [Test] public void CreateKeyFile() { var keyLocation = new PasswordEncryptionKeyLocation(CatalogueRepository); - var file = keyLocation.CreateNewKeyFile(Path.Combine(TestContext.CurrentContext.TestDirectory,"my.key")); + var file = keyLocation.CreateNewKeyFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "my.key")); Console.WriteLine($"Key file location is:{file.FullName}"); Console.WriteLine($"Text put into file is:{Environment.NewLine}{File.ReadAllText(file.FullName)}"); @@ -69,8 +68,8 @@ public void Encrypt() //should do pass through encryption encrypter.Value = value; - Assert.AreNotEqual(value,encrypter.Value); - Assert.AreEqual(value,encrypter.GetDecryptedValue()); + Assert.AreNotEqual(value, encrypter.Value); + Assert.AreEqual(value, encrypter.GetDecryptedValue()); Console.WriteLine($"Encrypted (stock) is:{encrypter.Value}"); Console.WriteLine($"Decrypted (stock) is:{encrypter.GetDecryptedValue()}"); @@ -82,8 +81,9 @@ public void Encrypt() CatalogueRepository.EncryptionManager.ClearAllInjections(); var s = CatalogueRepository.EncryptionManager.GetEncrypter(); - var exception = Assert.Throws(()=>s.Decrypt(encrypter.Value)); - Assert.IsTrue(exception.Message.StartsWith("Could not decrypt an encrypted string, possibly you are trying to decrypt it after having changed the PrivateKey ")); + var exception = Assert.Throws(() => s.Decrypt(encrypter.Value)); + Assert.IsTrue(exception.Message.StartsWith( + "Could not decrypt an encrypted string, possibly you are trying to decrypt it after having changed the PrivateKey ")); var encrypted = s.Encrypt(value); Console.WriteLine($"Encrypted (with key) is:{encrypted}"); @@ -93,5 +93,4 @@ public void Encrypt() keyLocation.DeleteKey(); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/PipelineTests.cs b/Rdmp.Core.Tests/Curation/Integration/PipelineTests.cs index 74e5a1fb1d..a2904766d2 100644 --- a/Rdmp.Core.Tests/Curation/Integration/PipelineTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/PipelineTests.cs @@ -25,15 +25,16 @@ public void SetupAndSaveAPipeline() try { - Assert.AreEqual(pipeline.Name,"Bob"); + Assert.AreEqual(pipeline.Name, "Bob"); + + var pipelineComponent = + new PipelineComponent(CatalogueRepository, pipeline, typeof(BasicAnonymisationEngine), 0); - var pipelineComponent = new PipelineComponent(CatalogueRepository, pipeline, typeof (BasicAnonymisationEngine), 0); - try { - Assert.AreEqual(pipelineComponent.Class,typeof(BasicAnonymisationEngine).FullName); + Assert.AreEqual(pipelineComponent.Class, typeof(BasicAnonymisationEngine).FullName); - var argument1 = (PipelineComponentArgument) pipelineComponent.CreateNewArgument(); + var argument1 = (PipelineComponentArgument)pipelineComponent.CreateNewArgument(); var argument2 = new PipelineComponentArgument(CatalogueRepository, pipelineComponent); try @@ -42,19 +43,19 @@ public void SetupAndSaveAPipeline() argument1.SetValue("bob"); argument1.SaveToDatabase(); - var dt = DateTime.Now ; - dt = new DateTime(dt.Ticks - dt.Ticks % TimeSpan.TicksPerSecond,dt.Kind);//get rid of the milliseconds + var dt = DateTime.Now; + dt = new DateTime(dt.Ticks - dt.Ticks % TimeSpan.TicksPerSecond, + dt.Kind); //get rid of the milliseconds argument2.SetType(typeof(DateTime)); argument2.SetValue(dt); argument2.SaveToDatabase(); var argument2Copy = CatalogueRepository.GetObjectByID(argument2.ID); - Assert.AreEqual(dt,argument2Copy.GetValueAsSystemType()); + Assert.AreEqual(dt, argument2Copy.GetValueAsSystemType()); } - finally + finally { - argument1.DeleteInDatabase(); argument2.DeleteInDatabase(); } @@ -63,9 +64,8 @@ public void SetupAndSaveAPipeline() { pipelineComponent.DeleteInDatabase(); } - } - finally + finally { pipeline.DeleteInDatabase(); } @@ -84,15 +84,15 @@ public void ClonePipelineNaming() var clone2 = p.Clone(); var clone3 = p.Clone(); - Assert.AreEqual("My Pipe (Clone)",clone1.Name); - Assert.AreEqual("My Pipe (Clone2)",clone2.Name); - Assert.AreEqual("My Pipe (Clone3)",clone3.Name); + Assert.AreEqual("My Pipe (Clone)", clone1.Name); + Assert.AreEqual("My Pipe (Clone2)", clone2.Name); + Assert.AreEqual("My Pipe (Clone3)", clone3.Name); var cloneOfClone1 = clone3.Clone(); var cloneOfClone2 = clone3.Clone(); - - Assert.AreEqual("My Pipe (Clone3) (Clone)",cloneOfClone1.Name); - Assert.AreEqual("My Pipe (Clone3) (Clone2)",cloneOfClone2.Name); + + Assert.AreEqual("My Pipe (Clone3) (Clone)", cloneOfClone1.Name); + Assert.AreEqual("My Pipe (Clone3) (Clone2)", cloneOfClone2.Name); } @@ -106,18 +106,18 @@ public void CloneAPipeline() { var p = new Pipeline(CatalogueRepository); - var source = new PipelineComponent(CatalogueRepository, p, typeof (DelimitedFlatFileAttacher), 0); + var source = new PipelineComponent(CatalogueRepository, p, typeof(DelimitedFlatFileAttacher), 0); source.CreateArgumentsForClassIfNotExists(); - var middle = new PipelineComponent(CatalogueRepository, p, typeof (ColumnRenamer), 1); + var middle = new PipelineComponent(CatalogueRepository, p, typeof(ColumnRenamer), 1); middle.CreateArgumentsForClassIfNotExists(); var middle2 = new PipelineComponent(CatalogueRepository, p, typeof(ColumnForbidder), 1); middle2.CreateArgumentsForClassIfNotExists(); - var destination = new PipelineComponent(CatalogueRepository, p, typeof (DataTableUploadDestination), 2); + var destination = new PipelineComponent(CatalogueRepository, p, typeof(DataTableUploadDestination), 2); destination.CreateArgumentsForClassIfNotExists(); - + p.SourcePipelineComponent_ID = source.ID; p.DestinationPipelineComponent_ID = destination.ID; p.SaveToDatabase(); @@ -125,7 +125,8 @@ public void CloneAPipeline() var componentsBefore = RepositoryLocator.CatalogueRepository.GetAllObjects().Length; var argumentsBefore = RepositoryLocator.CatalogueRepository.GetAllObjects().Length; - var arg = p.PipelineComponents.Single(c => c.Class == typeof (ColumnRenamer).ToString()).PipelineComponentArguments.Single(a => a.Name == "ColumnNameToFind"); + var arg = p.PipelineComponents.Single(c => c.Class == typeof(ColumnRenamer).ToString()) + .PipelineComponentArguments.Single(a => a.Name == "ColumnNameToFind"); arg.SetValue("MyMostCoolestColumnEver"); arg.SaveToDatabase(); @@ -133,25 +134,29 @@ public void CloneAPipeline() var p2 = p.Clone(); Assert.AreNotEqual(p2, p); - Assert.AreNotEqual(p2.ID,p.ID); + Assert.AreNotEqual(p2.ID, p.ID); Assert.AreEqual(p2.Name, $"{p.Name} (Clone)"); - Assert.AreEqual(componentsBefore *2, RepositoryLocator.CatalogueRepository.GetAllObjects().Length); - Assert.AreEqual(argumentsBefore *2, RepositoryLocator.CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(componentsBefore * 2, + RepositoryLocator.CatalogueRepository.GetAllObjects().Length); + Assert.AreEqual(argumentsBefore * 2, + RepositoryLocator.CatalogueRepository.GetAllObjects().Length); //p the original should have a pipeline component that has the value we set earlier Assert.AreEqual( - p.PipelineComponents.Single(c => c.Class == typeof(ColumnRenamer).ToString()).PipelineComponentArguments.Single(a => a.Name == "ColumnNameToFind").Value, + p.PipelineComponents.Single(c => c.Class == typeof(ColumnRenamer).ToString()).PipelineComponentArguments + .Single(a => a.Name == "ColumnNameToFind").Value, "MyMostCoolestColumnEver" ); - + //p2 the clone should have a pipeline component too since it's a clone Assert.AreEqual( - p2.PipelineComponents.Single(c => c.Class == typeof(ColumnRenamer).ToString()).PipelineComponentArguments.Single(a => a.Name == "ColumnNameToFind").Value, + p2.PipelineComponents.Single(c => c.Class == typeof(ColumnRenamer).ToString()).PipelineComponentArguments + .Single(a => a.Name == "ColumnNameToFind").Value, "MyMostCoolestColumnEver" ); - + //both should have source and destination components Assert.NotNull(p2.DestinationPipelineComponent_ID); Assert.NotNull(p2.SourcePipelineComponent_ID); @@ -170,33 +175,32 @@ public void CloneAPipeline_BrokenPipes() var p = new Pipeline(CatalogueRepository); //Setup a pipeline with a source component type that doesn't exist - var source = new PipelineComponent(CatalogueRepository, p, typeof (DelimitedFlatFileAttacher), 0) - { - Class = "Trollololol" - }; + var source = new PipelineComponent(CatalogueRepository, p, typeof(DelimitedFlatFileAttacher), 0) + { + Class = "Trollololol" + }; source.SaveToDatabase(); var arg = source.CreateNewArgument(); //Also give the source component a non existent argument - arg.GetType().GetProperty("Type").SetValue(arg,"fffffzololz"); + arg.GetType().GetProperty("Type").SetValue(arg, "fffffzololz"); arg.SaveToDatabase(); p.SourcePipelineComponent_ID = source.ID; p.SaveToDatabase(); - - Assert.AreEqual("fffffzololz",p.Source.GetAllArguments().Single().Type); + + Assert.AreEqual("fffffzololz", p.Source.GetAllArguments().Single().Type); var clone = p.Clone(); - Assert.AreEqual(clone.Source.Class,p.Source.Class); - Assert.AreEqual("fffffzololz",clone.Source.GetAllArguments().Single().Type); + Assert.AreEqual(clone.Source.Class, p.Source.Class); + Assert.AreEqual("fffffzololz", clone.Source.GetAllArguments().Single().Type); p.DeleteInDatabase(); clone.DeleteInDatabase(); - - } + [Test] public void DeletePipelineSource_ClearsReference() { diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateBuilderTestsBase.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateBuilderTestsBase.cs index 2242c444a3..bdb6dab974 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateBuilderTestsBase.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateBuilderTestsBase.cs @@ -51,5 +51,4 @@ protected override void SetUp() _dimension2.Order = 2; _dimension2.SaveToDatabase(); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateDataBasedTests.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateDataBasedTests.cs index 747257b8ea..fdb0024482 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateDataBasedTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/AggregateDataBasedTests.cs @@ -26,7 +26,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.QueryBuildingTests.AggregateBuilderTests; -public class AggregateDataBasedTests:DatabaseTests +public class AggregateDataBasedTests : DatabaseTests { private static DataTable GetTestDataTable() { @@ -47,14 +47,15 @@ private static DataTable GetTestDataTable() dt.Rows.Add("2002-03-02", "T", "17"); dt.Rows.Add("2003-01-01", "T", "19"); dt.Rows.Add("2003-04-02", "T", "23"); - + dt.Rows.Add("2002-01-01", "F", "29"); dt.Rows.Add("2002-01-01", "F", "31"); dt.Rows.Add("2001-01-01", "E&, %a' mp;E", "37"); dt.Rows.Add("2002-01-01", "E&, %a' mp;E", "41"); - dt.Rows.Add("2005-01-01", "E&, %a' mp;E", "59"); //note there are no records in 2004 it is important for axis tests (axis involves you having to build a calendar table) + dt.Rows.Add("2005-01-01", "E&, %a' mp;E", + "59"); //note there are no records in 2004 it is important for axis tests (axis involves you having to build a calendar table) dt.Rows.Add(null, "G", "47"); dt.Rows.Add("2001-01-01", "G", "53"); @@ -64,7 +65,8 @@ private static DataTable GetTestDataTable() #region Helper methods - private DiscoveredTable UploadTestDataAsTableToServer(DatabaseType type, out ICatalogue catalogue, out ExtractionInformation[] extractionInformations, out ITableInfo tableinfo) + private DiscoveredTable UploadTestDataAsTableToServer(DatabaseType type, out ICatalogue catalogue, + out ExtractionInformation[] extractionInformations, out ITableInfo tableinfo) { var listener = new ThrowImmediatelyDataLoadEventListener(); @@ -80,10 +82,11 @@ private DiscoveredTable UploadTestDataAsTableToServer(DatabaseType type, out ICa Assert.IsTrue(tbl.Exists()); - catalogue = Import(tbl,out tableinfo,out _,out _, out extractionInformations); + catalogue = Import(tbl, out tableinfo, out _, out _, out extractionInformations); return tbl; } + private static void Destroy(DiscoveredTable tbl, params IDeleteable[] deletablesInOrderOfDeletion) { tbl.Drop(); @@ -114,13 +117,14 @@ private static void AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(Aggregate var repo = new MemoryCatalogueRepository(); - var ORContainer = new SpontaneouslyInventedFilterContainer(repo,null, null, FilterContainerOperation.OR); + var ORContainer = new SpontaneouslyInventedFilterContainer(repo, null, null, FilterContainerOperation.OR); var constParam = new ConstantParameter(declaration, "'T'", "T Category Only", syntaxHelper); //this is deliberately duplication, it tests that the parameter compiles as well as that any dynamic sql doesn't get thrown by quotes - var filter1 = new SpontaneouslyInventedFilter(repo,ORContainer, "(Category=@category OR Category = 'T')", "Category Is @category", + var filter1 = new SpontaneouslyInventedFilter(repo, ORContainer, "(Category=@category OR Category = 'T')", + "Category Is @category", "ensures the records belong to the category @category", new ISqlParameter[] { constParam }); - var filter2 = new SpontaneouslyInventedFilter(repo,ORContainer, "NumberInTrouble > 42", + var filter2 = new SpontaneouslyInventedFilter(repo, ORContainer, "NumberInTrouble > 42", "number in trouble greater than 42", "See above", null); ORContainer.AddChild(filter1); @@ -129,7 +133,8 @@ private static void AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(Aggregate builder.RootFilterContainer = ORContainer; } - private AggregateConfiguration SetupAggregateWithAxis(DatabaseType type, ExtractionInformation[] extractionInformations, + private AggregateConfiguration SetupAggregateWithAxis(DatabaseType type, + ExtractionInformation[] extractionInformations, ICatalogue catalogue, out AggregateDimension axisDimension) { var dateDimension = @@ -147,7 +152,8 @@ private AggregateConfiguration SetupAggregateWithAxis(DatabaseType type, Extract return configuration; } - private AggregateConfiguration SetupAggregateWithPivot(DatabaseType type, ExtractionInformation[] extractionInformations, + private AggregateConfiguration SetupAggregateWithPivot(DatabaseType type, + ExtractionInformation[] extractionInformations, ICatalogue catalogue, out AggregateDimension axisDimension, out AggregateDimension pivotDimension) { var axisCol = @@ -179,9 +185,10 @@ private AggregateConfiguration SetupAggregateWithPivot(DatabaseType type, Extrac //[TestCase(DatabaseType.Oracle)]// doesn't quite work yet :) needs full implementation of database abstraction layer for Oracle to work public void Count_CorrectNumberOfRowsCalculated(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type,out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); - var builder = new AggregateBuilder(null, "count(*)", null,new []{tableInfo}); + var builder = new AggregateBuilder(null, "count(*)", null, new[] { tableInfo }); var resultTable = GetResultForBuilder(builder, tbl); try { @@ -199,11 +206,13 @@ public void Count_CorrectNumberOfRowsCalculated(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_CategoryWithCount_Correct(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate - var categoryDimension = extractionInformations.Single(e => e.GetRuntimeName().Equals("Category", StringComparison.CurrentCultureIgnoreCase)); - var configuration = new AggregateConfiguration(CatalogueRepository,catalogue,"GroupBy_Category"); + var categoryDimension = extractionInformations.Single(e => + e.GetRuntimeName().Equals("Category", StringComparison.CurrentCultureIgnoreCase)); + var configuration = new AggregateConfiguration(CatalogueRepository, catalogue, "GroupBy_Category"); var dimension = new AggregateDimension(CatalogueRepository, categoryDimension, configuration); try @@ -229,10 +238,12 @@ public void GroupBy_CategoryWithCount_Correct(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_CategoryWithSum_Correct(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate - var categoryDimension = extractionInformations.Single(e => e.GetRuntimeName().Equals("Category", StringComparison.CurrentCultureIgnoreCase)); + var categoryDimension = extractionInformations.Single(e => + e.GetRuntimeName().Equals("Category", StringComparison.CurrentCultureIgnoreCase)); var configuration = new AggregateConfiguration(CatalogueRepository, catalogue, "GroupBy_Category"); var dimension = new AggregateDimension(CatalogueRepository, categoryDimension, configuration); @@ -249,7 +260,7 @@ public void GroupBy_CategoryWithSum_Correct(DatabaseType type) VerifyRowExist(resultTable, "F", 60); VerifyRowExist(resultTable, "E&, %a' mp;E", 137); VerifyRowExist(resultTable, "G", 100); - Assert.AreEqual(4,resultTable.Rows.Count); + Assert.AreEqual(4, resultTable.Rows.Count); } finally { @@ -262,10 +273,12 @@ public void GroupBy_CategoryWithSum_Correct(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_CategoryWithSum_WHEREStatement(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate - var categoryDimension = extractionInformations.Single(e => e.GetRuntimeName().Equals("Category", StringComparison.CurrentCultureIgnoreCase)); + var categoryDimension = extractionInformations.Single(e => + e.GetRuntimeName().Equals("Category", StringComparison.CurrentCultureIgnoreCase)); var configuration = new AggregateConfiguration(CatalogueRepository, catalogue, "GroupBy_Category"); var dimension = new AggregateDimension(CatalogueRepository, categoryDimension, configuration); @@ -278,7 +291,7 @@ public void GroupBy_CategoryWithSum_WHEREStatement(DatabaseType type) var builder = new AggregateBuilder(null, configuration.CountSQL, configuration); builder.AddColumn(dimension); - AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder,type); + AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder, type); var resultTable = GetResultForBuilder(builder, tbl); @@ -294,12 +307,14 @@ public void GroupBy_CategoryWithSum_WHEREStatement(DatabaseType type) Destroy(tbl, configuration, catalogue, tableInfo); } } + [Test] [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] public void GroupBy_AxisWithSum_Correct(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate with axis var configuration = SetupAggregateWithAxis(type, extractionInformations, catalogue, out var dimension); @@ -316,9 +331,10 @@ public void GroupBy_AxisWithSum_Correct(DatabaseType type) var resultTable = GetResultForBuilder(builder, tbl); //axis is ordered ascending by date starting in 2000 so that row should come first - Assert.IsTrue(AreBasicallyEquals( "2000",resultTable.Rows[0][0])); + Assert.IsTrue(AreBasicallyEquals("2000", resultTable.Rows[0][0])); - VerifyRowExist(resultTable, "2000", null); //because it is a SUM the ANSI return should be null not 0 since it is a sum of no records + VerifyRowExist(resultTable, "2000", + null); //because it is a SUM the ANSI return should be null not 0 since it is a sum of no records VerifyRowExist(resultTable, "2001", 157); VerifyRowExist(resultTable, "2002", 131); VerifyRowExist(resultTable, "2003", 42); @@ -331,14 +347,15 @@ public void GroupBy_AxisWithSum_Correct(DatabaseType type) { Destroy(tbl, configuration, catalogue, tableInfo); } - } + [Test] [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] public void GroupBy_AxisWithCount_HAVING(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate with axis var configuration = SetupAggregateWithAxis(type, extractionInformations, catalogue, out var dimension); @@ -358,7 +375,8 @@ public void GroupBy_AxisWithCount_HAVING(DatabaseType type) //axis is ordered ascending by date starting in 2000 so that row should come first Assert.IsTrue(AreBasicallyEquals("2000", resultTable.Rows[0][0])); - VerifyRowExist(resultTable, "2000", null); //records only showing where there are more than 3 records (HAVING refers to the year since there's no pivot) + VerifyRowExist(resultTable, "2000", + null); //records only showing where there are more than 3 records (HAVING refers to the year since there's no pivot) VerifyRowExist(resultTable, "2001", 5); VerifyRowExist(resultTable, "2002", 5); VerifyRowExist(resultTable, "2003", null); @@ -371,7 +389,6 @@ public void GroupBy_AxisWithCount_HAVING(DatabaseType type) { Destroy(tbl, configuration, catalogue, tableInfo); } - } @@ -380,7 +397,8 @@ public void GroupBy_AxisWithCount_HAVING(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_AxisWithCount_WHERECorrect(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate with axis var configuration = SetupAggregateWithAxis(type, extractionInformations, catalogue, out var dimension); @@ -393,7 +411,7 @@ public void GroupBy_AxisWithCount_WHERECorrect(DatabaseType type) var builder = new AggregateBuilder(null, configuration.CountSQL, configuration); builder.AddColumn(dimension); - AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder,type); + AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder, type); var resultTable = GetResultForBuilder(builder, tbl); @@ -416,10 +434,12 @@ public void GroupBy_AxisWithCount_WHERECorrect(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_PivotWithSum_Correct(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate pivot (and axis) - var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, out var pivotDimension); + var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, + out var pivotDimension); configuration.CountSQL = "sum(NumberInTrouble)"; configuration.PivotOnDimensionID = pivotDimension.ID; //pivot on the Category @@ -438,18 +458,19 @@ public void GroupBy_PivotWithSum_Correct(DatabaseType type) //axis is ordered ascending by date starting in 2000 so that row should come first Assert.IsTrue(AreBasicallyEquals("2000", resultTable.Rows[0][0])); - Assert.AreEqual("T",resultTable.Columns[1].ColumnName); + Assert.AreEqual("T", resultTable.Columns[1].ColumnName); Assert.AreEqual("E&, %a' mp;E", resultTable.Columns[2].ColumnName); Assert.AreEqual("F", resultTable.Columns[3].ColumnName); Assert.AreEqual("G", resultTable.Columns[4].ColumnName); //T,E,F,G - VerifyRowExist(resultTable, "2000", null, null, null, null);//no records in 2000 but it is important it appears still because that is what the axis says + VerifyRowExist(resultTable, "2000", null, null, null, + null); //no records in 2000 but it is important it appears still because that is what the axis says VerifyRowExist(resultTable, "2001", 67, 37, null, 53); VerifyRowExist(resultTable, "2002", 30, 41, 60, null); VerifyRowExist(resultTable, "2003", 42, null, null, null); VerifyRowExist(resultTable, "2004", null, null, null, null); - VerifyRowExist(resultTable, "2005", null, 59,null , null); + VerifyRowExist(resultTable, "2005", null, 59, null, null); VerifyRowExist(resultTable, "2006", null, null, null, null); VerifyRowExist(resultTable, "2007", null, null, null, null); } @@ -457,7 +478,6 @@ public void GroupBy_PivotWithSum_Correct(DatabaseType type) { Destroy(tbl, configuration, catalogue, tableInfo); } - } @@ -466,10 +486,12 @@ public void GroupBy_PivotWithSum_Correct(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_PivotWithSum_WHEREStatement(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate pivot (and axis) - var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, out var pivotDimension); + var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, + out var pivotDimension); configuration.CountSQL = "sum(NumberInTrouble)"; configuration.PivotOnDimensionID = pivotDimension.ID; //pivot on the Category @@ -483,7 +505,7 @@ public void GroupBy_PivotWithSum_WHEREStatement(DatabaseType type) builder.AddColumn(pivotDimension); builder.SetPivotToDimensionID(pivotDimension); - AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder,type); + AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder, type); var resultTable = GetResultForBuilder(builder, tbl); @@ -495,14 +517,15 @@ public void GroupBy_PivotWithSum_WHEREStatement(DatabaseType type) Assert.AreEqual("G", resultTable.Columns[3].ColumnName); //T,E,G - F does not appear because WHERE throws it out (both counts are below 42) - VerifyRowExist(resultTable, "2000", null, null, null); //no records in 2000 but it is important it appears still because that is what the axis says + VerifyRowExist(resultTable, "2000", null, null, + null); //no records in 2000 but it is important it appears still because that is what the axis says VerifyRowExist(resultTable, "2001", 67, null, 53); VerifyRowExist(resultTable, "2002", 30, null, null); VerifyRowExist(resultTable, "2003", 42, null, null); VerifyRowExist(resultTable, "2004", null, null, null); - VerifyRowExist(resultTable, "2005", null, 59, null); + VerifyRowExist(resultTable, "2005", null, 59, null); VerifyRowExist(resultTable, "2006", null, null, null); - VerifyRowExist(resultTable, "2007", null, null, null); + VerifyRowExist(resultTable, "2007", null, null, null); } finally { @@ -521,10 +544,12 @@ public void GroupBy_PivotWithSum_WHEREStatement(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_PivotWithSum_Top2BasedonCountColumnDesc(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate pivot (and axis) - var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, out var pivotDimension); + var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, + out var pivotDimension); configuration.CountSQL = "sum(NumberInTrouble)"; configuration.PivotOnDimensionID = pivotDimension.ID; //pivot on the Category @@ -554,7 +579,8 @@ public void GroupBy_PivotWithSum_Top2BasedonCountColumnDesc(DatabaseType type) Assert.AreEqual("E&, %a' mp;E", resultTable.Columns[2].ColumnName); //T,E,G - F does not appear because WHERE throws it out (both counts are below 42) - VerifyRowExist(resultTable, "2000", null, null); //no records in 2000 but it is important it appears still because that is what the axis says + VerifyRowExist(resultTable, "2000", null, + null); //no records in 2000 but it is important it appears still because that is what the axis says VerifyRowExist(resultTable, "2001", 67, 37); VerifyRowExist(resultTable, "2002", 30, 41); VerifyRowExist(resultTable, "2003", 42, null); @@ -579,10 +605,12 @@ public void GroupBy_PivotWithSum_Top2BasedonCountColumnDesc(DatabaseType type) [TestCase(DatabaseType.MySql)] public void GroupBy_PivotWithSum_Top2AlphabeticalAsc_WHEREStatement(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate pivot (and axis) - var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, out var pivotDimension); + var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, + out var pivotDimension); configuration.CountSQL = "sum(NumberInTrouble)"; configuration.PivotOnDimensionID = pivotDimension.ID; //pivot on the Category @@ -604,7 +632,7 @@ public void GroupBy_PivotWithSum_Top2AlphabeticalAsc_WHEREStatement(DatabaseType builder.AddColumn(pivotDimension); builder.SetPivotToDimensionID(pivotDimension); - AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder,type); + AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder, type); var resultTable = GetResultForBuilder(builder, tbl); @@ -616,7 +644,8 @@ public void GroupBy_PivotWithSum_Top2AlphabeticalAsc_WHEREStatement(DatabaseType Assert.AreEqual("G", resultTable.Columns[2].ColumnName); //E,G (note that only 1 value appears for E because WHERE throws out rest). Also note the two columns are E and G because that is Top 2 when alphabetically sorted of the pivot values (E,F,G,T) that match the filter (F doesn't) - VerifyRowExist(resultTable, "2000", null, null); //no records in 2000 but it is important it appears still because that is what the axis says + VerifyRowExist(resultTable, "2000", null, + null); //no records in 2000 but it is important it appears still because that is what the axis says VerifyRowExist(resultTable, "2001", null, 53); VerifyRowExist(resultTable, "2002", null, null); VerifyRowExist(resultTable, "2003", null, null); @@ -640,10 +669,12 @@ public void GroupBy_PivotWithSum_Top2AlphabeticalAsc_WHEREStatement(DatabaseType [TestCase(DatabaseType.MySql)] public void GroupBy_PivotWithSum_HAVING_Top1_WHERE(DatabaseType type) { - var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, out var tableInfo); + var tbl = UploadTestDataAsTableToServer(type, out var catalogue, out var extractionInformations, + out var tableInfo); //setup the aggregate pivot (and axis) - var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, out var pivotDimension); + var configuration = SetupAggregateWithPivot(type, extractionInformations, catalogue, out var axisDimension, + out var pivotDimension); configuration.CountSQL = "sum(NumberInTrouble)"; configuration.PivotOnDimensionID = pivotDimension.ID; //pivot on the Category @@ -666,7 +697,7 @@ public void GroupBy_PivotWithSum_HAVING_Top1_WHERE(DatabaseType type) builder.AddColumn(pivotDimension); builder.SetPivotToDimensionID(pivotDimension); - AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder,type); + AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(builder, type); var resultTable = GetResultForBuilder(builder, tbl); @@ -677,7 +708,8 @@ public void GroupBy_PivotWithSum_HAVING_Top1_WHERE(DatabaseType type) Assert.AreEqual("E&, %a' mp;E", resultTable.Columns[1].ColumnName); //Only E appears because of Top 1 pivot statement - VerifyRowExist(resultTable, "2000", null); //all E records are discarded except 59 because that is the WHERE logic + VerifyRowExist(resultTable, "2000", + null); //all E records are discarded except 59 because that is the WHERE logic VerifyRowExist(resultTable, "2001", null); VerifyRowExist(resultTable, "2002", null); VerifyRowExist(resultTable, "2003", null); diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MicrosoftAggregateBuilderTests.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MicrosoftAggregateBuilderTests.cs index e1452f6726..1933221130 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MicrosoftAggregateBuilderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MicrosoftAggregateBuilderTests.cs @@ -11,10 +11,8 @@ namespace Rdmp.Core.Tests.Curation.Integration.QueryBuildingTests.AggregateBuilderTests; -public class MicrosoftAggregateBuilderTests:AggregateBuilderTestsBase +public class MicrosoftAggregateBuilderTests : AggregateBuilderTestsBase { - - [Test] public void TestAggregateBuilding_NoConfigurationOneDimension() { @@ -32,7 +30,7 @@ group by order by Col1"), CollapseWhitespace(builder.SQL)); } - + /// /// Tests the systems ability to figure out the alias of the count column when it has " AS " (e.g. in a cast scalar function) /// @@ -104,15 +102,15 @@ public void TwoTopXObjects() var topX1 = new AggregateTopX(CatalogueRepository, _configuration, 10); var ex = Assert.Throws(() => new AggregateTopX(CatalogueRepository, _configuration, 10)); - Assert.AreEqual("AggregateConfiguration MyConfig already has a TopX",ex.Message); + Assert.AreEqual("AggregateConfiguration MyConfig already has a TopX", ex.Message); topX1.DeleteInDatabase(); } - [TestCase("count(*)",true)] + [TestCase("count(*)", true)] [TestCase("count(*)", false)] - [TestCase("max(Col1)",true)] + [TestCase("max(Col1)", true)] [TestCase("max(Col2)", false)] - public void TestAggregateBuilding_NoConfigurationTwoDimension_Top10(string countColField,bool asc) + public void TestAggregateBuilding_NoConfigurationTwoDimension_Top10(string countColField, bool asc) { var topX = new AggregateTopX(CatalogueRepository, _configuration, 10) { @@ -126,7 +124,7 @@ public void TestAggregateBuilding_NoConfigurationTwoDimension_Top10(string count _configuration.CountSQL = countColField; var builder = _configuration.GetQueryBuilder(); - + Assert.AreEqual(CollapseWhitespace($@"/*MyConfig*/ SELECT TOP 10 @@ -174,20 +172,19 @@ group by Col2 order by Col1 {(asc ? "asc" : "desc")}"), CollapseWhitespace(builder.SQL)); - + topX.DeleteInDatabase(); } [Test] public void TestAggregateBuilding_NoConfigurationNoDimensions() { - var builder = new AggregateBuilder(null, "count(*)", null,new []{_ti}); - + var builder = new AggregateBuilder(null, "count(*)", null, new[] { _ti }); + Assert.AreEqual(CollapseWhitespace(@"/**/ SELECT count(*) AS MyCount FROM T1"), CollapseWhitespace(builder.SQL)); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MySqlAggregateBuilderTests.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MySqlAggregateBuilderTests.cs index 7898cf4e32..ff628881a7 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MySqlAggregateBuilderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/AggregateBuilderTests/MySqlAggregateBuilderTests.cs @@ -30,8 +30,8 @@ public void Test_AggregateBuilder_MySql_Top32() topx.SaveToDatabase(); builder.AggregateTopX = topx; - - + + Assert.AreEqual(CollapseWhitespace(@"/**/ SELECT Col1, @@ -47,6 +47,7 @@ Col1 desc topx.DeleteInDatabase(); } + [TestCase(true)] [TestCase(false)] public void Test_AggregateBuilder_MySql_Top31OrderByCountAsc(bool useAliasForGroupBy) diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MicrosoftQueryBuilderTests.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MicrosoftQueryBuilderTests.cs index 105159a88a..04be62e17b 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MicrosoftQueryBuilderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MicrosoftQueryBuilderTests.cs @@ -12,7 +12,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.QueryBuildingTests.QueryBuilderTests; -internal class MicrosoftQueryBuilderTests:DatabaseTests +internal class MicrosoftQueryBuilderTests : DatabaseTests { [Test] public void TestQueryBuilder_MicrosoftSQLServer_Top35() @@ -55,6 +55,5 @@ TOP 50 FROM [db]..[tbl]") , CollapseWhitespace(qb.SQL)); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MySqlQueryBuilderTests.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MySqlQueryBuilderTests.cs index 23173d5fe7..ffba53ee6b 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MySqlQueryBuilderTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/MySqlQueryBuilderTests.cs @@ -23,10 +23,10 @@ public void TestQueryBuilder_MySql_Normal() }; t.SaveToDatabase(); - var col = new ColumnInfo(CatalogueRepository, "`db`.`tbl`.`col`","varchar(10)",t); - Assert.AreEqual("col",col.GetRuntimeName()); + var col = new ColumnInfo(CatalogueRepository, "`db`.`tbl`.`col`", "varchar(10)", t); + Assert.AreEqual("col", col.GetRuntimeName()); - var cata = new Catalogue(CatalogueRepository,"cata"); + var cata = new Catalogue(CatalogueRepository, "cata"); var catalogueItem = new CatalogueItem(CatalogueRepository, cata, "col"); var extractionInfo = new ExtractionInformation(CatalogueRepository, catalogueItem, col, col.Name); @@ -38,8 +38,8 @@ public void TestQueryBuilder_MySql_Normal() FROM `db`.`tbl`" ), CollapseWhitespace(qb.SQL)); - } + [Test] public void TestQueryBuilder_MySql_Top35() { @@ -81,6 +81,5 @@ public void TestQueryBuilder_MySql_Top35() `db`.`tbl` LIMIT 50") , CollapseWhitespace(qb.SQL)); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/QueryBuilderUnitTests.cs b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/QueryBuilderUnitTests.cs index 6023257862..4db76ed05f 100644 --- a/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/QueryBuilderUnitTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/QueryBuildingTests/QueryBuilderTests/QueryBuilderUnitTests.cs @@ -12,7 +12,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.QueryBuildingTests.QueryBuilderTests; -internal class QueryBuilderUnitTests:UnitTests +internal class QueryBuilderUnitTests : UnitTests { [Test] public void Test_IsPrimaryExtractionTable_TwoTables() @@ -27,12 +27,15 @@ public void Test_IsPrimaryExtractionTable_TwoTables() c2.TableInfo.SaveToDatabase(); var builder = new QueryBuilder(null, null); - builder.AddColumn(new ColumnInfoToIColumn(Repository,c1)); + builder.AddColumn(new ColumnInfoToIColumn(Repository, c1)); builder.AddColumn(new ColumnInfoToIColumn(Repository, c2)); - var ex = Assert.Throws(()=>{ var s = builder.SQL;}); + var ex = Assert.Throws(() => + { + var s = builder.SQL; + }); - StringAssert.Contains("There are multiple tables marked as IsPrimaryExtractionTable",ex.Message); + StringAssert.Contains("There are multiple tables marked as IsPrimaryExtractionTable", ex.Message); } [Test] @@ -67,7 +70,7 @@ public void Test_FourTables_MultipleRoutes() c1.Name = "c1"; c1.SaveToDatabase(); c1.TableInfo.Name = "t1"; - c1.TableInfo.IsPrimaryExtractionTable = true; //t1 is primary + c1.TableInfo.IsPrimaryExtractionTable = true; //t1 is primary c1.TableInfo.SaveToDatabase(); var c2 = WhenIHaveA(); @@ -93,11 +96,11 @@ public void Test_FourTables_MultipleRoutes() * / \ * c1 c4 * \ / - * c3 - * + * c3 + * * */ - var j1 = new JoinInfo(Repository,c2,c1,ExtractionJoinType.Inner,null); + var j1 = new JoinInfo(Repository, c2, c1, ExtractionJoinType.Inner, null); var j2 = new JoinInfo(Repository, c3, c1, ExtractionJoinType.Inner, null); var j3 = new JoinInfo(Repository, c4, c2, ExtractionJoinType.Inner, null); var j4 = new JoinInfo(Repository, c4, c3, ExtractionJoinType.Inner, null); @@ -105,7 +108,7 @@ public void Test_FourTables_MultipleRoutes() var builder = new QueryBuilder(null, null); builder.AddColumn(new ColumnInfoToIColumn(Repository, c1)); - builder.AddColumn(new ColumnInfoToIColumn(Repository, c2)); + builder.AddColumn(new ColumnInfoToIColumn(Repository, c2)); builder.AddColumn(new ColumnInfoToIColumn(Repository, c3)); builder.AddColumn(new ColumnInfoToIColumn(Repository, c4)); @@ -113,7 +116,7 @@ public void Test_FourTables_MultipleRoutes() //should be using only 3 of the 4 joins because we already have a route to c4 without a fourth join Assert.AreEqual(3, builder.JoinsUsedInQuery.Count); - Assert.Contains(j1,builder.JoinsUsedInQuery); + Assert.Contains(j1, builder.JoinsUsedInQuery); Assert.Contains(j2, builder.JoinsUsedInQuery); Assert.Contains(j3, builder.JoinsUsedInQuery); } diff --git a/Rdmp.Core.Tests/Curation/Integration/ServerDefaultsTests.cs b/Rdmp.Core.Tests/Curation/Integration/ServerDefaultsTests.cs index 6a4f427123..68ac9c50b6 100644 --- a/Rdmp.Core.Tests/Curation/Integration/ServerDefaultsTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/ServerDefaultsTests.cs @@ -27,23 +27,25 @@ public void TestClearSameDefaultTwice() [Test] public void CreateNewExternalServerAndConfigureItAsDefault() { - var databaseServer = new ExternalDatabaseServer(CatalogueRepository, "Deleteme",null); + var databaseServer = new ExternalDatabaseServer(CatalogueRepository, "Deleteme", null); try { - Assert.AreEqual("Deleteme",databaseServer.Name); + Assert.AreEqual("Deleteme", databaseServer.Name); databaseServer.Password = "nothing"; //automatically encrypts password - Assert.AreNotEqual("nothing",databaseServer.Password);//should not match what we just set it to - Assert.AreEqual("nothing", databaseServer.GetDecryptedPassword());//should match what we set it to because of explicit call to decrypt + Assert.AreNotEqual("nothing", databaseServer.Password); //should not match what we just set it to + Assert.AreEqual("nothing", + databaseServer + .GetDecryptedPassword()); //should match what we set it to because of explicit call to decrypt databaseServer.Server = "Bob"; databaseServer.Database = "TEST"; databaseServer.SaveToDatabase(); - var cata = new Catalogue(CatalogueRepository, "TestCatalogueFor_CreateNewExternalServerAndConfigureItAsDefault"); + var cata = new Catalogue(CatalogueRepository, + "TestCatalogueFor_CreateNewExternalServerAndConfigureItAsDefault"); cata.DeleteInDatabase(); - } finally { @@ -60,7 +62,7 @@ public void TestDeletingClearsDefault() try { //make the new server the default for logging - CatalogueRepository.SetDefault(PermissableDefaults.LiveLoggingServer_ID,eds); + CatalogueRepository.SetDefault(PermissableDefaults.LiveLoggingServer_ID, eds); //now we deleted it! eds.DeleteInDatabase(); @@ -69,8 +71,7 @@ public void TestDeletingClearsDefault() } finally { - CatalogueRepository.SetDefault(PermissableDefaults.LiveLoggingServer_ID, old); - } + } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/SupportingDocumentTests.cs b/Rdmp.Core.Tests/Curation/Integration/SupportingDocumentTests.cs index c24eb0dbbb..1d9cc9cf09 100644 --- a/Rdmp.Core.Tests/Curation/Integration/SupportingDocumentTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/SupportingDocumentTests.cs @@ -16,9 +16,9 @@ public class SupportingDocumentTests : DatabaseTests public void test_SupportingDocument_CreateAndDestroy() { var cata = new Catalogue(CatalogueRepository, "deleteme"); - var doc = new SupportingDocument(CatalogueRepository, cata,"davesFile"); + var doc = new SupportingDocument(CatalogueRepository, cata, "davesFile"); - Assert.AreEqual(doc.Name ,"davesFile"); + Assert.AreEqual(doc.Name, "davesFile"); doc.DeleteInDatabase(); cata.DeleteInDatabase(); @@ -39,7 +39,7 @@ public void test_SupportingDocument_CreateChangeSaveDestroy() var docAfterCommit = CatalogueRepository.GetObjectByID(doc.ID); - Assert.AreEqual(docAfterCommit.Description,doc.Description); + Assert.AreEqual(docAfterCommit.Description, doc.Description); doc.DeleteInDatabase(); cata.DeleteInDatabase(); diff --git a/Rdmp.Core.Tests/Curation/Integration/TableInfoSynchronizerTests.cs b/Rdmp.Core.Tests/Curation/Integration/TableInfoSynchronizerTests.cs index dd54715de8..8590cce446 100644 --- a/Rdmp.Core.Tests/Curation/Integration/TableInfoSynchronizerTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/TableInfoSynchronizerTests.cs @@ -16,7 +16,7 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class TableInfoSynchronizerTests:DatabaseTests +public class TableInfoSynchronizerTests : DatabaseTests { private DiscoveredServer _server; private ITableInfo tableInfoCreated; @@ -36,22 +36,23 @@ protected override void SetUp() using (var con = _server.GetConnection()) { con.Open(); - _server.GetCommand($"CREATE TABLE {TABLE_NAME}(Name varchar(10), Address varchar(500))",con).ExecuteNonQuery(); + _server.GetCommand($"CREATE TABLE {TABLE_NAME}(Name varchar(10), Address varchar(500))", con) + .ExecuteNonQuery(); } var tbl = _database.ExpectTable("TableInfoSynchronizerTests"); - var importer = new TableInfoImporter(CatalogueRepository,tbl); - importer.DoImport(out tableInfoCreated,out columnInfosCreated); + var importer = new TableInfoImporter(CatalogueRepository, tbl); + importer.DoImport(out tableInfoCreated, out columnInfosCreated); } [Test] public void SynchronizationTests_NoChanges() { - Assert.AreEqual(TABLE_NAME , tableInfoCreated.GetRuntimeName()); + Assert.AreEqual(TABLE_NAME, tableInfoCreated.GetRuntimeName()); var synchronizer = new TableInfoSynchronizer(tableInfoCreated); - Assert.AreEqual(true,synchronizer.Synchronize(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual(true, synchronizer.Synchronize(new ThrowImmediatelyCheckNotifier())); } [Test] @@ -70,15 +71,14 @@ public void SynchronizationTests_ColumnDropped(bool acceptChanges) if (acceptChanges) { //accept changes should result in a synchronized table - Assert.AreEqual(true,synchronizer.Synchronize(new AcceptAllCheckNotifier())); - Assert.AreEqual(1,tableInfoCreated.ColumnInfos.Length);//should only be 1 remaining + Assert.AreEqual(true, synchronizer.Synchronize(new AcceptAllCheckNotifier())); + Assert.AreEqual(1, tableInfoCreated.ColumnInfos.Length); //should only be 1 remaining } else { var ex = Assert.Throws(() => synchronizer.Synchronize(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("The ColumnInfo Address no longer appears in the live table.", ex.Message); + Assert.AreEqual("The ColumnInfo Address no longer appears in the live table.", ex.Message); } - } [Test] @@ -86,7 +86,6 @@ public void SynchronizationTests_ColumnDropped(bool acceptChanges) [TestCase(false)] public void SynchronizationTests_ColumnAdded(bool acceptChanges) { - using (var con = _database.Server.GetConnection()) { con.Open(); @@ -100,7 +99,7 @@ public void SynchronizationTests_ColumnAdded(bool acceptChanges) { //accept changes should result in a synchronized table Assert.AreEqual(true, synchronizer.Synchronize(new AcceptAllCheckNotifier())); - Assert.AreEqual(3, tableInfoCreated.ColumnInfos.Length);//should 3 now + Assert.AreEqual(3, tableInfoCreated.ColumnInfos.Length); //should 3 now } else { @@ -119,10 +118,10 @@ public void SynchronizationTests_ColumnAddedWithCatalogue(bool acceptChanges) try { - Assert.AreEqual(TABLE_NAME,cata.Name); + Assert.AreEqual(TABLE_NAME, cata.Name); Assert.AreEqual(2, cataItems.Length); Assert.AreEqual(2, extractionInformations.Length); - + using (var con = _server.GetConnection()) { con.Open(); @@ -135,12 +134,14 @@ public void SynchronizationTests_ColumnAddedWithCatalogue(bool acceptChanges) { //accept changes should result in a synchronized table Assert.AreEqual(true, synchronizer.Synchronize(new AcceptAllCheckNotifier())); - Assert.AreEqual(3, tableInfoCreated.ColumnInfos.Length);//should 3 now - Assert.AreEqual(3, cata.CatalogueItems.Length);//should 3 now - Assert.AreEqual(3, cata.GetAllExtractionInformation(ExtractionCategory.Any).Length);//should 3 now - - Assert.AreEqual(1,cata.GetAllExtractionInformation(ExtractionCategory.Any).Count(e=>e.SelectSQL.Contains("Birthday"))); - Assert.AreEqual(1,cata.CatalogueItems.Count(ci => ci.Name.Contains("Birthday"))); + Assert.AreEqual(3, tableInfoCreated.ColumnInfos.Length); //should 3 now + Assert.AreEqual(3, cata.CatalogueItems.Length); //should 3 now + Assert.AreEqual(3, cata.GetAllExtractionInformation(ExtractionCategory.Any).Length); //should 3 now + + Assert.AreEqual(1, + cata.GetAllExtractionInformation(ExtractionCategory.Any) + .Count(e => e.SelectSQL.Contains("Birthday"))); + Assert.AreEqual(1, cata.CatalogueItems.Count(ci => ci.Name.Contains("Birthday"))); } else { @@ -165,20 +166,20 @@ public void Test_SynchronizeTable_BracketsInTableName() var db = _database; //FAnsi doesn't let you create tables with brackets in the names so we have to do it manually - using(var con = db.Server.GetConnection()) + using (var con = db.Server.GetConnection()) { con.Open(); - var cmd = db.Server.GetCommand("CREATE TABLE [BB (ff)] (A int not null)",con); + var cmd = db.Server.GetCommand("CREATE TABLE [BB (ff)] (A int not null)", con); cmd.ExecuteNonQuery(); } var tbl = db.CreateTable("FF", new DatabaseColumnRequest[] { - new DatabaseColumnRequest("F",new DatabaseTypeRequest(typeof(int))) + new("F", new DatabaseTypeRequest(typeof(int))) }); - Import(tbl,out var ti,out _); + Import(tbl, out var ti, out _); var s = new TableInfoSynchronizer(ti); s.Synchronize(new ThrowImmediatelyCheckNotifier()); diff --git a/Rdmp.Core.Tests/Curation/Integration/TableInfoTests.cs b/Rdmp.Core.Tests/Curation/Integration/TableInfoTests.cs index b4ad89fe19..55af18df2d 100644 --- a/Rdmp.Core.Tests/Curation/Integration/TableInfoTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/TableInfoTests.cs @@ -69,7 +69,6 @@ public void update_changeAllProperties_pass() } - [Test] [TestCase("[TestDB]..[TestTableName]", "[TestDB]..[TestTableName].[ANOMyCol]")] [TestCase("TestDB..TestTableName", "TestDB..TestTableName.ANOMyCol")] @@ -88,7 +87,7 @@ public void CreateNewTableInfoInDatabase_Naming(string tableName, string columnN try { - Assert.AreEqual("ANOMyCol",c.GetRuntimeName()); + Assert.AreEqual("ANOMyCol", c.GetRuntimeName()); Assert.AreEqual("MyCol", c.GetRuntimeName(LoadStage.AdjustRaw)); Assert.AreEqual("ANOMyCol", c.GetRuntimeName(LoadStage.PostLoad)); @@ -97,12 +96,12 @@ public void CreateNewTableInfoInDatabase_Naming(string tableName, string columnN Assert.AreEqual("TestDB_TestTableName_STAGING", table.GetRuntimeName(LoadBubble.Staging)); Assert.AreEqual("TestTableName_STAGING", table.GetRuntimeName(LoadBubble.Staging, new SuffixBasedNamer())); - Assert.AreEqual("TestDB_TestTableName_STAGING", table.GetRuntimeName(LoadBubble.Staging, new FixedStagingDatabaseNamer("TestDB"))); + Assert.AreEqual("TestDB_TestTableName_STAGING", + table.GetRuntimeName(LoadBubble.Staging, new FixedStagingDatabaseNamer("TestDB"))); Assert.AreEqual("TestTableName", table.GetRuntimeName(LoadBubble.Live)); - } - finally + finally { c.DeleteInDatabase(); table.DeleteInDatabase(); @@ -120,19 +119,20 @@ public void TestCreateTableInSchemaAndImportAsTableInfo() db.Server.GetCommand("CREATE SCHEMA Omg", con).ExecuteNonQuery(); - var tbl = db.CreateTable("Fish", new [] {new DatabaseColumnRequest("MyCol", "int"){IsPrimaryKey = true}},schema: "Omg"); + var tbl = db.CreateTable("Fish", + new[] { new DatabaseColumnRequest("MyCol", "int") { IsPrimaryKey = true } }, "Omg"); Assert.AreEqual("Fish", tbl.GetRuntimeName()); - Assert.AreEqual( "Omg", tbl.Schema); + Assert.AreEqual("Omg", tbl.Schema); Assert.IsTrue(tbl.GetFullyQualifiedName().EndsWith("[Omg].[Fish]")); Assert.IsTrue(tbl.Exists()); - Import(tbl,out var ti, out var cols); + Import(tbl, out var ti, out var cols); - Assert.AreEqual("Omg",ti.Schema); + Assert.AreEqual("Omg", ti.Schema); var tbl2 = ti.Discover(DataAccessContext.InternalDataProcessing); - Assert.AreEqual("Omg",tbl2.Schema); + Assert.AreEqual("Omg", tbl2.Schema); Assert.IsTrue(tbl2.Exists()); Assert.IsTrue(ti.Name.EndsWith("[Omg].[Fish]")); @@ -141,44 +141,45 @@ public void TestCreateTableInSchemaAndImportAsTableInfo() var c = cols.Single(); - Assert.AreEqual("MyCol",c.GetRuntimeName()); - StringAssert.Contains("[Omg].[Fish]",c.GetFullyQualifiedName()); + Assert.AreEqual("MyCol", c.GetRuntimeName()); + StringAssert.Contains("[Omg].[Fish]", c.GetFullyQualifiedName()); //should be primary key Assert.IsTrue(c.IsPrimaryKey); var triggerFactory = new TriggerImplementerFactory(DatabaseType.MicrosoftSQLServer); var impl = triggerFactory.Create(tbl); - - Assert.AreEqual(TriggerStatus.Missing,impl.GetTriggerStatus()); + + Assert.AreEqual(TriggerStatus.Missing, impl.GetTriggerStatus()); impl.CreateTrigger(new ThrowImmediatelyCheckNotifier()); Assert.AreEqual(TriggerStatus.Enabled, impl.GetTriggerStatus()); - Assert.IsTrue( impl.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); + Assert.IsTrue(impl.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); //should be synced var sync = new TableInfoSynchronizer(ti); sync.Synchronize(new AcceptAllCheckNotifier()); //Test importing the _Legacy table valued function that should be created in the Omg schema and test synching that too. - var tvf = ti.Discover(DataAccessContext.InternalDataProcessing).Database.ExpectTableValuedFunction("Fish_Legacy", "Omg"); + var tvf = ti.Discover(DataAccessContext.InternalDataProcessing).Database + .ExpectTableValuedFunction("Fish_Legacy", "Omg"); Assert.IsTrue(tvf.Exists()); var importerTvf = new TableValuedFunctionImporter(CatalogueRepository, tvf); importerTvf.DoImport(out var tvfTi, out var tvfCols); - Assert.AreEqual("Omg",tvfTi.Schema); + Assert.AreEqual("Omg", tvfTi.Schema); var syncTvf = new TableInfoSynchronizer(tvfTi); syncTvf.Synchronize(new ThrowImmediatelyCheckNotifier()); - StringAssert.EndsWith("[Omg].Fish_Legacy(@index) AS Fish_Legacy",tvfTi.Name); + StringAssert.EndsWith("[Omg].Fish_Legacy(@index) AS Fish_Legacy", tvfTi.Name); } } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void TestView(DatabaseType dbType) { var db = GetCleanedServer(dbType); @@ -187,18 +188,18 @@ public void TestView(DatabaseType dbType) var dt = new DataTable(); dt.Columns.Add("FF"); - var tbl = db.CreateTable("MyTable",dt); - Import(tbl,out var tblInfo,out _); - + var tbl = db.CreateTable("MyTable", dt); + Import(tbl, out var tblInfo, out _); + Assert.IsTrue(tblInfo.Discover(DataAccessContext.InternalDataProcessing).Exists()); - Assert.AreEqual(TableType.Table,tblInfo.Discover(DataAccessContext.InternalDataProcessing).TableType); + Assert.AreEqual(TableType.Table, tblInfo.Discover(DataAccessContext.InternalDataProcessing).TableType); var viewName = "MyView"; //oracle likes to create stuff under your user account not the database your actually using! - if(dbType == DatabaseType.Oracle) + if (dbType == DatabaseType.Oracle) viewName = syntax.EnsureFullyQualified(tbl.Database.GetRuntimeName(), null, "MyView"); - + //postgres hates upper case tables (unless they are wrapped) if (dbType == DatabaseType.PostgreSql) viewName = syntax.EnsureWrapped(viewName); @@ -210,25 +211,24 @@ public void TestView(DatabaseType dbType) tbl.GetFullyQualifiedName(), syntax.EnsureWrapped("FF")); - using(var con = tbl.Database.Server.GetConnection()) + using (var con = tbl.Database.Server.GetConnection()) { con.Open(); - var cmd = tbl.GetCommand(sql,con); + var cmd = tbl.GetCommand(sql, con); cmd.ExecuteNonQuery(); } - var view = tbl.Database.ExpectTable("MyView",null,TableType.View); - Import(view,out var viewInfo,out _); + var view = tbl.Database.ExpectTable("MyView", null, TableType.View); + Import(view, out var viewInfo, out _); var sync = new TableInfoSynchronizer(viewInfo); sync.Synchronize(new ThrowImmediatelyCheckNotifier()); - + Assert.IsTrue(viewInfo.Discover(DataAccessContext.InternalDataProcessing).Exists()); - Assert.AreEqual(TableType.View,viewInfo.Discover(DataAccessContext.InternalDataProcessing).TableType); + Assert.AreEqual(TableType.View, viewInfo.Discover(DataAccessContext.InternalDataProcessing).TableType); view.Drop(); Assert.IsFalse(view.Exists()); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/TableNamingConventionTests.cs b/Rdmp.Core.Tests/Curation/Integration/TableNamingConventionTests.cs index 997d6d1c46..7f1cf105f4 100644 --- a/Rdmp.Core.Tests/Curation/Integration/TableNamingConventionTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/TableNamingConventionTests.cs @@ -45,7 +45,6 @@ public void update_changeAllProperties_pass() Assert.IsTrue(tableInfoAfter.DatabaseType == DatabaseType.Oracle); tableInfoAfter.DeleteInDatabase(); - } [Test] @@ -60,5 +59,4 @@ public void SuffixBasedTableNamingConventionHelper() var newLookupTable = namingScheme.GetName(baseTableName, LoadBubble.Live); Assert.AreEqual("MyTable", newLookupTable); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/AggregationTests.cs b/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/AggregationTests.cs index 48562f3b4e..ae934e8e1c 100644 --- a/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/AggregationTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/AggregationTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.TableValuedFunctionTests; -public class AggregationTests :DatabaseTests +public class AggregationTests : DatabaseTests { private TestableTableValuedFunction _function; @@ -30,7 +30,7 @@ public void GenerateAggregateManuallyTest() CreateFunction(CatalogueRepository); //do a count * on the query builder - var queryBuilder = new AggregateBuilder("", "count(*)", null,new[] { _function.TableInfoCreated }); + var queryBuilder = new AggregateBuilder("", "count(*)", null, new[] { _function.TableInfoCreated }); Assert.IsTrue(queryBuilder.SQL.Contains(@"SELECT")); Assert.IsTrue(queryBuilder.SQL.Contains(@"count(*)")); @@ -38,20 +38,21 @@ public void GenerateAggregateManuallyTest() Assert.IsTrue(queryBuilder.SQL.Contains(@"DECLARE @name AS varchar(50);")); Assert.IsTrue(queryBuilder.SQL.Contains(@"SET @name='fish';")); - Assert.IsTrue(queryBuilder.SQL.Contains("..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction")); + Assert.IsTrue( + queryBuilder.SQL.Contains("..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction")); Console.WriteLine(queryBuilder.SQL); } - + [TestCase(false)] [TestCase(true)] public void GenerateAggregateViaAggregateConfigurationTest(bool memoryRepo) { - var repo = memoryRepo ? (ICatalogueRepository) new MemoryCatalogueRepository() : CatalogueRepository; + var repo = memoryRepo ? (ICatalogueRepository)new MemoryCatalogueRepository() : CatalogueRepository; CreateFunction(repo); var agg = new AggregateConfiguration(repo, _function.Cata, "MyExcitingAggregate"); - + try { agg.HavingSQL = "count(*)>1"; @@ -61,7 +62,7 @@ public void GenerateAggregateViaAggregateConfigurationTest(bool memoryRepo) aggregateForcedJoin.CreateLinkBetween(agg, _function.TableInfoCreated); var queryBuilder = agg.GetQueryBuilder(); - + Assert.AreEqual( $@"DECLARE @startNumber AS int; SET @startNumber=5; @@ -76,7 +77,6 @@ public void GenerateAggregateViaAggregateConfigurationTest(bool memoryRepo) [{TestDatabaseNames.Prefix}ScratchArea]..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction HAVING count(*)>1", queryBuilder.SQL); - } finally { @@ -94,9 +94,9 @@ public void GenerateAggregateUsingOverridenParametersTest() try { var param = new AnyTableSqlParameter(CatalogueRepository, agg, "DECLARE @name AS varchar(50);") - { - Value = "'lobster'" - }; + { + Value = "'lobster'" + }; param.SaveToDatabase(); var aggregateForcedJoin = new AggregateForcedJoin(CatalogueTableRepository); @@ -115,7 +115,8 @@ public void GenerateAggregateUsingOverridenParametersTest() //isntead of this verison of things Assert.IsFalse(queryBuilder.SQL.Contains(@"SET @name='fish';")); - Assert.IsTrue(queryBuilder.SQL.Contains("..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction")); + Assert.IsTrue( + queryBuilder.SQL.Contains("..MyAwesomeFunction(@startNumber,@stopNumber,@name) AS MyAwesomeFunction")); Console.WriteLine(queryBuilder.SQL); } diff --git a/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/ImportAndTestTests.cs b/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/ImportAndTestTests.cs index 30ad0396a5..8afed19794 100644 --- a/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/ImportAndTestTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/TableValuedFunctionTests/ImportAndTestTests.cs @@ -38,7 +38,7 @@ public void FunctionWorks() using (var con = server.GetConnection()) { con.Open(); - var r = server.GetCommand("Select * from dbo.MyAwesomeFunction(5,10,'Fish')",con).ExecuteReader(); + var r = server.GetCommand("Select * from dbo.MyAwesomeFunction(5,10,'Fish')", con).ExecuteReader(); r.Read(); Assert.AreEqual(5, r["Number"]); @@ -69,7 +69,7 @@ public void FunctionWorks() } } - + [Test] public void ImportFunctionIntoCatalogue() { @@ -81,18 +81,19 @@ public void ImportFunctionIntoCatalogue() public void TestDiscovery() { var db = _database; - + using (var con = db.Server.BeginNewTransactedConnection()) { - //drop function - outside of transaction db.Server.GetCommand("drop function MyAwesomeFunction", con).ExecuteNonQuery(); //create it within the scope of the transaction - var cmd = db.Server.GetCommand(_function.CreateFunctionSQL[(_function.CreateFunctionSQL.IndexOf("GO") + 3)..], con); + var cmd = db.Server.GetCommand( + _function.CreateFunctionSQL[(_function.CreateFunctionSQL.IndexOf("GO") + 3)..], con); cmd.ExecuteNonQuery(); - Assert.IsTrue(db.DiscoverTableValuedFunctions(con.ManagedTransaction).Any(tbv => tbv.GetRuntimeName().Equals("MyAwesomeFunction"))); + Assert.IsTrue(db.DiscoverTableValuedFunctions(con.ManagedTransaction) + .Any(tbv => tbv.GetRuntimeName().Equals("MyAwesomeFunction"))); Assert.IsTrue(db.ExpectTableValuedFunction("MyAwesomeFunction").Exists(con.ManagedTransaction)); var cols = db.ExpectTableValuedFunction("MyAwesomeFunction").DiscoverColumns(con.ManagedTransaction); @@ -114,17 +115,18 @@ public void Synchronization_ExtraParameter() var expectedMessage = "MyAwesomeFunction is a Table Valued Function, in the Catalogue it has a parameter called @fish but this parameter no longer appears in the underlying database"; - var excessParameter = new AnyTableSqlParameter(CatalogueRepository, _function.TableInfoCreated, "DECLARE @fish as int"); + var excessParameter = + new AnyTableSqlParameter(CatalogueRepository, _function.TableInfoCreated, "DECLARE @fish as int"); var checker = new ToMemoryCheckNotifier(); _function.TableInfoCreated.Check(checker); - - Assert.IsTrue(checker.Messages.Any(m=>m.Result == CheckResult.Fail - && - m.Message.Contains(expectedMessage))); + + Assert.IsTrue(checker.Messages.Any(m => m.Result == CheckResult.Fail + && + m.Message.Contains(expectedMessage))); var syncer = new TableInfoSynchronizer(_function.TableInfoCreated); - var ex = Assert.Throws(()=>syncer.Synchronize(new ThrowImmediatelyCheckNotifier())); + var ex = Assert.Throws(() => syncer.Synchronize(new ThrowImmediatelyCheckNotifier())); Assert.IsTrue(ex.Message.Contains(expectedMessage)); //no changes yet @@ -135,15 +137,16 @@ public void Synchronization_ExtraParameter() //now parameter shouldnt be there Assert.IsTrue(excessParameter.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyWasDeleted); - } [Test] public void Synchronization_MissingParameter() { - var expectedMessage = "MyAwesomeFunction is a Table Valued Function but it does not have a record of the parameter @startNumber which appears in the underlying database"; + var expectedMessage = + "MyAwesomeFunction is a Table Valued Function but it does not have a record of the parameter @startNumber which appears in the underlying database"; - var parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters().Single(p => p.ParameterName.Equals("@startNumber")); + var parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters() + .Single(p => p.ParameterName.Equals("@startNumber")); parameter.DeleteInDatabase(); var syncer = new TableInfoSynchronizer(_function.TableInfoCreated); @@ -159,7 +162,6 @@ public void Synchronization_MissingParameter() //now parameter should have reappeared due to accepthing change Assert.IsTrue(_function.TableInfoCreated.GetAllParameters().Any(p => p.ParameterName.Equals("@startNumber"))); - } [Test] @@ -168,14 +170,15 @@ public void Synchronization_ParameterDefinitionChanged() var expectedMessage = "Parameter @startNumber is declared as 'DECLARE @startNumber AS int;' but in the Catalogue it appears as 'DECLARE @startNumber AS datetime;'"; - var parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters().Single(p => p.ParameterName.Equals("@startNumber")); + var parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters() + .Single(p => p.ParameterName.Equals("@startNumber")); parameter.ParameterSQL = "DECLARE @startNumber AS datetime;"; parameter.SaveToDatabase(); var syncer = new TableInfoSynchronizer(_function.TableInfoCreated); var ex = Assert.Throws(() => syncer.Synchronize(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains(expectedMessage,ex.Message); + StringAssert.Contains(expectedMessage, ex.Message); //no changes should yet have taken place since we didn't accept it yet Assert.IsTrue(parameter.HasLocalChanges().Evaluation == ChangeDescription.NoChanges); @@ -183,26 +186,24 @@ public void Synchronization_ParameterDefinitionChanged() //sync should have proposed to adjusting the datatype Assert.IsTrue(syncer.Synchronize(new AcceptAllCheckNotifier())); - if(CatalogueRepository is not TableRepository) - { + if (CatalogueRepository is not TableRepository) // with a Yaml repository there is only one copy of the object so no need // to check for differences in db return; - } //now parameter should have the correct datatype Assert.IsTrue(parameter.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent); var diff = parameter.HasLocalChanges().Differences.Single(); - Assert.AreEqual("DECLARE @startNumber AS datetime;",diff.LocalValue); + Assert.AreEqual("DECLARE @startNumber AS datetime;", diff.LocalValue); Assert.AreEqual("DECLARE @startNumber AS int;", diff.DatabaseValue); - } [Test] public void Synchronization_ParameterRenamed() { - var parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters().Single(p => p.ParameterName.Equals("@startNumber")); + var parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters() + .Single(p => p.ParameterName.Equals("@startNumber")); parameter.ParameterSQL = "DECLARE @startNum AS int"; parameter.SaveToDatabase(); @@ -217,8 +218,7 @@ public void Synchronization_ParameterRenamed() Assert.IsTrue(after.Any(p => p.ParameterName.Equals("@startNumber"))); //still there should only be 3 parameters - Assert.AreEqual(3,after.Length); - + Assert.AreEqual(3, after.Length); } @@ -227,7 +227,7 @@ public void TableInfoCheckingWorks() { _function.TableInfoCreated.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); } - + [Test] public void CatalogueCheckingWorks() { diff --git a/Rdmp.Core.Tests/Curation/Integration/TriggerTests.cs b/Rdmp.Core.Tests/Curation/Integration/TriggerTests.cs index 4aa57d6f24..447be16734 100644 --- a/Rdmp.Core.Tests/Curation/Integration/TriggerTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/TriggerTests.cs @@ -22,30 +22,30 @@ namespace Rdmp.Core.Tests.Curation.Integration; -public class TriggerTests :DatabaseTests +public class TriggerTests : DatabaseTests { private DiscoveredTable _table; private DiscoveredTable _archiveTable; private DiscoveredDatabase _database; - + public void CreateTable(DatabaseType dbType) { _database = GetCleanedServer(dbType); - _table =_database.CreateTable("TriggerTests",new DatabaseColumnRequest[]{ - new DatabaseColumnRequest("name",new DatabaseTypeRequest(typeof(string),30)){AllowNulls = false }, - new DatabaseColumnRequest("bubbles",new DatabaseTypeRequest(typeof(int))) + _table = _database.CreateTable("TriggerTests", new DatabaseColumnRequest[] + { + new("name", new DatabaseTypeRequest(typeof(string), 30)) { AllowNulls = false }, + new("bubbles", new DatabaseTypeRequest(typeof(int))) }); _archiveTable = _database.ExpectTable("TriggerTests_Archive"); } - private ITriggerImplementer GetImplementer() - { - return new TriggerImplementerFactory(_database.Server.DatabaseType).Create(_table); - } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + private ITriggerImplementer GetImplementer() => + new TriggerImplementerFactory(_database.Server.DatabaseType).Create(_table); + + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void NoTriggerExists(DatabaseType dbType) { CreateTable(dbType); @@ -58,36 +58,39 @@ public void NoTriggerExists(DatabaseType dbType) Assert.AreEqual(TriggerStatus.Missing, implementer.GetTriggerStatus()); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void CreateWithNoPks_Complain(DatabaseType dbType) { CreateTable(dbType); - var ex = Assert.Throws(() => GetImplementer().CreateTrigger(new ThrowImmediatelyCheckNotifier())); + var ex = Assert.Throws(() => + GetImplementer().CreateTrigger(new ThrowImmediatelyCheckNotifier())); Assert.AreEqual("There must be at least 1 primary key", ex.Message); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void CreateWithPks_Valid(DatabaseType dbType) { CreateTable(dbType); - _table.CreatePrimaryKey(new []{_table.DiscoverColumn("name")}); + _table.CreatePrimaryKey(new[] { _table.DiscoverColumn("name") }); GetImplementer().CreateTrigger(new ThrowImmediatelyCheckNotifier()); Assert.AreEqual(TriggerStatus.Enabled, GetImplementer().GetTriggerStatus()); Assert.AreEqual(true, GetImplementer().CheckUpdateTriggerIsEnabledAndHasExpectedBody()); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void Create_WithDodgyColumnNames(DatabaseType dbType) { _database = GetCleanedServer(dbType); - _table =_database.CreateTable("Trol lol My Table Select * from Group by fish",new DatabaseColumnRequest[]{ - new DatabaseColumnRequest("My Lovely Column Select * From Lolz",new DatabaseTypeRequest(typeof(string),30)){AllowNulls = false,IsPrimaryKey = true}, - new DatabaseColumnRequest("ANormalColumnName",new DatabaseTypeRequest(typeof(int))), - new DatabaseColumnRequest("Group By Meeee Colll trollolol",new DatabaseTypeRequest(typeof(int))) + _table = _database.CreateTable("Trol lol My Table Select * from Group by fish", new DatabaseColumnRequest[] + { + new("My Lovely Column Select * From Lolz", new DatabaseTypeRequest(typeof(string), 30)) + { AllowNulls = false, IsPrimaryKey = true }, + new("ANormalColumnName", new DatabaseTypeRequest(typeof(int))), + new("Group By Meeee Colll trollolol", new DatabaseTypeRequest(typeof(int))) }); GetImplementer().CreateTrigger(new ThrowImmediatelyCheckNotifier()); @@ -96,16 +99,17 @@ public void Create_WithDodgyColumnNames(DatabaseType dbType) Assert.AreEqual(true, GetImplementer().CheckUpdateTriggerIsEnabledAndHasExpectedBody()); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void AlterTest_InvalidThenRecreateItAndItsValidAgain(DatabaseType dbType) { CreateWithPks_Valid(dbType); - _table.AddColumn("fish",new DatabaseTypeRequest(typeof(int)),true,500); - _archiveTable.AddColumn("fish",new DatabaseTypeRequest(typeof(int)),true,500); + _table.AddColumn("fish", new DatabaseTypeRequest(typeof(int)), true, 500); + _archiveTable.AddColumn("fish", new DatabaseTypeRequest(typeof(int)), true, 500); //still not valid because trigger SQL is missing it in the column list - var ex = Assert.Throws(() => GetImplementer().CheckUpdateTriggerIsEnabledAndHasExpectedBody()); + var ex = Assert.Throws(() => + GetImplementer().CheckUpdateTriggerIsEnabledAndHasExpectedBody()); Assert.IsNotNull(ex.Message); var implementer = GetImplementer(); @@ -117,94 +121,99 @@ public void AlterTest_InvalidThenRecreateItAndItsValidAgain(DatabaseType dbType) Assert.AreEqual(true, implementer.CheckUpdateTriggerIsEnabledAndHasExpectedBody()); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void NowTestDataInsertion(DatabaseType dbType) { AlterTest_InvalidThenRecreateItAndItsValidAgain(dbType); - + _table.Insert(new Dictionary - { - {"name","Franky" } , - {"bubbles",3 } , - {"hic_validFrom",new DateTime(2001,1,2)} , - {"hic_dataLoadRunID",7 } + { + { "name", "Franky" }, + { "bubbles", 3 }, + { "hic_validFrom", new DateTime(2001, 1, 2) }, + { "hic_dataLoadRunID", 7 } }); - var liveOldRow = _table.GetDataTable().Rows.Cast().Single(r=>r["bubbles"] as int? ==3); - Assert.AreEqual(new DateTime(2001,1,2),(DateTime)liveOldRow[SpecialFieldNames.ValidFrom]); + var liveOldRow = _table.GetDataTable().Rows.Cast().Single(r => r["bubbles"] as int? == 3); + Assert.AreEqual(new DateTime(2001, 1, 2), (DateTime)liveOldRow[SpecialFieldNames.ValidFrom]); - RunSQL("UPDATE {0} set bubbles =99",_table.GetFullyQualifiedName()); + RunSQL("UPDATE {0} set bubbles =99", _table.GetFullyQualifiedName()); //new value is 99 - Assert.AreEqual(99,ExecuteScalar("Select bubbles FROM {0} where name = 'Franky'",_table.GetFullyQualifiedName())); + Assert.AreEqual(99, + ExecuteScalar("Select bubbles FROM {0} where name = 'Franky'", _table.GetFullyQualifiedName())); //archived value is 3 - Assert.AreEqual(3, ExecuteScalar("Select bubbles FROM {0} where name = 'Franky'", _archiveTable.GetFullyQualifiedName())); + Assert.AreEqual(3, + ExecuteScalar("Select bubbles FROM {0} where name = 'Franky'", _archiveTable.GetFullyQualifiedName())); //Legacy table valued function only works for MicrosoftSQLServer - if(dbType == DatabaseType.MicrosoftSQLServer) + if (dbType == DatabaseType.MicrosoftSQLServer) { //legacy in 2001-01-01 it didn't exist - Assert.IsNull( ExecuteScalar("Select bubbles FROM TriggerTests_Legacy('2001-01-01') where name = 'Franky'")); + Assert.IsNull(ExecuteScalar("Select bubbles FROM TriggerTests_Legacy('2001-01-01') where name = 'Franky'")); //legacy in 2001-01-03 it did exist and was 3 - Assert.AreEqual(3, ExecuteScalar("Select bubbles FROM TriggerTests_Legacy('2001-01-03') where name = 'Franky'")); + Assert.AreEqual(3, + ExecuteScalar("Select bubbles FROM TriggerTests_Legacy('2001-01-03') where name = 'Franky'")); //legacy boundary case? - Assert.AreEqual(3, ExecuteScalar("Select bubbles FROM TriggerTests_Legacy('2001-01-02') where name = 'Franky'")); - + Assert.AreEqual(3, + ExecuteScalar("Select bubbles FROM TriggerTests_Legacy('2001-01-02') where name = 'Franky'")); + //legacy today it is 99 - Assert.AreEqual(99, ExecuteScalar("Select bubbles FROM TriggerTests_Legacy(GETDATE()) where name = 'Franky'")); + Assert.AreEqual(99, + ExecuteScalar("Select bubbles FROM TriggerTests_Legacy(GETDATE()) where name = 'Franky'")); } // Live row should now reflect that it is validFrom today - var liveNewRow = _table.GetDataTable().Rows.Cast().Single(r=>r["bubbles"] as int? ==99); - Assert.AreEqual(DateTime.Now.Date,((DateTime)liveNewRow[SpecialFieldNames.ValidFrom]).Date); + var liveNewRow = _table.GetDataTable().Rows.Cast().Single(r => r["bubbles"] as int? == 99); + Assert.AreEqual(DateTime.Now.Date, ((DateTime)liveNewRow[SpecialFieldNames.ValidFrom]).Date); // Archived row should not have had its validFrom field broken - var archivedRow = _archiveTable.GetDataTable().Rows.Cast().Single(r=>r["bubbles"] as int? ==3); - Assert.AreEqual(new DateTime(2001,1,2),(DateTime)archivedRow[SpecialFieldNames.ValidFrom]); + var archivedRow = _archiveTable.GetDataTable().Rows.Cast().Single(r => r["bubbles"] as int? == 3); + Assert.AreEqual(new DateTime(2001, 1, 2), (DateTime)archivedRow[SpecialFieldNames.ValidFrom]); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void DiffDatabaseDataFetcherTest(DatabaseType dbType) { CreateTable(dbType); - + _table.CreatePrimaryKey(_table.DiscoverColumn("name")); - + GetImplementer().CreateTrigger(new ThrowImmediatelyCheckNotifier()); - + _table.Insert(new Dictionary - { - {"name","Franky" } , - {"bubbles",3 } , - {"hic_validFrom",new DateTime(2001,1,2)} , - {"hic_dataLoadRunID",7 } + { + { "name", "Franky" }, + { "bubbles", 3 }, + { "hic_validFrom", new DateTime(2001, 1, 2) }, + { "hic_dataLoadRunID", 7 } }); - + Thread.Sleep(1000); - RunSQL("UPDATE {0} SET bubbles=1",_table.GetFullyQualifiedName()); - + RunSQL("UPDATE {0} SET bubbles=1", _table.GetFullyQualifiedName()); + Thread.Sleep(1000); - RunSQL("UPDATE {0} SET bubbles=2",_table.GetFullyQualifiedName()); - + RunSQL("UPDATE {0} SET bubbles=2", _table.GetFullyQualifiedName()); + Thread.Sleep(1000); - RunSQL("UPDATE {0} SET bubbles=3",_table.GetFullyQualifiedName()); - + RunSQL("UPDATE {0} SET bubbles=3", _table.GetFullyQualifiedName()); + Thread.Sleep(1000); - RunSQL("UPDATE {0} SET bubbles=4",_table.GetFullyQualifiedName()); + RunSQL("UPDATE {0} SET bubbles=4", _table.GetFullyQualifiedName()); Thread.Sleep(1000); - Assert.AreEqual(1,_table.GetRowCount()); - Assert.AreEqual(4,_archiveTable.GetRowCount()); + Assert.AreEqual(1, _table.GetRowCount()); + Assert.AreEqual(4, _archiveTable.GetRowCount()); + + Import(_table, out var ti, out var cols); + var fetcher = new DiffDatabaseDataFetcher(1, ti, 7, 100); - Import(_table,out var ti, out var cols); - var fetcher = new DiffDatabaseDataFetcher(1,ti,7,100); - fetcher.FetchData(new AcceptAllCheckNotifier()); - Assert.AreEqual(4,fetcher.Updates_New.Rows[0]["bubbles"]); + Assert.AreEqual(4, fetcher.Updates_New.Rows[0]["bubbles"]); Assert.AreEqual(3, fetcher.Updates_Replaced.Rows[0]["bubbles"]); - Assert.AreEqual(1,fetcher.Updates_New.Rows.Count); + Assert.AreEqual(1, fetcher.Updates_New.Rows.Count); Assert.AreEqual(1, fetcher.Updates_Replaced.Rows.Count); } @@ -213,7 +222,7 @@ public void DiffDatabaseDataFetcherTest(DatabaseType dbType) public void IdentityTest() { CreateTable(DatabaseType.MicrosoftSQLServer); - + RunSQL("Alter TABLE TriggerTests ADD myident int identity(1,1) PRIMARY KEY"); var implementer = new MicrosoftSQLTriggerImplementer(_table); @@ -224,8 +233,8 @@ public void IdentityTest() private object ExecuteScalar(string sql, params string[] args) { - if(args.Length != 0) - sql = string.Format(sql,args); + if (args.Length != 0) + sql = string.Format(sql, args); var svr = _database.Server; using (var con = svr.GetConnection()) @@ -237,8 +246,8 @@ private object ExecuteScalar(string sql, params string[] args) private void RunSQL(string sql, params string[] args) { - if(args.Length != 0) - sql = string.Format(sql,args); + if (args.Length != 0) + sql = string.Format(sql, args); if (_database == null) throw new Exception("You must call CreateTable first"); diff --git a/Rdmp.Core.Tests/Curation/Integration/Validation/ReferentialIntegrityConstraintTests.cs b/Rdmp.Core.Tests/Curation/Integration/Validation/ReferentialIntegrityConstraintTests.cs index 11b053c3df..0736fb0b00 100644 --- a/Rdmp.Core.Tests/Curation/Integration/Validation/ReferentialIntegrityConstraintTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/Validation/ReferentialIntegrityConstraintTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.Curation.Integration.Validation; -public class ReferentialIntegrityConstraintTests :DatabaseTests +public class ReferentialIntegrityConstraintTests : DatabaseTests { private ITableInfo _tableInfo; private ColumnInfo[] _columnInfo; @@ -25,23 +25,25 @@ protected override void OneTimeSetUp() { base.OneTimeSetUp(); - var tbl = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer).ExpectTable("ReferentialIntegrityConstraintTests"); + var tbl = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer) + .ExpectTable("ReferentialIntegrityConstraintTests"); - if(tbl.Exists()) + if (tbl.Exists()) tbl.Drop(); var server = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer).Server; - + using (var con = server.GetConnection()) { con.Open(); server.GetCommand("CREATE TABLE ReferentialIntegrityConstraintTests(MyValue int)", con).ExecuteNonQuery(); - server.GetCommand("INSERT INTO ReferentialIntegrityConstraintTests (MyValue) VALUES (5)", con).ExecuteNonQuery(); + server.GetCommand("INSERT INTO ReferentialIntegrityConstraintTests (MyValue) VALUES (5)", con) + .ExecuteNonQuery(); } var importer = new TableInfoImporter(CatalogueRepository, tbl); - importer.DoImport(out _tableInfo,out _columnInfo); + importer.DoImport(out _tableInfo, out _columnInfo); _constraint = new ReferentialIntegrityConstraint(CatalogueRepository) { @@ -61,11 +63,11 @@ public void NormalLogic(object value, bool expectFailure) var failure = _constraint.Validate(value, null, null); //if it did not fail validation and we expected failure - if(failure == null && expectFailure) + if (failure == null && expectFailure) Assert.Fail(); //or it did fail validation and we did not expect failure - if(failure != null && !expectFailure) + if (failure != null && !expectFailure) Assert.Fail(); Assert.Pass(); diff --git a/Rdmp.Core.Tests/Curation/Integration/Validation/StandardRegexTests.cs b/Rdmp.Core.Tests/Curation/Integration/Validation/StandardRegexTests.cs index 84d88fa562..3f71fb2c43 100644 --- a/Rdmp.Core.Tests/Curation/Integration/Validation/StandardRegexTests.cs +++ b/Rdmp.Core.Tests/Curation/Integration/Validation/StandardRegexTests.cs @@ -13,13 +13,14 @@ namespace Rdmp.Core.Tests.Curation.Integration.Validation; -public class StandardRegexTests:DatabaseTests +public class StandardRegexTests : DatabaseTests { [Test] public void CreateNew_UseConstraint() { // Clean SetUp any existing regexes - CatalogueRepository.GetAllObjects().Where(r=>r.ConceptName == "Fish").ToList().ForEach(r => r.DeleteInDatabase()); + CatalogueRepository.GetAllObjects().Where(r => r.ConceptName == "Fish").ToList() + .ForEach(r => r.DeleteInDatabase()); var regex = new StandardRegex(CatalogueRepository); try @@ -36,7 +37,7 @@ public void CreateNew_UseConstraint() CatalogueStandardRegex = regex }; - Assert.IsNull(constraint.Validate("Fish",null,null)); + Assert.IsNull(constraint.Validate("Fish", null, null)); var failure = constraint.Validate("FishFingers", null, null); Assert.IsNotNull(failure); } diff --git a/Rdmp.Core.Tests/Curation/JsonSerializationTests/JsonSerializationTests.cs b/Rdmp.Core.Tests/Curation/JsonSerializationTests/JsonSerializationTests.cs index 619100cbee..7793b3f28c 100644 --- a/Rdmp.Core.Tests/Curation/JsonSerializationTests/JsonSerializationTests.cs +++ b/Rdmp.Core.Tests/Curation/JsonSerializationTests/JsonSerializationTests.cs @@ -15,7 +15,7 @@ namespace Rdmp.Core.Tests.Curation.JsonSerializationTests; -public class JsonSerializationTests:DatabaseTests +public class JsonSerializationTests : DatabaseTests { [Test] public void TestSerialization_Catalogue() @@ -23,20 +23,21 @@ public void TestSerialization_Catalogue() if (CatalogueRepository is not TableRepository) Assert.Inconclusive("This test does not apply for non db repos"); - var c = new Catalogue(RepositoryLocator.CatalogueRepository,"Fish"); + var c = new Catalogue(RepositoryLocator.CatalogueRepository, "Fish"); var mySerializeable = new MySerializeableTestClass(new ShareManager(RepositoryLocator)) - { - SelectedCatalogue = c, - Title = "War and Pieces" - }; + { + SelectedCatalogue = c, + Title = "War and Pieces" + }; var dbConverter = new DatabaseEntityJsonConverter(RepositoryLocator); var lazyConverter = new PickAnyConstructorJsonConverter(RepositoryLocator); - var asString = JsonConvert.SerializeObject(mySerializeable, dbConverter,lazyConverter); - var mySerializeableAfter = (MySerializeableTestClass)JsonConvert.DeserializeObject(asString, typeof(MySerializeableTestClass), new JsonConverter[] { dbConverter, lazyConverter }); + var asString = JsonConvert.SerializeObject(mySerializeable, dbConverter, lazyConverter); + var mySerializeableAfter = (MySerializeableTestClass)JsonConvert.DeserializeObject(asString, + typeof(MySerializeableTestClass), new JsonConverter[] { dbConverter, lazyConverter }); Assert.AreNotEqual(mySerializeable, mySerializeableAfter); Assert.AreEqual(mySerializeable.SelectedCatalogue, mySerializeableAfter.SelectedCatalogue); @@ -44,14 +45,13 @@ public void TestSerialization_Catalogue() Assert.AreEqual("War and Pieces", mySerializeableAfter.Title); mySerializeableAfter.SelectedCatalogue.Name = "Cannon balls"; mySerializeableAfter.SelectedCatalogue.SaveToDatabase(); - + Assert.AreNotEqual(mySerializeable.SelectedCatalogue.Name, mySerializeableAfter.SelectedCatalogue.Name); } //todo null Catalogue test case } - - + public class MySerializeableTestClass { public string Title { get; set; } @@ -64,7 +64,7 @@ public MySerializeableTestClass(IRDMPPlatformRepositoryServiceLocator locator) { _sm = new ShareManager(locator); } - + public MySerializeableTestClass(ShareManager sm) { _sm = sm; diff --git a/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryTests.cs b/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryTests.cs index ce20e37f96..038dd4d822 100644 --- a/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryTests.cs +++ b/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryTests.cs @@ -43,7 +43,7 @@ public void TestMemoryRepository_QueryBuilder() { var memCatalogue = new Catalogue(_repo, "My New Catalogue"); - var myCol = new CatalogueItem(_repo,memCatalogue,"MyCol1"); + var myCol = new CatalogueItem(_repo, memCatalogue, "MyCol1"); var ti = new TableInfo(_repo, "My table"); var col = new ColumnInfo(_repo, "Mycol", "varchar(10)", ti); @@ -52,7 +52,7 @@ public void TestMemoryRepository_QueryBuilder() Assert.AreEqual(memCatalogue, _repo.GetObjectByID(memCatalogue.ID)); - var qb = new QueryBuilder(null,null); + var qb = new QueryBuilder(null, null); qb.AddColumnRange(memCatalogue.GetAllExtractionInformation(ExtractionCategory.Any)); Assert.AreEqual(@" diff --git a/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryVsDatabaseRepository.cs b/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryVsDatabaseRepository.cs index 490763a898..623cd20528 100644 --- a/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryVsDatabaseRepository.cs +++ b/Rdmp.Core.Tests/Curation/MemoryRepositoryTests/MemoryRepositoryVsDatabaseRepository.cs @@ -19,7 +19,7 @@ namespace Rdmp.Core.Tests.Curation.MemoryRepositoryTests; -internal class MemoryRepositoryVsDatabaseRepository:DatabaseTests +internal class MemoryRepositoryVsDatabaseRepository : DatabaseTests { [Test] public void TestMemoryVsDatabaseRepository_CatalogueConstructor() @@ -27,9 +27,9 @@ public void TestMemoryVsDatabaseRepository_CatalogueConstructor() var memoryRepository = new MemoryCatalogueRepository(CatalogueRepository); var memCatalogue = new Catalogue(memoryRepository, "My New Catalogue"); - var dbCatalogue = new Catalogue(CatalogueRepository,"My New Catalogue"); - - UnitTests.AssertAreEqual(memCatalogue,dbCatalogue); + var dbCatalogue = new Catalogue(CatalogueRepository, "My New Catalogue"); + + UnitTests.AssertAreEqual(memCatalogue, dbCatalogue); } [Test] @@ -44,7 +44,7 @@ public void TestMemoryVsDatabaseRepository_ProcessTaskConstructor() var memPt = new ProcessTask(memoryRepository, memLmd, LoadStage.AdjustRaw) { Name = "MyPt" }; var dbPt = new ProcessTask(CatalogueRepository, dbLmd, LoadStage.AdjustRaw) { Name = "MyPt" }; - + UnitTests.AssertAreEqual(memPt, dbPt); } @@ -62,17 +62,17 @@ public void TestMemoryRepository_AggregateConfigurationConstructor() UnitTests.AssertAreEqual(memAggregate, dbAggregate); } - + [Test] public void TestMemoryRepository_LiveLogging() { var memoryRepository = new MemoryCatalogueRepository(); - var loggingServer = new ExternalDatabaseServer(memoryRepository, "My Logging Server",null); + var loggingServer = new ExternalDatabaseServer(memoryRepository, "My Logging Server", null); memoryRepository.SetDefault(PermissableDefaults.LiveLoggingServer_ID, loggingServer); var memCatalogue = new Catalogue(memoryRepository, "My New Catalogue"); - Assert.AreEqual(memCatalogue.LiveLoggingServer_ID,loggingServer.ID); + Assert.AreEqual(memCatalogue.LiveLoggingServer_ID, loggingServer.ID); } [TestCase(DatabaseType.MicrosoftSQLServer)] @@ -87,7 +87,7 @@ public void TestImportingATable(DatabaseType dbType) dt.Columns.Add("So"); var db = GetCleanedServer(dbType); - var tbl = db.CreateTable("OmgTables",dt); + var tbl = db.CreateTable("OmgTables", dt); var memoryRepository = new MemoryCatalogueRepository(CatalogueRepository); @@ -95,26 +95,25 @@ public void TestImportingATable(DatabaseType dbType) importer1.DoImport(out var memTableInfo, out var memColumnInfos); var forwardEngineer1 = new ForwardEngineerCatalogue(memTableInfo, memColumnInfos); - forwardEngineer1.ExecuteForwardEngineering(out var memCatalogue, out var memCatalogueItems, out var memExtractionInformations); + forwardEngineer1.ExecuteForwardEngineering(out var memCatalogue, out var memCatalogueItems, + out var memExtractionInformations); var importerdb = new TableInfoImporter(CatalogueRepository, tbl, DataAccessContext.Any); importerdb.DoImport(out var dbTableInfo, out var dbColumnInfos); var forwardEngineer2 = new ForwardEngineerCatalogue(dbTableInfo, dbColumnInfos); - forwardEngineer2.ExecuteForwardEngineering(out var dbCatalogue, out var dbCatalogueItems, out var dbExtractionInformations); + forwardEngineer2.ExecuteForwardEngineering(out var dbCatalogue, out var dbCatalogueItems, + out var dbExtractionInformations); - UnitTests.AssertAreEqual(memCatalogue,dbCatalogue); - UnitTests.AssertAreEqual(memTableInfo,dbTableInfo); + UnitTests.AssertAreEqual(memCatalogue, dbCatalogue); + UnitTests.AssertAreEqual(memTableInfo, dbTableInfo); - UnitTests.AssertAreEqual(memCatalogue.CatalogueItems,dbCatalogue.CatalogueItems); - UnitTests.AssertAreEqual(memCatalogue.GetAllExtractionInformation(ExtractionCategory.Any), dbCatalogue.GetAllExtractionInformation(ExtractionCategory.Any)); - - UnitTests.AssertAreEqual(memCatalogue.CatalogueItems.Select(ci => ci.ColumnInfo), dbCatalogue.CatalogueItems.Select(ci => ci.ColumnInfo)); + UnitTests.AssertAreEqual(memCatalogue.CatalogueItems, dbCatalogue.CatalogueItems); + UnitTests.AssertAreEqual(memCatalogue.GetAllExtractionInformation(ExtractionCategory.Any), + dbCatalogue.GetAllExtractionInformation(ExtractionCategory.Any)); + UnitTests.AssertAreEqual(memCatalogue.CatalogueItems.Select(ci => ci.ColumnInfo), + dbCatalogue.CatalogueItems.Select(ci => ci.ColumnInfo)); } - - - - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/RefactoringTests/SelectSQLRefactorerTests.cs b/Rdmp.Core.Tests/Curation/RefactoringTests/SelectSQLRefactorerTests.cs index 8b85f69aad..d3fcc6575a 100644 --- a/Rdmp.Core.Tests/Curation/RefactoringTests/SelectSQLRefactorerTests.cs +++ b/Rdmp.Core.Tests/Curation/RefactoringTests/SelectSQLRefactorerTests.cs @@ -13,7 +13,7 @@ namespace Rdmp.Core.Tests.Curation.RefactoringTests; -public class SelectSQLRefactorerTests:UnitTests +public class SelectSQLRefactorerTests : UnitTests { [Test] public void RefactorTableName_TestValidReplacement_ColumnInfo() @@ -26,7 +26,7 @@ public void RefactorTableName_TestValidReplacement_ColumnInfo() tableInfo.Name = "[database]..[table]"; var refactorer = new SelectSQLRefactorer(); - SelectSQLRefactorer.RefactorTableName(columnInfo,tableInfo,"[database]..[table2]"); + SelectSQLRefactorer.RefactorTableName(columnInfo, tableInfo, "[database]..[table2]"); Assert.AreEqual("[database]..[table2].[column]", columnInfo.Name); } @@ -54,12 +54,17 @@ public void RefactorTableName_TestValidReplacement_ExtractionInformation() } [Test] - [TestCase("UPPER([database]..[table].[column])",true)] - [TestCase("dbo.MyScalarFunction([database]..[table].[column]) in Select(distinct [database]..[table].[column] from bob)", true)] + [TestCase("UPPER([database]..[table].[column])", true)] + [TestCase( + "dbo.MyScalarFunction([database]..[table].[column]) in Select(distinct [database]..[table].[column] from bob)", + true)] [TestCase("dbo.MyNewRand()", false)] - [TestCase("[dbo].MyScalarFunction([database]..[table].[column]) in Select(distinct [database]..[table].[column] from bob)", true)] + [TestCase( + "[dbo].MyScalarFunction([database]..[table].[column]) in Select(distinct [database]..[table].[column] from bob)", + true)] [TestCase("[dbo].MyNewRand()", false)] - public void RefactorTableName_IsRefactorable_ExtractionInformation(string transformSql,bool expectedToBeRefactorable) + public void RefactorTableName_IsRefactorable_ExtractionInformation(string transformSql, + bool expectedToBeRefactorable) { var ei = WhenIHaveA(); ei.SelectSQL = transformSql; @@ -76,16 +81,17 @@ public void RefactorTableName_IsRefactorable_ExtractionInformation(string transf tableInfo.SaveToDatabase(); var refactorer = new SelectSQLRefactorer(); - + Assert.AreEqual(expectedToBeRefactorable, SelectSQLRefactorer.IsRefactorable(ei)); if (expectedToBeRefactorable) SelectSQLRefactorer.RefactorTableName(ei, tableInfo, "[database]..[table2]"); else - Assert.Throws(() => SelectSQLRefactorer.RefactorTableName(ei, tableInfo, "[database]..[table2]")); + Assert.Throws(() => + SelectSQLRefactorer.RefactorTableName(ei, tableInfo, "[database]..[table2]")); } - [TestCase("[Fish]..[MyTbl]","[Fish]..[MyTbl2]")] + [TestCase("[Fish]..[MyTbl]", "[Fish]..[MyTbl2]")] public void RefactorTableName_IsRefactorable_TableInfoWithNoColumnInfos(string oldName, string newName) { var ti = WhenIHaveA(); @@ -93,32 +99,33 @@ public void RefactorTableName_IsRefactorable_TableInfoWithNoColumnInfos(string o ti.Database = "Fish"; ti.SaveToDatabase(); - foreach(IDeleteable d in ti.ColumnInfos) + foreach (IDeleteable d in ti.ColumnInfos) d.DeleteInDatabase(); var refactorer = new SelectSQLRefactorer(); Assert.IsTrue(SelectSQLRefactorer.IsRefactorable(ti)); - Assert.AreEqual(1,SelectSQLRefactorer.RefactorTableName(ti,newName)); - Assert.AreEqual(newName,ti.Name); + Assert.AreEqual(1, SelectSQLRefactorer.RefactorTableName(ti, newName)); + Assert.AreEqual(newName, ti.Name); } - [TestCase("[Donkey]..[MyTbl]","[Fish]..[MyTbl2]","'[Donkey]..[MyTbl]' has incorrect database propery 'Fish'")] - public void RefactorTableName_IsNotRefactorable_TableInfoWithNoColumnInfos(string oldName, string newName,string expectedReason) + [TestCase("[Donkey]..[MyTbl]", "[Fish]..[MyTbl2]", "'[Donkey]..[MyTbl]' has incorrect database propery 'Fish'")] + public void RefactorTableName_IsNotRefactorable_TableInfoWithNoColumnInfos(string oldName, string newName, + string expectedReason) { var ti = WhenIHaveA(); ti.Name = oldName; ti.Database = "Fish"; ti.SaveToDatabase(); - foreach(IDeleteable d in ti.ColumnInfos) + foreach (IDeleteable d in ti.ColumnInfos) d.DeleteInDatabase(); var refactorer = new SelectSQLRefactorer(); Assert.IsFalse(SelectSQLRefactorer.IsRefactorable(ti)); - var ex = Assert.Throws(()=>SelectSQLRefactorer.RefactorTableName(ti,newName)); - StringAssert.Contains(expectedReason,ex.Message); + var ex = Assert.Throws(() => SelectSQLRefactorer.RefactorTableName(ti, newName)); + StringAssert.Contains(expectedReason, ex.Message); } @@ -132,14 +139,14 @@ public void RefactorTableName_IsNotRefactorable_TableInfoWithNoColumnInfos(strin /// /// A column that belongs to which should be refactored even if its name isn't an exact match to the table name /// The table being renamed, will be renamed MyTbl to MyNewTbl - [TestCase("[Fish]..[MyTbl].[A]", "[Fish]..[MyTbl]")] - [TestCase("[Fish].[dbo].[MyTbl].[A]","[Fish]..[MyTbl]")] - [TestCase("[Fish]..[MyTbl].[A]", "[Fish].[dbo].[MyTbl]")] - [TestCase("[Fish].[dbo].[MyTbl].[A]","[Fish].[dbo].[MyTbl]")] - [TestCase("[Fish].dbo.[MyTbl].[A]", "[Fish]..[MyTbl]")] - [TestCase("[Fish]..[MyTbl].[A]", "[Fish].dbo.[MyTbl]")] - [TestCase("[Fish].dbo.[MyTbl].[A]", "[Fish].dbo.[MyTbl]")] - public void RefactorTableName_IsRefactorable_ColumnInfo(string columnName,string findTableName) + [TestCase("[Fish]..[MyTbl].[A]", "[Fish]..[MyTbl]")] + [TestCase("[Fish].[dbo].[MyTbl].[A]", "[Fish]..[MyTbl]")] + [TestCase("[Fish]..[MyTbl].[A]", "[Fish].[dbo].[MyTbl]")] + [TestCase("[Fish].[dbo].[MyTbl].[A]", "[Fish].[dbo].[MyTbl]")] + [TestCase("[Fish].dbo.[MyTbl].[A]", "[Fish]..[MyTbl]")] + [TestCase("[Fish]..[MyTbl].[A]", "[Fish].dbo.[MyTbl]")] + [TestCase("[Fish].dbo.[MyTbl].[A]", "[Fish].dbo.[MyTbl]")] + public void RefactorTableName_IsRefactorable_ColumnInfo(string columnName, string findTableName) { var col = WhenIHaveA(); col.Name = columnName; @@ -148,10 +155,10 @@ public void RefactorTableName_IsRefactorable_ColumnInfo(string columnName,string var refactorer = new SelectSQLRefactorer(); var oldName = findTableName; - var newName = oldName.Replace("MyTbl","MyNewTbl"); + var newName = oldName.Replace("MyTbl", "MyNewTbl"); - Assert.AreEqual(1, SelectSQLRefactorer.RefactorTableName(col,oldName,newName)); + Assert.AreEqual(1, SelectSQLRefactorer.RefactorTableName(col, oldName, newName)); - Assert.AreEqual($"{newName}.[A]",col.Name); + Assert.AreEqual($"{newName}.[A]", col.Name); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/SimpleExampleTests.cs b/Rdmp.Core.Tests/Curation/SimpleExampleTests.cs index 5bbc89f0fc..23b62713f2 100644 --- a/Rdmp.Core.Tests/Curation/SimpleExampleTests.cs +++ b/Rdmp.Core.Tests/Curation/SimpleExampleTests.cs @@ -23,7 +23,7 @@ public void Test1() Assert.IsTrue(cata.Exists()); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void Test2(DatabaseType type) { var database = GetCleanedServer(type); @@ -33,7 +33,7 @@ public void Test2(DatabaseType type) Assert.IsNotNull(database.GetRuntimeName()); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void TestReadDataLowPrivileges(DatabaseType type) { var database = GetCleanedServer(type); @@ -42,7 +42,7 @@ public void TestReadDataLowPrivileges(DatabaseType type) var dt = new DataTable(); dt.Columns.Add("MyCol"); dt.Rows.Add("Hi"); - dt.PrimaryKey = new[] {dt.Columns[0]}; + dt.PrimaryKey = new[] { dt.Columns[0] }; var tbl = database.CreateTable("MyTable", dt); @@ -55,7 +55,7 @@ public void TestReadDataLowPrivileges(DatabaseType type) Import(tbl, out var tableInfo, out var columnInfos); //setup credentials for the table in RDMP (this will be Inconclusive if you have not enabled it in TestDatabases.txt - SetupLowPrivilegeUserRightsFor(tableInfo,TestLowPrivilegePermissions.Reader); + SetupLowPrivilegeUserRightsFor(tableInfo, TestLowPrivilegePermissions.Reader); //request access to the database using DataLoad context var newDatabase = DataAccessPortal.ExpectDatabase(tableInfo, DataAccessContext.DataLoad); @@ -65,14 +65,14 @@ public void TestReadDataLowPrivileges(DatabaseType type) //the credentials should be different Assert.AreNotEqual(tbl.Database.Server.ExplicitUsernameIfAny, newTbl.Database.Server.ExplicitUsernameIfAny); - + //try re-reading the data Assert.AreEqual(1, newTbl.GetRowCount()); Assert.AreEqual(1, newTbl.DiscoverColumns().Length); Assert.IsTrue(newTbl.DiscoverColumn("MyCol").IsPrimaryKey); //low priority user shouldn't be able to drop tables - Assert.That(newTbl.Drop,Throws.Exception); + Assert.That(newTbl.Drop, Throws.Exception); //normal testing user should be able to tbl.Drop(); diff --git a/Rdmp.Core.Tests/Curation/Unit/AggregateConfigurationTests.cs b/Rdmp.Core.Tests/Curation/Unit/AggregateConfigurationTests.cs index 3ca439816d..aae025d9a3 100644 --- a/Rdmp.Core.Tests/Curation/Unit/AggregateConfigurationTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/AggregateConfigurationTests.cs @@ -39,16 +39,16 @@ public void TestStripZeroSeries_Nulls(bool includeZeroSeries) dt.Columns.Add("col1"); dt.Columns.Add("col2"); - dt.Rows.Add("2001",0, 12); - dt.Rows.Add("2002",null, 333); + dt.Rows.Add("2001", 0, 12); + dt.Rows.Add("2002", null, 333); UserSettings.IncludeZeroSeriesInGraphs = includeZeroSeries; AggregateConfiguration.AdjustGraphDataTable(dt); - if(includeZeroSeries) + if (includeZeroSeries) { - Assert.AreEqual(3,dt.Columns.Count); + Assert.AreEqual(3, dt.Columns.Count); } else { diff --git a/Rdmp.Core.Tests/Curation/Unit/CacheFetchRequestProviderTests.cs b/Rdmp.Core.Tests/Curation/Unit/CacheFetchRequestProviderTests.cs index 85c3560f67..455a6073a5 100644 --- a/Rdmp.Core.Tests/Curation/Unit/CacheFetchRequestProviderTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/CacheFetchRequestProviderTests.cs @@ -92,7 +92,7 @@ public void FailedCacheFetchRequest_SavesPreviousFailure() { var previousFailure = GetFailureMock(); - var cacheProgress = Mock.Of(c => c.PermissionWindow==Mock.Of()); + var cacheProgress = Mock.Of(c => c.PermissionWindow == Mock.Of()); var request = new CacheFetchRequest(previousFailure.Object, cacheProgress); request.RequestFailed(new Exception()); @@ -108,7 +108,7 @@ public void FailedCacheFetchRequest_ResolveCalled() { var previousFailure = GetFailureMock(); - var cacheProgress = Mock.Of(c => c.PermissionWindow==Mock.Of()); + var cacheProgress = Mock.Of(c => c.PermissionWindow == Mock.Of()); var request = new CacheFetchRequest(previousFailure.Object, cacheProgress); request.RequestSucceeded(); @@ -118,10 +118,10 @@ public void FailedCacheFetchRequest_ResolveCalled() private static Mock GetFailureMock() { - var failure = Mock.Of(f=> + var failure = Mock.Of(f => f.FetchRequestEnd == DateTime.Now && f.FetchRequestStart == DateTime.Now.Subtract(new TimeSpan(1, 0, 0))); - + return Mock.Get(failure); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/CatalogueNamingTests.cs b/Rdmp.Core.Tests/Curation/Unit/CatalogueNamingTests.cs index 9a3cc85c43..4771256035 100644 --- a/Rdmp.Core.Tests/Curation/Unit/CatalogueNamingTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/CatalogueNamingTests.cs @@ -12,7 +12,6 @@ namespace Rdmp.Core.Tests.Curation.Unit; [Category("Unit")] public class CatalogueNamingTests { - [Test] [TestCase("###")] [TestCase("Bob\\bob")] @@ -22,6 +21,7 @@ public void StupidCatalogueNames(string name) { Assert.IsFalse(Catalogue.IsAcceptableName(name)); } + [Test] [TestCase("Hi")] [TestCase("MyhExchiting dAtaset")] diff --git a/Rdmp.Core.Tests/Curation/Unit/CommitAssemblyTest.cs b/Rdmp.Core.Tests/Curation/Unit/CommitAssemblyTest.cs index 3f5ed549b7..27e6c4aa70 100644 --- a/Rdmp.Core.Tests/Curation/Unit/CommitAssemblyTest.cs +++ b/Rdmp.Core.Tests/Curation/Unit/CommitAssemblyTest.cs @@ -19,9 +19,10 @@ public void TestGetTypeByName() Console.Write(s.GetType().FullName); var t = Type.GetType(s.GetType().AssemblyQualifiedName); - - Assert.AreEqual(s.GetType(),t); + + Assert.AreEqual(s.GetType(), t); } + public enum ScheduleStrategy { NotSet, diff --git a/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestBiochemistryCreation.cs b/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestBiochemistryCreation.cs index e8ec4fae84..c5e48e64e4 100644 --- a/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestBiochemistryCreation.cs +++ b/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestBiochemistryCreation.cs @@ -23,9 +23,9 @@ public void CreateCSV(int numberOfRecords) { var r = new Random(500); var people = new PersonCollection(); - people.GeneratePeople(100,r); + people.GeneratePeople(100, r); - var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"DeleteMeTestBiochemistry.csv")); + var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "DeleteMeTestBiochemistry.csv")); var finished = false; var finishedWithRecords = -1; @@ -43,7 +43,8 @@ public void CreateCSV(int numberOfRecords) Assert.IsTrue(finished); Assert.AreEqual(numberOfRecords, finishedWithRecords); - Assert.GreaterOrEqual(File.ReadAllLines(f.FullName).Length, numberOfRecords);//can be newlines in middle of file + Assert.GreaterOrEqual(File.ReadAllLines(f.FullName).Length, + numberOfRecords); //can be newlines in middle of file Console.WriteLine($"Created file: {f.FullName}"); f.Delete(); diff --git a/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestDemographyCreation.cs b/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestDemographyCreation.cs index 31dda1346e..e1efc2deea 100644 --- a/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestDemographyCreation.cs +++ b/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestDemographyCreation.cs @@ -24,9 +24,9 @@ public void CreateCSV(int numberOfRecords) var r = new Random(500); var people = new PersonCollection(); - people.GeneratePeople(100,r); + people.GeneratePeople(100, r); - var f =new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"DeleteMeTestPeople.csv")); + var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "DeleteMeTestPeople.csv")); var finished = false; var finishedWithRecords = -1; @@ -46,9 +46,9 @@ public void CreateCSV(int numberOfRecords) Assert.IsTrue(finished); Assert.AreEqual(numberOfRecords, finishedWithRecords); - Assert.GreaterOrEqual(File.ReadAllLines(f.FullName).Length, numberOfRecords);//can be newlines in middle of file + Assert.GreaterOrEqual(File.ReadAllLines(f.FullName).Length, + numberOfRecords); //can be newlines in middle of file f.Delete(); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestPrescribingCreation.cs b/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestPrescribingCreation.cs index 6edfa1c68a..061fc37c31 100644 --- a/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestPrescribingCreation.cs +++ b/Rdmp.Core.Tests/Curation/Unit/ExerciseData/TestPrescribingCreation.cs @@ -25,9 +25,9 @@ public void CreateCSV(int numberOfRecords) var r = new Random(500); var people = new PersonCollection(); - people.GeneratePeople(100,r); + people.GeneratePeople(100, r); - var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"DeleteMeTestPrescribing.csv")); + var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "DeleteMeTestPrescribing.csv")); var finished = false; var finishedWithRecords = -1; @@ -45,9 +45,7 @@ public void CreateCSV(int numberOfRecords) Assert.IsTrue(finished); Assert.AreEqual(numberOfRecords, finishedWithRecords); - Assert.GreaterOrEqual(File.ReadLines(f.FullName).Count(), numberOfRecords);//can be newlines in middle of file + Assert.GreaterOrEqual(File.ReadLines(f.FullName).Count(), numberOfRecords); //can be newlines in middle of file f.Delete(); } - - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/IColumnTests.cs b/Rdmp.Core.Tests/Curation/Unit/IColumnTests.cs index f766ce0799..e1bcd87b02 100644 --- a/Rdmp.Core.Tests/Curation/Unit/IColumnTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/IColumnTests.cs @@ -21,16 +21,15 @@ namespace Rdmp.Core.Tests.Curation.Unit; [Category("Unit")] internal class IColumnTests { - /// /// For tests /// - private class TestColumn:SpontaneousObject,IColumn + private class TestColumn : SpontaneousObject, IColumn { - public TestColumn():base(new MemoryRepository()) + public TestColumn() : base(new MemoryRepository()) { - } + public string GetRuntimeName() { var helper = MicrosoftQuerySyntaxHelper.Instance; @@ -41,12 +40,12 @@ public string GetRuntimeName() public ColumnInfo ColumnInfo { get; private set; } public int Order { get; set; } - [Sql] - public string SelectSQL { get; set; } + [Sql] public string SelectSQL { get; set; } public string Alias { get; set; } public bool HashOnDataRelease { get; private set; } public bool IsExtractionIdentifier { get; private set; } public bool IsPrimaryKey { get; private set; } + public void Check(ICheckNotifier notifier) { new ColumnSyntaxChecker(this).Check(notifier); @@ -75,15 +74,14 @@ public void GetRuntimeName_IColumns_Pass() Alias = "test" }; - Assert.AreEqual(tc.GetRuntimeName(),"test"); + Assert.AreEqual(tc.GetRuntimeName(), "test"); tc.SelectSQL = "MangleQuery([mydb]..[myExcitingField])"; //still has Alias - Assert.AreEqual(tc.GetRuntimeName(),"test"); + Assert.AreEqual(tc.GetRuntimeName(), "test"); tc.Alias = null; - tc.SelectSQL = "[mydb]..[myExcitingField]"; + tc.SelectSQL = "[mydb]..[myExcitingField]"; Assert.AreEqual(tc.GetRuntimeName(), "myExcitingField"); - } [Test] @@ -94,7 +92,7 @@ public void GetRuntimeName_IColumns_ThrowBecauseMissingAliasOnScalarValueFunctio SelectSQL = "MangleQuery([mydb]..[myExcitingField])" }; - var ex = Assert.Throws(()=> tc.GetRuntimeName()); + var ex = Assert.Throws(() => tc.GetRuntimeName()); } @@ -111,7 +109,6 @@ public void CheckSyntax_IColumn_Valid() tc.Check(new ThrowImmediatelyCheckNotifier()); tc.Alias = "`[bob smith]`"; tc.Check(new ThrowImmediatelyCheckNotifier()); - } @@ -122,9 +119,8 @@ public void CheckSyntax_IColumn_ThrowBecauseInvalidAlias1() { Alias = "bob smith" }; - var ex = Assert.Throws(()=>tc.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Whitespace found in unwrapped Alias \"bob smith\"",ex.Message); - + var ex = Assert.Throws(() => tc.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual("Whitespace found in unwrapped Alias \"bob smith\"", ex.Message); } [Test] @@ -136,9 +132,9 @@ public void CheckSyntax_IColumn_ThrowBecauseInvalidAlias2() }; var ex = Assert.Throws(() => tc.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Invalid characters found in Alias \"`bob\"",ex.Message); - + Assert.AreEqual("Invalid characters found in Alias \"`bob\"", ex.Message); } + [Test] public void CheckSyntax_IColumn_ThrowBecauseInvalidAlias3() { @@ -147,12 +143,10 @@ public void CheckSyntax_IColumn_ThrowBecauseInvalidAlias3() Alias = "bob]" }; var ex = Assert.Throws(() => tc.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Invalid characters found in Alias \"bob]\"",ex.Message); - + Assert.AreEqual("Invalid characters found in Alias \"bob]\"", ex.Message); } - [Test] - + [Test] public void CheckSyntax_IColumn_ThrowBecauseInvalidSelectSQL() { var tc = new TestColumn @@ -161,6 +155,6 @@ public void CheckSyntax_IColumn_ThrowBecauseInvalidSelectSQL() SelectSQL = "GetSomething('here'" }; var ex = Assert.Throws(() => tc.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Mismatch in the number of opening '(' and closing ')'",ex.Message); + Assert.AreEqual("Mismatch in the number of opening '(' and closing ')'", ex.Message); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/IMightBeReadOnlyTests.cs b/Rdmp.Core.Tests/Curation/Unit/IMightBeReadOnlyTests.cs index e51262f3a4..a42e97f7b3 100644 --- a/Rdmp.Core.Tests/Curation/Unit/IMightBeReadOnlyTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/IMightBeReadOnlyTests.cs @@ -28,16 +28,16 @@ public void IsReadonly_AggregateFilterContainer() var cic = WhenIHaveA(); cic.Name = "fff"; cic.CreateRootContainerIfNotExists(); - cic.RootCohortAggregateContainer.AddChild(c.GetAggregate(),0); - + cic.RootCohortAggregateContainer.AddChild(c.GetAggregate(), 0); + Assert.IsFalse(c.ShouldBeReadOnly(out _)); cic.Frozen = true; Assert.IsTrue(c.ShouldBeReadOnly(out var reason)); - - Assert.AreEqual("fff is Frozen",reason); + + Assert.AreEqual("fff is Frozen", reason); } - + [Test] public void IsReadonly_ExtractionFilterContainer() { @@ -45,26 +45,26 @@ public void IsReadonly_ExtractionFilterContainer() Assert.IsFalse(c.ShouldBeReadOnly(out _)); var ec = c.GetSelectedDataSetIfAny().ExtractionConfiguration; - + Assert.IsFalse(c.ShouldBeReadOnly(out _)); ec.Name = "lll"; ec.IsReleased = true; Assert.IsTrue(c.ShouldBeReadOnly(out var reason)); - - Assert.AreEqual("lll has already been released",reason); + + Assert.AreEqual("lll has already been released", reason); } [Test] public void IsReadonly_SpontaneousContainer() { var memoryrepo = new MemoryCatalogueRepository(); - var c = new SpontaneouslyInventedFilterContainer(memoryrepo,null,null,FilterContainerOperation.AND); - Assert.IsFalse(c.ShouldBeReadOnly(out _),"Spont containers should never be in UI but let's not tell the programmer they shouldn't be edited"); + var c = new SpontaneouslyInventedFilterContainer(memoryrepo, null, null, FilterContainerOperation.AND); + Assert.IsFalse(c.ShouldBeReadOnly(out _), + "Spont containers should never be in UI but let's not tell the programmer they shouldn't be edited"); } - [Test] public void IsReadonly_AggregateFilter() { @@ -76,27 +76,27 @@ public void IsReadonly_AggregateFilter() var cic = WhenIHaveA(); cic.Name = "fff"; cic.CreateRootContainerIfNotExists(); - cic.RootCohortAggregateContainer.AddChild(f.GetAggregate(),0); - + cic.RootCohortAggregateContainer.AddChild(f.GetAggregate(), 0); + Assert.IsFalse(f.ShouldBeReadOnly(out _)); cic.Frozen = true; Assert.IsTrue(f.ShouldBeReadOnly(out var reason)); - - Assert.AreEqual("fff is Frozen",reason); + + Assert.AreEqual("fff is Frozen", reason); } - + [Test] public void IsReadonly_DeployedExtractionFilter() { var f = WhenIHaveA(); Assert.IsFalse(f.ShouldBeReadOnly(out _)); - var ec = ((FilterContainer) f.FilterContainer).GetSelectedDataSetIfAny().ExtractionConfiguration; + var ec = ((FilterContainer)f.FilterContainer).GetSelectedDataSetIfAny().ExtractionConfiguration; ec.Name = "lll"; ec.IsReleased = true; Assert.IsTrue(f.ShouldBeReadOnly(out var reason)); - - Assert.AreEqual("lll has already been released",reason); + + Assert.AreEqual("lll has already been released", reason); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/ObjectConstructorTests.cs b/Rdmp.Core.Tests/Curation/Unit/ObjectConstructorTests.cs index 23b923ecfb..6c478e6dab 100644 --- a/Rdmp.Core.Tests/Curation/Unit/ObjectConstructorTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/ObjectConstructorTests.cs @@ -20,12 +20,12 @@ public class ObjectConstructorTests : UnitTests [Test] public void ConstructValidTests() { - var constructor =new ObjectConstructor(); - var testarg = new TestArg {Text = "amagad"}; + var constructor = new ObjectConstructor(); + var testarg = new TestArg { Text = "amagad" }; var testarg2 = new TestArg2 { Text = "amagad" }; //anyone can construct on object! - ObjectConstructor.Construct(typeof(TestClass1),testarg); + ObjectConstructor.Construct(typeof(TestClass1), testarg); ObjectConstructor.Construct(typeof(TestClass1), testarg2); //basic case - identical Type parameter @@ -35,7 +35,8 @@ public void ConstructValidTests() ObjectConstructor.Construct(typeof(TestClass2), testarg2); //not allowed because class 3 explicitly requires a TestArg2 - Assert.Throws(()=> ObjectConstructor.Construct(typeof(TestClass3), testarg)); + Assert.Throws(() => + ObjectConstructor.Construct(typeof(TestClass3), testarg)); //allowed ObjectConstructor.Construct(typeof(TestClass3), testarg2); @@ -46,23 +47,24 @@ public void ConstructValidTests() var testarg3 = new TestArg3(); //not valid because there are 2 constructors that are both base classes of TestArg3 so ObjectConstructor doesn't know which to invoke - var ex = Assert.Throws(()=> ObjectConstructor.Construct(typeof (TestClass4), testarg3)); + var ex = Assert.Throws(() => + ObjectConstructor.Construct(typeof(TestClass4), testarg3)); Assert.IsTrue(ex.Message.Contains("Could not pick the correct constructor between")); //exactly the same as the above case but one constructor has been decorated with [UseWithObjectConstructor] attribute - ObjectConstructor.Construct(typeof (TestClass5), testarg3); + ObjectConstructor.Construct(typeof(TestClass5), testarg3); } [Test] public void ConstructIfPossibleTests_BlankConstructors() { var constructor = new ObjectConstructor(); - + //blank constructors are only used if no params are specified Assert.IsNotNull(ObjectConstructor.ConstructIfPossible(typeof(TestClassDefaultConstructor))); - + //no constructor taking an int - Assert.IsNull(ObjectConstructor.ConstructIfPossible(typeof(TestClassDefaultConstructor),8)); + Assert.IsNull(ObjectConstructor.ConstructIfPossible(typeof(TestClassDefaultConstructor), 8)); } [Test] @@ -72,9 +74,8 @@ public void GetRepositoryConstructor_AllDatabaseEntities_OneWinningConstructor() var countCompatible = 0; - var badTypes = new Dictionary(); + var badTypes = new Dictionary(); foreach (var t in MEF.GetAllTypes().Where(typeof(DatabaseEntity).IsAssignableFrom)) - { try { var oc = new ObjectConstructor(); @@ -83,25 +84,22 @@ public void GetRepositoryConstructor_AllDatabaseEntities_OneWinningConstructor() } catch (Exception e) { - badTypes.Add(t,e); + badTypes.Add(t, e); } - } Assert.IsEmpty(badTypes); - Assert.GreaterOrEqual(countCompatible,10); + Assert.GreaterOrEqual(countCompatible, 10); Console.WriteLine($"Found compatible constructors on {countCompatible} objects"); } private class TestClassDefaultConstructor { - } private class TestClass1 { public TestClass1(object o) { - } } @@ -148,6 +146,7 @@ public TestClass5(TestArg a) { A = a; } + [UseWithObjectConstructor] public TestClass5(TestArg2 a) { @@ -160,13 +159,11 @@ private class TestArg public string Text { get; set; } } - private class TestArg2:TestArg + private class TestArg2 : TestArg { - } private class TestArg3 : TestArg2 { - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/ParameterManagerTests.cs b/Rdmp.Core.Tests/Curation/Unit/ParameterManagerTests.cs index 8d4ce9899a..9544eae61a 100644 --- a/Rdmp.Core.Tests/Curation/Unit/ParameterManagerTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/ParameterManagerTests.cs @@ -19,13 +19,15 @@ public class ParameterManagerTests [Test] public void Test_ParameterManager_SimpleRename() { - var p1 = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here",MicrosoftQuerySyntaxHelper.Instance); - var p2 = new ConstantParameter("DECLARE @fish as int", "2", "fishes be here",MicrosoftQuerySyntaxHelper.Instance); + var p1 = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", + MicrosoftQuerySyntaxHelper.Instance); + var p2 = new ConstantParameter("DECLARE @fish as int", "2", "fishes be here", + MicrosoftQuerySyntaxHelper.Instance); var pm1 = new ParameterManager(); var pm2 = new ParameterManager(); var pm3 = new ParameterManager(); - + pm1.ParametersFoundSoFarInQueryGeneration[ParameterLevel.QueryLevel].Add(p1); pm2.ParametersFoundSoFarInQueryGeneration[ParameterLevel.QueryLevel].Add(p2); @@ -35,24 +37,26 @@ public void Test_ParameterManager_SimpleRename() var final = pm3.GetFinalResolvedParametersList().ToArray(); //the final composite parameters should have a rename in them - Assert.AreEqual("@fish",final[0].ParameterName); - Assert.AreEqual("@fish_2",final[1].ParameterName); + Assert.AreEqual("@fish", final[0].ParameterName); + Assert.AreEqual("@fish_2", final[1].ParameterName); Assert.IsEmpty(renames1); - Assert.AreEqual("@fish",renames2.Single().Key); - Assert.AreEqual("@fish_2",renames2.Single().Value); + Assert.AreEqual("@fish", renames2.Single().Key); + Assert.AreEqual("@fish_2", renames2.Single().Value); } [Test] - [TestCase(ParameterLevel.TableInfo,ParameterLevel.Global)] + [TestCase(ParameterLevel.TableInfo, ParameterLevel.Global)] [TestCase(ParameterLevel.QueryLevel, ParameterLevel.Global)] - [TestCase(ParameterLevel.TableInfo,ParameterLevel.CompositeQueryLevel)] - [TestCase(ParameterLevel.TableInfo,ParameterLevel.QueryLevel)] + [TestCase(ParameterLevel.TableInfo, ParameterLevel.CompositeQueryLevel)] + [TestCase(ParameterLevel.TableInfo, ParameterLevel.QueryLevel)] public void FindOverridenParameters_OneOnlyTest(ParameterLevel addAt, ParameterLevel overridingLevel) { - var myParameter = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here",MicrosoftQuerySyntaxHelper.Instance); - var overridingParameter = new ConstantParameter("DECLARE @fish as int", "999", "overriding value",MicrosoftQuerySyntaxHelper.Instance); + var myParameter = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", + MicrosoftQuerySyntaxHelper.Instance); + var overridingParameter = new ConstantParameter("DECLARE @fish as int", "999", "overriding value", + MicrosoftQuerySyntaxHelper.Instance); var pm = new ParameterManager(); pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Add(myParameter); @@ -63,19 +67,21 @@ public void FindOverridenParameters_OneOnlyTest(ParameterLevel addAt, ParameterL Assert.IsNull(pm.GetOverrideIfAnyFor(overridingParameter)); Assert.AreEqual(pm.GetOverrideIfAnyFor(myParameter), overridingParameter); - Assert.AreEqual(1,overrides.Length); + Assert.AreEqual(1, overrides.Length); Assert.AreEqual(myParameter, overrides[0]); var final = pm.GetFinalResolvedParametersList().ToArray(); Assert.AreEqual(1, final.Length); Assert.AreEqual(overridingParameter, final[0]); } - + [Test] public void FindOverridenParameters_CaseSensitivityTest() { - var baseParameter = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", MicrosoftQuerySyntaxHelper.Instance); - var overridingParameter = new ConstantParameter("DECLARE @Fish as int", "3", "overriding value", MicrosoftQuerySyntaxHelper.Instance); + var baseParameter = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", + MicrosoftQuerySyntaxHelper.Instance); + var overridingParameter = new ConstantParameter("DECLARE @Fish as int", "3", "overriding value", + MicrosoftQuerySyntaxHelper.Instance); var pm = new ParameterManager(); pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Add(baseParameter); @@ -86,17 +92,20 @@ public void FindOverridenParameters_CaseSensitivityTest() Assert.AreEqual(1, parameters.Length); var final = parameters.Single(); - Assert.AreEqual("@Fish",final.ParameterName); + Assert.AreEqual("@Fish", final.ParameterName); Assert.AreEqual("3", final.Value); } [Test] public void FindOverridenParameters_TwoTest() { - var myParameter1 = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here",MicrosoftQuerySyntaxHelper.Instance); - var myParameter2 = new ConstantParameter("DECLARE @fish as int", "2", "fishes be here",MicrosoftQuerySyntaxHelper.Instance); + var myParameter1 = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", + MicrosoftQuerySyntaxHelper.Instance); + var myParameter2 = new ConstantParameter("DECLARE @fish as int", "2", "fishes be here", + MicrosoftQuerySyntaxHelper.Instance); - var overridingParameter = new ConstantParameter("DECLARE @fish as int", "3", "overriding value",MicrosoftQuerySyntaxHelper.Instance); + var overridingParameter = new ConstantParameter("DECLARE @fish as int", "3", "overriding value", + MicrosoftQuerySyntaxHelper.Instance); var pm = new ParameterManager(); pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Add(myParameter1); @@ -114,14 +123,15 @@ public void FindOverridenParameters_TwoTest() Assert.AreEqual(myParameter2, overrides[1]); var final = pm.GetFinalResolvedParametersList().ToArray(); - Assert.AreEqual(1,final.Length); + Assert.AreEqual(1, final.Length); Assert.AreEqual(overridingParameter, final[0]); } [Test] public void ParameterDeclarationAndDeconstruction() { - var param = new ConstantParameter("DECLARE @Fish as int;","3","I've got a lovely bunch of coconuts",MicrosoftQuerySyntaxHelper.Instance); + var param = new ConstantParameter("DECLARE @Fish as int;", "3", "I've got a lovely bunch of coconuts", + MicrosoftQuerySyntaxHelper.Instance); var sql = QueryBuilder.GetParameterDeclarationSQL(param); Assert.AreEqual(@"/*I've got a lovely bunch of coconuts*/ @@ -131,9 +141,8 @@ public void ParameterDeclarationAndDeconstruction() var after = ConstantParameter.Parse(sql, MicrosoftQuerySyntaxHelper.Instance); - Assert.AreEqual(param.ParameterSQL,after.ParameterSQL); + Assert.AreEqual(param.ParameterSQL, after.ParameterSQL); Assert.AreEqual(param.Value, after.Value); Assert.AreEqual(param.Comment, after.Comment); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs b/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs index 7965abcc88..7681a46a28 100644 --- a/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs @@ -12,14 +12,14 @@ namespace Rdmp.Core.Tests.Curation.Unit; -public class PermissionWindowTests:DatabaseTests +public class PermissionWindowTests : DatabaseTests { - [Test] public void TestSerialisation() { - var period1 = new PermissionWindowPeriod((int) DayOfWeek.Monday, new TimeSpan(0, 0, 0), new TimeSpan(6, 0, 0)); - var period2 = new PermissionWindowPeriod((int) DayOfWeek.Monday, new TimeSpan(17, 0, 0), new TimeSpan(23, 59, 59)); + var period1 = new PermissionWindowPeriod((int)DayOfWeek.Monday, new TimeSpan(0, 0, 0), new TimeSpan(6, 0, 0)); + var period2 = + new PermissionWindowPeriod((int)DayOfWeek.Monday, new TimeSpan(17, 0, 0), new TimeSpan(23, 59, 59)); var permissionWindow = new PermissionWindow(CatalogueRepository); permissionWindow.SetPermissionWindowPeriods(new List @@ -39,14 +39,14 @@ public void TestSerialisation() Assert.AreEqual(2, periods.Count); var newPeriod1 = periods[0]; - Assert.AreEqual((int) DayOfWeek.Monday, newPeriod1.DayOfWeek); + Assert.AreEqual((int)DayOfWeek.Monday, newPeriod1.DayOfWeek); Assert.AreEqual(6, newPeriod1.End.Hours); var newPeriod2 = periods[1]; Assert.AreEqual(17, newPeriod2.Start.Hours); } - + [Test] public void TestCurrentlyWithinPermissionPeriod() { @@ -58,9 +58,10 @@ public void TestCurrentlyWithinPermissionPeriod() var fiveMinutes = new TimeSpan(0, 5, 0); var utcTime = new TimeSpan(dtNow.Hour, dtNow.Minute, dtNow.Second); - var period1 = new PermissionWindowPeriod((int)DateTime.UtcNow.DayOfWeek, utcTime.Subtract(fiveMinutes), utcTime.Add(fiveMinutes)); + var period1 = new PermissionWindowPeriod((int)DateTime.UtcNow.DayOfWeek, utcTime.Subtract(fiveMinutes), + utcTime.Add(fiveMinutes)); - var permissionWindow = new PermissionWindow(CatalogueRepository); + var permissionWindow = new PermissionWindow(CatalogueRepository); permissionWindow.SetPermissionWindowPeriods(new List { period1 }); Assert.IsTrue(permissionWindow.WithinPermissionWindow()); } @@ -75,7 +76,8 @@ public void TestCurrentlyOutsidePermissionPeriod() var oneMinute = new TimeSpan(0, 1, 0); var utcTime = new TimeSpan(dtNow.Hour, dtNow.Minute, dtNow.Second); - var period1 = new PermissionWindowPeriod((int)DateTime.Now.DayOfWeek, utcTime.Add(oneMinute), utcTime.Add(oneMinute)); + var period1 = + new PermissionWindowPeriod((int)DateTime.Now.DayOfWeek, utcTime.Add(oneMinute), utcTime.Add(oneMinute)); var permissionWindow = new PermissionWindow(CatalogueRepository); permissionWindow.SetPermissionWindowPeriods(new List { period1 }); diff --git a/Rdmp.Core.Tests/Curation/Unit/PreInitializeTests.cs b/Rdmp.Core.Tests/Curation/Unit/PreInitializeTests.cs index 743316d845..3ce90f2832 100644 --- a/Rdmp.Core.Tests/Curation/Unit/PreInitializeTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/PreInitializeTests.cs @@ -22,35 +22,33 @@ public class PreInitializeTests [Test] public void TestNormal() { - var fishUser = new FishUser(); Assert.AreNotEqual(fishUser.IFish, fish); - context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(),fishUser, fish); + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, fish); Assert.AreEqual(fishUser.IFish, fish); } [Test] public void TestOneOFMany() { - var fishUser = new FishUser(); - + Assert.AreNotEqual(fishUser.IFish, fish); - context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser,new object(), fish); + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, new object(), fish); Assert.AreEqual(fishUser.IFish, fish); } + [Test] public void TestCasting() { - var fishUser = new FishUser(); Assert.AreNotEqual(fishUser.IFish, fish); context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, (IFish)fish); Assert.AreEqual(fishUser.IFish, fish); } - + [Test] public void TestDownCasting() { @@ -61,11 +59,13 @@ public void TestDownCasting() context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, f); Assert.AreEqual(fishUser.IFish, fish); } + [Test] public void TestNoObjects() { var fishUser = new SpecificFishUser(); - var ex = Assert.Throws(()=>context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, Array.Empty())); + var ex = Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, Array.Empty())); Assert.IsTrue(ex.Message.Contains("The following expected types were not passed to PreInitialize:Fish")); } @@ -73,30 +73,28 @@ public void TestNoObjects() public void TestWrongObjects() { var fishUser = new SpecificFishUser(); - var ex = Assert.Throws(() => context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, new Penguin())); + var ex = Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), fishUser, new Penguin())); Assert.IsTrue(ex.Message.Contains("The following expected types were not passed to PreInitialize:Fish")); Assert.IsTrue(ex.Message.Contains("The object types passed were:")); Assert.IsTrue(ex.Message.Contains("Penguin")); } - - - private class FishUser:IPipelineRequirement, IDataFlowComponent + private class FishUser : IPipelineRequirement, IDataFlowComponent { public IFish IFish; public void PreInitialize(IFish value, IDataLoadEventListener listener) { IFish = value; - } + #region boiler plate + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, - GracefulCancellationToken cancellationToken) - { + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); - } public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -107,8 +105,10 @@ public void Abort(IDataLoadEventListener listener) { throw new NotImplementedException(); } + #endregion } + private class SpecificFishUser : IPipelineRequirement, IDataFlowComponent { public IFish IFish; @@ -116,14 +116,13 @@ private class SpecificFishUser : IPipelineRequirement, IDataFlowComponent< public void PreInitialize(Fish value, IDataLoadEventListener listener) { IFish = value; - } + #region boiler plate + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, - GracefulCancellationToken cancellationToken) - { + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); - } public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -134,25 +133,22 @@ public void Abort(IDataLoadEventListener listener) { throw new NotImplementedException(); } + #endregion } + private interface IFish { string GetFish(); } - private class Fish:IFish + private class Fish : IFish { - public string GetFish() - { - return "fish"; - } + public string GetFish() => "fish"; } + private class Penguin { - public static string GetPenguin() - { - return "Penguin"; - } + public static string GetPenguin() => "Penguin"; } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/Unit/SimpleColumnInfoTests.cs b/Rdmp.Core.Tests/Curation/Unit/SimpleColumnInfoTests.cs index 720a9e9ab0..15064a041d 100644 --- a/Rdmp.Core.Tests/Curation/Unit/SimpleColumnInfoTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/SimpleColumnInfoTests.cs @@ -16,7 +16,7 @@ namespace Rdmp.Core.Tests.Curation.Unit; public class SimpleColumnInfoTests : DatabaseTests { [Test] - [TestCase("varchar(5)",5)] + [TestCase("varchar(5)", 5)] [TestCase("int", -1)] [TestCase("datetime2", -1)] [TestCase("nchar(100)", 100)] @@ -32,8 +32,9 @@ public void GetColumnLength(string type, int? expectedLength) }); Import(t, out var ti, out var cis); - - Assert.AreEqual(expectedLength,cis.Single().Discover(DataAccessContext.InternalDataProcessing).DataType.GetLengthIfString()); + + Assert.AreEqual(expectedLength, + cis.Single().Discover(DataAccessContext.InternalDataProcessing).DataType.GetLengthIfString()); ti.DeleteInDatabase(); } diff --git a/Rdmp.Core.Tests/Curation/Unit/SqlSyntaxHelperTests.cs b/Rdmp.Core.Tests/Curation/Unit/SqlSyntaxHelperTests.cs index a6f50ac719..a313225bcd 100644 --- a/Rdmp.Core.Tests/Curation/Unit/SqlSyntaxHelperTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/SqlSyntaxHelperTests.cs @@ -18,17 +18,24 @@ public class SqlSyntaxHelperTests [Test] public void GetNullSubstituteTests() { - Assert.AreEqual("-999", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3)", true)); - Assert.AreEqual("-9999999999", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(10)", true)); - Assert.AreEqual("-99.9", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3,1)", true)); - Assert.AreEqual("-.9999", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(4,4)", true)); - - - Assert.AreEqual("999", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3)", false)); - Assert.AreEqual("9999999999", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(10)", false)); - Assert.AreEqual("99.9", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3,1)", false)); - Assert.AreEqual(".9999", PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(4,4)", false)); - + Assert.AreEqual("-999", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3)", true)); + Assert.AreEqual("-9999999999", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(10)", true)); + Assert.AreEqual("-99.9", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3,1)", true)); + Assert.AreEqual("-.9999", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(4,4)", true)); + + + Assert.AreEqual("999", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3)", false)); + Assert.AreEqual("9999999999", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(10)", false)); + Assert.AreEqual("99.9", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(3,1)", false)); + Assert.AreEqual(".9999", + PrimaryKeyCollisionResolver.GetNullSubstituteForComparisonsWithDataType("decimal(4,4)", false)); } [Test] @@ -36,10 +43,10 @@ public void SplitMethod() { var syntaxHelper = MicrosoftQuerySyntaxHelper.Instance; - syntaxHelper.SplitLineIntoOuterMostMethodAndContents("count(*)",out var method, out var contents); - - Assert.AreEqual("count",method); - Assert.AreEqual("*",contents); + syntaxHelper.SplitLineIntoOuterMostMethodAndContents("count(*)", out var method, out var contents); + + Assert.AreEqual("count", method); + Assert.AreEqual("*", contents); syntaxHelper.SplitLineIntoOuterMostMethodAndContents("count()", out method, out contents); diff --git a/Rdmp.Core.Tests/Curation/Unit/TestAcronymGeneration.cs b/Rdmp.Core.Tests/Curation/Unit/TestAcronymGeneration.cs index 010c442fd5..26b988e34a 100644 --- a/Rdmp.Core.Tests/Curation/Unit/TestAcronymGeneration.cs +++ b/Rdmp.Core.Tests/Curation/Unit/TestAcronymGeneration.cs @@ -12,9 +12,8 @@ namespace Rdmp.Core.Tests.Curation.Unit; public class TestAcronymGeneration : DatabaseTests { - [Test] - [TestCase("bob","bob")] + [TestCase("bob", "bob")] [TestCase("Demography", "Demog")] [TestCase("DMPCatalogue", "DMPC")] [TestCase("Datasheet1", "D1")] @@ -26,6 +25,6 @@ public void Predict(string name, string predictedAcronym) var suggestion = DitaCatalogueExtractor.GetAcronymSuggestionFromCatalogueName(name); - Assert.AreEqual(predictedAcronym,suggestion); + Assert.AreEqual(predictedAcronym, suggestion); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/Curation/UnitTestsAllObjectsSupported.cs b/Rdmp.Core.Tests/Curation/UnitTestsAllObjectsSupported.cs index e2e94b5e09..185b6391b7 100644 --- a/Rdmp.Core.Tests/Curation/UnitTestsAllObjectsSupported.cs +++ b/Rdmp.Core.Tests/Curation/UnitTestsAllObjectsSupported.cs @@ -18,7 +18,7 @@ namespace Rdmp.Core.Tests.Curation; -internal class UnitTestsAllObjectsSupported:UnitTests +internal class UnitTestsAllObjectsSupported : UnitTests { /// /// Who tests the tester? this method does! It makes sure that supports all classes (except @@ -29,20 +29,22 @@ public void TestAllSupported() { //load all DatabaseEntity types var mef = new MEF(); - mef.Setup(new SafeDirectoryCatalog(new IgnoreAllErrorsCheckNotifier(), TestContext.CurrentContext.TestDirectory)); + mef.Setup( + new SafeDirectoryCatalog(new IgnoreAllErrorsCheckNotifier(), TestContext.CurrentContext.TestDirectory)); var types = mef.GetAllTypes() - .Where(t => typeof (DatabaseEntity).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).ToArray(); + .Where(t => typeof(DatabaseEntity).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).ToArray(); var methods = typeof(UnitTests).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance); var method = methods.Single(m => m.Name.Equals("WhenIHaveA") && !m.GetParameters().Any()); var notSupported = new List(); - + foreach (var t in types) { //ignore these types too - if (SkipTheseTypes.Contains(t.Name) || t.Name.StartsWith("Spontaneous") || typeof(SpontaneousObject).IsAssignableFrom(t)) + if (SkipTheseTypes.Contains(t.Name) || t.Name.StartsWith("Spontaneous") || + typeof(SpontaneousObject).IsAssignableFrom(t)) continue; DatabaseEntity instance = null; @@ -63,20 +65,18 @@ public void TestAllSupported() //if the instance returned by MakeGenericMethod does not pass checks that's a dealbreaker! if (instance != null) - { try { //and that it returns an instance Assert.IsNotNull(instance); Assert.IsTrue(instance.Exists()); - Assert.AreEqual(ChangeDescription.NoChanges, instance.HasLocalChanges().Evaluation,"Type was '" + t.Name+"'"); + Assert.AreEqual(ChangeDescription.NoChanges, instance.HasLocalChanges().Evaluation, + "Type was '" + t.Name + "'"); } catch (Exception e) { - throw new Exception($"Implementation of WhenIHaveA<{t.Name}> is flawed",e); + throw new Exception($"Implementation of WhenIHaveA<{t.Name}> is flawed", e); } - } - } Assert.IsEmpty(notSupported, diff --git a/Rdmp.Core.Tests/Curation/YamlRepositoryTests.cs b/Rdmp.Core.Tests/Curation/YamlRepositoryTests.cs index 93eceeec8c..87c7964f99 100644 --- a/Rdmp.Core.Tests/Curation/YamlRepositoryTests.cs +++ b/Rdmp.Core.Tests/Curation/YamlRepositoryTests.cs @@ -30,7 +30,7 @@ public void BlankConstructorsForEveryone() { var sb = new StringBuilder(); - foreach(var t in new YamlRepository(GetUniqueDirectory()).GetCompatibleTypes()) + foreach (var t in new YamlRepository(GetUniqueDirectory()).GetCompatibleTypes()) { var blankConstructor = t.GetConstructor(Type.EmptyTypes); @@ -38,10 +38,9 @@ public void BlankConstructorsForEveryone() sb.AppendLine(t.Name); } - if(sb.Length > 0) - { - Assert.Fail($"All data classes must have a blank constructor. The following did not:{Environment.NewLine}{sb}"); - } + if (sb.Length > 0) + Assert.Fail( + $"All data classes must have a blank constructor. The following did not:{Environment.NewLine}{sb}"); } [Test] @@ -50,7 +49,7 @@ public void PersistDefaults() var dir = GetUniqueDirectory(); var repo1 = new YamlRepository(dir); - var eds = new ExternalDatabaseServer(repo1,"myServer",null); + var eds = new ExternalDatabaseServer(repo1, "myServer", null); repo1.SetDefault(PermissableDefaults.LiveLoggingServer_ID, eds); var repo2 = new YamlRepository(dir); @@ -83,7 +82,7 @@ public void PersistDataExportPropertyManagerValues() var dir = GetUniqueDirectory(); var repo1 = new YamlRepository(dir); - repo1.DataExportPropertyManager.SetValue(DataExportProperty.HashingAlgorithmPattern,"yarg"); + repo1.DataExportPropertyManager.SetValue(DataExportProperty.HashingAlgorithmPattern, "yarg"); // A fresh repo loaded from the same directory should have persisted object relationships var repo2 = new YamlRepository(dir); @@ -122,7 +121,7 @@ public void PersistForcedJoins() Assert.IsEmpty(ac.ForcedJoins); Assert.IsEmpty(repo1.AggregateForcedJoinManager.GetAllForcedJoinsFor(ac)); - repo1.AggregateForcedJoinManager.CreateLinkBetween(ac,t); + repo1.AggregateForcedJoinManager.CreateLinkBetween(ac, t); Assert.IsNotEmpty(ac.ForcedJoins); Assert.IsNotEmpty(repo1.AggregateForcedJoinManager.GetAllForcedJoinsFor(ac)); @@ -141,17 +140,17 @@ public void PersistCohortSubcontainers() var repo1 = new YamlRepository(dir); var root = UnitTests.WhenIHaveA(repo1); - var sub1 = new CohortAggregateContainer(repo1,SetOperation.INTERSECT); + var sub1 = new CohortAggregateContainer(repo1, SetOperation.INTERSECT); var ac = UnitTests.WhenIHaveA(repo1); - + sub1.Order = 2; sub1.SaveToDatabase(); - root.AddChild(sub1); + root.AddChild(sub1); root.AddChild(ac, 0); Assert.IsNotEmpty(root.GetOrderedContents()); - Assert.AreEqual(ac,root.GetOrderedContents().ToArray()[0]); + Assert.AreEqual(ac, root.GetOrderedContents().ToArray()[0]); Assert.AreEqual(sub1, root.GetOrderedContents().ToArray()[1]); // A fresh repo loaded from the same directory should have persisted object relationships @@ -175,10 +174,10 @@ public void PersistFilterContainers() var f = new AggregateFilter(repo1, "my filter"); ac.RootFilterContainer.AddChild(f); - var sub = new AggregateFilterContainer(repo1,FilterContainerOperation.AND); + var sub = new AggregateFilterContainer(repo1, FilterContainerOperation.AND); ac.RootFilterContainer.AddChild(sub); - Assert.AreEqual(sub,ac.RootFilterContainer.GetSubContainers().Single()); + Assert.AreEqual(sub, ac.RootFilterContainer.GetSubContainers().Single()); Assert.AreEqual(f, ac.RootFilterContainer.GetFilters().Single()); // A fresh repo loaded from the same directory should have persisted object relationships @@ -202,10 +201,10 @@ public void PersistFilterContainers_Orphans() var f = new AggregateFilter(repo1, "my filter"); ac.RootFilterContainer.AddChild(f); - var sub = new AggregateFilterContainer(repo1,FilterContainerOperation.AND); + var sub = new AggregateFilterContainer(repo1, FilterContainerOperation.AND); ac.RootFilterContainer.AddChild(sub); - Assert.AreEqual(sub,ac.RootFilterContainer.GetSubContainers().Single()); + Assert.AreEqual(sub, ac.RootFilterContainer.GetSubContainers().Single()); Assert.AreEqual(f, ac.RootFilterContainer.GetFilters().Single()); // A fresh repo loaded from the same directory should have persisted object relationships @@ -218,7 +217,8 @@ public void PersistFilterContainers_Orphans() // Make an orphan container by deleting the root // don't check before deleting stuff - ((CatalogueObscureDependencyFinder)ac.CatalogueRepository.ObscureDependencyFinder).OtherDependencyFinders.Clear(); + ((CatalogueObscureDependencyFinder)ac.CatalogueRepository.ObscureDependencyFinder).OtherDependencyFinders + .Clear(); // delete the root filter ac.RootFilterContainer.DeleteInDatabase(); @@ -230,7 +230,6 @@ public void PersistFilterContainers_Orphans() Assert.IsFalse(repo3.StillExists(sub)); Assert.IsFalse(repo3.StillExists(root)); Assert.IsFalse(repo3.StillExists(f)); - } [Test] @@ -243,15 +242,18 @@ public void PersistCredentials() var creds = UnitTests.WhenIHaveA(repo1); var t = UnitTests.WhenIHaveA(repo1); - Assert.IsEmpty(creds.GetAllTableInfosThatUseThis().SelectMany(v=>v.Value)); + Assert.IsEmpty(creds.GetAllTableInfosThatUseThis().SelectMany(v => v.Value)); Assert.IsNull(t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad)); - Assert.IsNull(t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing)); + Assert.IsNull( + t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing)); - repo1.TableInfoCredentialsManager.CreateLinkBetween(creds,t, ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad); + repo1.TableInfoCredentialsManager.CreateLinkBetween(creds, t, + ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad); - Assert.AreEqual(t,creds.GetAllTableInfosThatUseThis().SelectMany(v => v.Value).Single()); - Assert.AreEqual(creds,t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad)); - Assert.IsNull(t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing)); + Assert.AreEqual(t, creds.GetAllTableInfosThatUseThis().SelectMany(v => v.Value).Single()); + Assert.AreEqual(creds, t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad)); + Assert.IsNull( + t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing)); // A fresh repo loaded from the same directory should have persisted object relationships @@ -260,13 +262,11 @@ public void PersistCredentials() Assert.AreEqual(t, creds.GetAllTableInfosThatUseThis().SelectMany(v => v.Value).Single()); Assert.AreEqual(creds, t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad)); - Assert.IsNull(t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing)); - - + Assert.IsNull( + t.GetCredentialsIfExists(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing)); } - [Test] public void YamlRepository_LoadSavePluginClass() { @@ -289,8 +289,8 @@ public void YamlRepository_LoadSavePluginClass() lma1.SaveToDatabase(); lma2.Plugin.Name = "MyPlugin1.1.1.2.nupkg"; - lma2.Plugin.RdmpVersion = new Version(version);//the version of Rdmp.Core targetted (same as above) - lma2.Plugin.PluginVersion = new Version(1, 1, 1, 2);//the version of the plugin (higher) + lma2.Plugin.RdmpVersion = new Version(version); //the version of Rdmp.Core targetted (same as above) + lma2.Plugin.PluginVersion = new Version(1, 1, 1, 2); //the version of the plugin (higher) lma2.Plugin.SaveToDatabase(); lma2.SaveToDatabase(); @@ -339,13 +339,8 @@ public void TestYamlRepository_Save() Assert.AreEqual("ffff", repo2.AllObjects.OfType().Single().Name); } - private static string GetUniqueDirectoryName() - { - return Path.Combine(TestContext.CurrentContext.WorkDirectory, Guid.NewGuid().ToString().Replace("-", "")); - } + private static string GetUniqueDirectoryName() => Path.Combine(TestContext.CurrentContext.WorkDirectory, + Guid.NewGuid().ToString().Replace("-", "")); - private static DirectoryInfo GetUniqueDirectory() - { - return new DirectoryInfo(GetUniqueDirectoryName()); - } + private static DirectoryInfo GetUniqueDirectory() => new(GetUniqueDirectoryName()); } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/Cloning/CloneExtractionConfigurationTests.cs b/Rdmp.Core.Tests/DataExport/Cloning/CloneExtractionConfigurationTests.cs index a103204171..b7d777e376 100644 --- a/Rdmp.Core.Tests/DataExport/Cloning/CloneExtractionConfigurationTests.cs +++ b/Rdmp.Core.Tests/DataExport/Cloning/CloneExtractionConfigurationTests.cs @@ -18,9 +18,8 @@ namespace Rdmp.Core.Tests.DataExport.Cloning; -public class CloneExtractionConfigurationTests:TestsRequiringAnExtractionConfiguration +public class CloneExtractionConfigurationTests : TestsRequiringAnExtractionConfiguration { - [Test] [TestCase(false)] [TestCase(true)] @@ -37,13 +36,14 @@ public void CloneWithFilters(bool introduceOrphanExtractionInformation) //setup a filter with a parameter filter.WhereSQL = "Fish = @fish"; - new ParameterCreator(new ExtractionFilterFactory(_extractionInformations[0]), null, null).CreateAll(filter,null); + new ParameterCreator(new ExtractionFilterFactory(_extractionInformations[0]), null, null).CreateAll(filter, + null); filter.SaveToDatabase(); - Assert.IsTrue(filter.ExtractionFilterParameters.Count()==1); + Assert.IsTrue(filter.ExtractionFilterParameters.Count() == 1); //create a root container - var container = new FilterContainer(DataExportRepository); + var container = new FilterContainer(DataExportRepository); _selectedDataSet.RootFilterContainer_ID = container.ID; _selectedDataSet.SaveToDatabase(); @@ -58,7 +58,7 @@ public void CloneWithFilters(bool introduceOrphanExtractionInformation) param.Value = "'jormungander'"; param.SaveToDatabase(); - var request = new ExtractDatasetCommand(_configuration,new ExtractableDatasetBundle(_extractableDataSet)); + var request = new ExtractDatasetCommand(_configuration, new ExtractableDatasetBundle(_extractableDataSet)); request.GenerateQueryBuilder(); Assert.AreEqual( CollapseWhitespace( @@ -91,24 +91,22 @@ SELECT DISTINCT , CollapseWhitespace(request.QueryBuilder.SQL)); var deepClone = _configuration.DeepCloneWithNewIDs(); - Assert.AreEqual(deepClone.Cohort_ID,_configuration.Cohort_ID); - Assert.AreNotEqual(deepClone.ID,_configuration.ID); + Assert.AreEqual(deepClone.Cohort_ID, _configuration.Cohort_ID); + Assert.AreNotEqual(deepClone.ID, _configuration.ID); try { var request2 = new ExtractDatasetCommand(deepClone, new ExtractableDatasetBundle(_extractableDataSet)); request2.GenerateQueryBuilder(); - - Assert.AreEqual(request.QueryBuilder.SQL,request2.QueryBuilder.SQL); + Assert.AreEqual(request.QueryBuilder.SQL, request2.QueryBuilder.SQL); } finally { deepClone.DeleteInDatabase(); } } - finally + finally { - filter.DeleteInDatabase(); } } @@ -120,9 +118,9 @@ public void CloneWithExtractionProgress() var sds = _configuration.SelectedDataSets[0]; var ci = sds.GetCatalogue().CatalogueItems.First(); var origProgress = new ExtractionProgress(DataExportRepository, sds, null, DateTime.Now, 10, "fff drrr", ci.ID) - { - ProgressDate = new DateTime(2001, 01, 01) - }; + { + ProgressDate = new DateTime(2001, 01, 01) + }; origProgress.SaveToDatabase(); var deepClone = _configuration.DeepCloneWithNewIDs(); @@ -135,8 +133,9 @@ public void CloneWithExtractionProgress() Assert.IsNotNull(clonedProgress); Assert.IsNull(clonedProgress.StartDate); - Assert.IsNull(clonedProgress.ProgressDate, "Cloning a ExtractionProgress should reset its ProgressDate back to null in anticipation of it being extracted again"); - + Assert.IsNull(clonedProgress.ProgressDate, + "Cloning a ExtractionProgress should reset its ProgressDate back to null in anticipation of it being extracted again"); + Assert.AreEqual(clonedProgress.EndDate, origProgress.EndDate); Assert.AreEqual(clonedProgress.NumberOfDaysPerBatch, origProgress.NumberOfDaysPerBatch); Assert.AreEqual(clonedProgress.Name, origProgress.Name); @@ -159,8 +158,8 @@ public void IntroduceOrphan() using (var con = DataExportTableRepository.GetConnection()) { DataExportTableRepository.DiscoveredServer.GetCommand( - $"UPDATE ExtractableColumn set CatalogueExtractionInformation_ID = {int.MaxValue} where ID = {name.ID}", con).ExecuteNonQuery(); + $"UPDATE ExtractableColumn set CatalogueExtractionInformation_ID = {int.MaxValue} where ID = {name.ID}", + con).ExecuteNonQuery(); } - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/Cohort/CohortTests.cs b/Rdmp.Core.Tests/DataExport/Cohort/CohortTests.cs index d210acd62c..4f32a96364 100644 --- a/Rdmp.Core.Tests/DataExport/Cohort/CohortTests.cs +++ b/Rdmp.Core.Tests/DataExport/Cohort/CohortTests.cs @@ -23,11 +23,11 @@ public void TestOverridingReleaseIdentifier() //should match global release identifier (from its source because there is no override) Assert.AreEqual("ReleaseID", _extractableCohort.GetReleaseIdentifier(true)); - + //appy override _extractableCohort.OverrideReleaseIdentifierSQL = "Fish"; _extractableCohort.SaveToDatabase(); - + //should now match override Assert.AreEqual("Fish", _extractableCohort.GetReleaseIdentifier()); @@ -37,9 +37,8 @@ public void TestOverridingReleaseIdentifier() //now check that we are back to the original release identifier Assert.AreEqual("ReleaseID", _extractableCohort.GetReleaseIdentifier(true)); - } - + [Test] public void TestSelf_RecordAllFailures() { @@ -47,15 +46,14 @@ public void TestSelf_RecordAllFailures() failures.FailureMessages.Add("Hi there Thomas, How's it going?"); Assert.IsFalse(failures.AnyFailMessageLike("Carmageddon")); - + Assert.IsTrue(failures.AnyFailMessageLike("Thomas")); - Assert.IsTrue(failures.AnyFailMessageLike("Thomas","going")); + Assert.IsTrue(failures.AnyFailMessageLike("Thomas", "going")); Assert.IsTrue(failures.AnyFailMessageLike("Thomas", "going", "Hi")); Assert.IsTrue(failures.AnyFailMessageLike("thomas", "gOIng", "hi")); - Assert.IsFalse(failures.AnyFailMessageLike("Thomas", "going", "Hi","Fear the babadook")); - + Assert.IsFalse(failures.AnyFailMessageLike("Thomas", "going", "Hi", "Fear the babadook")); } private class RecordAllFailures : ICheckNotifier @@ -64,6 +62,7 @@ public RecordAllFailures() { FailureMessages = new List(); } + public List FailureMessages { get; set; } public bool AnyFailMessageLike(params string[] bitsTofind) @@ -72,8 +71,8 @@ public bool AnyFailMessageLike(params string[] bitsTofind) { var found = bitsTofind.Any(); - foreach(var s in bitsTofind) - if(!m.ToLower().Contains(s.ToLower())) + foreach (var s in bitsTofind) + if (!m.ToLower().Contains(s.ToLower())) found = false; return found; @@ -84,12 +83,11 @@ public bool AnyFailMessageLike(params string[] bitsTofind) public bool OnCheckPerformed(CheckEventArgs args) { - if(args.Result == CheckResult.Fail) + if (args.Result == CheckResult.Fail) FailureMessages.Add(args.Message); //accept all proposed changes return true; } } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/Cohort/CommittingNewCohortsTests.cs b/Rdmp.Core.Tests/DataExport/Cohort/CommittingNewCohortsTests.cs index ad5f2567e1..42bda521c5 100644 --- a/Rdmp.Core.Tests/DataExport/Cohort/CommittingNewCohortsTests.cs +++ b/Rdmp.Core.Tests/DataExport/Cohort/CommittingNewCohortsTests.cs @@ -35,7 +35,7 @@ protected override void SetUp() filename = Path.Combine(TestContext.CurrentContext.TestDirectory, "CommittingNewCohorts.csv"); - var sw = new StreamWriter(filename); + var sw = new StreamWriter(filename); sw.WriteLine("PrivateID,ReleaseID,SomeHeader"); sw.WriteLine("Priv_1111,Pub_1111,Smile buddy"); sw.WriteLine("Priv_2222,Pub_2222,Your on tv"); @@ -49,9 +49,13 @@ public void CommittingNewCohortFile_IDPopulated_Throws() { var proj = new Project(DataExportRepository, projName); - var request = new CohortCreationRequest(proj, new CohortDefinition(511, "CommittingNewCohorts",1,999,_externalCohortTable), DataExportRepository, "fish"); - var ex = Assert.Throws(()=>request.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Expected the cohort definition CommittingNewCohorts(Version 1, ID=511) to have a null ID - we are trying to create this, why would it already exist?",ex.Message); + var request = new CohortCreationRequest(proj, + new CohortDefinition(511, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, + "fish"); + var ex = Assert.Throws(() => request.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual( + "Expected the cohort definition CommittingNewCohorts(Version 1, ID=511) to have a null ID - we are trying to create this, why would it already exist?", + ex.Message); } [Test] @@ -59,20 +63,27 @@ public void CommittingNewCohortFile_ProjectNumberNumberMissing() { var proj = new Project(DataExportRepository, projName); - var request = new CohortCreationRequest(proj, new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, "fish"); - var ex = Assert.Throws(()=>request.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Project MyProj does not have a ProjectNumber specified, it should have the same number as the CohortCreationRequest (999)",ex.Message); + var request = new CohortCreationRequest(proj, + new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, + "fish"); + var ex = Assert.Throws(() => request.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual( + "Project MyProj does not have a ProjectNumber specified, it should have the same number as the CohortCreationRequest (999)", + ex.Message); } [Test] public void CommittingNewCohortFile_ProjectNumberMismatch() { - var proj = new Project(DataExportRepository, projName) {ProjectNumber = 321}; + var proj = new Project(DataExportRepository, projName) { ProjectNumber = 321 }; proj.SaveToDatabase(); - var request = new CohortCreationRequest(proj, new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, "fish"); - var ex = Assert.Throws(()=>request.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Project MyProj has ProjectNumber=321 but the CohortCreationRequest.ProjectNumber is 999",ex.Message); + var request = new CohortCreationRequest(proj, + new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, + "fish"); + var ex = Assert.Throws(() => request.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual("Project MyProj has ProjectNumber=321 but the CohortCreationRequest.ProjectNumber is 999", + ex.Message); } [Test] @@ -86,26 +97,30 @@ public void CommittingNewCohortFile_CallPipeline() }; proj.SaveToDatabase(); - var request = new CohortCreationRequest(proj, new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, "fish"); + var request = new CohortCreationRequest(proj, + new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable), DataExportRepository, + "fish"); request.Check(new ThrowImmediatelyCheckNotifier()); var source = new DelimitedFlatFileDataFlowSource(); var destination = new BasicCohortDestination(); - + source.Separator = ","; source.StronglyTypeInput = true; - var pipeline = new DataFlowPipelineEngine((DataFlowPipelineContext) request.GetContext(),source,destination,listener); - pipeline.Initialize(new FlatFileToLoad(new FileInfo(filename)),request); + var pipeline = new DataFlowPipelineEngine((DataFlowPipelineContext)request.GetContext(), + source, destination, listener); + pipeline.Initialize(new FlatFileToLoad(new FileInfo(filename)), request); pipeline.ExecutePipeline(new GracefulCancellationToken()); //there should be a new ExtractableCohort now Assert.NotNull(request.NewCohortDefinition.ID); - var ec = DataExportRepository.GetAllObjects().Single(c => c.OriginID == request.NewCohortDefinition.ID); + var ec = DataExportRepository.GetAllObjects() + .Single(c => c.OriginID == request.NewCohortDefinition.ID); //with the data in it from the test file - Assert.AreEqual(ec.Count,3); + Assert.AreEqual(ec.Count, 3); } [TestCase(true)] @@ -187,7 +202,7 @@ public void MigrateUsages(bool migrate) ec1.SaveToDatabase(); // legit user 2 - var ec2 = new ExtractionConfiguration(DataExportRepository,proj) + var ec2 = new ExtractionConfiguration(DataExportRepository, proj) { IsReleased = false, Cohort_ID = cohort998.ID @@ -195,10 +210,10 @@ public void MigrateUsages(bool migrate) ec2.SaveToDatabase(); // has no cohort yet defined so should not be migrated - var ec3 = new ExtractionConfiguration(DataExportRepository,proj); + var ec3 = new ExtractionConfiguration(DataExportRepository, proj); // is frozen so should not be migrated - var ec4 = new ExtractionConfiguration(DataExportRepository,proj) + var ec4 = new ExtractionConfiguration(DataExportRepository, proj) { IsReleased = true, Cohort_ID = cohort998.ID @@ -225,7 +240,7 @@ public void MigrateUsages(bool migrate) // should have been updated to use the new cohort Assert.AreEqual(ec1.Cohort_ID, migrate ? cohort999.ID : cohort998.ID); - Assert.AreEqual(ec2.Cohort_ID, migrate ? cohort999.ID: cohort998.ID); + Assert.AreEqual(ec2.Cohort_ID, migrate ? cohort999.ID : cohort998.ID); // should not have magically gotten a cohort Assert.IsNull(ec3.Cohort_ID); diff --git a/Rdmp.Core.Tests/DataExport/Cohort/ProjectConsistentGuidReleaseIdentifierAllocatorTests.cs b/Rdmp.Core.Tests/DataExport/Cohort/ProjectConsistentGuidReleaseIdentifierAllocatorTests.cs index 475f4d169e..7b6f2c1f39 100644 --- a/Rdmp.Core.Tests/DataExport/Cohort/ProjectConsistentGuidReleaseIdentifierAllocatorTests.cs +++ b/Rdmp.Core.Tests/DataExport/Cohort/ProjectConsistentGuidReleaseIdentifierAllocatorTests.cs @@ -18,7 +18,7 @@ namespace Rdmp.Core.Tests.DataExport.Cohort; -internal class ProjectConsistentGuidReleaseIdentifierAllocatorTests:DatabaseTests +internal class ProjectConsistentGuidReleaseIdentifierAllocatorTests : DatabaseTests { [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] @@ -26,21 +26,24 @@ public void TestPreserveHistoricalReleaseIdentifiers(DatabaseType databaseType) { var db = GetCleanedServer(databaseType); - var privateIdentifierDataType = db.Server.GetQuerySyntaxHelper().TypeTranslater.GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string),10)); + var privateIdentifierDataType = db.Server.GetQuerySyntaxHelper().TypeTranslater + .GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string), 10)); - var wizard = new CreateNewCohortDatabaseWizard(db,CatalogueRepository,DataExportRepository,false); - var ect = wizard.CreateDatabase(new PrivateIdentifierPrototype("chi", privateIdentifierDataType),new AcceptAllCheckNotifier()); + var wizard = new CreateNewCohortDatabaseWizard(db, CatalogueRepository, DataExportRepository, false); + var ect = wizard.CreateDatabase(new PrivateIdentifierPrototype("chi", privateIdentifierDataType), + new AcceptAllCheckNotifier()); var defTable = ect.DiscoverDefinitionTable(); var cohortTable = ect.DiscoverCohortTable(); - var p = new Project(DataExportRepository,"MyProject") + var p = new Project(DataExportRepository, "MyProject") { ProjectNumber = 10 }; p.SaveToDatabase(); - var req = new CohortCreationRequest(p,new CohortDefinition(null,"TestCohort1",1,p.ProjectNumber.Value,ect),DataExportRepository,"Ignoreme"); + var req = new CohortCreationRequest(p, new CohortDefinition(null, "TestCohort1", 1, p.ProjectNumber.Value, ect), + DataExportRepository, "Ignoreme"); var allocator = new ProjectConsistentGuidReleaseIdentifierAllocator(); allocator.Initialize(req); @@ -48,50 +51,50 @@ public void TestPreserveHistoricalReleaseIdentifiers(DatabaseType databaseType) //allocator is being asked to allocate when there are no cohorts at all defined Assert.AreEqual(0, defTable.GetRowCount()); Assert.IsNotNull(allocator.AllocateReleaseIdentifier("0101010101")); - + //Now let's define a cohort identifier for someone (0202020202) who is not in our project defTable.Insert(new Dictionary { - {"projectNumber", 11}, //project is not our project - {"version", 1}, - {"description","flibble"} + { "projectNumber", 11 }, //project is not our project + { "version", 1 }, + { "description", "flibble" } }); - Assert.AreEqual(1,defTable.GetRowCount()); + Assert.AreEqual(1, defTable.GetRowCount()); cohortTable.Insert(new Dictionary { - {ect.GetQuerySyntaxHelper().GetRuntimeName(ect.DefinitionTableForeignKeyField), 1}, - {"chi", "0202020202"}, - {"ReleaseId", "0x0123"} + { ect.GetQuerySyntaxHelper().GetRuntimeName(ect.DefinitionTableForeignKeyField), 1 }, + { "chi", "0202020202" }, + { "ReleaseId", "0x0123" } }); - + //recreate allocator to clear map allocator = new ProjectConsistentGuidReleaseIdentifierAllocator(); allocator.Initialize(req); //allocator is being asked to allocate when there are cohorts defined including one with our person 02020202 but that person was in a different project Assert.AreEqual(1, defTable.GetRowCount()); - Assert.AreEqual(1,cohortTable.GetRowCount()); + Assert.AreEqual(1, cohortTable.GetRowCount()); Assert.IsNotNull(allocator.AllocateReleaseIdentifier("0202020202")); - Assert.AreNotEqual("0x0123",allocator.AllocateReleaseIdentifier("0202020202")); + Assert.AreNotEqual("0x0123", allocator.AllocateReleaseIdentifier("0202020202")); //Now let's define a cohort identifier for someone (0202020202) who IS in our project defTable.Insert(new Dictionary { - {"projectNumber", 10}, //this is our project number! - {"version", 1}, - {"description","flibble"} + { "projectNumber", 10 }, //this is our project number! + { "version", 1 }, + { "description", "flibble" } }); Assert.AreEqual(2, defTable.GetRowCount()); cohortTable.Insert(new Dictionary { - {ect.GetQuerySyntaxHelper().GetRuntimeName(ect.DefinitionTableForeignKeyField), 2}, - {"chi", "0202020202"}, - {"ReleaseId", "0x0127"} + { ect.GetQuerySyntaxHelper().GetRuntimeName(ect.DefinitionTableForeignKeyField), 2 }, + { "chi", "0202020202" }, + { "ReleaseId", "0x0127" } }); //recreate allocator to clear map @@ -109,18 +112,18 @@ public void TestPreserveHistoricalReleaseIdentifiers(DatabaseType databaseType) //let's pretend that previously we had already got 2 historical batches for the project, batch 1 released 0202020202 as 0x0127 (see above) and batch 2 released 0202020202 as 0x0128 defTable.Insert(new Dictionary { - {"projectNumber", 10}, //this is our project number! - {"version", 2}, - {"description","flibble"} + { "projectNumber", 10 }, //this is our project number! + { "version", 2 }, + { "description", "flibble" } }); Assert.AreEqual(3, defTable.GetRowCount()); cohortTable.Insert(new Dictionary { - {ect.GetQuerySyntaxHelper().GetRuntimeName(ect.DefinitionTableForeignKeyField), 3}, - {"chi", "0202020202"}, - {"ReleaseId", "0x0128"} + { ect.GetQuerySyntaxHelper().GetRuntimeName(ect.DefinitionTableForeignKeyField), 3 }, + { "chi", "0202020202" }, + { "ReleaseId", "0x0128" } }); //recreate allocator to clear map @@ -134,14 +137,15 @@ public void TestPreserveHistoricalReleaseIdentifiers(DatabaseType databaseType) var ex = Assert.Throws(() => allocator.AllocateReleaseIdentifier("0202020202")); //should be complaining about both of these conflicting release identifiers existing - StringAssert.Contains("0x0127",ex.Message); + StringAssert.Contains("0x0127", ex.Message); StringAssert.Contains("0x0128", ex.Message); //fix the problem using (var con = db.Server.GetConnection()) { con.Open(); - db.Server.GetCommand($"UPDATE {cohortTable} SET ReleaseId='0x0127' WHERE ReleaseId='0x0128'", con).ExecuteScalar(); + db.Server.GetCommand($"UPDATE {cohortTable} SET ReleaseId='0x0127' WHERE ReleaseId='0x0128'", con) + .ExecuteScalar(); } //should be happy now again @@ -149,7 +153,5 @@ public void TestPreserveHistoricalReleaseIdentifiers(DatabaseType databaseType) Assert.AreEqual(3, cohortTable.GetRowCount()); Assert.IsNotNull(allocator.AllocateReleaseIdentifier("0202020202")); Assert.AreEqual("0x0127", allocator.AllocateReleaseIdentifier("0202020202")); - } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/ConfigurationPropertiesTests.cs b/Rdmp.Core.Tests/DataExport/ConfigurationPropertiesTests.cs index feac45748e..b22e9e50e9 100644 --- a/Rdmp.Core.Tests/DataExport/ConfigurationPropertiesTests.cs +++ b/Rdmp.Core.Tests/DataExport/ConfigurationPropertiesTests.cs @@ -14,12 +14,14 @@ public class ConfigurationPropertiesTests : DatabaseTests { [Test] public void CreateNewArgumentAndGetValue() - { + { DataExportRepository.DataExportPropertyManager.SetValue(DataExportProperty.HashingAlgorithmPattern, "hi"); - Assert.AreEqual(DataExportRepository.DataExportPropertyManager.GetValue(DataExportProperty.HashingAlgorithmPattern), "hi"); + Assert.AreEqual( + DataExportRepository.DataExportPropertyManager.GetValue(DataExportProperty.HashingAlgorithmPattern), "hi"); //make sure delete DataExportRepository.DataExportPropertyManager.SetValue(DataExportProperty.HashingAlgorithmPattern, null); - Assert.AreEqual(DataExportRepository.DataExportPropertyManager.GetValue(DataExportProperty.HashingAlgorithmPattern), null); + Assert.AreEqual( + DataExportRepository.DataExportPropertyManager.GetValue(DataExportProperty.HashingAlgorithmPattern), null); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/CustomData/CustomDataImportingTests.cs b/Rdmp.Core.Tests/DataExport/CustomData/CustomDataImportingTests.cs index 08e176abbd..6edcdcc971 100644 --- a/Rdmp.Core.Tests/DataExport/CustomData/CustomDataImportingTests.cs +++ b/Rdmp.Core.Tests/DataExport/CustomData/CustomDataImportingTests.cs @@ -35,8 +35,9 @@ public void Extract_ProjectSpecificCatalogue_WholeDataset() try { - _request = new ExtractDatasetCommand(_configuration,new ExtractableDatasetBundle(CustomExtractableDataSet)); - Execute(out ExtractionPipelineUseCase useCase, out var results); + _request = new ExtractDatasetCommand(_configuration, + new ExtractableDatasetBundle(CustomExtractableDataSet)); + Execute(out var useCase, out var results); var customDataCsv = results.DirectoryPopulated.GetFiles().Single(f => f.Name.Equals("custTable99.csv")); @@ -44,10 +45,9 @@ public void Extract_ProjectSpecificCatalogue_WholeDataset() var lines = File.ReadAllLines(customDataCsv.FullName); - Assert.AreEqual("SuperSecretThing,ReleaseID",lines[0]); - Assert.AreEqual("monkeys can all secretly fly,Pub_54321",lines[1]); - Assert.AreEqual("the wizard of OZ was a man behind a machine,Pub_11ftw",lines[2]); - + Assert.AreEqual("SuperSecretThing,ReleaseID", lines[0]); + Assert.AreEqual("monkeys can all secretly fly,Pub_54321", lines[1]); + Assert.AreEqual("the wizard of OZ was a man behind a machine,Pub_11ftw", lines[2]); } finally { @@ -70,37 +70,41 @@ public void Extract_ProjectSpecificCatalogue_AppendedColumn() pipe.Name = "Extract_ProjectSpecificCatalogue_AppendedColumn Pipe"; pipe.SaveToDatabase(); - var extraColumn = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific).Single(e => e.GetRuntimeName().Equals("SuperSecretThing")); - var asExtractable = new ExtractableColumn(DataExportRepository, _extractableDataSet, _configuration, extraColumn, 10,extraColumn.SelectSQL); + var extraColumn = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific) + .Single(e => e.GetRuntimeName().Equals("SuperSecretThing")); + var asExtractable = new ExtractableColumn(DataExportRepository, _extractableDataSet, _configuration, + extraColumn, 10, extraColumn.SelectSQL); //get rid of any lingering joins foreach (var j in CatalogueRepository.GetAllObjects()) j.DeleteInDatabase(); //add the ability to join the two tables in the query - var idCol = _extractableDataSet.Catalogue.GetAllExtractionInformation(ExtractionCategory.Core).Single(c => c.IsExtractionIdentifier).ColumnInfo; - var otherIdCol = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific).Single(e => e.GetRuntimeName().Equals("PrivateID")).ColumnInfo; - new JoinInfo(CatalogueRepository,idCol, otherIdCol,ExtractionJoinType.Left,null); + var idCol = _extractableDataSet.Catalogue.GetAllExtractionInformation(ExtractionCategory.Core) + .Single(c => c.IsExtractionIdentifier).ColumnInfo; + var otherIdCol = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific) + .Single(e => e.GetRuntimeName().Equals("PrivateID")).ColumnInfo; + new JoinInfo(CatalogueRepository, idCol, otherIdCol, ExtractionJoinType.Left, null); //generate a new request (this will include the newly created column) - _request = new ExtractDatasetCommand( _configuration, new ExtractableDatasetBundle(_extractableDataSet)); + _request = new ExtractDatasetCommand(_configuration, new ExtractableDatasetBundle(_extractableDataSet)); var tbl = Database.ExpectTable("TestTable"); tbl.Truncate(); - using(var blk = tbl.BeginBulkInsert()) + using (var blk = tbl.BeginBulkInsert()) { var dt = new DataTable(); dt.Columns.Add("PrivateID"); dt.Columns.Add("Name"); dt.Columns.Add("DateOfBirth"); - dt.Rows.Add(new object[] {"Priv_12345", "Bob","2001-01-01"}); - dt.Rows.Add(new object[] {"Priv_wtf11", "Frank","2001-10-29"}); + dt.Rows.Add(new object[] { "Priv_12345", "Bob", "2001-01-01" }); + dt.Rows.Add(new object[] { "Priv_wtf11", "Frank", "2001-10-29" }); blk.Upload(dt); } - Execute(out ExtractionPipelineUseCase useCase, out var results); + Execute(out var useCase, out var results); var mainDataTableCsv = results.DirectoryPopulated.GetFiles().Single(f => f.Name.Equals("TestTable.csv")); @@ -139,9 +143,9 @@ public void Extract_ProjectSpecificCatalogue_FilterReference() _selectedDataSet.SaveToDatabase(); var filter = new DeployedExtractionFilter(DataExportRepository, "monkeys only", rootContainer) - { - WhereSQL = "SuperSecretThing = 'monkeys can all secretly fly'" - }; + { + WhereSQL = "SuperSecretThing = 'monkeys can all secretly fly'" + }; filter.SaveToDatabase(); rootContainer.AddChild(filter); @@ -150,14 +154,16 @@ public void Extract_ProjectSpecificCatalogue_FilterReference() j.DeleteInDatabase(); //add the ability to join the two tables in the query - var idCol = _extractableDataSet.Catalogue.GetAllExtractionInformation(ExtractionCategory.Core).Single(c => c.IsExtractionIdentifier).ColumnInfo; - var otherIdCol = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific).Single(e => e.GetRuntimeName().Equals("PrivateID")).ColumnInfo; - new JoinInfo(CatalogueRepository,idCol, otherIdCol, ExtractionJoinType.Left, null); + var idCol = _extractableDataSet.Catalogue.GetAllExtractionInformation(ExtractionCategory.Core) + .Single(c => c.IsExtractionIdentifier).ColumnInfo; + var otherIdCol = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific) + .Single(e => e.GetRuntimeName().Equals("PrivateID")).ColumnInfo; + new JoinInfo(CatalogueRepository, idCol, otherIdCol, ExtractionJoinType.Left, null); new SelectedDataSetsForcedJoin(DataExportRepository, _selectedDataSet, CustomTableInfo); //generate a new request (this will include the newly created column) - _request = new ExtractDatasetCommand( _configuration, new ExtractableDatasetBundle(_extractableDataSet)); + _request = new ExtractDatasetCommand(_configuration, new ExtractableDatasetBundle(_extractableDataSet)); var tbl = Database.ExpectTable("TestTable"); tbl.Truncate(); @@ -174,7 +180,7 @@ public void Extract_ProjectSpecificCatalogue_FilterReference() blk.Upload(dt); } - Execute(out ExtractionPipelineUseCase useCase, out var results); + Execute(out var useCase, out var results); var mainDataTableCsv = results.DirectoryPopulated.GetFiles().Single(f => f.Name.Equals("TestTable.csv")); @@ -184,16 +190,13 @@ public void Extract_ProjectSpecificCatalogue_FilterReference() Assert.AreEqual("ReleaseID,Name,DateOfBirth", lines[0]); Assert.AreEqual("Pub_54321,Bob,2001-01-01", lines[1]); - Assert.AreEqual(2,lines.Length); - - + Assert.AreEqual(2, lines.Length); } - /* private List _customTablesToCleanup = new List(); - + [Test] public void CSVImportPipeline() { @@ -205,7 +208,7 @@ public void CSVImportPipeline() engine.ExecutePipeline(new GracefulCancellationToken()); var customTableNames = _extractableCohort.GetCustomTableNames().ToArray(); - + Console.WriteLine("Found the following custom tables:"); foreach (string tableName in customTableNames) Console.WriteLine(tableName); @@ -234,7 +237,7 @@ public void IterativeBatchLoadingTest(int numberOfBatches) var engine = GetEnginePointedAtFile("fish.txt"); ToMemoryDataLoadEventListener listener = new ToMemoryDataLoadEventListener(true); - + Random r = new Random(); var token = new GracefulCancellationTokenSource(); @@ -255,9 +258,9 @@ public void IterativeBatchLoadingTest(int numberOfBatches) engine.Source.Dispose(new ThrowImmediatelyDataLoadEventListener(),null ); engine.Destination.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); - //batches are 1 record each so + //batches are 1 record each so Assert.AreEqual(numberOfBatches, listener.LastProgressRecieivedByTaskName["Comitting rows to cohort 99_unitTestDataForCohort_V1fish"].Progress.Value); - + var customTableNames = _extractableCohort.GetCustomTableNames().ToArray(); Console.WriteLine("Found the following custom tables:"); foreach (string tableName in customTableNames) diff --git a/Rdmp.Core.Tests/DataExport/Data/ExternalCohortTableTests.cs b/Rdmp.Core.Tests/DataExport/Data/ExternalCohortTableTests.cs index d1b643e69c..b2e956db2e 100644 --- a/Rdmp.Core.Tests/DataExport/Data/ExternalCohortTableTests.cs +++ b/Rdmp.Core.Tests/DataExport/Data/ExternalCohortTableTests.cs @@ -15,7 +15,7 @@ namespace Rdmp.Core.Tests.DataExport.Data; -internal class ExternalCohortTableTests:UnitTests +internal class ExternalCohortTableTests : UnitTests { /// /// Demonstrates the minimum properties required to create a . See @@ -26,19 +26,19 @@ public void Create_ExternalCohortTable_Manually() { var repository = new MemoryDataExportRepository(); var table = new ExternalCohortTable(repository, "My Cohort Database", DatabaseType.MicrosoftSQLServer) - { - Database = "mydb", - PrivateIdentifierField = "chi", - ReleaseIdentifierField = "release", - DefinitionTableForeignKeyField = "c_id", - TableName = "Cohorts", - DefinitionTableName = "InventoryTable", - Server = "superfastdatabaseserver\\sqlexpress" - }; + { + Database = "mydb", + PrivateIdentifierField = "chi", + ReleaseIdentifierField = "release", + DefinitionTableForeignKeyField = "c_id", + TableName = "Cohorts", + DefinitionTableName = "InventoryTable", + Server = "superfastdatabaseserver\\sqlexpress" + }; table.SaveToDatabase(); - var ex = Assert.Throws(()=>table.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Could not connect to Cohort database called 'My Cohort Database'",ex.Message); + var ex = Assert.Throws(() => table.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual("Could not connect to Cohort database called 'My Cohort Database'", ex.Message); } /// @@ -48,7 +48,7 @@ public void Create_ExternalCohortTable_Manually() public void Create_ExternalCohortTable_InTests() { var tbl = WhenIHaveA(); - + Assert.IsNotNull(tbl); Assert.IsNotNull(tbl.PrivateIdentifierField); Assert.IsNotNull(tbl.ReleaseIdentifierField); @@ -57,7 +57,8 @@ public void Create_ExternalCohortTable_InTests() [Test] public void TestExternalCohortTableProperties_BasicValues() { - var table = new ExternalCohortTable(RepositoryLocator.DataExportRepository,"ffff",DatabaseType.MicrosoftSQLServer); + var table = new ExternalCohortTable(RepositoryLocator.DataExportRepository, "ffff", + DatabaseType.MicrosoftSQLServer); Assert.IsNull(table.Database); Assert.IsNull(table.Server); @@ -73,19 +74,21 @@ public void TestExternalCohortTableProperties_BasicValues() table.ReleaseIdentifierField = "rel"; table.DefinitionTableForeignKeyField = "fk"; - Assert.AreEqual("mydb",table.Database); - Assert.AreEqual("myserver",table.Server); - Assert.AreEqual("[mydb]..[mytbl]",table.TableName); + Assert.AreEqual("mydb", table.Database); + Assert.AreEqual("myserver", table.Server); + Assert.AreEqual("[mydb]..[mytbl]", table.TableName); Assert.IsNull(table.DefinitionTableName); - Assert.AreEqual("[mydb]..[mytbl].[priv]",table.PrivateIdentifierField); - Assert.AreEqual("[mydb]..[mytbl].[rel]",table.ReleaseIdentifierField); - Assert.AreEqual("[mydb]..[mytbl].[fk]",table.DefinitionTableForeignKeyField); + Assert.AreEqual("[mydb]..[mytbl].[priv]", table.PrivateIdentifierField); + Assert.AreEqual("[mydb]..[mytbl].[rel]", table.ReleaseIdentifierField); + Assert.AreEqual("[mydb]..[mytbl].[fk]", table.DefinitionTableForeignKeyField); } + [Test] public void TestExternalCohortTableProperties_SetFullValues() { - var table = new ExternalCohortTable(RepositoryLocator.DataExportRepository,"ffff",DatabaseType.MicrosoftSQLServer); + var table = new ExternalCohortTable(RepositoryLocator.DataExportRepository, "ffff", + DatabaseType.MicrosoftSQLServer); Assert.IsNull(table.Database); Assert.IsNull(table.Server); @@ -101,13 +104,13 @@ public void TestExternalCohortTableProperties_SetFullValues() table.Server = "myserver"; table.TableName = "[mydb]..[mytbl]"; - Assert.AreEqual("mydb",table.Database); - Assert.AreEqual("myserver",table.Server); - Assert.AreEqual("[mydb]..[mytbl]",table.TableName); + Assert.AreEqual("mydb", table.Database); + Assert.AreEqual("myserver", table.Server); + Assert.AreEqual("[mydb]..[mytbl]", table.TableName); Assert.IsNull(table.DefinitionTableName); - Assert.AreEqual("[mydb]..[mytbl].[priv]",table.PrivateIdentifierField); - Assert.AreEqual("[mydb]..[mytbl].[rel]",table.ReleaseIdentifierField); - Assert.AreEqual("[mydb]..[mytbl].[fk]",table.DefinitionTableForeignKeyField); + Assert.AreEqual("[mydb]..[mytbl].[priv]", table.PrivateIdentifierField); + Assert.AreEqual("[mydb]..[mytbl].[rel]", table.ReleaseIdentifierField); + Assert.AreEqual("[mydb]..[mytbl].[fk]", table.DefinitionTableForeignKeyField); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortAuditLogBuilderTests.cs b/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortAuditLogBuilderTests.cs index 9654625ccd..0bda53fcf7 100644 --- a/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortAuditLogBuilderTests.cs +++ b/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortAuditLogBuilderTests.cs @@ -46,7 +46,7 @@ public void AuditLogReFetch_CohortIdentificationConfiguration() Assert.IsNotNull(cic2); Assert.IsInstanceOf(cic2); - Assert.AreEqual(cic,cic2); + Assert.AreEqual(cic, cic2); } [Test] @@ -72,6 +72,7 @@ public void AuditLogReFetch_WhenAuditLogIsNull() var moqCohort = Mock.Of(e => e.AuditLog == null); Assert.IsNull(builder.GetObjectIfAny(moqCohort, RepositoryLocator)); } + [Test] public void AuditLogReFetch_WhenAuditLogIsRubbish() { @@ -89,10 +90,10 @@ public void AuditLogReFetch_WhenSourceIsDeleted() var desc = ExtractableCohortAuditLogBuilder.GetDescription(ei); var moqCohort = Mock.Of(e => e.AuditLog == desc); - + // delete the source ei.DeleteInDatabase(); - + // should now return null Assert.IsNull(builder.GetObjectIfAny(moqCohort, RepositoryLocator)); } diff --git a/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortTests.cs b/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortTests.cs index cca51e956f..6839416933 100644 --- a/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortTests.cs +++ b/Rdmp.Core.Tests/DataExport/Data/ExtractableCohortTests.cs @@ -20,7 +20,7 @@ public void TestExtractableCohort_Identifiable() var cohort = _extractableCohort; Assert.IsNotNull(cohort.GetPrivateIdentifier()); - Assert.AreNotEqual(cohort.GetReleaseIdentifier(),cohort.GetPrivateIdentifier()); + Assert.AreNotEqual(cohort.GetReleaseIdentifier(), cohort.GetPrivateIdentifier()); var ect = cohort.ExternalCohortTable; ect.ReleaseIdentifierField = ect.PrivateIdentifierField; @@ -28,13 +28,15 @@ public void TestExtractableCohort_Identifiable() UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable, CheckResult.Fail); - var ex = Assert.Throws(()=>cohort.GetReleaseIdentifier()); + var ex = Assert.Throws(() => cohort.GetReleaseIdentifier()); - Assert.AreEqual("R004 PrivateIdentifierField and ReleaseIdentifierField are the same, this means your cohort will extract identifiable data (no cohort identifier substitution takes place)", ex.Message); + Assert.AreEqual( + "R004 PrivateIdentifierField and ReleaseIdentifierField are the same, this means your cohort will extract identifiable data (no cohort identifier substitution takes place)", + ex.Message); UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable, CheckResult.Warning); - Assert.AreEqual(cohort.GetReleaseIdentifier(),cohort.GetPrivateIdentifier()); + Assert.AreEqual(cohort.GetReleaseIdentifier(), cohort.GetPrivateIdentifier()); UserSettings.SetErrorReportingLevelFor(ErrorCodes.ExtractionIsIdentifiable, CheckResult.Fail); } diff --git a/Rdmp.Core.Tests/DataExport/Data/ExtractionProgressTests.cs b/Rdmp.Core.Tests/DataExport/Data/ExtractionProgressTests.cs index 21f41fb587..2388273b6b 100644 --- a/Rdmp.Core.Tests/DataExport/Data/ExtractionProgressTests.cs +++ b/Rdmp.Core.Tests/DataExport/Data/ExtractionProgressTests.cs @@ -17,7 +17,6 @@ namespace Rdmp.Core.Tests.DataExport.Data; internal class ExtractionProgressTests : TestsRequiringAnExtractionConfiguration { - [Test] public void ExtractionProgressConstructor_NoTimePeriodicity() { @@ -25,18 +24,19 @@ public void ExtractionProgressConstructor_NoTimePeriodicity() var eds = new ExtractableDataSet(DataExportRepository, cata); var project = new Project(DataExportRepository, "My Proj"); var config = new ExtractionConfiguration(DataExportRepository, project); - var sds = new SelectedDataSets(DataExportRepository, config,eds,null); - - var ex = Assert.Throws(()=> new ExtractionProgress(DataExportRepository, sds)); - Assert.AreEqual("Cannot create ExtractionProgress because Catalogue MyCata does not have a time coverage column", ex.Message); + var sds = new SelectedDataSets(DataExportRepository, config, eds, null); + var ex = Assert.Throws(() => new ExtractionProgress(DataExportRepository, sds)); + Assert.AreEqual( + "Cannot create ExtractionProgress because Catalogue MyCata does not have a time coverage column", + ex.Message); } [Test] public void ExtractionProgressConstructor_Normal() { ExtractionProgress progress = null; - Assert.DoesNotThrow(()=> progress = CreateAnExtractionProgress()); + Assert.DoesNotThrow(() => progress = CreateAnExtractionProgress()); progress?.DeleteInDatabase(); } @@ -86,14 +86,15 @@ public void ExtractionProgress_RetrySave() Assert.AreEqual(freshCopy.Retry, RetryStrategy.IterativeBackoff1Hour); progress.DeleteInDatabase(); - } + [Test] public void TestQueryGeneration_FirstBatch() { Reset(); - _catalogue.TimeCoverage_ExtractionInformation_ID = _extractionInformations.Single(e => e.GetRuntimeName().Equals("DateOfBirth")).ID; + _catalogue.TimeCoverage_ExtractionInformation_ID = + _extractionInformations.Single(e => e.GetRuntimeName().Equals("DateOfBirth")).ID; _catalogue.SaveToDatabase(); var progress = new ExtractionProgress(DataExportRepository, _request.SelectedDataSets) @@ -112,7 +113,9 @@ public void TestQueryGeneration_FirstBatch() var fileContents = File.ReadAllText(result.OutputFile); // Headers should be in file because it is a first batch - Assert.AreEqual($"ReleaseID,Name,DateOfBirth{Environment.NewLine}Pub_54321,Dave,2001-01-01{Environment.NewLine}", fileContents); + Assert.AreEqual( + $"ReleaseID,Name,DateOfBirth{Environment.NewLine}Pub_54321,Dave,2001-01-01{Environment.NewLine}", + fileContents); File.Delete(result.OutputFile); progress.DeleteInDatabase(); @@ -142,15 +145,13 @@ public void TestCloneResetsProgress() // should be different instances Assert.AreNotSame(origProgress, cloneProgress); - Assert.AreEqual(cloneProgress.StartDate , new DateTime(2001, 01, 01)); - Assert.IsNull(cloneProgress.ProgressDate,"Expected progress to be reset on clone"); - Assert.AreEqual(cloneProgress.EndDate , new DateTime(2020, 01, 01)); + Assert.AreEqual(cloneProgress.StartDate, new DateTime(2001, 01, 01)); + Assert.IsNull(cloneProgress.ProgressDate, "Expected progress to be reset on clone"); + Assert.AreEqual(cloneProgress.EndDate, new DateTime(2020, 01, 01)); } - private ExtractionProgress CreateAnExtractionProgress() - { - return CreateAnExtractionProgress(out _); - } + private ExtractionProgress CreateAnExtractionProgress() => CreateAnExtractionProgress(out _); + private ExtractionProgress CreateAnExtractionProgress(out ExtractionConfiguration config) { var cata = new Catalogue(CatalogueRepository, "MyCata"); @@ -166,7 +167,7 @@ private ExtractionProgress CreateAnExtractionProgress(out ExtractionConfiguratio var project = new Project(DataExportRepository, "My Proj"); config = new ExtractionConfiguration(DataExportRepository, project); var sds = new SelectedDataSets(DataExportRepository, config, eds, null); - + return new ExtractionProgress(DataExportRepository, sds); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/Data/SelectedDataSetsCheckerTests.cs b/Rdmp.Core.Tests/DataExport/Data/SelectedDataSetsCheckerTests.cs index 9e0a382e7d..f28422ff1f 100644 --- a/Rdmp.Core.Tests/DataExport/Data/SelectedDataSetsCheckerTests.cs +++ b/Rdmp.Core.Tests/DataExport/Data/SelectedDataSetsCheckerTests.cs @@ -18,7 +18,6 @@ namespace Rdmp.Core.Tests.DataExport.Data; public class SelectedDataSetsCheckerTests : TestsRequiringAnExtractionConfiguration { - [Test] public void NormalUseCasePasses() { @@ -33,7 +32,8 @@ public void TestExtractionProgress_MidwayWithNoAuditRecord() // normal checks pass var checker = new SelectedDataSetsChecker(new ThrowImmediatelyActivator(RepositoryLocator), _selectedDataSet); - var ep = new ExtractionProgress(DataExportRepository, _selectedDataSet, new DateTime(1990, 1, 1), new DateTime(2001, 1, 1),100,"mybatch", + var ep = new ExtractionProgress(DataExportRepository, _selectedDataSet, new DateTime(1990, 1, 1), + new DateTime(2001, 1, 1), 100, "mybatch", _extractionInformations[0].ID) { ProgressDate = new DateTime(1995, 1, 1) // we are half way through @@ -41,8 +41,10 @@ public void TestExtractionProgress_MidwayWithNoAuditRecord() ep.SaveToDatabase(); - var ex = Assert.Throws(()=>checker.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("R0016 ExtractionProgress 'mybatch' is 'in progress' (ProgressDate is not null) but there is no audit of previously extracted SQL (needed for checking cohort changes)", ex.Message); + var ex = Assert.Throws(() => checker.Check(new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual( + "R0016 ExtractionProgress 'mybatch' is 'in progress' (ProgressDate is not null) but there is no audit of previously extracted SQL (needed for checking cohort changes)", + ex.Message); } [Test] @@ -51,12 +53,10 @@ public void TestExtractionProgress_AuditRecordHasDifferentCohort() // normal checks pass var checker = new SelectedDataSetsChecker(new ThrowImmediatelyActivator(RepositoryLocator), _selectedDataSet); - foreach (var r in DataExportRepository.GetAllObjects()) - { - r.DeleteInDatabase(); - } + foreach (var r in DataExportRepository.GetAllObjects()) r.DeleteInDatabase(); - var ep = new ExtractionProgress(DataExportRepository, _selectedDataSet, new DateTime(1990, 1, 1), new DateTime(2001, 1, 1), 100, "mybatch", + var ep = new ExtractionProgress(DataExportRepository, _selectedDataSet, new DateTime(1990, 1, 1), + new DateTime(2001, 1, 1), 100, "mybatch", _extractionInformations[0].ID) { ProgressDate = new DateTime(1995, 1, 1) // we are half way through @@ -65,13 +65,16 @@ public void TestExtractionProgress_AuditRecordHasDifferentCohort() ep.SaveToDatabase(); // audit has SQL that does not contain the cohort ID - var audit = new CumulativeExtractionResults(DataExportRepository, _configuration, _selectedDataSet.ExtractableDataSet, "select * from [yohoho and a bottle of rum]"); - audit.CompleteAudit(typeof(ExecuteFullExtractionToDatabaseMSSql), "[over the hills and far away]", 333, true, false); + var audit = new CumulativeExtractionResults(DataExportRepository, _configuration, + _selectedDataSet.ExtractableDataSet, "select * from [yohoho and a bottle of rum]"); + audit.CompleteAudit(typeof(ExecuteFullExtractionToDatabaseMSSql), "[over the hills and far away]", 333, true, + false); audit.SaveToDatabase(); var ex = Assert.Throws(() => checker.Check(new ThrowImmediatelyCheckNotifier())); Assert.AreEqual( - $"R0017 ExtractionProgress 'mybatch' is 'in progress' (ProgressDate is not null) but we did not find the expected Cohort WHERE Sql in the audit of SQL extracted with the last batch. Did you change the cohort without resetting the ProgressDate? The SQL we expected to find was '[{TestDatabaseNames.Prefix}CohortDatabase]..[Cohort].[cohortDefinition_id]=-599'",ex.Message); + $"R0017 ExtractionProgress 'mybatch' is 'in progress' (ProgressDate is not null) but we did not find the expected Cohort WHERE Sql in the audit of SQL extracted with the last batch. Did you change the cohort without resetting the ProgressDate? The SQL we expected to find was '[{TestDatabaseNames.Prefix}CohortDatabase]..[Cohort].[cohortDefinition_id]=-599'", + ex.Message); // tidy up ep.DeleteInDatabase(); @@ -83,7 +86,8 @@ public void TestExtractionProgress_AuditRecordIsGood_NoProblems() // normal checks pass var checker = new SelectedDataSetsChecker(new ThrowImmediatelyActivator(RepositoryLocator), _selectedDataSet); - var ep = new ExtractionProgress(DataExportRepository, _selectedDataSet, new DateTime(1990, 1, 1), new DateTime(2001, 1, 1), 100, "mybatch", + var ep = new ExtractionProgress(DataExportRepository, _selectedDataSet, new DateTime(1990, 1, 1), + new DateTime(2001, 1, 1), 100, "mybatch", _extractionInformations[0].ID) { ProgressDate = new DateTime(1995, 1, 1) // we are half way through @@ -91,17 +95,16 @@ public void TestExtractionProgress_AuditRecordIsGood_NoProblems() ep.SaveToDatabase(); - foreach (var r in DataExportRepository.GetAllObjects()) - { - r.DeleteInDatabase(); - } + foreach (var r in DataExportRepository.GetAllObjects()) r.DeleteInDatabase(); // audit has SQL is good, it contains the correct cohort - var audit = new CumulativeExtractionResults(DataExportRepository, _configuration, _selectedDataSet.ExtractableDataSet, + var audit = new CumulativeExtractionResults(DataExportRepository, _configuration, + _selectedDataSet.ExtractableDataSet, $"select * from [yohoho and a bottle of rum] WHERE [{TestDatabaseNames.Prefix}CohortDatabase]..[Cohort].[cohortDefinition_id]=-599'"); - audit.CompleteAudit(typeof(ExecuteFullExtractionToDatabaseMSSql), "[over the hills and far away]", 333, true, false); + audit.CompleteAudit(typeof(ExecuteFullExtractionToDatabaseMSSql), "[over the hills and far away]", 333, true, + false); audit.SaveToDatabase(); Assert.DoesNotThrow(() => checker.Check(new ThrowImmediatelyCheckNotifier())); diff --git a/Rdmp.Core.Tests/DataExport/DataAccess/PackageContentsTests.cs b/Rdmp.Core.Tests/DataExport/DataAccess/PackageContentsTests.cs index ccc13ca979..0c3cdf0382 100644 --- a/Rdmp.Core.Tests/DataExport/DataAccess/PackageContentsTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataAccess/PackageContentsTests.cs @@ -12,19 +12,19 @@ namespace Rdmp.Core.Tests.DataExport.DataAccess; -public class PackageContentsTests:DatabaseTests +public class PackageContentsTests : DatabaseTests { [Test] public void AddAndRemove() { var cata = new Catalogue(CatalogueRepository, "PackageContentsTests"); - var ds = new ExtractableDataSet(DataExportRepository,cata); + var ds = new ExtractableDataSet(DataExportRepository, cata); var package = new ExtractableDataSetPackage(DataExportRepository, "My Cool Package"); try { - Assert.AreEqual("My Cool Package",package.Name); + Assert.AreEqual("My Cool Package", package.Name); package.Name = "FishPackage"; package.SaveToDatabase(); @@ -32,15 +32,15 @@ public void AddAndRemove() var packageContents = DataExportRepository; var results = packageContents.GetAllDataSets(package, null); - Assert.AreEqual(0,results.Length); + Assert.AreEqual(0, results.Length); - packageContents.AddDataSetToPackage(package,ds); + packageContents.AddDataSetToPackage(package, ds); results = packageContents.GetAllDataSets(package, DataExportRepository.GetAllObjects()); Assert.AreEqual(1, results.Length); - Assert.AreEqual(ds,results[0]); + Assert.AreEqual(ds, results[0]); - packageContents.RemoveDataSetFromPackage(package,ds); + packageContents.RemoveDataSetFromPackage(package, ds); //cannot delete the relationship twice Assert.Throws(() => packageContents.RemoveDataSetFromPackage(package, ds)); diff --git a/Rdmp.Core.Tests/DataExport/DataAccess/SelectedColumnsTests.cs b/Rdmp.Core.Tests/DataExport/DataAccess/SelectedColumnsTests.cs index fee0109010..6ae4116960 100644 --- a/Rdmp.Core.Tests/DataExport/DataAccess/SelectedColumnsTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataAccess/SelectedColumnsTests.cs @@ -12,31 +12,30 @@ namespace Rdmp.Core.Tests.DataExport.DataAccess; -public class SelectedColumnsTests:DatabaseTests +public class SelectedColumnsTests : DatabaseTests { //Simple test SelectedColumns in which an extraction configuration is built for a test dataset with a single column configured for extraction [Test] public void CreateAndAssociateColumns() { var cata = new Catalogue(CatalogueRepository, "MyCat"); - var cataItem = new CatalogueItem(CatalogueRepository, cata,"MyCataItem"); + var cataItem = new CatalogueItem(CatalogueRepository, cata, "MyCataItem"); var TableInfo = new TableInfo(CatalogueRepository, "Cata"); - var ColumnInfo = new ColumnInfo(CatalogueRepository, "Col","varchar(10)",TableInfo); + var ColumnInfo = new ColumnInfo(CatalogueRepository, "Col", "varchar(10)", TableInfo); var ExtractionInfo = new ExtractionInformation(CatalogueRepository, cataItem, ColumnInfo, "fish"); - var ds = new ExtractableDataSet(DataExportRepository,cata); + var ds = new ExtractableDataSet(DataExportRepository, cata); var proj = new Project(DataExportRepository, "MyProj"); var config = new ExtractionConfiguration(DataExportRepository, proj); - + SelectedDataSets selectedDataSets; var extractableColumn = new ExtractableColumn(DataExportRepository, ds, config, ExtractionInfo, 1, "fish"); try { - - selectedDataSets = new SelectedDataSets(DataExportRepository,config, ds,null); + selectedDataSets = new SelectedDataSets(DataExportRepository, config, ds, null); var cols = config.GetAllExtractableColumnsFor(ds); @@ -58,8 +57,6 @@ public void CreateAndAssociateColumns() TableInfo.DeleteInDatabase(); cata.DeleteInDatabase(); - } } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExportRepositoryTests.cs b/Rdmp.Core.Tests/DataExport/DataExportRepositoryTests.cs index a444c3ec2a..b7727ecb7e 100644 --- a/Rdmp.Core.Tests/DataExport/DataExportRepositoryTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExportRepositoryTests.cs @@ -12,7 +12,7 @@ namespace Rdmp.Core.Tests.DataExport; -internal class DataExportRepositoryTests:DatabaseTests +internal class DataExportRepositoryTests : DatabaseTests { [Test] public void TestNoIsExtractionIdentifierFinding() @@ -29,14 +29,14 @@ public void TestNoIsExtractionIdentifierFinding() //only one selected dataset var dodgy = DataExportRepository.GetSelectedDatasetsWithNoExtractionIdentifiers().ToArray(); Assert.AreEqual(1, dodgy.Length); - Assert.AreEqual(sds,dodgy[0]); + Assert.AreEqual(sds, dodgy[0]); //make an extarctable column on that dataset - var col = new ColumnInfo(CatalogueRepository,"ff","varchar(1)",new TableInfo(CatalogueRepository, "fff")); + var col = new ColumnInfo(CatalogueRepository, "ff", "varchar(1)", new TableInfo(CatalogueRepository, "fff")); var ci = new CatalogueItem(CatalogueRepository, cata, "A"); - var ei = new ExtractionInformation(CatalogueRepository, ci, col,col.Name); + var ei = new ExtractionInformation(CatalogueRepository, ci, col, col.Name); var ec = new ExtractableColumn(DataExportRepository, ds, config, ei, 0, col.Name); - + //still shouldn't be dodgy dodgy = DataExportRepository.GetSelectedDatasetsWithNoExtractionIdentifiers().ToArray(); Assert.AreEqual(1, dodgy.Length); @@ -49,6 +49,5 @@ public void TestNoIsExtractionIdentifierFinding() //no longer dodgy because there is an extraction identifier dodgy = DataExportRepository.GetSelectedDatasetsWithNoExtractionIdentifiers().ToArray(); Assert.AreEqual(0, dodgy.Length); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/EmptyDataExtractionTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/EmptyDataExtractionTests.cs index 6a586cfb31..3123e94e63 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/EmptyDataExtractionTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/EmptyDataExtractionTests.cs @@ -20,9 +20,8 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; -public class EmptyDataExtractionTests:TestsRequiringAnExtractionConfiguration +public class EmptyDataExtractionTests : TestsRequiringAnExtractionConfiguration { - private void TruncateDataTable() { var server = Database.Server; @@ -30,12 +29,11 @@ private void TruncateDataTable() { con.Open(); - var cmdTruncate = server.GetCommand("TRUNCATE TABLE TestTable",con); + var cmdTruncate = server.GetCommand("TRUNCATE TABLE TestTable", con); cmdTruncate.ExecuteNonQuery(); con.Close(); } - } [Test] @@ -44,28 +42,29 @@ private void TruncateDataTable() public void TestAllowingEmptyDatasets(bool allowEmptyDatasetExtractions) { var p = SetupPipeline(); - + TruncateDataTable(); - var host = new ExtractionPipelineUseCase(new ThrowImmediatelyActivator(RepositoryLocator),_request.Configuration.Project, _request, p, DataLoadInfo.Empty); + var host = new ExtractionPipelineUseCase(new ThrowImmediatelyActivator(RepositoryLocator), + _request.Configuration.Project, _request, p, DataLoadInfo.Empty); var engine = host.GetEngine(p, new ThrowImmediatelyDataLoadEventListener()); host.Source.AllowEmptyExtractions = allowEmptyDatasetExtractions; var token = new GracefulCancellationToken(); - - if(allowEmptyDatasetExtractions) - { + if (allowEmptyDatasetExtractions) + { var dt = host.Source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), token); Assert.IsNull(host.Source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), token)); - Assert.AreEqual(0,dt.Rows.Count); + Assert.AreEqual(0, dt.Rows.Count); Assert.AreEqual(3, dt.Columns.Count); } else { - var exception = Assert.Throws(() => host.Source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), token)); + var exception = Assert.Throws(() => + host.Source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), token)); Assert.IsTrue(exception.Message.StartsWith("There is no data to load, query returned no rows, query was")); } @@ -82,7 +81,7 @@ public void ProducesEmptyCSV() Assert.AreEqual(1, _request.ColumnsToExtract.Count(c => c.IsExtractionIdentifier)); - Execute(out ExtractionPipelineUseCase execute, out var result); + Execute(out var execute, out var result); var r = (ExecuteDatasetExtractionFlatFileDestination)result; diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteCrossServerDatasetExtractionSourceTest.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteCrossServerDatasetExtractionSourceTest.cs index 95c3fd4dbc..8b255768c5 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteCrossServerDatasetExtractionSourceTest.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteCrossServerDatasetExtractionSourceTest.cs @@ -24,8 +24,7 @@ public class ExecuteCrossServerDatasetExtractionSourceTest : TestsRequiringAnExt [Test] public void CrossServerExtraction() { - - Execute(out ExtractionPipelineUseCase execute, out var result); + Execute(out var execute, out var result); var r = (ExecuteDatasetExtractionFlatFileDestination)result; @@ -39,26 +38,33 @@ public void CrossServerExtraction() protected override Pipeline SetupPipeline() { var pipeline = new Pipeline(CatalogueRepository, "Empty extraction pipeline"); - var component = new PipelineComponent(CatalogueRepository, pipeline, typeof(ExecuteDatasetExtractionFlatFileDestination), 0, "Destination"); - var arguments = component.CreateArgumentsForClassIfNotExists().ToArray(); + var component = new PipelineComponent(CatalogueRepository, pipeline, + typeof(ExecuteDatasetExtractionFlatFileDestination), 0, "Destination"); + var arguments = component.CreateArgumentsForClassIfNotExists() + .ToArray(); if (arguments.Length < 3) - throw new Exception("Expected only 2 arguments for type ExecuteDatasetExtractionFlatFileDestination, did somebody add another [DemandsInitialization]? if so handle it below"); + throw new Exception( + "Expected only 2 arguments for type ExecuteDatasetExtractionFlatFileDestination, did somebody add another [DemandsInitialization]? if so handle it below"); arguments.Single(a => a.Name.Equals("DateFormat")).SetValue("yyyy-MM-dd"); arguments.Single(a => a.Name.Equals("DateFormat")).SaveToDatabase(); - arguments.Single(a=>a.Name.Equals("FlatFileType")).SetValue(ExecuteExtractionToFlatFileType.CSV); - arguments.Single(a=>a.Name.Equals("FlatFileType")).SaveToDatabase(); - + arguments.Single(a => a.Name.Equals("FlatFileType")).SetValue(ExecuteExtractionToFlatFileType.CSV); + arguments.Single(a => a.Name.Equals("FlatFileType")).SaveToDatabase(); + AdjustPipelineComponentDelegate?.Invoke(component); - var component2 = new PipelineComponent(CatalogueRepository, pipeline, typeof(ExecuteCrossServerDatasetExtractionSource), -1, "Source"); - var arguments2 = component2.CreateArgumentsForClassIfNotExists().ToArray(); - arguments2.Single(a=>a.Name.Equals("AllowEmptyExtractions")).SetValue(false); - arguments2.Single(a => a.Name.Equals("AllowEmptyExtractions")).SaveToDatabase(); - arguments2.Single(a => a.Name.Equals(nameof(ExecuteCrossServerDatasetExtractionSource.TemporaryTableName))).SetValue(""); - arguments2.Single(a => a.Name.Equals(nameof(ExecuteCrossServerDatasetExtractionSource.TemporaryTableName))).SaveToDatabase(); + var component2 = new PipelineComponent(CatalogueRepository, pipeline, + typeof(ExecuteCrossServerDatasetExtractionSource), -1, "Source"); + var arguments2 = component2.CreateArgumentsForClassIfNotExists() + .ToArray(); + arguments2.Single(a => a.Name.Equals("AllowEmptyExtractions")).SetValue(false); + arguments2.Single(a => a.Name.Equals("AllowEmptyExtractions")).SaveToDatabase(); + arguments2.Single(a => a.Name.Equals(nameof(ExecuteCrossServerDatasetExtractionSource.TemporaryTableName))) + .SetValue(""); + arguments2.Single(a => a.Name.Equals(nameof(ExecuteCrossServerDatasetExtractionSource.TemporaryTableName))) + .SaveToDatabase(); AdjustPipelineComponentDelegate?.Invoke(component2); @@ -100,7 +106,8 @@ SELECT DISTINCT var ect = (ExternalCohortTable)_request.ExtractableCohort.ExternalCohortTable; ect.Server = "bob"; - var e = DataExportRepository.GetObjectByID(_request.ExtractableCohort.ExternalCohortTable_ID); + var e = DataExportRepository.GetObjectByID(_request.ExtractableCohort + .ExternalCohortTable_ID); var origValue = e.Database; e.Database = CohortDatabaseName; @@ -112,9 +119,10 @@ SELECT DISTINCT TemporaryDatabaseName = "tempdb" }; s.PreInitialize(_request, new ThrowImmediatelyDataLoadEventListener()); - var hacked = s.HackExtractionSQL(_request.QueryBuilder.SQL, new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }); + var hacked = s.HackExtractionSQL(_request.QueryBuilder.SQL, + new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }); - Assert.AreEqual(expectedOutput.Trim(),hacked.Trim()); + Assert.AreEqual(expectedOutput.Trim(), hacked.Trim()); } finally { @@ -122,9 +130,4 @@ SELECT DISTINCT e.SaveToDatabase(); } } - - - - - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteDatasetExtractionFlatFileDestinationTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteDatasetExtractionFlatFileDestinationTests.cs index c59140f949..64f09b78e8 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteDatasetExtractionFlatFileDestinationTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteDatasetExtractionFlatFileDestinationTests.cs @@ -33,12 +33,10 @@ public void ExtractionDestination_FloatRounding(bool lotsOfDecimalPlaces) var lm = new LogManager(new DiscoveredServer(UnitTestLoggingConnectionString)); lm.CreateNewLoggingTaskIfNotExists("ExtractionDestination_FloatRounding"); - var dli = lm.CreateDataLoadInfo("ExtractionDestination_FloatRounding", nameof(ExecuteDatasetExtractionFlatFileDestinationTests), "test", "", true); + var dli = lm.CreateDataLoadInfo("ExtractionDestination_FloatRounding", + nameof(ExecuteDatasetExtractionFlatFileDestinationTests), "test", "", true); - if(_request.QueryBuilder == null) - { - _request.GenerateQueryBuilder(); - } + if (_request.QueryBuilder == null) _request.GenerateQueryBuilder(); dest.RoundFloatsTo = lotsOfDecimalPlaces ? 10 : 2; dest.PreInitialize(_request, new ThrowImmediatelyDataLoadEventListener()); @@ -46,7 +44,7 @@ public void ExtractionDestination_FloatRounding(bool lotsOfDecimalPlaces) dest.PreInitialize((DataLoadInfo)dli, new ThrowImmediatelyDataLoadEventListener()); dest.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - dest.Dispose(new ThrowImmediatelyDataLoadEventListener(),null); + dest.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); Assert.IsNotNull(dest.OutputFile); FileAssert.Exists(dest.OutputFile); diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlChecksTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlChecksTests.cs index 9d63d97028..3147028ceb 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlChecksTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlChecksTests.cs @@ -18,7 +18,7 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; -public class ExecuteFullExtractionToDatabaseMSSqlChecksTests:DatabaseTests +public class ExecuteFullExtractionToDatabaseMSSqlChecksTests : DatabaseTests { private IProject _projectStub; private IExtractCommand _commandStub; @@ -34,15 +34,13 @@ protected override void SetUp() _projectStub.ProjectNumber = -123; var cfg = Mock.Of(); - - _commandStub = Mock.Of(cmd => cmd.Configuration==cfg); + + _commandStub = Mock.Of(cmd => cmd.Configuration == cfg); Database = GetCleanedServer(DatabaseType.MicrosoftSQLServer); } - - [Test] public void NoServer() { @@ -51,13 +49,14 @@ public void NoServer() var tomemory = new ToMemoryCheckNotifier(); destination.Check(tomemory); - Assert.AreEqual(CheckResult.Fail,tomemory.Messages[0].Result); + Assert.AreEqual(CheckResult.Fail, tomemory.Messages[0].Result); Assert.IsTrue(tomemory.Messages[0].Message.StartsWith("Target database server property has not been set")); } + [Test] public void ServerMissingServerName() { - var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction",null); + var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction", null); try { var destination = new ExecuteFullExtractionToDatabaseMSSql @@ -69,7 +68,8 @@ public void ServerMissingServerName() destination.Check(tomemory); Assert.AreEqual(CheckResult.Fail, tomemory.Messages[0].Result); - Assert.IsTrue(tomemory.Messages[0].Message.StartsWith("TargetDatabaseServer does not have a .Server specified")); + Assert.IsTrue(tomemory.Messages[0].Message + .StartsWith("TargetDatabaseServer does not have a .Server specified")); } finally { @@ -81,7 +81,7 @@ public void ServerMissingServerName() [TestCase(true)] public void ServerDatabaseIsPresentAndCorrect(bool alreadyExists) { - var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction",null) + var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction", null) { Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name, Username = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExplicitUsernameIfAny, @@ -89,10 +89,9 @@ public void ServerDatabaseIsPresentAndCorrect(bool alreadyExists) }; //server.Database = "FictionalDatabase"; Ignored by the extractor! - + try { - var destination = new ExecuteFullExtractionToDatabaseMSSql(); destination.PreInitialize(_projectStub, new ThrowImmediatelyDataLoadEventListener()); destination.PreInitialize(_commandStub, new ThrowImmediatelyDataLoadEventListener()); @@ -100,14 +99,15 @@ public void ServerDatabaseIsPresentAndCorrect(bool alreadyExists) destination.TargetDatabaseServer = server; destination.TableNamingPattern = "$d"; - destination.DatabaseNamingPattern = alreadyExists ? Database.GetRuntimeName() : //database that exists + destination.DatabaseNamingPattern = alreadyExists + ? Database.GetRuntimeName() + : //database that exists "Fictional$nDatabase"; //database does not exist (but server does) var tomemory = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); destination.Check(tomemory); - Assert.AreEqual(alreadyExists? CheckResult.Warning: CheckResult.Success, tomemory.GetWorst()); - + Assert.AreEqual(alreadyExists ? CheckResult.Warning : CheckResult.Success, tomemory.GetWorst()); } finally { @@ -118,21 +118,21 @@ public void ServerDatabaseIsPresentAndCorrect(bool alreadyExists) [Test] public void ServerDatabaseIsPresentAndCorrectButHasTablesInIt() { - var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction",null) + var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction", null) { Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name, Username = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExplicitUsernameIfAny, Password = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExplicitPasswordIfAny }; //server.Database = "FictionalDatabase"; Ignored by the extractor! - + using (var con = Database.Server.GetConnection()) { con.Open(); Database.Server.GetCommand("CREATE TABLE Bob(name varchar(10))", con).ExecuteNonQuery(); } - + try { var destination = new ExecuteFullExtractionToDatabaseMSSql(); diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlDestinationTest.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlDestinationTest.cs index d34d066435..e9399f7a20 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlDestinationTest.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecuteFullExtractionToDatabaseMSSqlDestinationTest.cs @@ -22,10 +22,10 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; -public class ExecuteFullExtractionToDatabaseMSSqlDestinationTest :TestsRequiringAnExtractionConfiguration +public class ExecuteFullExtractionToDatabaseMSSqlDestinationTest : TestsRequiringAnExtractionConfiguration { private ExternalDatabaseServer _extractionServer; - + private readonly string _expectedTableName = "ExecuteFullExtractionToDatabaseMSSqlDestinationTest_TestTable"; private ColumnInfo _columnToTransform; private Pipeline _pipeline; @@ -36,12 +36,14 @@ public void SQLServerDestination() DiscoveredDatabase dbToExtractTo = null; var ci = new CatalogueItem(CatalogueRepository, _catalogue, "YearOfBirth"); - _columnToTransform = _columnInfos.Single(c=>c.GetRuntimeName().Equals("DateOfBirth",StringComparison.CurrentCultureIgnoreCase)); + _columnToTransform = _columnInfos.Single(c => + c.GetRuntimeName().Equals("DateOfBirth", StringComparison.CurrentCultureIgnoreCase)); var transform = $"YEAR({_columnToTransform.Name})"; - if (_catalogue.GetAllExtractionInformation(ExtractionCategory.Any).All(ei => ei.GetRuntimeName() != "YearOfBirth")) + if (_catalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .All(ei => ei.GetRuntimeName() != "YearOfBirth")) { var ei = new ExtractionInformation(CatalogueRepository, ci, _columnToTransform, transform) { @@ -51,15 +53,16 @@ public void SQLServerDestination() ei.SaveToDatabase(); //make it part of the ExtractionConfiguration - var newColumn = new ExtractableColumn(DataExportRepository, _selectedDataSet.ExtractableDataSet, (ExtractionConfiguration)_selectedDataSet.ExtractionConfiguration, ei, 0, ei.SelectSQL) - { - Alias = ei.Alias - }; + var newColumn = new ExtractableColumn(DataExportRepository, _selectedDataSet.ExtractableDataSet, + (ExtractionConfiguration)_selectedDataSet.ExtractionConfiguration, ei, 0, ei.SelectSQL) + { + Alias = ei.Alias + }; newColumn.SaveToDatabase(); _extractableColumns.Add(newColumn); } - + CreateLookupsEtc(); try @@ -80,18 +83,19 @@ public void SQLServerDestination() var dt = destinationTable.GetDataTable(); Assert.AreEqual(1, dt.Rows.Count); - Assert.AreEqual(_cohortKeysGenerated[_cohortKeysGenerated.Keys.First()].Trim(),dt.Rows[0]["ReleaseID"]); - Assert.AreEqual(new DateTime(2001,1,1), dt.Rows[0]["DateOfBirth"]); + Assert.AreEqual(_cohortKeysGenerated[_cohortKeysGenerated.Keys.First()].Trim(), dt.Rows[0]["ReleaseID"]); + Assert.AreEqual(new DateTime(2001, 1, 1), dt.Rows[0]["DateOfBirth"]); Assert.AreEqual(2001, dt.Rows[0]["YearOfBirth"]); - Assert.AreEqual(_columnToTransform.Data_type, destinationTable.DiscoverColumn("DateOfBirth").DataType.SQLType); - Assert.AreEqual("int",destinationTable.DiscoverColumn("YearOfBirth").DataType.SQLType); + Assert.AreEqual(_columnToTransform.Data_type, + destinationTable.DiscoverColumn("DateOfBirth").DataType.SQLType); + Assert.AreEqual("int", destinationTable.DiscoverColumn("YearOfBirth").DataType.SQLType); AssertLookupsEtcExist(dbToExtractTo); } finally { - if(dbToExtractTo != null && dbToExtractTo.Exists()) + if (dbToExtractTo != null && dbToExtractTo.Exists()) dbToExtractTo.Drop(); _pipeline?.DeleteInDatabase(); @@ -100,9 +104,12 @@ public void SQLServerDestination() private static void AssertLookupsEtcExist(DiscoveredDatabase dbToExtractTo) { - Assert.IsTrue(dbToExtractTo.ExpectTable("ExecuteFullExtractionToDatabaseMSSqlDestinationTest_TestTable_Biochem").Exists()); - Assert.IsTrue(dbToExtractTo.ExpectTable("ExecuteFullExtractionToDatabaseMSSqlDestinationTest_Globals_Hosp").Exists()); - Assert.IsTrue(dbToExtractTo.ExpectTable("ExecuteFullExtractionToDatabaseMSSqlDestinationTest_TestTable_z_fff").Exists()); + Assert.IsTrue(dbToExtractTo.ExpectTable("ExecuteFullExtractionToDatabaseMSSqlDestinationTest_TestTable_Biochem") + .Exists()); + Assert.IsTrue(dbToExtractTo.ExpectTable("ExecuteFullExtractionToDatabaseMSSqlDestinationTest_Globals_Hosp") + .Exists()); + Assert.IsTrue(dbToExtractTo.ExpectTable("ExecuteFullExtractionToDatabaseMSSqlDestinationTest_TestTable_z_fff") + .Exists()); } private void CreateLookupsEtc() @@ -110,7 +117,7 @@ private void CreateLookupsEtc() //an extractable file var filename = Path.Combine(TestContext.CurrentContext.WorkDirectory, "bob.txt"); - File.WriteAllText(filename,"fishfishfish"); + File.WriteAllText(filename, "fishfishfish"); var doc = new SupportingDocument(CatalogueRepository, _catalogue, "bob") { URL = new Uri($"file://{filename}"), @@ -121,7 +128,7 @@ private void CreateLookupsEtc() //an extractable global file (comes out regardless of datasets) var filename2 = Path.Combine(TestContext.CurrentContext.WorkDirectory, "bob2.txt"); - File.WriteAllText(filename2,"fishfishfish2"); + File.WriteAllText(filename2, "fishfishfish2"); var doc2 = new SupportingDocument(CatalogueRepository, _catalogue, "bob2") { URL = new Uri($"file://{filename2}"), @@ -131,7 +138,7 @@ private void CreateLookupsEtc() doc2.SaveToDatabase(); //an supplemental table in the database (not linked against cohort) - var tbl = CreateDataset(Database,500, 1000, new Random(50)); + var tbl = CreateDataset(Database, 500, 1000, new Random(50)); var sql = new SupportingSQLTable(CatalogueRepository, _catalogue, "Biochem"); var server = new ExternalDatabaseServer(CatalogueRepository, "myserver", null); @@ -143,7 +150,7 @@ private void CreateLookupsEtc() //an supplemental (global) table in the database (not linked against cohort) - var tbl2 = CreateDataset(Database,500, 1000, new Random(50)); + var tbl2 = CreateDataset(Database, 500, 1000, new Random(50)); var sql2 = new SupportingSQLTable(CatalogueRepository, _catalogue, "Hosp") { @@ -167,10 +174,10 @@ private void CreateLookupsEtc() Import(lookupTbl, out var ti, out var columnInfos); - var lookup = new Lookup(CatalogueRepository, columnInfos[0], + var lookup = new Lookup(CatalogueRepository, columnInfos[0], _columnToTransform, columnInfos[1], - ExtractionJoinType.Left,null); + ExtractionJoinType.Left, null); //we need a CatalogueItem for the description in order to pick SetUp the Lookup as associated with the Catalogue var ci = new CatalogueItem(CatalogueRepository, _catalogue, "SomeDesc") @@ -184,7 +191,7 @@ private void CreateLookupsEtc() protected override Pipeline SetupPipeline() { //create a target server pointer - _extractionServer = new ExternalDatabaseServer(CatalogueRepository, "myserver",null) + _extractionServer = new ExternalDatabaseServer(CatalogueRepository, "myserver", null) { Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name, Username = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExplicitUsernameIfAny, @@ -196,8 +203,10 @@ protected override Pipeline SetupPipeline() _pipeline = new Pipeline(CatalogueRepository, "Empty extraction pipeline"); //set the destination pipeline - var component = new PipelineComponent(CatalogueRepository, _pipeline, typeof(ExecuteFullExtractionToDatabaseMSSql), 0, "MS SQL Destination"); - var destinationArguments = component.CreateArgumentsForClassIfNotExists().ToList(); + var component = new PipelineComponent(CatalogueRepository, _pipeline, + typeof(ExecuteFullExtractionToDatabaseMSSql), 0, "MS SQL Destination"); + var destinationArguments = component.CreateArgumentsForClassIfNotExists() + .ToList(); var argumentServer = destinationArguments.Single(a => a.Name == "TargetDatabaseServer"); var argumentDbNamePattern = destinationArguments.Single(a => a.Name == "DatabaseNamingPattern"); var argumentTblNamePattern = destinationArguments.Single(a => a.Name == "TableNamingPattern"); @@ -211,9 +220,11 @@ protected override Pipeline SetupPipeline() argumentTblNamePattern.SaveToDatabase(); AdjustPipelineComponentDelegate?.Invoke(component); - var component2 = new PipelineComponent(CatalogueRepository, _pipeline, typeof(ExecuteCrossServerDatasetExtractionSource), -1, "Source"); - var arguments2 = component2.CreateArgumentsForClassIfNotExists().ToArray(); - arguments2.Single(a=>a.Name.Equals("AllowEmptyExtractions")).SetValue(false); + var component2 = new PipelineComponent(CatalogueRepository, _pipeline, + typeof(ExecuteCrossServerDatasetExtractionSource), -1, "Source"); + var arguments2 = component2.CreateArgumentsForClassIfNotExists() + .ToArray(); + arguments2.Single(a => a.Name.Equals("AllowEmptyExtractions")).SetValue(false); arguments2.Single(a => a.Name.Equals("AllowEmptyExtractions")).SaveToDatabase(); AdjustPipelineComponentDelegate?.Invoke(component2); diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecutePkSynthesizerDatasetExtractionSourceTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecutePkSynthesizerDatasetExtractionSourceTests.cs index 439657dc32..e2388c6991 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/ExecutePkSynthesizerDatasetExtractionSourceTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/ExecutePkSynthesizerDatasetExtractionSourceTests.cs @@ -34,20 +34,23 @@ protected override void SetUp() { base.SetUp(); - DataExportRepository.DataExportPropertyManager.SetValue(DataExportProperty.HashingAlgorithmPattern, "CONCAT('HASHED: ',{0})"); + DataExportRepository.DataExportPropertyManager.SetValue(DataExportProperty.HashingAlgorithmPattern, + "CONCAT('HASHED: ',{0})"); } [Test] public void Test_CatalogueItems_ExtractionInformationPrimaryKey_IsRespected() { - var request = SetupExtractDatasetCommand("ExtractionInformationPrimaryKey_IsRespected", new[] { "DateOfBirth" }); + var request = + SetupExtractDatasetCommand("ExtractionInformationPrimaryKey_IsRespected", new[] { "DateOfBirth" }); var source = new ExecutePkSynthesizerDatasetExtractionSource(); source.PreInitialize(request, new ThrowImmediatelyDataLoadEventListener()); var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.That(chunk.PrimaryKey, Is.Not.Null); - Assert.That(chunk.Columns.Cast().ToList(), Has.Count.EqualTo(_columnInfos.Length)); // NO new column added + Assert.That(chunk.Columns.Cast().ToList(), + Has.Count.EqualTo(_columnInfos.Length)); // NO new column added Assert.That(chunk.PrimaryKey, Has.Length.EqualTo(1)); Assert.That(chunk.PrimaryKey.First().ColumnName, Is.EqualTo("DateOfBirth")); } @@ -55,7 +58,8 @@ public void Test_CatalogueItems_ExtractionInformationPrimaryKey_IsRespected() [Test] public void Test_CatalogueItems_ExtractionInformationMultiPrimaryKey_IsRespected() { - var request = SetupExtractDatasetCommand("ExtractionInformationMultiPrimaryKey_IsRespected", new[] { "PrivateID", "DateOfBirth" }); + var request = SetupExtractDatasetCommand("ExtractionInformationMultiPrimaryKey_IsRespected", + new[] { "PrivateID", "DateOfBirth" }); var source = new ExecutePkSynthesizerDatasetExtractionSource(); source.PreInitialize(request, new ThrowImmediatelyDataLoadEventListener()); @@ -70,14 +74,16 @@ public void Test_CatalogueItems_ExtractionInformationMultiPrimaryKey_IsRespected [Test] public void Test_CatalogueItems_NonExtractedPrimaryKey_AreRespected() { - var request = SetupExtractDatasetCommand("NonExtractedPrimaryKey_AreRespected", System.Array.Empty(), pkColumnInfos: new [] { "DateOfBirth" }); + var request = SetupExtractDatasetCommand("NonExtractedPrimaryKey_AreRespected", System.Array.Empty(), + new[] { "DateOfBirth" }); var source = new ExecutePkSynthesizerDatasetExtractionSource(); source.PreInitialize(request, new ThrowImmediatelyDataLoadEventListener()); var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.That(chunk.PrimaryKey, Is.Not.Null); - Assert.That(chunk.Columns.Cast().ToList(), Has.Count.EqualTo(_columnInfos.Length + 1)); // synth PK is added + Assert.That(chunk.Columns.Cast().ToList(), + Has.Count.EqualTo(_columnInfos.Length + 1)); // synth PK is added Assert.That(chunk.PrimaryKey, Has.Length.EqualTo(1)); Assert.That(chunk.PrimaryKey.First().ColumnName, Is.EqualTo("SynthesizedPk")); @@ -88,14 +94,16 @@ public void Test_CatalogueItems_NonExtractedPrimaryKey_AreRespected() [Test] public void Test_CatalogueItems_NonExtractedPrimaryKey_MultiTable_PksAreMerged() { - var request = SetupExtractDatasetCommand("MultiTable_PksAreMerged", System.Array.Empty(), new[] { "DateOfBirth" }, true, true); + var request = SetupExtractDatasetCommand("MultiTable_PksAreMerged", System.Array.Empty(), + new[] { "DateOfBirth" }, true, true); var source = new ExecutePkSynthesizerDatasetExtractionSource(); source.PreInitialize(request, new ThrowImmediatelyDataLoadEventListener()); var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.That(chunk.PrimaryKey, Is.Not.Null); - Assert.That(chunk.Columns.Cast().ToList(), Has.Count.EqualTo(_columnInfos.Length + 3)); // the "desc" column is added to the existing ones + Assert.That(chunk.Columns.Cast().ToList(), + Has.Count.EqualTo(_columnInfos.Length + 3)); // the "desc" column is added to the existing ones Assert.That(chunk.PrimaryKey, Has.Length.EqualTo(1)); Assert.That(chunk.PrimaryKey.First().ColumnName, Is.EqualTo("SynthesizedPk")); @@ -109,14 +117,17 @@ public void Test_CatalogueItems_NonExtractedPrimaryKey_MultiTable_PksAreMerged() [Test] public void Test_CatalogueItems_NonExtractedPrimaryKey_LookupsOnly_IsRespected() { - var request = SetupExtractDatasetCommand("LookupsOnly_IsRespected", System.Array.Empty(), pkColumnInfos: new[] { "DateOfBirth" }, withLookup: true); + var request = SetupExtractDatasetCommand("LookupsOnly_IsRespected", System.Array.Empty(), + new[] { "DateOfBirth" }, true); var source = new ExecutePkSynthesizerDatasetExtractionSource(); source.PreInitialize(request, new ThrowImmediatelyDataLoadEventListener()); var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.That(chunk.PrimaryKey, Is.Not.Null); - Assert.That(chunk.Columns.Cast().ToList(), Has.Count.EqualTo(_columnInfos.Length + 2)); // the "desc" column is added to the existing ones + the SynthPk + Assert.That(chunk.Columns.Cast().ToList(), + Has.Count.EqualTo(_columnInfos.Length + + 2)); // the "desc" column is added to the existing ones + the SynthPk Assert.That(chunk.PrimaryKey, Has.Length.EqualTo(1)); Assert.That(chunk.PrimaryKey.First().ColumnName, Is.EqualTo("SynthesizedPk")); @@ -132,17 +143,22 @@ private void SetupJoin() dt.Columns.Add("Name"); dt.Columns.Add("Description"); - + dt.Rows.Add(new object[] { "Dave", "Is a maniac" }); - var tbl = Database.CreateTable("SimpleJoin", dt, new[] { new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 50)) { IsPrimaryKey = true } }); + var tbl = Database.CreateTable("SimpleJoin", dt, + new[] + { + new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 50)) { IsPrimaryKey = true } + }); var lookupCata = Import(tbl); - var fkEi = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(n => n.GetRuntimeName() == "Name"); + var fkEi = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(n => n.GetRuntimeName() == "Name"); var pk = lookupCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "Name"); - - new JoinInfo(CatalogueRepository,fkEi.ColumnInfo, pk, ExtractionJoinType.Left, null); + + new JoinInfo(CatalogueRepository, fkEi.ColumnInfo, pk, ExtractionJoinType.Left, null); var ci = new CatalogueItem(CatalogueRepository, _catalogue, "Name_2"); var ei = new ExtractionInformation(CatalogueRepository, ci, pk, pk.Name) @@ -161,20 +177,24 @@ private void SetupLookupTable() dt.Rows.Add(new object[] { "Dave", "Is a maniac" }); - var tbl = Database.CreateTable("SimpleLookup", dt, new[] { new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 50)) }); + var tbl = Database.CreateTable("SimpleLookup", dt, + new[] { new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 50)) }); var lookupCata = Import(tbl); - var fkEi = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(n => n.GetRuntimeName() == "Name"); + var fkEi = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(n => n.GetRuntimeName() == "Name"); var pk = lookupCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "Name"); - var descLine1 = lookupCata.GetTableInfoList(false).Single().ColumnInfos.Single(n => n.GetRuntimeName() == "Description"); + var descLine1 = lookupCata.GetTableInfoList(false).Single().ColumnInfos + .Single(n => n.GetRuntimeName() == "Description"); - var cmd = new ExecuteCommandCreateLookup(CatalogueRepository, fkEi, descLine1, pk, null, true); + var cmd = new ExecuteCommandCreateLookup(CatalogueRepository, fkEi, descLine1, pk, null, true); cmd.Execute(); } - private ExtractDatasetCommand SetupExtractDatasetCommand(string testTableName, string[] pkExtractionColumns, string[] pkColumnInfos = null, bool withLookup = false, bool withJoin = false) + private ExtractDatasetCommand SetupExtractDatasetCommand(string testTableName, string[] pkExtractionColumns, + string[] pkColumnInfos = null, bool withLookup = false, bool withJoin = false) { var dt = new DataTable(); @@ -190,9 +210,10 @@ private ExtractDatasetCommand SetupExtractDatasetCommand(string testTableName, s var tbl = Database.CreateTable(testTableName, dt, - new[] { new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 50))}); + new[] { new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 50)) }); - _catalogue = Import(tbl, out var tableInfo, out var columnInfos, out var cataItems, out var extractionInformations); + _catalogue = Import(tbl, out var tableInfo, out var columnInfos, out var cataItems, + out var extractionInformations); var privateID = extractionInformations.First(e => e.GetRuntimeName().Equals("PrivateID")); privateID.IsExtractionIdentifier = true; @@ -220,10 +241,12 @@ private ExtractDatasetCommand SetupExtractDatasetCommand(string testTableName, s configuration.Cohort_ID = _extractableCohort.ID; configuration.SaveToDatabase(); - return new ExtractDatasetCommand( configuration, new ExtractableDatasetBundle(extractableDataSet)); + return new ExtractDatasetCommand(configuration, new ExtractableDatasetBundle(extractableDataSet)); } - private void SetupDataExport(string testDbName, ICatalogue catalogue, out ExtractionConfiguration extractionConfiguration, out IExtractableDataSet extractableDataSet, out IProject project) + private void SetupDataExport(string testDbName, ICatalogue catalogue, + out ExtractionConfiguration extractionConfiguration, out IExtractableDataSet extractableDataSet, + out IProject project) { extractableDataSet = new ExtractableDataSet(DataExportRepository, catalogue); @@ -241,8 +264,6 @@ private void SetupDataExport(string testDbName, ICatalogue catalogue, out Extrac extractionConfiguration.AddDatasetToConfiguration(extractableDataSet); foreach (var ei in _catalogue.GetAllExtractionInformation(ExtractionCategory.Supplemental)) - { extractionConfiguration.AddColumnToExtraction(extractableDataSet, ei); - } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/ExtractionSubdirectoryPatternTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/ExtractionSubdirectoryPatternTests.cs index d39e6c3d75..b25d70af15 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/ExtractionSubdirectoryPatternTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/ExtractionSubdirectoryPatternTests.cs @@ -17,7 +17,6 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; internal class ExtractionSubdirectoryPatternTests : UnitTests { - [Test] public void Test_NoRelativePaths() { @@ -26,8 +25,8 @@ public void Test_NoRelativePaths() ExtractionSubdirectoryPattern = "../../troll" }; - var ex = Assert.Throws(()=>dest.Check(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains("ExtractionSubdirectoryPattern cannot contain dots",ex.Message); + var ex = Assert.Throws(() => dest.Check(new ThrowImmediatelyCheckNotifier())); + StringAssert.Contains("ExtractionSubdirectoryPattern cannot contain dots", ex.Message); } [TestCase("bad")] @@ -42,8 +41,8 @@ public void Test_NoConfigToken(string badString) ExtractionSubdirectoryPattern = badString }; - var ex = Assert.Throws(()=>dest.Check(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains("ExtractionSubdirectoryPattern must contain a Configuration element",ex.Message); + var ex = Assert.Throws(() => dest.Check(new ThrowImmediatelyCheckNotifier())); + StringAssert.Contains("ExtractionSubdirectoryPattern must contain a Configuration element", ex.Message); } [TestCase("$c/fff")] @@ -55,8 +54,8 @@ public void Test_NoDatasetToken(string badString) ExtractionSubdirectoryPattern = badString }; - var ex = Assert.Throws(()=>dest.Check(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains("ExtractionSubdirectoryPattern must contain a Dataset element",ex.Message); + var ex = Assert.Throws(() => dest.Check(new ThrowImmediatelyCheckNotifier())); + StringAssert.Contains("ExtractionSubdirectoryPattern must contain a Dataset element", ex.Message); } /* @@ -78,7 +77,6 @@ public void Test_ValidPaths(string goodString, string pattern) { var sds = WhenIHaveA(); - sds.ExtractionConfiguration.Project.ExtractionDirectory = TestContext.CurrentContext.WorkDirectory; sds.ExtractionConfiguration.Name = "AAA"; @@ -86,15 +84,16 @@ public void Test_ValidPaths(string goodString, string pattern) sds.ExtractableDataSet.Catalogue.Acronym = "C"; - var cmd = new ExtractDatasetCommand(sds.ExtractionConfiguration, new ExtractableDatasetBundle(sds.ExtractableDataSet)); + var cmd = new ExtractDatasetCommand(sds.ExtractionConfiguration, + new ExtractableDatasetBundle(sds.ExtractableDataSet)); var dest = new ExecuteDatasetExtractionFlatFileDestination { ExtractionSubdirectoryPattern = goodString }; - Assert.DoesNotThrow(()=>dest.Check(new ThrowImmediatelyCheckNotifier())); + Assert.DoesNotThrow(() => dest.Check(new ThrowImmediatelyCheckNotifier())); var answer = dest.GetDirectoryFor(cmd); - StringAssert.IsMatch(pattern,answer.FullName.Replace('\\','/')); + StringAssert.IsMatch(pattern, answer.FullName.Replace('\\', '/')); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/HashedDataExtractionTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/HashedDataExtractionTests.cs index 8268d394d8..b24cf8582a 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/HashedDataExtractionTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/HashedDataExtractionTests.cs @@ -38,21 +38,23 @@ public void ExtractNormally() Assert.AreEqual(1, _request.ColumnsToExtract.Count(c => c.IsExtractionIdentifier)); var listener = new ToMemoryDataLoadEventListener(true); - Execute(out ExtractionPipelineUseCase execute,out var result,listener); + Execute(out var execute, out var result, listener); var messages = listener.EventsReceivedBySender.SelectMany(m => m.Value) - .Where(m=>m.ProgressEventType == ProgressEventType.Information && m.Message.Contains("/*Decided on extraction SQL:*/")) + .Where(m => m.ProgressEventType == ProgressEventType.Information && + m.Message.Contains("/*Decided on extraction SQL:*/")) .ToArray(); - Assert.AreEqual(1,messages.Length,"Expected a message about what the final extraction SQL was"); - Assert.IsTrue(messages[0].Message.Contains(" HASH JOIN "), "expected use of hash matching was not reported by ExecuteDatasetExtractionSource in the SQL actually executed"); + Assert.AreEqual(1, messages.Length, "Expected a message about what the final extraction SQL was"); + Assert.IsTrue(messages[0].Message.Contains(" HASH JOIN "), + "expected use of hash matching was not reported by ExecuteDatasetExtractionSource in the SQL actually executed"); var r = (ExecuteDatasetExtractionFlatFileDestination)result; //this should be what is in the file, the private identifier and the 1 that was put into the table in the first place (see parent class for the test data setup) Assert.AreEqual($@"ReleaseID,Name,DateOfBirth -{_cohortKeysGenerated[_cohortKeysGenerated.Keys.First()]},Dave,2001-01-01", File.ReadAllText(r.OutputFile).Trim()); +{_cohortKeysGenerated[_cohortKeysGenerated.Keys.First()]},Dave,2001-01-01", File.ReadAllText(r.OutputFile).Trim()); Assert.AreEqual(1, _request.QueryBuilder.SelectColumns.Count(c => c.IColumn is ReleaseIdentifierSubstitution)); File.Delete(r.OutputFile); diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/NormalDataExtractionTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/NormalDataExtractionTests.cs index a7c802a6ae..27675db426 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/NormalDataExtractionTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/NormalDataExtractionTests.cs @@ -17,25 +17,24 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; -public class NormalDataExtractionTests:TestsRequiringAnExtractionConfiguration +public class NormalDataExtractionTests : TestsRequiringAnExtractionConfiguration { [Test] public void ExtractNormally() { - _catalogue.Name = "TestTable"; _catalogue.SaveToDatabase(); _request.DatasetBundle.DataSet.RevertToDatabaseState(); Assert.AreEqual(1, _request.ColumnsToExtract.Count(c => c.IsExtractionIdentifier)); - - Execute(out ExtractionPipelineUseCase execute,out var result); + + Execute(out var execute, out var result); var r = (ExecuteDatasetExtractionFlatFileDestination)result; //this should be what is in the file, the private identifier and the 1 that was put into the table in the first place (see parent class for the test data setup) Assert.AreEqual($@"ReleaseID,Name,DateOfBirth -{_cohortKeysGenerated[_cohortKeysGenerated.Keys.First()]},Dave,2001-01-01", File.ReadAllText(r.OutputFile).Trim()); +{_cohortKeysGenerated[_cohortKeysGenerated.Keys.First()]},Dave,2001-01-01", File.ReadAllText(r.OutputFile).Trim()); Assert.AreEqual(1, _request.QueryBuilder.SelectColumns.Count(c => c.IColumn is ReleaseIdentifierSubstitution)); File.Delete(r.OutputFile); @@ -57,9 +56,14 @@ public void DodgyCharactersInCatalogueName() var extractionDirectory = new ExtractionDirectory(TestContext.CurrentContext.WorkDirectory, _configuration); - var ex = Assert.Throws(() => { var dir = extractionDirectory.GetDirectoryForDataset(_extractableDataSet); }); + var ex = Assert.Throws(() => + { + var dir = extractionDirectory.GetDirectoryForDataset(_extractableDataSet); + }); - Assert.AreEqual("Cannot extract dataset Fish;#:::FishFish because it points at Catalogue with an invalid name, name is invalid because:The following invalid characters were found:'#'", ex.Message); + Assert.AreEqual( + "Cannot extract dataset Fish;#:::FishFish because it points at Catalogue with an invalid name, name is invalid because:The following invalid characters were found:'#'", + ex.Message); } finally { diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/RowPeekerTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/RowPeekerTests.cs index 3f7244f43e..c3e6cb604f 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/RowPeekerTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/RowPeekerTests.cs @@ -26,55 +26,53 @@ public void Peeker() dt.Rows.Add("splish"); var mock = new Mock(); - mock.SetupSequence(m=>m.ReadOneRow()) + mock.SetupSequence(m => m.ReadOneRow()) .Returns(dt.Rows[0]) .Returns(dt.Rows[1]) .Returns(dt.Rows[2]) - .Returns(()=>{return null;}); + .Returns(() => { return null; }); var p = new RowPeeker(); var dt2 = new DataTable(); dt2.Columns.Add("MyCol"); //Reads fish and peeks dish - p.AddWhile(mock.Object,r=>(string) r["MyCol"] == "fish",dt2); + p.AddWhile(mock.Object, r => (string)r["MyCol"] == "fish", dt2); //read one row - Assert.AreEqual(1,dt2.Rows.Count); - Assert.AreEqual("fish",dt2.Rows[0]["MyCol"]); + Assert.AreEqual(1, dt2.Rows.Count); + Assert.AreEqual("fish", dt2.Rows[0]["MyCol"]); var dt3 = new DataTable(); dt3.Columns.Add("MyCol"); - + //cannot add while there is a peek stored - Assert.Throws(() => p.AddWhile(mock.Object, r => (string) r["MyCol"] == "fish", dt2)); + Assert.Throws(() => p.AddWhile(mock.Object, r => (string)r["MyCol"] == "fish", dt2)); //clear the peek //unpeeks dish p.AddPeekedRowsIfAny(dt3); - Assert.AreEqual(1,dt3.Rows.Count); - Assert.AreEqual("dish",dt3.Rows[0]["MyCol"]); + Assert.AreEqual(1, dt3.Rows.Count); + Assert.AreEqual("dish", dt3.Rows[0]["MyCol"]); //now we can read into dt4 but the condition is false //Reads nothing but peeks splish var dt4 = new DataTable(); dt4.Columns.Add("MyCol"); - p.AddWhile(mock.Object, r => (string) r["MyCol"] == "fish", dt4); + p.AddWhile(mock.Object, r => (string)r["MyCol"] == "fish", dt4); - Assert.AreEqual(0,dt4.Rows.Count); + Assert.AreEqual(0, dt4.Rows.Count); //we passed a null chunk and that pulls back the legit data table var dt5 = p.AddPeekedRowsIfAny(null); - + Assert.IsNotNull(dt5); - Assert.AreEqual("splish",dt5.Rows[0]["MyCol"]); + Assert.AreEqual("splish", dt5.Rows[0]["MyCol"]); var dt6 = new DataTable(); dt6.Columns.Add("MyCol"); - p.AddWhile(mock.Object, r => (string) r["MyCol"] == "fish", dt6); + p.AddWhile(mock.Object, r => (string)r["MyCol"] == "fish", dt6); - Assert.AreEqual(0,dt6.Rows.Count); + Assert.AreEqual(0, dt6.Rows.Count); } - - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/SimpleFileExtractorTests.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/SimpleFileExtractorTests.cs index 8280b791e2..0faa71c142 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/SimpleFileExtractorTests.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/SimpleFileExtractorTests.cs @@ -26,15 +26,14 @@ internal class SimpleFileExtractorTests [SetUp] public void SetUp() { - _extractor = new SimpleFileExtractor(); - _inDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory,"In")); - _outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory,"Out")); + _inDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "In")); + _outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "Out")); - if(_inDir.Exists) + if (_inDir.Exists) _inDir.Delete(true); - if(_outDir.Exists) + if (_outDir.Exists) _outDir.Delete(true); _inDir.Create(); @@ -42,15 +41,15 @@ public void SetUp() _extractor.LocationOfFiles = _inDir; - File.WriteAllText(Path.Combine(_inDir.FullName,"blah.txt"),"fff"); - File.WriteAllText(Path.Combine(_inDir.FullName,"blah2.txt"),"fff"); - File.WriteAllText(Path.Combine(_inDir.FullName,"Pat1.txt"),"fff"); + File.WriteAllText(Path.Combine(_inDir.FullName, "blah.txt"), "fff"); + File.WriteAllText(Path.Combine(_inDir.FullName, "blah2.txt"), "fff"); + File.WriteAllText(Path.Combine(_inDir.FullName, "Pat1.txt"), "fff"); _inDirSub1 = _inDir.CreateSubdirectory("Sub1"); _inDirSub2 = _inDir.CreateSubdirectory("Sub2"); - File.WriteAllText(Path.Combine(_inDirSub1.FullName,"subBlah.txt"),"fff"); - File.WriteAllText(Path.Combine(_inDirSub2.FullName,"subBlah2.txt"),"fff"); + File.WriteAllText(Path.Combine(_inDirSub1.FullName, "subBlah.txt"), "fff"); + File.WriteAllText(Path.Combine(_inDirSub2.FullName, "subBlah2.txt"), "fff"); } [Test] @@ -61,14 +60,15 @@ public void AllFiles() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); - _extractor.MoveAll(_outDir,new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + _extractor.MoveAll(_outDir, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - FileAssert.Exists(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.Exists(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.Exists(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.Exists(Path.Combine(_outDir.FullName, "blah2.txt")); } + [Test] public void OneFile() { @@ -77,16 +77,17 @@ public void OneFile() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); - _extractor.MoveAll(_outDir,new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + _extractor.MoveAll(_outDir, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - FileAssert.Exists(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub1")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub2")); + FileAssert.Exists(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub1")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub2")); } + [Test] public void AllDirs() { @@ -95,16 +96,17 @@ public void AllDirs() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); - _extractor.MoveAll(_outDir,new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + _extractor.MoveAll(_outDir, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - DirectoryAssert.Exists(Path.Combine(_outDir.FullName,"Sub1")); - DirectoryAssert.Exists(Path.Combine(_outDir.FullName,"Sub2")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + DirectoryAssert.Exists(Path.Combine(_outDir.FullName, "Sub1")); + DirectoryAssert.Exists(Path.Combine(_outDir.FullName, "Sub2")); } + [Test] public void OneDir() { @@ -113,16 +115,17 @@ public void OneDir() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); - _extractor.MoveAll(_outDir,new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + _extractor.MoveAll(_outDir, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - DirectoryAssert.Exists(Path.Combine(_outDir.FullName,"Sub1")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub2")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + DirectoryAssert.Exists(Path.Combine(_outDir.FullName, "Sub1")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub2")); } + [Test] public void PatientFiles() { @@ -132,15 +135,17 @@ public void PatientFiles() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); - _extractor.MovePatient("Pat1","Rel1",_outDir,new ThrowImmediatelyDataLoadEventListener {ThrowOnWarning=true},new GracefulCancellationToken()); - - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - FileAssert.Exists(Path.Combine(_outDir.FullName,"Rel1.txt")); + _extractor.MovePatient("Pat1", "Rel1", _outDir, + new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }, new GracefulCancellationToken()); + + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + FileAssert.Exists(Path.Combine(_outDir.FullName, "Rel1.txt")); } + [Test] public void PatientFileMissingOne() { @@ -150,22 +155,24 @@ public void PatientFileMissingOne() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); var mem = new ToMemoryDataLoadEventListener(true); - - _extractor.MovePatient("Pat1","Rel1",_outDir,mem,new GracefulCancellationToken()); - _extractor.MovePatient("Pat2","Rel2",_outDir,mem,new GracefulCancellationToken()); - - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - FileAssert.Exists(Path.Combine(_outDir.FullName,"Rel1.txt")); - - Assert.AreEqual(ProgressEventType.Warning,mem.GetWorst()); - - StringAssert.StartsWith("No Files were found matching Pattern Pat2.txt in ",mem.GetAllMessagesByProgressEventType()[ProgressEventType.Warning].Single().Message); + + _extractor.MovePatient("Pat1", "Rel1", _outDir, mem, new GracefulCancellationToken()); + _extractor.MovePatient("Pat2", "Rel2", _outDir, mem, new GracefulCancellationToken()); + + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + FileAssert.Exists(Path.Combine(_outDir.FullName, "Rel1.txt")); + + Assert.AreEqual(ProgressEventType.Warning, mem.GetWorst()); + + StringAssert.StartsWith("No Files were found matching Pattern Pat2.txt in ", + mem.GetAllMessagesByProgressEventType()[ProgressEventType.Warning].Single().Message); } + [Test] public void PatientDirs() { @@ -175,18 +182,20 @@ public void PatientDirs() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - - _extractor.MovePatient("Sub1","Rel1",_outDir,new ThrowImmediatelyDataLoadEventListener {ThrowOnWarning=true},new GracefulCancellationToken()); - - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - DirectoryAssert.Exists(Path.Combine(_outDir.FullName,"Rel1")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Rel2")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub1")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub2")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + + _extractor.MovePatient("Sub1", "Rel1", _outDir, + new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }, new GracefulCancellationToken()); + + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + DirectoryAssert.Exists(Path.Combine(_outDir.FullName, "Rel1")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Rel2")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub1")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub2")); } + [Test] public void PatientBothDirs() { @@ -196,24 +205,30 @@ public void PatientBothDirs() _extractor.OutputDirectoryName = _outDir.FullName; _extractor.Check(new ThrowImmediatelyCheckNotifier()); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); - _extractor.MovePatient("Sub1","Rel1",_outDir,new ThrowImmediatelyDataLoadEventListener {ThrowOnWarning=true},new GracefulCancellationToken()); - _extractor.MovePatient("Sub2","Rel2",_outDir,new ThrowImmediatelyDataLoadEventListener {ThrowOnWarning=true},new GracefulCancellationToken()); + _extractor.MovePatient("Sub1", "Rel1", _outDir, + new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }, new GracefulCancellationToken()); + _extractor.MovePatient("Sub2", "Rel2", _outDir, + new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }, new GracefulCancellationToken()); // does not exist - var ex = Assert.Throws(()=>_extractor.MovePatient("Sub3", "Rel3", _outDir, new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }, new GracefulCancellationToken())); - Assert.AreEqual($"No Directories were found matching Pattern Sub3 in {_inDir.FullName}. For private identifier 'Sub3'", ex.Message); - + var ex = Assert.Throws(() => _extractor.MovePatient("Sub3", "Rel3", _outDir, + new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }, new GracefulCancellationToken())); + Assert.AreEqual( + $"No Directories were found matching Pattern Sub3 in {_inDir.FullName}. For private identifier 'Sub3'", + ex.Message); + // if not throwing on warnings then a missing sub just passes through and is ignored - _extractor.MovePatient("Sub3", "Rel3", _outDir, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah.txt")); - FileAssert.DoesNotExist(Path.Combine(_outDir.FullName,"blah2.txt")); - DirectoryAssert.Exists(Path.Combine(_outDir.FullName,"Rel1")); - DirectoryAssert.Exists(Path.Combine(_outDir.FullName,"Rel2")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub1")); - DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName,"Sub2")); + _extractor.MovePatient("Sub3", "Rel3", _outDir, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); + + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah.txt")); + FileAssert.DoesNotExist(Path.Combine(_outDir.FullName, "blah2.txt")); + DirectoryAssert.Exists(Path.Combine(_outDir.FullName, "Rel1")); + DirectoryAssert.Exists(Path.Combine(_outDir.FullName, "Rel2")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub1")); + DirectoryAssert.DoesNotExist(Path.Combine(_outDir.FullName, "Sub2")); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/SupplementalExtractionResultsTest.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/SupplementalExtractionResultsTest.cs index 4f61a1c23c..c45b91d115 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/SupplementalExtractionResultsTest.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/SupplementalExtractionResultsTest.cs @@ -11,7 +11,7 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; -internal class SupplementalExtractionResultsTest:DatabaseTests +internal class SupplementalExtractionResultsTest : DatabaseTests { [Test] public void TestCreating() @@ -21,15 +21,14 @@ public void TestCreating() var ec = new ExtractionConfiguration(DataExportRepository, p); var cata = new Catalogue(CatalogueRepository, "MyCata"); - var tbl = new SupportingSQLTable(CatalogueRepository,cata,"Some global data"); + var tbl = new SupportingSQLTable(CatalogueRepository, cata, "Some global data"); var othertbl = new SupportingSQLTable(CatalogueRepository, cata, "Some global data"); - var result = new SupplementalExtractionResults(DataExportRepository,ec,"select * from Globalsglba",tbl); + var result = new SupplementalExtractionResults(DataExportRepository, ec, "select * from Globalsglba", tbl); Assert.IsTrue(result.IsReferenceTo(typeof(SupportingSQLTable))); Assert.IsTrue(result.IsReferenceTo(tbl)); Assert.IsFalse(result.IsReferenceTo(othertbl)); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/DataExtraction/TestCohortRefreshing.cs b/Rdmp.Core.Tests/DataExport/DataExtraction/TestCohortRefreshing.cs index f0fcbd941c..37fe0de4e1 100644 --- a/Rdmp.Core.Tests/DataExport/DataExtraction/TestCohortRefreshing.cs +++ b/Rdmp.Core.Tests/DataExport/DataExtraction/TestCohortRefreshing.cs @@ -27,26 +27,25 @@ namespace Rdmp.Core.Tests.DataExport.DataExtraction; public class TestCohortRefreshing : TestsRequiringAnExtractionConfiguration { - [Test] public void RefreshCohort() { - var pipe = SetupPipeline(); pipe.Name = "RefreshPipe"; pipe.SaveToDatabase(); - Execute(out ExtractionPipelineUseCase useCase, out IExecuteDatasetExtractionDestination results); + Execute(out var useCase, out var results); var oldcohort = _configuration.Cohort; - _configuration.CohortIdentificationConfiguration_ID =new CohortIdentificationConfiguration(RepositoryLocator.CatalogueRepository, "RefreshCohort.cs").ID; + _configuration.CohortIdentificationConfiguration_ID = + new CohortIdentificationConfiguration(RepositoryLocator.CatalogueRepository, "RefreshCohort.cs").ID; _configuration.CohortRefreshPipeline_ID = pipe.ID; _configuration.SaveToDatabase(); var engine = new CohortRefreshEngine(new ThrowImmediatelyDataLoadEventListener(), _configuration); - + Assert.NotNull(engine.Request.NewCohortDefinition); var oldData = oldcohort.GetExternalData(); @@ -75,16 +74,16 @@ public void RefreshCohort() [Test] public void RefreshCohort_WithCaching() { - var pipe = new Pipeline(CatalogueRepository, "RefreshPipeWithCaching"); - var source = new PipelineComponent(CatalogueRepository, pipe, typeof (CohortIdentificationConfigurationSource), 0); + var source = + new PipelineComponent(CatalogueRepository, pipe, typeof(CohortIdentificationConfigurationSource), 0); var args = source.CreateArgumentsForClassIfNotExists(); var freezeArg = args.Single(a => a.Name.Equals("FreezeAfterSuccessfulImport")); freezeArg.SetValue(false); freezeArg.SaveToDatabase(); - var dest = new PipelineComponent(CatalogueRepository, pipe, typeof (BasicCohortDestination), 0); + var dest = new PipelineComponent(CatalogueRepository, pipe, typeof(BasicCohortDestination), 0); var argsDest = dest.CreateArgumentsForClassIfNotExists(); var allocatorArg = argsDest.Single(a => a.Name.Equals("ReleaseIdentifierAllocator")); allocatorArg.SetValue(null); @@ -94,7 +93,7 @@ public void RefreshCohort_WithCaching() pipe.DestinationPipelineComponent_ID = dest.ID; pipe.SaveToDatabase(); - Execute(out ExtractionPipelineUseCase useCase, out IExecuteDatasetExtractionDestination results); + Execute(out var useCase, out var results); var oldcohort = _configuration.Cohort; @@ -102,7 +101,8 @@ public void RefreshCohort_WithCaching() var p = new QueryCachingPatcher(); var queryCacheServer = new ExternalDatabaseServer(CatalogueRepository, "TestCohortRefreshing_CacheTest", p); - var cachedb = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase("TestCohortRefreshing_CacheTest"); + var cachedb = + DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase("TestCohortRefreshing_CacheTest"); if (cachedb.Exists()) cachedb.Drop(); @@ -123,7 +123,7 @@ public void RefreshCohort_WithCaching() //add the sub query as the only entry in the cic (in the root container) cic.CreateRootContainerIfNotExists(); - cic.RootCohortAggregateContainer.AddChild(agg,1); + cic.RootCohortAggregateContainer.AddChild(agg, 1); //make the ExtractionConfiguration refresh cohort query be the cic _configuration.CohortIdentificationConfiguration_ID = cic.ID; @@ -141,10 +141,11 @@ public void RefreshCohort_WithCaching() Assert.AreEqual(oldData.ExternalDescription, engine.Request.NewCohortDefinition.Description); Assert.AreEqual(oldData.ExternalVersion + 1, engine.Request.NewCohortDefinition.Version); - Assert.AreNotEqual(oldcohort.CountDistinct,engine.Request.CohortCreatedIfAny.CountDistinct); + Assert.AreNotEqual(oldcohort.CountDistinct, engine.Request.CohortCreatedIfAny.CountDistinct); //now nuke all data in the catalogue so the cic returns nobody (except that the identifiers are cached eh?) - DataAccessPortal.ExpectDatabase(_tableInfo,DataAccessContext.InternalDataProcessing).ExpectTable(_tableInfo.GetRuntimeName()).Truncate(); + DataAccessPortal.ExpectDatabase(_tableInfo, DataAccessContext.InternalDataProcessing) + .ExpectTable(_tableInfo.GetRuntimeName()).Truncate(); var toMem = new ToMemoryDataLoadEventListener(false); @@ -152,15 +153,17 @@ public void RefreshCohort_WithCaching() engine = new CohortRefreshEngine(toMem, _configuration); //execute it - var ex = Assert.Throws(()=>engine.Execute()); + var ex = Assert.Throws(() => engine.Execute()); - Assert.IsTrue(ex.InnerException.InnerException.Message.Contains("CohortIdentificationCriteria execution resulted in an empty dataset")); + Assert.IsTrue( + ex.InnerException.InnerException.Message.Contains( + "CohortIdentificationCriteria execution resulted in an empty dataset")); //expected this message to happen //that it did clear the cache - Assert.AreEqual(1,toMem.EventsReceivedBySender.SelectMany(kvp=>kvp.Value).Count(msg=>msg.Message.Equals("Clearing Cohort Identifier Cache"))); - - + Assert.AreEqual(1, + toMem.EventsReceivedBySender.SelectMany(kvp => kvp.Value) + .Count(msg => msg.Message.Equals("Clearing Cohort Identifier Cache"))); } finally { diff --git a/Rdmp.Core.Tests/DataExport/ExtractionConfigurationTest.cs b/Rdmp.Core.Tests/DataExport/ExtractionConfigurationTest.cs index 0fd15d604b..42eac27cdc 100644 --- a/Rdmp.Core.Tests/DataExport/ExtractionConfigurationTest.cs +++ b/Rdmp.Core.Tests/DataExport/ExtractionConfigurationTest.cs @@ -17,7 +17,7 @@ public class ExtractionConfigurationTest : DatabaseTests [Test] public void ExtractableColumnTest() { - ExtractableDataSet dataSet =null; + ExtractableDataSet dataSet = null; ExtractionConfiguration configuration = null; Project project = null; @@ -26,11 +26,11 @@ public void ExtractableColumnTest() ColumnInfo column = null; TableInfo table = null; - ExtractionInformation extractionInformation=null; - ExtractableColumn extractableColumn=null; - + ExtractionInformation extractionInformation = null; + ExtractableColumn extractableColumn = null; + try - { + { //setup catalogue side of things cata = new Catalogue(CatalogueRepository, "unit_test_ExtractableColumnTest_Cata"); cataItem = new CatalogueItem(CatalogueRepository, cata, "unit_test_ExtractableColumnTest_CataItem"); @@ -46,10 +46,11 @@ public void ExtractableColumnTest() configuration = new ExtractionConfiguration(DataExportRepository, project); - extractableColumn = new ExtractableColumn(DataExportRepository, dataSet, configuration, extractionInformation, 0, "Hashme2(Name)"); + extractableColumn = new ExtractableColumn(DataExportRepository, dataSet, configuration, + extractionInformation, 0, "Hashme2(Name)"); Assert.AreEqual(configuration.GetAllExtractableColumnsFor(dataSet).Length, 1); } - finally + finally { extractionInformation?.DeleteInDatabase(); @@ -66,9 +67,6 @@ public void ExtractableColumnTest() dataSet?.DeleteInDatabase(); cata?.DeleteInDatabase(); - - - } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/ImportFileTests.cs b/Rdmp.Core.Tests/DataExport/ImportFileTests.cs index 15e7085ffd..8ad343e438 100644 --- a/Rdmp.Core.Tests/DataExport/ImportFileTests.cs +++ b/Rdmp.Core.Tests/DataExport/ImportFileTests.cs @@ -18,14 +18,14 @@ namespace Rdmp.Core.Tests.DataExport; -public class ImportFileTests:DatabaseTests +public class ImportFileTests : DatabaseTests { [Test] public void ImportFile() { var file = Path.GetTempFileName(); var databaseName = TestDatabaseNames.GetConsistentName(GetType().Name); - + try { using (var sw = new StreamWriter(file)) @@ -48,7 +48,8 @@ public void ImportFile() StronglyTypeInput = true }; - source.PreInitialize(new FlatFileToLoad(new FileInfo(file)), new ThrowImmediatelyDataLoadEventListener());//this is the file we want to load + source.PreInitialize(new FlatFileToLoad(new FileInfo(file)), + new ThrowImmediatelyDataLoadEventListener()); //this is the file we want to load source.Check(new ThrowImmediatelyCheckNotifier()); var server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn; @@ -56,7 +57,7 @@ public void ImportFile() //recreate it database.Create(true); - + server.ChangeDatabase(databaseName); var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); @@ -80,7 +81,7 @@ public void ImportFile() Assert.AreEqual("decimal(3,2)", GetColumnType(database, tableName, "Healthiness")); Assert.AreEqual("datetime2", GetColumnType(database, tableName, "DateOfImagining")); - using (var con = (SqlConnection) server.GetConnection()) + using (var con = (SqlConnection)server.GetConnection()) { con.Open(); @@ -107,7 +108,7 @@ public void ImportFile() server.ExpectDatabase(databaseName).Drop(); Assert.IsFalse(server.ExpectDatabase(databaseName).Exists()); } - finally + finally { try { @@ -117,14 +118,9 @@ public void ImportFile() { //Couldn't delete temporary file... oh well } - } - } - private static string GetColumnType(DiscoveredDatabase database, string tableName, string colName) - { - return - database.ExpectTable(tableName).DiscoverColumn(colName).DataType.SQLType; - } + private static string GetColumnType(DiscoveredDatabase database, string tableName, string colName) => + database.ExpectTable(tableName).DiscoverColumn(colName).DataType.SQLType; } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/ProjectChecksTestsComplex.cs b/Rdmp.Core.Tests/DataExport/ProjectChecksTestsComplex.cs index b719a538da..2aecf68e18 100644 --- a/Rdmp.Core.Tests/DataExport/ProjectChecksTestsComplex.cs +++ b/Rdmp.Core.Tests/DataExport/ProjectChecksTestsComplex.cs @@ -16,12 +16,13 @@ namespace Rdmp.Core.Tests.DataExport; -public class ProjectChecksTestsComplex:TestsRequiringAnExtractionConfiguration +public class ProjectChecksTestsComplex : TestsRequiringAnExtractionConfiguration { [Test] public void CheckBasicConfiguration() { - new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator),_project).Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); + new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator), _project).Check( + new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); } [Test] @@ -31,13 +32,18 @@ public void DatasetIsDisabled() _extractableDataSet.SaveToDatabase(); //checking should fail - var exception = Assert.Throws(() => new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator), _project).Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); - Assert.AreEqual("Dataset TestTable is set to DisableExtraction=true, probably someone doesn't want you extracting this dataset at the moment", exception.Message); + var exception = Assert.Throws(() => + new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator), _project).Check( + new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); + Assert.AreEqual( + "Dataset TestTable is set to DisableExtraction=true, probably someone doesn't want you extracting this dataset at the moment", + exception.Message); //but if the user goes ahead and executes the extraction that should fail too var source = new ExecuteDatasetExtractionSource(); source.PreInitialize(_request, new ThrowImmediatelyDataLoadEventListener()); - var exception2 = Assert.Throws(() => source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var exception2 = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); Assert.AreEqual("Cannot extract TestTable because DisableExtraction is set to true", exception2.Message); } diff --git a/Rdmp.Core.Tests/DataExport/ProjectChecksTestsSimple.cs b/Rdmp.Core.Tests/DataExport/ProjectChecksTestsSimple.cs index b2fcf18c73..cf2f20960e 100644 --- a/Rdmp.Core.Tests/DataExport/ProjectChecksTestsSimple.cs +++ b/Rdmp.Core.Tests/DataExport/ProjectChecksTestsSimple.cs @@ -17,7 +17,7 @@ namespace Rdmp.Core.Tests.DataExport; -public class ProjectChecksTestsSimple:DatabaseTests +public class ProjectChecksTestsSimple : DatabaseTests { [Test] public void Project_NoConfigurations() @@ -26,9 +26,10 @@ public void Project_NoConfigurations() try { - var ex = Assert.Throws(()=>new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator),p).Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Project does not have any ExtractionConfigurations yet",ex.Message); - + var ex = Assert.Throws(() => + new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator), p).Check( + new ThrowImmediatelyCheckNotifier())); + Assert.AreEqual("Project does not have any ExtractionConfigurations yet", ex.Message); } finally { @@ -40,9 +41,8 @@ public void Project_NoConfigurations() public void Project_NoDirectory() { var p = GetProjectWithConfig(out var config); - var ex = Assert.Throws(()=>RunTestWithCleanup(p, config)); + var ex = Assert.Throws(() => RunTestWithCleanup(p, config)); Assert.AreEqual("Project does not have an ExtractionDirectory", ex.Message); - } [Test] @@ -52,11 +52,10 @@ public void Project_NoDirectory() public void Project_NonExistentDirectory(string dir) { var p = GetProjectWithConfig(out var config); - - p.ExtractionDirectory = dir; - var ex = Assert.Throws(()=>RunTestWithCleanup(p, config)); - Assert.IsTrue(Regex.IsMatch(ex.Message,@"Project ExtractionDirectory .* Does Not Exist")); + p.ExtractionDirectory = dir; + var ex = Assert.Throws(() => RunTestWithCleanup(p, config)); + Assert.IsTrue(Regex.IsMatch(ex.Message, @"Project ExtractionDirectory .* Does Not Exist")); } [Test] @@ -65,7 +64,7 @@ public void Project_DodgyCharactersInExtractionDirectoryName() var p = GetProjectWithConfig(out var config); p.ExtractionDirectory = @"C:\|||"; - var ex = Assert.Throws(()=>RunTestWithCleanup(p,config)); + var ex = Assert.Throws(() => RunTestWithCleanup(p, config)); Assert.AreEqual(@"Project ExtractionDirectory ('C:\|||') Does Not Exist", ex.Message); } @@ -76,11 +75,11 @@ public void ConfigurationFrozen_Remnants() //create remnant directory (empty) var remnantDir = dir.CreateSubdirectory($"Extr_{config.ID}20011225"); - + //with empty subdirectories remnantDir.CreateSubdirectory("DMPTestCatalogue").CreateSubdirectory("Lookups"); - config.IsReleased = true;//make environment think config is released + config.IsReleased = true; //make environment think config is released config.SaveToDatabase(); try @@ -90,12 +89,11 @@ public void ConfigurationFrozen_Remnants() Assert.IsTrue(remnantDir.Exists); //resolve accepting deletion - new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator),p).Check(new AcceptAllCheckNotifier()); + new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator), p).Check(new AcceptAllCheckNotifier()); //boom remnant doesnt exist anymore (but parent does obviously) Assert.IsTrue(dir.Exists); - Assert.IsFalse(Directory.Exists(remnantDir.FullName));//cant use .Exists for some reason, c# caches answer? - + Assert.IsFalse(Directory.Exists(remnantDir.FullName)); //cant use .Exists for some reason, c# caches answer? } finally { @@ -117,18 +115,19 @@ public void ConfigurationFrozen_RemnantsWithFiles() var lookupDir = remnantDir.CreateSubdirectory("DMPTestCatalogue").CreateSubdirectory("Lookups"); //this time put a file in - File.AppendAllLines(Path.Combine(lookupDir.FullName,"Text.txt"),new string[]{"Amagad"}); + File.AppendAllLines(Path.Combine(lookupDir.FullName, "Text.txt"), new string[] { "Amagad" }); - config.IsReleased = true;//make environment think config is released + config.IsReleased = true; //make environment think config is released config.SaveToDatabase(); try { var notifier = new ToMemoryCheckNotifier(); - RunTestWithCleanup(p,config,notifier); + RunTestWithCleanup(p, config, notifier); Assert.IsTrue(notifier.Messages.Any( - m=>m.Result == CheckResult.Fail && - Regex.IsMatch(m.Message,@"Found non-empty folder .* which is left over extracted folder after data release \(First file found was '.*[/\\]DMPTestCatalogue[/\\]Lookups[/\\]Text.txt' but there may be others\)"))); + m => m.Result == CheckResult.Fail && + Regex.IsMatch(m.Message, + @"Found non-empty folder .* which is left over extracted folder after data release \(First file found was '.*[/\\]DMPTestCatalogue[/\\]Lookups[/\\]Text.txt' but there may be others\)"))); } finally { @@ -139,27 +138,30 @@ public void ConfigurationFrozen_RemnantsWithFiles() [Test] public void Configuration_NoDatasets() { - var p = GetProjectWithConfigDirectory(out var config, out DirectoryInfo dir); - var ex = Assert.Throws(()=>RunTestWithCleanup(p,config)); - StringAssert.StartsWith("There are no datasets selected for open configuration 'New ExtractionConfiguration",ex.Message); - + var p = GetProjectWithConfigDirectory(out var config, out var dir); + var ex = Assert.Throws(() => RunTestWithCleanup(p, config)); + StringAssert.StartsWith("There are no datasets selected for open configuration 'New ExtractionConfiguration", + ex.Message); } [Test] public void Configuration_NoProjectNumber() { - var p = GetProjectWithConfigDirectory(out var config, out DirectoryInfo dir); + var p = GetProjectWithConfigDirectory(out var config, out var dir); p.ProjectNumber = null; - var ex = Assert.Throws(()=>RunTestWithCleanup(p, config)); - StringAssert.Contains("Project does not have a Project Number, this is a number which is meaningful to you (as opposed to ID which is the ",ex.Message); + var ex = Assert.Throws(() => RunTestWithCleanup(p, config)); + StringAssert.Contains( + "Project does not have a Project Number, this is a number which is meaningful to you (as opposed to ID which is the ", + ex.Message); } - private void RunTestWithCleanup(Project p,ExtractionConfiguration config, ICheckNotifier notifier = null) + private void RunTestWithCleanup(Project p, ExtractionConfiguration config, ICheckNotifier notifier = null) { try { - new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator),p).Check(notifier??new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); + new ProjectChecker(new ThrowImmediatelyActivator(RepositoryLocator), p).Check(notifier ?? + new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); } finally { @@ -174,18 +176,18 @@ private Project GetProjectWithConfig(out ExtractionConfiguration config) { ProjectNumber = -5000 }; - config = new ExtractionConfiguration(DataExportRepository,p); + config = new ExtractionConfiguration(DataExportRepository, p); return p; } - private Project GetProjectWithConfigDirectory(out ExtractionConfiguration config,out DirectoryInfo dir) + private Project GetProjectWithConfigDirectory(out ExtractionConfiguration config, out DirectoryInfo dir) { var p = new Project(DataExportRepository, "Fish"); config = new ExtractionConfiguration(DataExportRepository, p); var projectFolder = Path.Combine(TestContext.CurrentContext.WorkDirectory, "ProjectCheckerTestDir"); - dir = new DirectoryInfo(projectFolder ); + dir = new DirectoryInfo(projectFolder); dir.Create(); p.ExtractionDirectory = projectFolder; diff --git a/Rdmp.Core.Tests/DataExport/ProjectCohortIdentificationConfigurationAssociationTests.cs b/Rdmp.Core.Tests/DataExport/ProjectCohortIdentificationConfigurationAssociationTests.cs index 92400a188a..c6329b2fd2 100644 --- a/Rdmp.Core.Tests/DataExport/ProjectCohortIdentificationConfigurationAssociationTests.cs +++ b/Rdmp.Core.Tests/DataExport/ProjectCohortIdentificationConfigurationAssociationTests.cs @@ -20,21 +20,20 @@ namespace Rdmp.Core.Tests.DataExport; [Category("Unit")] public class ProjectCohortIdentificationConfigurationAssociationTests { - [Test] public void TestOrphanCic() { var memory = new MemoryDataExportRepository(); var cic = new CohortIdentificationConfiguration(memory, "Mycic"); - var p = new Project(memory,"my proj"); + var p = new Project(memory, "my proj"); p.AssociateWithCohortIdentification(cic); //fetch the instance var cicAssoc = memory.GetAllObjects().Single(); - + //relationship from p should resolve to the association link - Assert.AreEqual(cicAssoc,p.ProjectCohortIdentificationConfigurationAssociations[0]); - + Assert.AreEqual(cicAssoc, p.ProjectCohortIdentificationConfigurationAssociations[0]); + //relationship from p should resolve to the cic Assert.AreEqual(cic, p.GetAssociatedCohortIdentificationConfigurations()[0]); @@ -45,25 +44,31 @@ public void TestOrphanCic() //make the assoc an orphan cic.DeleteInDatabase(); cicAssoc.ClearAllInjections(); - + //assoc should still exist Assert.AreEqual(cicAssoc, p.ProjectCohortIdentificationConfigurationAssociations[0]); Assert.IsNull(p.ProjectCohortIdentificationConfigurationAssociations[0].CohortIdentificationConfiguration); - + //relationship from p should resolve to the cic - Assert.IsEmpty( p.GetAssociatedCohortIdentificationConfigurations()); + Assert.IsEmpty(p.GetAssociatedCohortIdentificationConfigurations()); //error should be reported in top right of program - var ex = Assert.Throws(()=>new DataExportChildProvider(new RepositoryProvider(memory), null, new ThrowImmediatelyCheckNotifier(),null)); - StringAssert.IsMatch(@"Failed to find Associated Cohort Identification Configuration with ID \d+ which was supposed to be associated with my proj", ex.Message); + var ex = Assert.Throws(() => + new DataExportChildProvider(new RepositoryProvider(memory), null, new ThrowImmediatelyCheckNotifier(), + null)); + StringAssert.IsMatch( + @"Failed to find Associated Cohort Identification Configuration with ID \d+ which was supposed to be associated with my proj", + ex.Message); //but UI should still respond - var childProvider = new DataExportChildProvider(new RepositoryProvider(memory), null, new IgnoreAllErrorsCheckNotifier(),null); + var childProvider = new DataExportChildProvider(new RepositoryProvider(memory), null, + new IgnoreAllErrorsCheckNotifier(), null); //the orphan cic should not appear in the tree view under Project=>Cohorts=>Associated Cics var cohorts = childProvider.GetChildren(p).OfType().Single(); - var cics = childProvider.GetChildren(cohorts).OfType().First(); - + var cics = childProvider.GetChildren(cohorts).OfType() + .First(); + Assert.IsEmpty(childProvider.GetChildren(cics)); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/TableValuedFunctionTests/EndToEndTableValuedFunction.cs b/Rdmp.Core.Tests/DataExport/TableValuedFunctionTests/EndToEndTableValuedFunction.cs index 9668b33401..eeed618fd0 100644 --- a/Rdmp.Core.Tests/DataExport/TableValuedFunctionTests/EndToEndTableValuedFunction.cs +++ b/Rdmp.Core.Tests/DataExport/TableValuedFunctionTests/EndToEndTableValuedFunction.cs @@ -31,7 +31,7 @@ namespace Rdmp.Core.Tests.DataExport.TableValuedFunctionTests; -public class EndToEndTableValuedFunction:DatabaseTests +public class EndToEndTableValuedFunction : DatabaseTests { private ExtractionInformation _nonTvfExtractionIdentifier; private ICatalogue _nonTvfCatalogue; @@ -42,6 +42,7 @@ public class EndToEndTableValuedFunction:DatabaseTests //the cohort database private DiscoveredDatabase _discoveredCohortDatabase; + //the data database (with the tvf in it) private DiscoveredDatabase _database; @@ -63,21 +64,23 @@ protected override void SetUp() public void EndToEndTest() { var cohortDatabaseNameWillBe = TestDatabaseNames.GetConsistentName("TbvCohort"); - _discoveredCohortDatabase = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(cohortDatabaseNameWillBe); + _discoveredCohortDatabase = + DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(cohortDatabaseNameWillBe); //cleanup - if(_discoveredCohortDatabase.Exists()) + if (_discoveredCohortDatabase.Exists()) _discoveredCohortDatabase.Drop(); //create a normal catalogue CreateANormalCatalogue(); //create a cohort database using wizard - var cohortDatabaseWizard = new CreateNewCohortDatabaseWizard(_discoveredCohortDatabase,CatalogueRepository,DataExportRepository,false); + var cohortDatabaseWizard = new CreateNewCohortDatabaseWizard(_discoveredCohortDatabase, CatalogueRepository, + DataExportRepository, false); _externalCohortTable = cohortDatabaseWizard.CreateDatabase( new PrivateIdentifierPrototype(_nonTvfExtractionIdentifier) - ,new ThrowImmediatelyCheckNotifier()); + , new ThrowImmediatelyCheckNotifier()); //create a table valued function CreateTvfCatalogue(cohortDatabaseNameWillBe); @@ -137,15 +140,17 @@ private void PopulateCohortDatabaseWithRecordsFromNonTvfCatalogue() _cic.CreateRootContainerIfNotExists(); //turn the catalogue _nonTvfCatalogue into a cohort set and add it to the root container - var newAggregate = _cic.CreateNewEmptyConfigurationForCatalogue(_nonTvfCatalogue,(s,e)=> { throw new Exception("Did not expect there to be more than 1!"); }); + var newAggregate = _cic.CreateNewEmptyConfigurationForCatalogue(_nonTvfCatalogue, + (s, e) => { throw new Exception("Did not expect there to be more than 1!"); }); var root = _cic.RootCohortAggregateContainer; - root.AddChild(newAggregate,0); + root.AddChild(newAggregate, 0); //create a pipeline for executing this CIC and turning it into a cohort _pipe = new Pipeline(CatalogueRepository, "CREATE COHORT:By Executing CIC"); - var source = new PipelineComponent(CatalogueRepository, _pipe,typeof (CohortIdentificationConfigurationSource), 0, "CIC Source"); + var source = new PipelineComponent(CatalogueRepository, _pipe, typeof(CohortIdentificationConfigurationSource), + 0, "CIC Source"); _project = new Project(DataExportRepository, "TvfProject") { @@ -154,7 +159,8 @@ private void PopulateCohortDatabaseWithRecordsFromNonTvfCatalogue() }; _project.SaveToDatabase(); - var destination = new PipelineComponent(CatalogueRepository, _pipe, typeof(BasicCohortDestination), 1, "Destination"); + var destination = + new PipelineComponent(CatalogueRepository, _pipe, typeof(BasicCohortDestination), 1, "Destination"); _pipe.SourcePipelineComponent_ID = source.ID; _pipe.DestinationPipelineComponent_ID = destination.ID; @@ -165,11 +171,13 @@ private void PopulateCohortDatabaseWithRecordsFromNonTvfCatalogue() destination.CreateArgumentsForClassIfNotExists(); //create pipeline initialization objects - var request = new CohortCreationRequest(_project, new CohortDefinition(null, "MyFirstCohortForTvfTest", 1, 12, _externalCohortTable), DataExportRepository, "Here goes nothing") - { - CohortIdentificationConfiguration = _cic - }; - var engine = request.GetEngine(_pipe,new ThrowImmediatelyDataLoadEventListener()); + var request = new CohortCreationRequest(_project, + new CohortDefinition(null, "MyFirstCohortForTvfTest", 1, 12, _externalCohortTable), DataExportRepository, + "Here goes nothing") + { + CohortIdentificationConfiguration = _cic + }; + var engine = request.GetEngine(_pipe, new ThrowImmediatelyDataLoadEventListener()); engine.ExecutePipeline(new GracefulCancellationToken()); } @@ -215,11 +223,9 @@ definitionID int Assert.AreEqual("chi", eis[0].GetRuntimeName()); eis[0].IsExtractionIdentifier = true; eis[0].SaveToDatabase(); - + _tvfCatalogue = cata; _tvfTableInfo = tbl; - - } private void CreateANormalCatalogue() @@ -228,7 +234,7 @@ private void CreateANormalCatalogue() using (var con = svr.GetConnection()) { con.Open(); - svr.GetCommand("CREATE TABLE NonTVFTable ( chi varchar(10))",con).ExecuteNonQuery(); + svr.GetCommand("CREATE TABLE NonTVFTable ( chi varchar(10))", con).ExecuteNonQuery(); svr.GetCommand("INSERT INTO NonTVFTable VALUES ('0101010101')", con).ExecuteNonQuery(); svr.GetCommand("INSERT INTO NonTVFTable VALUES ('0202020202')", con).ExecuteNonQuery(); svr.GetCommand("INSERT INTO NonTVFTable VALUES ('0303030303')", con).ExecuteNonQuery(); @@ -236,17 +242,18 @@ private void CreateANormalCatalogue() var importer = new TableInfoImporter(CatalogueRepository, svr.Name, _database.GetRuntimeName(), "NonTVFTable", - DatabaseType.MicrosoftSQLServer,_database.Server.ExplicitUsernameIfAny,_database.Server.ExplicitPasswordIfAny); + DatabaseType.MicrosoftSQLServer, _database.Server.ExplicitUsernameIfAny, + _database.Server.ExplicitPasswordIfAny); importer.DoImport(out var tbl, out var cols); var engineer = new ForwardEngineerCatalogue(tbl, cols); engineer.ExecuteForwardEngineering(out var cata, out var cis, out var eis); - - _nonTvfExtractionIdentifier = eis.Single(); + + _nonTvfExtractionIdentifier = eis.Single(); _nonTvfExtractionIdentifier.IsExtractionIdentifier = true; _nonTvfExtractionIdentifier.SaveToDatabase(); - + _nonTvfCatalogue = cata; _nonTvfTableInfo = tbl; } @@ -291,17 +298,16 @@ private void TestWithParameterValueThatRowsAreReturned() Assert.NotNull(r["definitionID"]); } - Assert.AreEqual(rowsReturned,5); + Assert.AreEqual(rowsReturned, 5); } } private void TestUsingTvfForAggregates() { + _aggregate = new AggregateConfiguration(CatalogueRepository, _tvfCatalogue, "tvfAggregate"); - - _aggregate = new AggregateConfiguration(CatalogueRepository, _tvfCatalogue,"tvfAggregate"); - - var ei = _tvfCatalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(e => !e.IsExtractionIdentifier); + var ei = _tvfCatalogue.GetAllExtractionInformation(ExtractionCategory.Any) + .Single(e => !e.IsExtractionIdentifier); _aggregate.AddDimension(ei); //change the parameter to 10 @@ -316,18 +322,18 @@ private void TestUsingTvfForAggregates() * DECLARE @numberOfRecords AS int; * SET @numberOfRecords=10; * tvfAggregate - * SELECT + * SELECT * GetTopXRandom.[definitionID], * count(*) - * FROM + * FROM * [TestDbName_ScratchArea]..GetTopXRandom(@numberOfRecords) AS GetTopXRandom - * group by + * group by + * GetTopXRandom.[definitionID] + * order by * GetTopXRandom.[definitionID] - * order by - * GetTopXRandom.[definitionID] - * - * --Since we only imported 1 cohort we should have 1 row and the count should be the number we requested - * + * + * --Since we only imported 1 cohort we should have 1 row and the count should be the number we requested + * * */ var sql = qb.SQL; @@ -340,16 +346,16 @@ private void TestUsingTvfForAggregates() Assert.IsTrue(r.Read()); - Assert.AreEqual(r[1],10); + Assert.AreEqual(r[1], 10); Assert.IsFalse(r.Read()); } //create a global overriding parameter on the aggregate var global = new AnyTableSqlParameter(CatalogueRepository, _aggregate, "DECLARE @numberOfRecords AS int;") - { - Value = "1" - }; + { + Value = "1" + }; global.SaveToDatabase(); @@ -363,7 +369,7 @@ private void TestUsingTvfForAggregates() Assert.IsTrue(r.Read()); - Assert.AreEqual(r[1], 1);//should now only have 1 record being retrned and counted when executing + Assert.AreEqual(r[1], 1); //should now only have 1 record being retrned and counted when executing Assert.IsFalse(r.Read()); } @@ -382,7 +388,7 @@ private void TestAddingTvfToCIC() Assert.AreEqual(1, _cicAggregate.GetAllParameters().Length); //add the new cic to the container - root.AddChild(_cicAggregate,2); + root.AddChild(_cicAggregate, 2); //So container is: // EXCEPT @@ -390,7 +396,7 @@ private void TestAddingTvfToCIC() //People in _tvfCatalogue (with @numberOfRecords = 1) (1) //result should be 2 - var qb = new CohortQueryBuilder(_cic,null); + var qb = new CohortQueryBuilder(_cic, null); var sql = qb.SQL; @@ -423,12 +429,13 @@ private void TestDataExportOfTvf() //make all columns part of the extraction foreach (var e in _tvfCatalogue.GetAllExtractionInformation(ExtractionCategory.Any)) config.AddColumnToExtraction(tvfExtractable, e); - + //the default value should be 10 - Assert.AreEqual("10",_tvfTableInfo.GetAllParameters().Single().Value); + Assert.AreEqual("10", _tvfTableInfo.GetAllParameters().Single().Value); //configure an extraction specific global of 1 so that only 1 chi number is fetched (which will be in the cohort) - var globalP = new GlobalExtractionFilterParameter(DataExportRepository, config, "DECLARE @numberOfRecords AS int;") + var globalP = + new GlobalExtractionFilterParameter(DataExportRepository, config, "DECLARE @numberOfRecords AS int;") { Value = "1" }; @@ -441,13 +448,13 @@ private void TestDataExportOfTvf() source.PreInitialize(extractionCommand, new ThrowImmediatelyDataLoadEventListener()); var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - - Assert.AreEqual(1,dt.Rows.Count); - Assert.AreEqual("ReleaseId",dt.Columns[0].ColumnName); + Assert.AreEqual(1, dt.Rows.Count); + + Assert.AreEqual("ReleaseId", dt.Columns[0].ColumnName); //should be a guid - Assert.IsTrue(dt.Rows[0][0].ToString().Length>10); + Assert.IsTrue(dt.Rows[0][0].ToString().Length > 10); Assert.IsTrue(dt.Rows[0][0].ToString().Contains('-')); selected.DeleteInDatabase(); @@ -455,6 +462,5 @@ private void TestDataExportOfTvf() config.DeleteInDatabase(); tvfExtractable.DeleteInDatabase(); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataExport/TestExtractableTables.cs b/Rdmp.Core.Tests/DataExport/TestExtractableTables.cs index a2f38e7602..3c35d94b7e 100644 --- a/Rdmp.Core.Tests/DataExport/TestExtractableTables.cs +++ b/Rdmp.Core.Tests/DataExport/TestExtractableTables.cs @@ -23,23 +23,22 @@ public class TestExtractableTables : TestsRequiringACohort [Test] public void DodgyID_CreateCohortDatabaseTable_Fails() { - var ex = Assert.Throws(() => new ExtractableCohort(DataExportRepository, _externalCohortTable,-899)); + var ex = Assert.Throws(() => + new ExtractableCohort(DataExportRepository, _externalCohortTable, -899)); Assert.IsTrue(ex.Message.StartsWith("ID -899 does not exist in Cohort Definitions")); } [Test] public void CreateExtractableDataSet() - { - + { ExtractableDataSet eds = null; - var cata = new Catalogue(CatalogueRepository,"TestExtractableTables Cata"); + var cata = new Catalogue(CatalogueRepository, "TestExtractableTables Cata"); try { //creates with a Null Catalogue until it is associated with a catalogue and saved eds = new ExtractableDataSet(DataExportRepository, cata); - Assert.AreEqual(cata.ID,eds.Catalogue_ID); - + Assert.AreEqual(cata.ID, eds.Catalogue_ID); } finally { @@ -69,7 +68,6 @@ public void UpdateProjectDatabaseTable() { table.DeleteInDatabase(); } - } [Test] @@ -85,17 +83,18 @@ public void CreateExtractionConfiguration() } finally { - table.DeleteInDatabase();//must delete child before parent to preserve referential integrity + table.DeleteInDatabase(); //must delete child before parent to preserve referential integrity parent.DeleteInDatabase(); } } #region helper methods + public static void PropertyValuesAreEquals(object actual, object expected) { var properties = expected.GetType().GetProperties() - .Where(info => !Attribute.IsDefined(info, typeof (DoNotExtractProperty))).ToArray(); + .Where(info => !Attribute.IsDefined(info, typeof(DoNotExtractProperty))).ToArray(); foreach (var property in properties) { @@ -106,24 +105,31 @@ public static void PropertyValuesAreEquals(object actual, object expected) var expectedValue = property.GetValue(expected, null); var actualValue = property.GetValue(actual, null); - if(expectedValue is SqlCommand && actualValue is SqlCommand) //don't compare sql commands they will be subtly different or just refer to different objects iwth the exact same values + if (expectedValue is SqlCommand && + actualValue is SqlCommand) //don't compare sql commands they will be subtly different or just refer to different objects iwth the exact same values continue; if (actualValue is IList list) AssertListsAreEquals(property, list, (IList)expectedValue); else if (!Equals(expectedValue, actualValue)) - Assert.Fail("Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType?.Name, property.Name, expectedValue, actualValue); + Assert.Fail("Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType?.Name, + property.Name, expectedValue, actualValue); } } private static void AssertListsAreEquals(PropertyInfo property, IList actualList, IList expectedList) { if (actualList.Count != expectedList.Count) - Assert.Fail("Property {0}.{1} does not match. Expected IList containing {2} elements but was IList containing {3} elements", property.PropertyType.Name, property.Name, expectedList.Count, actualList.Count); + Assert.Fail( + "Property {0}.{1} does not match. Expected IList containing {2} elements but was IList containing {3} elements", + property.PropertyType.Name, property.Name, expectedList.Count, actualList.Count); for (var i = 0; i < actualList.Count; i++) if (!Equals(actualList[i], expectedList[i])) - Assert.Fail("Property {0}.{1} does not match. Expected IList with element {1} equals to {2} but was IList with element {1} equals to {3}", property.PropertyType.Name, property.Name, expectedList[i], actualList[i]); + Assert.Fail( + "Property {0}.{1} does not match. Expected IList with element {1} equals to {2} but was IList with element {1} equals to {3}", + property.PropertyType.Name, property.Name, expectedList[i], actualList[i]); } + #endregion } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/EntityNaming/HICDatabaseConfigurationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/EntityNaming/HICDatabaseConfigurationTests.cs index 2a06496752..07d9dc77d5 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/EntityNaming/HICDatabaseConfigurationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/EntityNaming/HICDatabaseConfigurationTests.cs @@ -18,9 +18,8 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.DatabaseManagement.EntityNaming; -internal class HICDatabaseConfigurationTests: UnitTests +internal class HICDatabaseConfigurationTests : UnitTests { - /// /// Tests the ability of to predict where tables will exist /// during a load at various stages (RAW, STAGING etc). This is largely controlled by what tables the @@ -41,31 +40,31 @@ public void TestHICDatabaseConfiguration_ExpectTables(bool testLookup) lookup.Database = "LookupsDb"; lookup.SaveToDatabase(); - var job = Mock.Of(m=> - m.RegularTablesToLoad == new List(new []{ti}) && - m.LookupTablesToLoad == new List(new []{lookup})); + var job = Mock.Of(m => + m.RegularTablesToLoad == new List(new[] { ti }) && + m.LookupTablesToLoad == new List(new[] { lookup })); var result = conf.ExpectTables(job, LoadBubble.Raw, testLookup).ToArray(); - Assert.AreEqual(testLookup ? 2 : 1,result.Length); - StringAssert.AreEqualIgnoringCase("mydb_RAW",result[0].Database.GetRuntimeName()); - StringAssert.AreEqualIgnoringCase("My_Table",result[0].GetRuntimeName()); + Assert.AreEqual(testLookup ? 2 : 1, result.Length); + StringAssert.AreEqualIgnoringCase("mydb_RAW", result[0].Database.GetRuntimeName()); + StringAssert.AreEqualIgnoringCase("My_Table", result[0].GetRuntimeName()); if (testLookup) { - StringAssert.AreEqualIgnoringCase("mydb_RAW",result[1].Database.GetRuntimeName()); - StringAssert.AreEqualIgnoringCase("MyHeartyLookup",result[1].GetRuntimeName()); + StringAssert.AreEqualIgnoringCase("mydb_RAW", result[1].Database.GetRuntimeName()); + StringAssert.AreEqualIgnoringCase("MyHeartyLookup", result[1].GetRuntimeName()); } result = conf.ExpectTables(job, LoadBubble.Staging, testLookup).ToArray(); - Assert.AreEqual(testLookup ? 2 : 1,result.Length); - StringAssert.AreEqualIgnoringCase("DLE_STAGING",result[0].Database.GetRuntimeName()); - StringAssert.AreEqualIgnoringCase("mydb_My_Table_STAGING",result[0].GetRuntimeName()); + Assert.AreEqual(testLookup ? 2 : 1, result.Length); + StringAssert.AreEqualIgnoringCase("DLE_STAGING", result[0].Database.GetRuntimeName()); + StringAssert.AreEqualIgnoringCase("mydb_My_Table_STAGING", result[0].GetRuntimeName()); if (testLookup) { - StringAssert.AreEqualIgnoringCase("DLE_STAGING",result[1].Database.GetRuntimeName()); - StringAssert.AreEqualIgnoringCase("mydb_MyHeartyLookup_STAGING",result[1].GetRuntimeName()); + StringAssert.AreEqualIgnoringCase("DLE_STAGING", result[1].Database.GetRuntimeName()); + StringAssert.AreEqualIgnoringCase("mydb_MyHeartyLookup_STAGING", result[1].GetRuntimeName()); } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/TableInfoCloneOperationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/TableInfoCloneOperationTests.cs index 0d74158d9f..e6bcc11974 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/TableInfoCloneOperationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/DatabaseManagement/TableInfoCloneOperationTests.cs @@ -23,15 +23,17 @@ public void Test_CloneTable() dt.Columns.Add("FF"); var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); - var tbl = db.CreateTable("MyTable",dt); + var tbl = db.CreateTable("MyTable", dt); - Import(tbl,out var ti, out _); + Import(tbl, out var ti, out _); var config = new HICDatabaseConfiguration(tbl.Database.Server); //create a RAW table schema called TableName_Isolation - var cloner = new TableInfoCloneOperation(config,(TableInfo)ti,LoadBubble.Live,new ThrowImmediatelyDataLoadEventListener()); - cloner.CloneTable(tbl.Database, tbl.Database,tbl, $"{tbl.GetRuntimeName()}_copy", true, true, true, ti.PreLoadDiscardedColumns); + var cloner = new TableInfoCloneOperation(config, (TableInfo)ti, LoadBubble.Live, + new ThrowImmediatelyDataLoadEventListener()); + cloner.CloneTable(tbl.Database, tbl.Database, tbl, $"{tbl.GetRuntimeName()}_copy", true, true, true, + ti.PreLoadDiscardedColumns); var tbl2 = tbl.Database.ExpectTable($"{tbl.GetRuntimeName()}_copy"); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillSqlHelperTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillSqlHelperTests.cs index 818616112b..0d287188f5 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillSqlHelperTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillSqlHelperTests.cs @@ -40,12 +40,17 @@ public void TestGenerateSqlForThreeLevelJoinPath_TimePeriodIsGrandparent() { ThreeTableSetupWhereTimePeriodIsGrandparent(); - var ciTimePeriodicity = CatalogueRepository.GetAllObjects().SingleOrDefault(c => c.GetRuntimeName().Equals("HeaderDate")) ?? throw new InvalidOperationException("Could not find TimePeriodicity column"); + var ciTimePeriodicity = + CatalogueRepository.GetAllObjects() + .SingleOrDefault(c => c.GetRuntimeName().Equals("HeaderDate")) ?? + throw new InvalidOperationException("Could not find TimePeriodicity column"); var sqlHelper = new BackfillSqlHelper(ciTimePeriodicity, From, To); - var tiHeader = CatalogueRepository.GetAllObjects().Single(t=>t.GetRuntimeName().Equals("Headers")); - var tiSamples = CatalogueRepository.GetAllObjects().Single(t => t.GetRuntimeName().Equals("Samples")); - var tiResults = CatalogueRepository.GetAllObjects().Single(t => t.GetRuntimeName().Equals("Results")); + var tiHeader = CatalogueRepository.GetAllObjects().Single(t => t.GetRuntimeName().Equals("Headers")); + var tiSamples = CatalogueRepository.GetAllObjects() + .Single(t => t.GetRuntimeName().Equals("Samples")); + var tiResults = CatalogueRepository.GetAllObjects() + .Single(t => t.GetRuntimeName().Equals("Results")); var joinInfos = CatalogueRepository.GetAllObjects(); var joinPath = new List @@ -54,8 +59,8 @@ public void TestGenerateSqlForThreeLevelJoinPath_TimePeriodIsGrandparent() joinInfos.Single(info => info.PrimaryKey.TableInfo_ID == tiSamples.ID) }; - var sql = sqlHelper.CreateSqlForJoinToTimePeriodicityTable("CurrentTable", tiResults, "TimePeriodicityTable", From, joinPath); - + var sql = sqlHelper.CreateSqlForJoinToTimePeriodicityTable("CurrentTable", tiResults, "TimePeriodicityTable", + From, joinPath); Assert.AreEqual(string.Format(@"SELECT CurrentTable.*, TimePeriodicityTable.HeaderDate AS TimePeriodicityField @@ -68,8 +73,10 @@ FROM [{0}]..[Results] CurrentTable private void ThreeTableSetupWhereTimePeriodIsGrandparent() { CreateTables("Headers", "ID int NOT NULL, HeaderDate DATETIME, Discipline varchar(32)", "ID"); - CreateTables("Samples", "ID int NOT NULL, HeaderID int NOT NULL, SampleType varchar(32)", "ID", "CONSTRAINT [FK_Headers_Samples] FOREIGN KEY (HeaderID) REFERENCES Headers (ID)"); - CreateTables("Results", "ID int NOT NULL, SampleID int NOT NULL, Result int", "ID", "CONSTRAINT [FK_Samples_Results] FOREIGN KEY (SampleID) REFERENCES Samples (ID)"); + CreateTables("Samples", "ID int NOT NULL, HeaderID int NOT NULL, SampleType varchar(32)", "ID", + "CONSTRAINT [FK_Headers_Samples] FOREIGN KEY (HeaderID) REFERENCES Headers (ID)"); + CreateTables("Results", "ID int NOT NULL, SampleID int NOT NULL, Result int", "ID", + "CONSTRAINT [FK_Samples_Results] FOREIGN KEY (SampleID) REFERENCES Samples (ID)"); // Set SetUp catalogue entities @@ -86,17 +93,18 @@ private void ThreeTableSetupWhereTimePeriodIsGrandparent() Assert.AreEqual(15, _catalogue.CatalogueItems.Length, "Unexpected number of items in catalogue"); // Headers (1:M) Samples join - new JoinInfo(CatalogueRepository,ciSamples.Single(ci => ci.GetRuntimeName().Equals("HeaderID")), + new JoinInfo(CatalogueRepository, ciSamples.Single(ci => ci.GetRuntimeName().Equals("HeaderID")), ciHeaders.Single(ci => ci.GetRuntimeName().Equals("ID")), ExtractionJoinType.Left, ""); // Samples (1:M) Results join - new JoinInfo(CatalogueRepository,ciResults.Single(info => info.GetRuntimeName().Equals("SampleID")), + new JoinInfo(CatalogueRepository, ciResults.Single(info => info.GetRuntimeName().Equals("SampleID")), ciSamples.Single(info => info.GetRuntimeName().Equals("ID")), ExtractionJoinType.Left, ""); } - private void CreateTables(string tableName, string columnDefinitions, string pkColumn, string fkConstraintString = null) + private void CreateTables(string tableName, string columnDefinitions, string pkColumn, + string fkConstraintString = null) { // todo: doesn't do combo primary keys yet @@ -105,7 +113,9 @@ private void CreateTables(string tableName, string columnDefinitions, string pkC var pkConstraint = $"CONSTRAINT PK_{tableName} PRIMARY KEY ({pkColumn})"; var stagingTableDefinition = $"{columnDefinitions}, {pkConstraint}"; - var liveTableDefinition = columnDefinitions + string.Format(", "+SpecialFieldNames.ValidFrom+" DATETIME, "+SpecialFieldNames.DataLoadRunID+" int, " + pkConstraint); + var liveTableDefinition = columnDefinitions + string.Format(", " + SpecialFieldNames.ValidFrom + " DATETIME, " + + SpecialFieldNames.DataLoadRunID + " int, " + + pkConstraint); if (fkConstraintString != null) { @@ -113,13 +123,15 @@ private void CreateTables(string tableName, string columnDefinitions, string pkC liveTableDefinition += $", {fkConstraintString}"; } - CreateTableWithColumnDefinitions(From,tableName, stagingTableDefinition); - CreateTableWithColumnDefinitions(To,tableName, liveTableDefinition); + CreateTableWithColumnDefinitions(From, tableName, stagingTableDefinition); + CreateTableWithColumnDefinitions(To, tableName, liveTableDefinition); } - private ITableInfo AddTableToCatalogue(string databaseName, string tableName, string pkName, out ColumnInfo[] ciList, bool createCatalogue = false) + private ITableInfo AddTableToCatalogue(string databaseName, string tableName, string pkName, + out ColumnInfo[] ciList, bool createCatalogue = false) { - var expectedTable = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(databaseName).ExpectTable(tableName); + var expectedTable = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(databaseName) + .ExpectTable(tableName); var resultsImporter = new TableInfoImporter(CatalogueRepository, expectedTable); @@ -131,26 +143,26 @@ private ITableInfo AddTableToCatalogue(string databaseName, string tableName, st var forwardEngineer = new ForwardEngineerCatalogue(ti, ciList); if (createCatalogue) - { - - forwardEngineer.ExecuteForwardEngineering(out _catalogue, out CatalogueItem[] cataItems, out ExtractionInformation[] extractionInformations); - } + forwardEngineer.ExecuteForwardEngineering(out _catalogue, out var cataItems, + out var extractionInformations); else forwardEngineer.ExecuteForwardEngineering(_catalogue); return ti; } - public static void CreateTableWithColumnDefinitions(DiscoveredDatabase db, string tableName, string columnDefinitions) + public static void CreateTableWithColumnDefinitions(DiscoveredDatabase db, string tableName, + string columnDefinitions) { using (var conn = db.Server.GetConnection()) { conn.Open(); - CreateTableWithColumnDefinitions(db,tableName, columnDefinitions, conn); + CreateTableWithColumnDefinitions(db, tableName, columnDefinitions, conn); } } - public static void CreateTableWithColumnDefinitions(DiscoveredDatabase db, string tableName, string columnDefinitions, DbConnection conn) + public static void CreateTableWithColumnDefinitions(DiscoveredDatabase db, string tableName, + string columnDefinitions, DbConnection conn) { var sql = $"CREATE TABLE {tableName} ({columnDefinitions})"; db.Server.GetCommand(sql, conn).ExecuteNonQuery(); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillTests.cs index f76fe557e4..020c971a60 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/BackfillTests.cs @@ -22,7 +22,6 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; public class BackfillTests : FromToDatabaseTests { - private ICatalogue _catalogue; @@ -44,13 +43,15 @@ public void Backfill_SingleTable_LoadContainsNewerUpdate() SingleTableSetup(); #region Insert test data + // add To data using (var connection = (SqlConnection)To.Server.GetConnection()) { connection.Open(); var cmd = new SqlCommand( - $"INSERT INTO [Samples] (ID, SampleDate, Description, {SpecialFieldNames.ValidFrom}, {SpecialFieldNames.DataLoadRunID}) VALUES (10, '2016-01-10T12:00:00', 'Earlier than corresponding new data, should be updated', '2016-01-10T12:00:00', 1)", connection); + $"INSERT INTO [Samples] (ID, SampleDate, Description, {SpecialFieldNames.ValidFrom}, {SpecialFieldNames.DataLoadRunID}) VALUES (10, '2016-01-10T12:00:00', 'Earlier than corresponding new data, should be updated', '2016-01-10T12:00:00', 1)", + connection); cmd.ExecuteNonQuery(); } @@ -64,6 +65,7 @@ public void Backfill_SingleTable_LoadContainsNewerUpdate() "(10, '2016-01-11T12:00:00', 'Newer than in To, should update To')", connection); cmd.ExecuteNonQuery(); } + #endregion // databases are now represent state after push to From and before migration @@ -80,7 +82,8 @@ public void Backfill_SingleTable_LoadContainsNewerUpdate() cmd = new SqlCommand(@"SELECT Description FROM Samples", connection); var description = cmd.ExecuteScalar().ToString(); - Assert.AreEqual(description, "Newer than in To, should update To", "Description has been altered but is a valid update to To so should not have been touched."); + Assert.AreEqual(description, "Newer than in To, should update To", + "Description has been altered but is a valid update to To so should not have been touched."); } } @@ -89,7 +92,7 @@ private void SingleTableSetup() CreateTables("Samples", "ID int NOT NULL, SampleDate DATETIME, Description varchar(1024)", "ID"); // Set SetUp catalogue entities - AddTableToCatalogue(DatabaseName, "Samples", "ID", out ColumnInfo[] ciSamples, true); + AddTableToCatalogue(DatabaseName, "Samples", "ID", out var ciSamples, true); Assert.AreEqual(5, _catalogue.CatalogueItems.Length, "Unexpected number of items in catalogue"); } @@ -98,7 +101,8 @@ private void Mutilate(string timeColumnName) { var mutilator = new StagingBackfillMutilator { - TimePeriodicityField = CatalogueRepository.GetAllObjects().Single(c=>c.Name.Equals(timeColumnName)), + TimePeriodicityField = CatalogueRepository.GetAllObjects() + .Single(c => c.Name.Equals(timeColumnName)), TestContext = true, TableNamingScheme = new IdentityTableNamingScheme() }; @@ -114,13 +118,15 @@ public void Backfill_SingleTable_LoadContainsOlderUpdate() SingleTableSetup(); #region Insert test data + // add To data using (var connection = (SqlConnection)To.Server.GetConnection()) { connection.Open(); var cmd = new SqlCommand( - $"INSERT INTO [Samples] (ID, SampleDate, Description, {SpecialFieldNames.ValidFrom}, {SpecialFieldNames.DataLoadRunID}) VALUES (1, '2016-01-10T12:00:00', 'Later than corresponding new data, should not be updated', '2016-01-10T12:00:00', 1)", connection); + $"INSERT INTO [Samples] (ID, SampleDate, Description, {SpecialFieldNames.ValidFrom}, {SpecialFieldNames.DataLoadRunID}) VALUES (1, '2016-01-10T12:00:00', 'Later than corresponding new data, should not be updated', '2016-01-10T12:00:00', 1)", + connection); cmd.ExecuteNonQuery(); } @@ -131,9 +137,11 @@ public void Backfill_SingleTable_LoadContainsOlderUpdate() // newer update var cmd = new SqlCommand("INSERT INTO [Samples] (ID, SampleDate, Description) VALUES " + - "(1, '2016-01-09T12:00:00', 'Older than in To, should be deleted by the mutilator')", connection); + "(1, '2016-01-09T12:00:00', 'Older than in To, should be deleted by the mutilator')", + connection); cmd.ExecuteNonQuery(); } + #endregion // databases are now represent state after push to From and before migration @@ -146,7 +154,8 @@ public void Backfill_SingleTable_LoadContainsOlderUpdate() var cmd = new SqlCommand(@"SELECT COUNT(*) FROM Samples", connection); var numRows = cmd.ExecuteScalar(); - Assert.AreEqual(0, numRows, "The record to be loaded is older than the corresponding record in To, should have been deleted"); + Assert.AreEqual(0, numRows, + "The record to be loaded is older than the corresponding record in To, should have been deleted"); } } @@ -156,13 +165,16 @@ public void Backfill_SingleTable_LoadContainsInsert() SingleTableSetup(); #region Insert test data + // add To data using (var connection = (SqlConnection)To.Server.GetConnection()) { connection.Open(); - var cmd = new SqlCommand("INSERT INTO [Samples] (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(1, '2016-01-10T12:00:00', 'Later than corresponding new data, should not be updated', '2016-01-10T12:00:00', 1)", connection); + var cmd = new SqlCommand( + "INSERT INTO [Samples] (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(1, '2016-01-10T12:00:00', 'Later than corresponding new data, should not be updated', '2016-01-10T12:00:00', 1)", + connection); cmd.ExecuteNonQuery(); } @@ -173,9 +185,11 @@ public void Backfill_SingleTable_LoadContainsInsert() // newer update var cmd = new SqlCommand("INSERT INTO [Samples] (ID, SampleDate, Description) VALUES " + - "(2, '2016-01-09T12:00:00', 'Does not exist in To, should remain in From after mutilation.')", connection); + "(2, '2016-01-09T12:00:00', 'Does not exist in To, should remain in From after mutilation.')", + connection); cmd.ExecuteNonQuery(); } + #endregion // databases are now represent state after push to From and before migration @@ -192,8 +206,8 @@ public void Backfill_SingleTable_LoadContainsInsert() cmd = new SqlCommand(@"SELECT Description FROM Samples", connection); var description = cmd.ExecuteScalar().ToString(); - Assert.AreEqual(description, "Does not exist in To, should remain in From after mutilation.", "Description has been altered but is a valid update to To so should not have been touched."); - + Assert.AreEqual(description, "Does not exist in To, should remain in From after mutilation.", + "Description has been altered but is a valid update to To so should not have been touched."); } } @@ -203,14 +217,17 @@ public void Backfill_SingleTable_Combined() SingleTableSetup(); #region Insert test data + // add To data using (var connection = (SqlConnection)To.Server.GetConnection()) { connection.Open(); - var cmd = new SqlCommand("INSERT INTO [Samples] (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(1, '2016-01-10T12:00:00', 'Earlier than corresponding new data, should be updated', '2016-01-10T12:00:00', 1)," + - "(2, '2016-01-15T12:00:00', 'Later than corresponding new data, should not be updated', '2016-01-15T12:00:00', 2)", connection); + var cmd = new SqlCommand( + "INSERT INTO [Samples] (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(1, '2016-01-10T12:00:00', 'Earlier than corresponding new data, should be updated', '2016-01-10T12:00:00', 1)," + + "(2, '2016-01-15T12:00:00', 'Later than corresponding new data, should not be updated', '2016-01-15T12:00:00', 2)", + connection); cmd.ExecuteNonQuery(); } @@ -225,6 +242,7 @@ public void Backfill_SingleTable_Combined() "(3, '2016-01-12T12:00:00', 'New data')", connection); cmd.ExecuteNonQuery(); } + #endregion Mutilate($"[{DatabaseName}].[dbo].[Samples].[SampleDate]"); @@ -236,15 +254,16 @@ public void Backfill_SingleTable_Combined() var cmd = new SqlCommand(@"SELECT COUNT(*) FROM Samples", connection); var numRows = cmd.ExecuteScalar(); - Assert.AreEqual(2, numRows, "Record 2 should have been deleted as it is an update to a record for which we have a later version."); + Assert.AreEqual(2, numRows, + "Record 2 should have been deleted as it is an update to a record for which we have a later version."); } - } private void TwoTableSetupWhereTimePeriodIsParent() { CreateTables("Samples", "ID int NOT NULL, SampleDate DATETIME, Description varchar(1024)", "ID"); - CreateTables("Results", "ID int NOT NULL, SampleID int NOT NULL, Result int", "ID", "CONSTRAINT [FK_Samples_Results] FOREIGN KEY (SampleID) REFERENCES Samples (ID)"); + CreateTables("Results", "ID int NOT NULL, SampleID int NOT NULL, Result int", "ID", + "CONSTRAINT [FK_Samples_Results] FOREIGN KEY (SampleID) REFERENCES Samples (ID)"); // Set SetUp catalogue entities @@ -260,7 +279,7 @@ private void TwoTableSetupWhereTimePeriodIsParent() Assert.AreEqual(10, _catalogue.CatalogueItems.Length, "Unexpected number of items in catalogue"); // Samples (1:M) Results join - new JoinInfo(CatalogueRepository,ciResults.Single(info => info.GetRuntimeName().Equals("SampleID")), + new JoinInfo(CatalogueRepository, ciResults.Single(info => info.GetRuntimeName().Equals("SampleID")), ciSamples.Single(info => info.GetRuntimeName().Equals("ID")), ExtractionJoinType.Left, ""); } @@ -271,12 +290,15 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsNewerUpdate() TwoTableSetupWhereTimePeriodIsParent(); #region Insert To test data - const string liveSamplesSql = "INSERT INTO Samples (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; - const string liveResultsSql = "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(10, 1, 123, '2016-01-10T12:00:00', 1), " + - "(11, 1, 234, '2016-01-10T12:00:00', 1)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; + + const string liveResultsSql = + "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(10, 1, 123, '2016-01-10T12:00:00', 1), " + + "(11, 1, 234, '2016-01-10T12:00:00', 1)"; using (var connection = (SqlConnection)To.Server.GetConnection()) { @@ -288,9 +310,11 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsNewerUpdate() cmd = new SqlCommand(liveResultsSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingSamplesSql = "INSERT INTO Samples (ID, SampleDate, Description) VALUES " + "(1, '2016-01-15T12:00:00', 'Sample is later than corresponding record in To, contains a child update (ID=11), child insert (ID=12) and this updated description')"; @@ -311,7 +335,6 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsNewerUpdate() cmd.ExecuteNonQuery(); } - #endregion Mutilate($"[{DatabaseName}].[dbo].[Samples].[SampleDate]"); @@ -337,12 +360,15 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsOlderUpdate() TwoTableSetupWhereTimePeriodIsParent(); #region Insert To test data - const string liveSamplesSql = "INSERT INTO Samples (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; - const string liveResultsSql = "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(10, 1, 123, '2016-01-10T12:00:00', 1), " + - "(11, 1, 234, '2016-01-10T12:00:00', 1)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; + + const string liveResultsSql = + "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(10, 1, 123, '2016-01-10T12:00:00', 1), " + + "(11, 1, 234, '2016-01-10T12:00:00', 1)"; using (var connection = (SqlConnection)To.Server.GetConnection()) { @@ -354,9 +380,11 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsOlderUpdate() cmd = new SqlCommand(liveResultsSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingSamplesSql = "INSERT INTO Samples (ID, SampleDate, Description) VALUES " + "(1, '2016-01-09T12:00:00', 'Sample is earlier than corresponding record in To (also contains an item which has apparently been deleted in the set used for a later load)')"; @@ -377,7 +405,6 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsOlderUpdate() cmd.ExecuteNonQuery(); } - #endregion Mutilate($"[{DatabaseName}].[dbo].[Samples].[SampleDate]"); @@ -409,7 +436,8 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainsOlderUpdate() Assert.IsTrue(reader.HasRows); reader.Read(); - Assert.AreEqual("", reader["Description"].ToString(), "The To sample had a blank description which should have been copied in to the earlier From record."); + Assert.AreEqual("", reader["Description"].ToString(), + "The To sample had a blank description which should have been copied in to the earlier From record."); var hasMoreResults = reader.Read(); Assert.IsFalse(hasMoreResults, "Should only be one Samples row in From"); @@ -423,12 +451,15 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainInsert() TwoTableSetupWhereTimePeriodIsParent(); #region Insert To test data - const string liveSamplesSql = "INSERT INTO Samples (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; - const string liveResultsSql = "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(10, 1, 123, '2016-01-10T12:00:00', 1), " + - "(11, 1, 234, '2016-01-10T12:00:00', 1)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; + + const string liveResultsSql = + "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(10, 1, 123, '2016-01-10T12:00:00', 1), " + + "(11, 1, 234, '2016-01-10T12:00:00', 1)"; using (var connection = (SqlConnection)To.Server.GetConnection()) { @@ -440,9 +471,11 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainInsert() cmd = new SqlCommand(liveResultsSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingSamplesSql = "INSERT INTO Samples (ID, SampleDate, Description) VALUES " + "(2, '2016-01-15T12:00:00', 'New sample')"; @@ -463,7 +496,6 @@ public void Backfill_TwoTables_TimePeriodParent_LoadContainInsert() cmd.ExecuteNonQuery(); } - #endregion Mutilate($"[{DatabaseName}].[dbo].[Samples].[SampleDate]"); @@ -504,7 +536,7 @@ private void TwoTableSetupWhereTimePeriodIsChild() Assert.AreEqual(10, _catalogue.CatalogueItems.Length, "Unexpected number of items in catalogue"); // Headers (1:M) Samples join - new JoinInfo(CatalogueRepository,ciSamples.Single(info => info.GetRuntimeName().Equals("HeaderID")), + new JoinInfo(CatalogueRepository, ciSamples.Single(info => info.GetRuntimeName().Equals("HeaderID")), ciHeaders.Single(info => info.GetRuntimeName().Equals("ID")), ExtractionJoinType.Left, ""); } @@ -515,11 +547,13 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsOlderUpdate() TwoTableSetupWhereTimePeriodIsChild(); #region Insert To test data + const string liveHeaderSql = "INSERT INTO Headers (ID, Discipline, hic_validFrom, hic_dataLoadRunID) VALUES " + "(1, 'Biochemistry', '2016-01-10T12:00:00', 1)"; - const string liveSamplesSql = "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(10, 1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(10, 1, '2016-01-10T12:00:00', '', '2016-01-10T12:00:00', 1)"; using (var connection = (SqlConnection)To.Server.GetConnection()) @@ -532,9 +566,11 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsOlderUpdate() cmd = new SqlCommand(liveSamplesSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingHeadersSql = "INSERT INTO Headers (ID, Discipline) VALUES " + "(1, 'Biochemistry')"; @@ -553,7 +589,6 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsOlderUpdate() cmd.ExecuteNonQuery(); } - #endregion Mutilate($"[{DatabaseName}].[dbo].[Samples].[SampleDate]"); @@ -584,11 +619,13 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsOldInsert_WithOldPare TwoTableSetupWhereTimePeriodIsChild(); #region Insert To test data + const string liveHeaderSql = "INSERT INTO Headers (ID, Discipline, hic_validFrom, hic_dataLoadRunID) VALUES " + "(1, 'Biochemistry', '2016-01-15T12:00:00', 1)"; - const string liveSamplesSql = "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(11, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 1)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(11, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 1)"; using (var connection = (SqlConnection)To.Server.GetConnection()) @@ -601,9 +638,11 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsOldInsert_WithOldPare cmd = new SqlCommand(liveSamplesSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingHeadersSql = "INSERT INTO Headers (ID, Discipline) VALUES " + "(1, 'Haematology')"; // old and incorrect Discipline value @@ -637,11 +676,13 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsOldInsert_WithOldPare cmd = new SqlCommand(@"SELECT COUNT(*) FROM Headers", connection); numRows = cmd.ExecuteScalar(); - Assert.AreEqual(1, numRows, "Header should still be there (shouldn't be able to delete it as there should be a FK constraint with Samples)"); + Assert.AreEqual(1, numRows, + "Header should still be there (shouldn't be able to delete it as there should be a FK constraint with Samples)"); cmd = new SqlCommand(@"SELECT Discipline FROM Headers WHERE ID=1", connection); var discipline = cmd.ExecuteScalar().ToString(); - Assert.AreEqual("Biochemistry", discipline, "Header record in From be updated to reflect what is in To: the To record is authoritative as it contains at least one child from a later date."); + Assert.AreEqual("Biochemistry", discipline, + "Header record in From be updated to reflect what is in To: the To record is authoritative as it contains at least one child from a later date."); } } @@ -651,12 +692,14 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsNewInsert_WithNewPare TwoTableSetupWhereTimePeriodIsChild(); #region Insert To test data + const string liveHeaderSql = "INSERT INTO Headers (ID, Discipline, hic_validFrom, hic_dataLoadRunID) VALUES " + "(1, 'Biochemistry', '2016-01-15T12:00:00', 1)"; - const string liveSamplesSql = "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(10, 1, '2016-01-15T10:00:00', '', '2016-01-15T12:00:00', 1), " + - "(11, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 1)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(10, 1, '2016-01-15T10:00:00', '', '2016-01-15T12:00:00', 1), " + + "(11, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 1)"; using (var connection = (SqlConnection)To.Server.GetConnection()) @@ -669,9 +712,11 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsNewInsert_WithNewPare cmd = new SqlCommand(liveSamplesSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingHeadersSql = "INSERT INTO Headers (ID, Discipline) VALUES " + "(1, 'Haematology')"; // old and incorrect Discipline value @@ -705,11 +750,13 @@ public void Backfill_TwoTables_TimePeriodChild_LoadContainsNewInsert_WithNewPare cmd = new SqlCommand(@"SELECT COUNT(*) FROM Headers", connection); numRows = cmd.ExecuteScalar(); - Assert.AreEqual(1, numRows, "Header should still be there (shouldn't be able to delete it as there should be a FK constraint with Samples)"); + Assert.AreEqual(1, numRows, + "Header should still be there (shouldn't be able to delete it as there should be a FK constraint with Samples)"); cmd = new SqlCommand(@"SELECT Discipline FROM Headers WHERE ID=1", connection); var discipline = cmd.ExecuteScalar().ToString(); - Assert.AreEqual("Haematology", discipline, "Header record in From should not be updated as it is 'correct'."); + Assert.AreEqual("Haematology", discipline, + "Header record in From should not be updated as it is 'correct'."); } } @@ -719,18 +766,20 @@ public void Backfill_TwoTables_TimePeriodChild_Combined() TwoTableSetupWhereTimePeriodIsChild(); #region Insert To test data + const string liveHeaderSql = "INSERT INTO Headers (ID, Discipline, hic_validFrom, hic_dataLoadRunID) VALUES " + "(1, 'Haematology', '2016-01-15T12:00:00', 2), " + "(2, 'Haematology', '2016-01-05T12:00:00', 1), " + "(3, 'Biochemistry', '2016-01-15T12:00:00', 2), " + "(4, 'Haematology', '2016-01-15T12:00:00', 2)"; - const string liveSamplesSql = "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(12, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2), " + - "(13, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2), " + - "(14, 2, '2016-01-05T12:00:00', '', '2016-01-05T12:00:00', 1), " + - "(15, 3, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2), " + - "(16, 4, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2)"; + const string liveSamplesSql = + "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(12, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2), " + + "(13, 1, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2), " + + "(14, 2, '2016-01-05T12:00:00', '', '2016-01-05T12:00:00', 1), " + + "(15, 3, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2), " + + "(16, 4, '2016-01-15T12:00:00', '', '2016-01-15T12:00:00', 2)"; using (var connection = (SqlConnection)To.Server.GetConnection()) @@ -743,9 +792,11 @@ public void Backfill_TwoTables_TimePeriodChild_Combined() cmd = new SqlCommand(liveSamplesSql, connection); cmd.ExecuteNonQuery(); } + #endregion #region Add From test data + // add From data const string stagingHeadersSql = "INSERT INTO Headers (ID, Discipline) VALUES " + "(1, 'Biochemistry'), " + @@ -819,7 +870,8 @@ public void Backfill_TwoTables_TimePeriodChild_Combined() } } - private void CreateTables(string tableName, string columnDefinitions, string pkColumn, string fkConstraintString = null) + private void CreateTables(string tableName, string columnDefinitions, string pkColumn, + string fkConstraintString = null) { // todo: doesn't do combo primary keys yet @@ -828,7 +880,8 @@ private void CreateTables(string tableName, string columnDefinitions, string pkC var pkConstraint = $"CONSTRAINT PK_{tableName} PRIMARY KEY ({pkColumn})"; var stagingTableDefinition = $"{columnDefinitions}, {pkConstraint}"; - var liveTableDefinition = columnDefinitions + string.Format(", hic_validFrom DATETIME, hic_dataLoadRunID int, " + pkConstraint); + var liveTableDefinition = columnDefinitions + + string.Format(", hic_validFrom DATETIME, hic_dataLoadRunID int, " + pkConstraint); if (fkConstraintString != null) { @@ -837,23 +890,25 @@ private void CreateTables(string tableName, string columnDefinitions, string pkC } - using (var con = (SqlConnection) From.Server.GetConnection()) + using (var con = (SqlConnection)From.Server.GetConnection()) { con.Open(); - new SqlCommand($"CREATE TABLE {tableName} ({stagingTableDefinition})",con).ExecuteNonQuery(); + new SqlCommand($"CREATE TABLE {tableName} ({stagingTableDefinition})", con).ExecuteNonQuery(); } - using(var con = (SqlConnection)To.Server.GetConnection()) + using (var con = (SqlConnection)To.Server.GetConnection()) { con.Open(); - new SqlCommand($"CREATE TABLE {tableName} ({liveTableDefinition})",con).ExecuteNonQuery(); + new SqlCommand($"CREATE TABLE {tableName} ({liveTableDefinition})", con).ExecuteNonQuery(); } } - [Test, Ignore("Restructuring tests")] + [Test] + [Ignore("Restructuring tests")] public void DeleteNewerCollisionsFromTable() { #region Set SetUp databases + CreateTables("Header", "ID int NOT NULL, Discipline varchar(32) NOT NULL", "ID"); CreateTables("Samples", @@ -873,32 +928,38 @@ public void DeleteNewerCollisionsFromTable() // should be all entities set SetUp now Assert.AreEqual(15, _catalogue.CatalogueItems.Length, "Unexpected number of items in catalogue"); + #endregion // add data + #region Populate Tables + var connection = (SqlConnection)To.Server.GetConnection(); connection.Open(); - const string liveHeaderDataSql = "INSERT INTO Header (ID, Discipline, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(1, 'Biochemistry', '2016-01-15T15:00:00', 4), " + - "(3, 'Haematology', '2016-01-15T12:00:00', 3)"; + const string liveHeaderDataSql = + "INSERT INTO Header (ID, Discipline, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(1, 'Biochemistry', '2016-01-15T15:00:00', 4), " + + "(3, 'Haematology', '2016-01-15T12:00:00', 3)"; var liveHeaderDataSqlCommand = new SqlCommand(liveHeaderDataSql, connection); liveHeaderDataSqlCommand.ExecuteNonQuery(); - const string liveSampleDataSql = "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(10, 1, '2016-01-10T12:00:00', 'Earlier than corresponding new data, should be updated', '2016-01-10T12:00:00', 1), " + - "(11, 1, '2016-01-15T15:00:00', 'Later than corresponding new data, should not be touched', '2016-01-15T15:00:00', 4), " + - "(14, 3, '2016-01-15T12:00:00', 'Header data of newly loaded (but older) sample should *not* update this rows parent header', '2016-01-15T12:00:00', 3)"; + const string liveSampleDataSql = + "INSERT INTO Samples (ID, HeaderID, SampleDate, Description, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(10, 1, '2016-01-10T12:00:00', 'Earlier than corresponding new data, should be updated', '2016-01-10T12:00:00', 1), " + + "(11, 1, '2016-01-15T15:00:00', 'Later than corresponding new data, should not be touched', '2016-01-15T15:00:00', 4), " + + "(14, 3, '2016-01-15T12:00:00', 'Header data of newly loaded (but older) sample should *not* update this rows parent header', '2016-01-15T12:00:00', 3)"; var liveSampleDataSqlCommand = new SqlCommand(liveSampleDataSql, connection); liveSampleDataSqlCommand.ExecuteNonQuery(); - const string liveResultDataSql = "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + - "(100, 10, 999, '2016-01-10T12:00:00', 1), " + - "(101, 10, 888, '2016-01-10T12:00:00', 1), " + - "(102, 11, 456, '2016-01-15T15:00:00', 4), " + - "(103, 11, 654, '2016-01-15T15:00:00', 4), " + - "(107, 14, 111, '2016-01-15T12:00:00', 3)"; + const string liveResultDataSql = + "INSERT INTO Results (ID, SampleID, Result, hic_validFrom, hic_dataLoadRunID) VALUES " + + "(100, 10, 999, '2016-01-10T12:00:00', 1), " + + "(101, 10, 888, '2016-01-10T12:00:00', 1), " + + "(102, 11, 456, '2016-01-15T15:00:00', 4), " + + "(103, 11, 654, '2016-01-15T15:00:00', 4), " + + "(107, 14, 111, '2016-01-15T12:00:00', 3)"; var liveResultDataSqlCommand = new SqlCommand(liveResultDataSql, connection); liveResultDataSqlCommand.ExecuteNonQuery(); connection.Close(); @@ -928,18 +989,19 @@ public void DeleteNewerCollisionsFromTable() "(104, 10, 666), " + // added this "(102, 11, 400), " + // earlier data (which is also wrong, 456 in To), To data is newer and corrected "(103, 11, 654), " + - "(105, 12, 123), " + // new result (from new sample) + "(105, 12, 123), " + // new result (from new sample) "(106, 13, 123)"; // new result (from new sample) var stagingResultDataSqlCommand = new SqlCommand(stagingResultDataSql, connection); stagingResultDataSqlCommand.ExecuteNonQuery(); connection.Close(); + #endregion // databases are now represent state after push to From and before migration var mutilator = new StagingBackfillMutilator { - TimePeriodicityField = CatalogueRepository.GetAllObjects().Single(ci=>ci.Name == + TimePeriodicityField = CatalogueRepository.GetAllObjects().Single(ci => ci.Name == $"[{DatabaseName}]..[Samples].[SampleDate]"), TestContext = true, TableNamingScheme = new IdentityTableNamingScheme() @@ -950,6 +1012,7 @@ public void DeleteNewerCollisionsFromTable() mutilator.Mutilate(new ThrowImmediatelyDataLoadJob()); #region Assert + // check that From contains the correct data // Sample ID=2 should have been deleted, along with corresponding results 102 and 103 connection = (SqlConnection)From.Server.GetConnection(); @@ -961,7 +1024,8 @@ public void DeleteNewerCollisionsFromTable() cmd = new SqlCommand(@"SELECT Discipline FROM Header WHERE ID=1", connection); var discipline = cmd.ExecuteScalar(); - Assert.AreEqual("Biochemistry", discipline, "The mutilator should **NOT** have updated record 1 from Biochemistry to Haematology. Although the load updates one of the To samples, the most recent To sample is later than the most recent loaded sample so the parent data in To takes precedence over the parent data in From."); + Assert.AreEqual("Biochemistry", discipline, + "The mutilator should **NOT** have updated record 1 from Biochemistry to Haematology. Although the load updates one of the To samples, the most recent To sample is later than the most recent loaded sample so the parent data in To takes precedence over the parent data in From."); // Not convinced about this test case //cmd = new SqlCommand(@"SELECT Discipline FROM Header WHERE ID=3", connection); @@ -974,7 +1038,8 @@ public void DeleteNewerCollisionsFromTable() cmd = new SqlCommand(@"SELECT COUNT(*) FROM Samples", connection); numRows = cmd.ExecuteScalar(); - Assert.AreEqual(2, numRows, "Sample ID = 2 has been deleted but something has happened to the other samples (should be untouched)"); + Assert.AreEqual(2, numRows, + "Sample ID = 2 has been deleted but something has happened to the other samples (should be untouched)"); cmd = new SqlCommand(@"SELECT COUNT(*) FROM Results WHERE SampleID = 2", connection); numRows = cmd.ExecuteScalar(); @@ -982,9 +1047,11 @@ public void DeleteNewerCollisionsFromTable() cmd = new SqlCommand(@"SELECT COUNT(*) FROM Results", connection); numRows = cmd.ExecuteScalar(); - Assert.AreEqual(4, numRows, "Results belonging to Sample ID = 2 have been deleted but something has happeded to the other results (should be untouched)"); + Assert.AreEqual(4, numRows, + "Results belonging to Sample ID = 2 have been deleted but something has happeded to the other results (should be untouched)"); connection.Close(); + #endregion tiSamples.DeleteInDatabase(); @@ -1008,7 +1075,7 @@ private ITableInfo AddResultsTableToCatalogue(string databaseName, ColumnInfo[] var ti = AddTableToCatalogue(databaseName, "Results", "ID", out var ciList); // setup join infos - new JoinInfo(CatalogueRepository,ciList.Single(info => info.GetRuntimeName().Equals("SampleID")), + new JoinInfo(CatalogueRepository, ciList.Single(info => info.GetRuntimeName().Equals("SampleID")), ciSamples.Single(info => info.GetRuntimeName().Equals("ID")), ExtractionJoinType.Left, ""); return ti; @@ -1019,7 +1086,7 @@ private ITableInfo AddHeaderTableToCatalogue(string databaseName, ColumnInfo[] c var ti = AddTableToCatalogue(databaseName, "Header", "ID", out var ciList); // setup join infos - new JoinInfo(CatalogueRepository,ciSamples.Single(info => info.GetRuntimeName().Equals("HeaderID")), + new JoinInfo(CatalogueRepository, ciSamples.Single(info => info.GetRuntimeName().Equals("HeaderID")), ciList.Single(info => info.GetRuntimeName().Equals("ID")), ExtractionJoinType.Left, ""); @@ -1029,9 +1096,11 @@ private ITableInfo AddHeaderTableToCatalogue(string databaseName, ColumnInfo[] c return ti; } - private ITableInfo AddTableToCatalogue(string databaseName, string tableName, string pkName, out ColumnInfo[] ciList, bool createCatalogue = false) + private ITableInfo AddTableToCatalogue(string databaseName, string tableName, string pkName, + out ColumnInfo[] ciList, bool createCatalogue = false) { - var table = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(databaseName).ExpectTable(tableName); + var table = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(databaseName) + .ExpectTable(tableName); var resultsImporter = new TableInfoImporter(CatalogueRepository, table); resultsImporter.DoImport(out var ti, out ciList); @@ -1042,33 +1111,20 @@ private ITableInfo AddTableToCatalogue(string databaseName, string tableName, st var forwardEngineer = new ForwardEngineerCatalogue(ti, ciList); if (createCatalogue) - { - - forwardEngineer.ExecuteForwardEngineering(out _catalogue, out CatalogueItem[] cataItems, out ExtractionInformation[] extractionInformations); - } + forwardEngineer.ExecuteForwardEngineering(out _catalogue, out var cataItems, + out var extractionInformations); else forwardEngineer.ExecuteForwardEngineering(_catalogue); return ti; } - - } internal class IdentityTableNamingScheme : INameDatabasesAndTablesDuringLoads { - public string GetDatabaseName(string rootDatabaseName, LoadBubble convention) - { - return rootDatabaseName; - } + public string GetDatabaseName(string rootDatabaseName, LoadBubble convention) => rootDatabaseName; - public string GetName(string tableName, LoadBubble convention) - { - return tableName; - } + public string GetName(string tableName, LoadBubble convention) => tableName; - public static bool IsNamedCorrectly(string tableName, LoadBubble convention) - { - return true; - } + public static bool IsNamedCorrectly(string tableName, LoadBubble convention) => true; } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CachedFileRetrieverTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CachedFileRetrieverTests.cs index 814dc66f29..c2567088f7 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CachedFileRetrieverTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CachedFileRetrieverTests.cs @@ -34,10 +34,11 @@ public class CachedFileRetrieverTests : DatabaseTests public CachedFileRetrieverTests() { _cpMock = Mock.Of(); - _lpMock = Mock.Of(l=>l.CacheProgress == _cpMock); + _lpMock = Mock.Of(l => l.CacheProgress == _cpMock); } - - [Test(Description = "RDMPDEV-185: Tests the scenario where the files in ForLoading do not match the files that are expected given the job specification. In this case the load process should not continue, otherwise the wrong data will be loaded.")] + + [Test(Description = + "RDMPDEV-185: Tests the scenario where the files in ForLoading do not match the files that are expected given the job specification. In this case the load process should not continue, otherwise the wrong data will be loaded.")] public void AttemptToLoadDataWithFilesInForLoading_DisagreementBetweenCacheAndForLoading() { var tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); @@ -62,15 +63,19 @@ public void AttemptToLoadDataWithFilesInForLoading_DisagreementBetweenCacheAndFo }; // Set SetUp job - var job = CreateTestJob(loadDirectory); + var job = CreateTestJob(loadDirectory); job.DatesToRetrieve = new List { - new DateTime(2016, 01, 02) + new(2016, 01, 02) }; // Should fail after determining that the files in ForLoading do not match the job specification - var ex = Assert.Throws(() => retriever.Fetch(job, new GracefulCancellationToken())); - Assert.IsTrue(ex.Message.StartsWith("The files in ForLoading do not match what this job expects to be loading from the cache."), ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace); + var ex = Assert.Throws(() => + retriever.Fetch(job, new GracefulCancellationToken())); + Assert.IsTrue( + ex.Message.StartsWith( + "The files in ForLoading do not match what this job expects to be loading from the cache."), + ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace); } finally { @@ -78,7 +83,8 @@ public void AttemptToLoadDataWithFilesInForLoading_DisagreementBetweenCacheAndFo } } - [Test(Description = "RDMPDEV-185: Tests the scenario where the files in ForLoading match the files that are expected given the job specification, e.g. a load has after the cache has been populated and a subsequent load with *exactly the same parameters* has been triggered. In this case the load can proceed.")] + [Test(Description = + "RDMPDEV-185: Tests the scenario where the files in ForLoading match the files that are expected given the job specification, e.g. a load has after the cache has been populated and a subsequent load with *exactly the same parameters* has been triggered. In this case the load can proceed.")] public void AttemptToLoadDataWithFilesInForLoading_AgreementBetweenForLoadingAndCache() { var tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); @@ -100,15 +106,14 @@ public void AttemptToLoadDataWithFilesInForLoading_AgreementBetweenForLoadingAnd { ExtractFilesFromArchive = false, LoadProgress = _lpMock, - Layout = cacheLayout - + Layout = cacheLayout }; // Set SetUp job - var job = CreateTestJob(loadDirectory); + var job = CreateTestJob(loadDirectory); job.DatesToRetrieve = new List { - new DateTime(2016, 01, 01) + new(2016, 01, 01) }; // Should complete successfully, the file in ForLoading matches the job specification @@ -145,14 +150,13 @@ public void AttemptToLoadDataWithoutFilesInForLoading() ExtractFilesFromArchive = false, LoadProgress = _lpMock, Layout = cacheLayout - }; // Set SetUp job var job = CreateTestJob(loadDirectory); job.DatesToRetrieve = new List { - new DateTime(2016, 01, 01) + new(2016, 01, 01) }; // Should complete successfully, there are no files in ForLoading to worry about @@ -169,19 +173,20 @@ public void AttemptToLoadDataWithoutFilesInForLoading() private ScheduledDataLoadJob CreateTestJob(ILoadDirectory directory) { - var catalogue = Mock.Of(c => + var catalogue = Mock.Of(c => c.GetTableInfoList(false) == Array.Empty() && - c.GetLookupTableInfoList()==Array.Empty() && + c.GetLookupTableInfoList() == Array.Empty() && c.LoggingDataTask == "TestLogging" ); var logManager = Mock.Of(); - var loadMetadata = Mock.Of(lm => lm.GetAllCatalogues()==new[] { catalogue }); + var loadMetadata = Mock.Of(lm => lm.GetAllCatalogues() == new[] { catalogue }); - var j = new ScheduledDataLoadJob(RepositoryLocator, "Test job", logManager, loadMetadata, directory, new ThrowImmediatelyDataLoadEventListener(), null) - { - LoadProgress = _lpMock - }; + var j = new ScheduledDataLoadJob(RepositoryLocator, "Test job", logManager, loadMetadata, directory, + new ThrowImmediatelyDataLoadEventListener(), null) + { + LoadProgress = _lpMock + }; return j; } } @@ -192,7 +197,6 @@ internal class TestCachedFileRetriever : CachedFileRetriever public override void Initialize(ILoadDirectory directory, DiscoveredDatabase dbInfo) { - } public override ExitCodeType Fetch(IDataLoadJob dataLoadJob, GracefulCancellationToken cancellationToken) @@ -200,12 +204,10 @@ public override ExitCodeType Fetch(IDataLoadJob dataLoadJob, GracefulCancellatio var scheduledJob = ConvertToScheduledJob(dataLoadJob); GetDataLoadWorkload(scheduledJob); ExtractJobs(scheduledJob); - + return ExitCodeType.Success; } - protected override ICacheLayout CreateCacheLayout(ICacheProgress cacheProgress, IDataLoadEventListener listener) - { - return Layout; - } + protected override ICacheLayout CreateCacheLayout(ICacheProgress cacheProgress, IDataLoadEventListener listener) => + Layout; } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CheckingTests/ProcessTaskCheckingTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CheckingTests/ProcessTaskCheckingTests.cs index 7c26e7e5b5..fe52c02f6c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CheckingTests/ProcessTaskCheckingTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CheckingTests/ProcessTaskCheckingTests.cs @@ -20,7 +20,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.CheckingTests; -public class ProcessTaskCheckingTests:DatabaseTests +public class ProcessTaskCheckingTests : DatabaseTests { private LoadMetadata _lmd; private ProcessTask _task; @@ -32,49 +32,49 @@ public void CreateTask() { _lmd = new LoadMetadata(CatalogueRepository); - _dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"ProcessTaskCheckingTests")); + _dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "ProcessTaskCheckingTests")); _dir.Create(); var hicdir = LoadDirectory.CreateDirectoryStructure(_dir, "ProjDir", true); _lmd.LocationOfFlatFiles = hicdir.RootPath.FullName; _lmd.SaveToDatabase(); - var c = new Catalogue(CatalogueRepository,"c"); - var ci = new CatalogueItem(CatalogueRepository,c,"ci"); - var t = new TableInfo(CatalogueRepository,"t") + var c = new Catalogue(CatalogueRepository, "c"); + var ci = new CatalogueItem(CatalogueRepository, c, "ci"); + var t = new TableInfo(CatalogueRepository, "t") { Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name, Database = "mydb" }; t.SaveToDatabase(); - var col = new ColumnInfo(CatalogueRepository,"col","bit",t); + var col = new ColumnInfo(CatalogueRepository, "col", "bit", t); ci.SetColumnInfo(col); c.LoadMetadata_ID = _lmd.ID; c.SaveToDatabase(); - + _task = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles); _checker = new ProcessTaskChecks(_lmd); } - + [Test] - [TestCase(null,ProcessTaskType.Executable)] - [TestCase("",ProcessTaskType.Executable)] - [TestCase(" ",ProcessTaskType.Executable)] - [TestCase(null,ProcessTaskType.SQLFile)] - [TestCase("",ProcessTaskType.SQLFile)] - [TestCase(" ",ProcessTaskType.SQLFile)] + [TestCase(null, ProcessTaskType.Executable)] + [TestCase("", ProcessTaskType.Executable)] + [TestCase(" ", ProcessTaskType.Executable)] + [TestCase(null, ProcessTaskType.SQLFile)] + [TestCase("", ProcessTaskType.SQLFile)] + [TestCase(" ", ProcessTaskType.SQLFile)] public void EmptyFilePath(string path, ProcessTaskType typeThatRequiresFiles) { _task.ProcessTaskType = typeThatRequiresFiles; _task.Path = path; _task.SaveToDatabase(); - var ex = Assert.Throws(()=>_checker.Check(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains("does not have a path specified",ex.Message); + var ex = Assert.Throws(() => _checker.Check(new ThrowImmediatelyCheckNotifier())); + StringAssert.Contains("does not have a path specified", ex.Message); } [Test] - [TestCase(null, ProcessTaskType.MutilateDataTable,LoadStage.AdjustStaging)] + [TestCase(null, ProcessTaskType.MutilateDataTable, LoadStage.AdjustStaging)] [TestCase("", ProcessTaskType.MutilateDataTable, LoadStage.AdjustStaging)] [TestCase(" ", ProcessTaskType.MutilateDataTable, LoadStage.AdjustRaw)] [TestCase(null, ProcessTaskType.Attacher, LoadStage.Mounting)] @@ -85,8 +85,9 @@ public void EmptyClassPath(string path, ProcessTaskType typeThatRequiresMEF, Loa _task.Path = path; _task.LoadStage = stage; _task.SaveToDatabase(); - var ex = Assert.Throws(()=>_checker.Check(new ThrowImmediatelyCheckNotifier())); - Assert.IsTrue(Regex.IsMatch(ex.Message,"Path is blank for ProcessTask 'New Process.*' - it should be a class name of type")); + var ex = Assert.Throws(() => _checker.Check(new ThrowImmediatelyCheckNotifier())); + Assert.IsTrue(Regex.IsMatch(ex.Message, + "Path is blank for ProcessTask 'New Process.*' - it should be a class name of type")); } [Test] @@ -97,8 +98,11 @@ public void MEFIncompatibleType() _task.Path = typeof(object).ToString(); _task.SaveToDatabase(); var ex = Assert.Throws(() => _checker.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Requested typeToCreate 'System.Object' was not assignable to the required Type 'IMutilateDataTables'", ex.Message); + Assert.AreEqual( + "Requested typeToCreate 'System.Object' was not assignable to the required Type 'IMutilateDataTables'", + ex.Message); } + [Test] public void MEFCompatibleType_NoProjectDirectory() { @@ -111,15 +115,18 @@ public void MEFCompatibleType_NoProjectDirectory() _task.SaveToDatabase(); _task.CreateArgumentsForClassIfNotExists(); - var ex = Assert.Throws(()=>_checker.Check(new ThrowImmediatelyCheckNotifier {ThrowOnWarning = true})); - Assert.AreEqual($@"No Project Directory (LocationOfFlatFiles) has been configured on LoadMetadata {_lmd.Name}", ex.InnerException.Message); - + var ex = Assert.Throws(() => + _checker.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); + Assert.AreEqual($@"No Project Directory (LocationOfFlatFiles) has been configured on LoadMetadata {_lmd.Name}", + ex.InnerException.Message); } + [Test] public void MEFCompatibleType_NoArgs() { - - var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "DelMeProjDir", true); + var projDir = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "DelMeProjDir", true); try { _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; @@ -129,11 +136,12 @@ public void MEFCompatibleType_NoArgs() _task.SaveToDatabase(); - var ex = Assert.Throws(() => _checker.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); - - Assert.AreEqual(@"Class AnySeparatorFileAttacher has a Mandatory property 'Separator' marked with DemandsInitialization but no corresponding argument was provided in ArgumentCollection",ex.Message); - + var ex = Assert.Throws(() => + _checker.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); + Assert.AreEqual( + @"Class AnySeparatorFileAttacher has a Mandatory property 'Separator' marked with DemandsInitialization but no corresponding argument was provided in ArgumentCollection", + ex.Message); } finally { @@ -145,7 +153,9 @@ public void MEFCompatibleType_NoArgs() [Test] public void MEFCompatibleType_Passes() { - var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "DelMeProjDir", true); + var projDir = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "DelMeProjDir", true); try { _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; @@ -180,7 +190,7 @@ public void MEFCompatibleType_Passes() Console.WriteLine(ExceptionHelper.ExceptionToListOfInnerMessages(msg.Ex)); } - Assert.AreEqual( CheckResult.Success,results.GetWorst()); + Assert.AreEqual(CheckResult.Success, results.GetWorst()); } finally { @@ -198,8 +208,8 @@ public void ImaginaryFile(string path) _task.ProcessTaskType = ProcessTaskType.Executable; _task.Path = path; _task.SaveToDatabase(); - var ex = Assert.Throws(()=>_checker.Check(new ThrowImmediatelyCheckNotifier {ThrowOnWarning=true})); - StringAssert.Contains("bob.exe which does not exist at this time.",ex.Message); + var ex = Assert.Throws(() => + _checker.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true })); + StringAssert.Contains("bob.exe which does not exist at this time.", ex.Message); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CoalescerTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CoalescerTests.cs index e3e77c8224..fb2b5edf1d 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CoalescerTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CoalescerTests.cs @@ -20,13 +20,13 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class CoalescerTests:DatabaseTests +public class CoalescerTests : DatabaseTests { - [TestCase(DatabaseType.MicrosoftSQLServer,true)] + [TestCase(DatabaseType.MicrosoftSQLServer, true)] [TestCase(DatabaseType.MicrosoftSQLServer, false)] - [TestCase(DatabaseType.MySql,true)] + [TestCase(DatabaseType.MySql, true)] [TestCase(DatabaseType.MySql, false)] - public void TestCoalescer_RampantNullness(DatabaseType type,bool useCustomNamer) + public void TestCoalescer_RampantNullness(DatabaseType type, bool useCustomNamer) { var db = GetCleanedServer(type, "TestCoalescer"); @@ -51,15 +51,15 @@ public void TestCoalescer_RampantNullness(DatabaseType type,bool useCustomNamer) dt.Rows.Add(new object[] { randInt, DBNull.Value, DBNull.Value, randInt, DBNull.Value }); dt.Rows.Add(new object[] { randInt, DBNull.Value, DBNull.Value, randInt, randInt }); - if (randCompleteness >=1) + if (randCompleteness >= 1) { dt.Rows.Add(new object[] { randInt, DBNull.Value, randInt, DBNull.Value, DBNull.Value }); dt.Rows.Add(new object[] { randInt, DBNull.Value, randInt, DBNull.Value, randInt }); dt.Rows.Add(new object[] { randInt, DBNull.Value, randInt, randInt, DBNull.Value }); dt.Rows.Add(new object[] { randInt, DBNull.Value, randInt, randInt, randInt }); } - - if(randCompleteness >=2) + + if (randCompleteness >= 2) { dt.Rows.Add(new object[] { randInt, randInt, DBNull.Value, DBNull.Value, DBNull.Value }); dt.Rows.Add(new object[] { randInt, randInt, DBNull.Value, DBNull.Value, randInt }); @@ -68,7 +68,7 @@ public void TestCoalescer_RampantNullness(DatabaseType type,bool useCustomNamer) } - if(randCompleteness >= 3) + if (randCompleteness >= 3) { dt.Rows.Add(new object[] { randInt, randInt, randInt, DBNull.Value, DBNull.Value }); dt.Rows.Add(new object[] { randInt, randInt, randInt, DBNull.Value, randInt }); @@ -95,14 +95,14 @@ public void TestCoalescer_RampantNullness(DatabaseType type,bool useCustomNamer) namer = RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(db, "AAAA"); } - var configuration = new HICDatabaseConfiguration(db.Server,namer); + var configuration = new HICDatabaseConfiguration(db.Server, namer); var coalescer = new Coalescer { TableRegexPattern = new Regex(".*"), CreateIndex = true }; - coalescer.Initialize(db,LoadStage.AdjustRaw); + coalescer.Initialize(db, LoadStage.AdjustRaw); var job = new ThrowImmediatelyDataLoadJob(configuration, tableInfo); @@ -112,7 +112,7 @@ public void TestCoalescer_RampantNullness(DatabaseType type,bool useCustomNamer) foreach (DataRow row in dt2.Rows) { - Assert.AreNotEqual(DBNull.Value,row["f1"]); + Assert.AreNotEqual(DBNull.Value, row["f1"]); Assert.AreNotEqual(DBNull.Value, row["f2"]); Assert.AreNotEqual(DBNull.Value, row["f3"]); Assert.AreNotEqual(DBNull.Value, row["f4"]); @@ -120,5 +120,4 @@ public void TestCoalescer_RampantNullness(DatabaseType type,bool useCustomNamer) db.Drop(); } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseDataLoadTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseDataLoadTests.cs index 8e70280098..9c52d69c76 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseDataLoadTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseDataLoadTests.cs @@ -37,7 +37,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.CrossDatabaseTypeTests; /* Test currently requires for LowPrivilegeLoaderAccount (e.g. minion) --------------------------------------------------- - + create database DLE_STAGING use DLE_STAGING @@ -60,21 +60,21 @@ public enum TestCase AllPrimaryKeys, NoTrigger, WithNonPrimaryKeyIdentityColumn, - + WithCustomTableNamer, WithDiffColumnIgnoreRegex //tests ability of the system to skip a given column when doing the DLE diff section } - [TestCase(DatabaseType.Oracle,TestCase.Normal)] - [TestCase(DatabaseType.MicrosoftSQLServer,TestCase.Normal)] - [TestCase(DatabaseType.MicrosoftSQLServer,TestCase.NoTrigger)] + [TestCase(DatabaseType.Oracle, TestCase.Normal)] + [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.Normal)] + [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.NoTrigger)] [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.WithCustomTableNamer)] [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.WithNonPrimaryKeyIdentityColumn)] [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.DodgyCollation)] [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.LowPrivilegeLoaderAccount)] [TestCase(DatabaseType.MicrosoftSQLServer, TestCase.AllPrimaryKeys)] - [TestCase(DatabaseType.MySql,TestCase.Normal)] + [TestCase(DatabaseType.MySql, TestCase.Normal)] //[TestCase(DatabaseType.MySql, TestCase.WithNonPrimaryKeyIdentityColumn)] //Not supported by MySql:Incorrect table definition; there can be only one auto column and it must be defined as a key [TestCase(DatabaseType.MySql, TestCase.DodgyCollation)] [TestCase(DatabaseType.MySql, TestCase.WithCustomTableNamer)] @@ -90,17 +90,18 @@ public void Load(DatabaseType databaseType, TestCase testCase) var db = GetCleanedServer(databaseType); var raw = db.Server.ExpectDatabase($"{db.GetRuntimeName()}_RAW"); - if(raw.Exists()) + if (raw.Exists()) raw.Drop(); - + using var dt = new DataTable("MyTable"); dt.Columns.Add("Name"); dt.Columns.Add("DateOfBirth"); dt.Columns.Add("FavouriteColour"); - dt.Rows.Add("Bob", "2001-01-01","Pink"); - dt.Rows.Add("Frank", "2001-01-01","Orange"); + dt.Rows.Add("Bob", "2001-01-01", "Pink"); + dt.Rows.Add("Frank", "2001-01-01", "Orange"); - var nameCol = new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof (string), 20), false){IsPrimaryKey = true}; + var nameCol = new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 20), false) + { IsPrimaryKey = true }; if (testCase == TestCase.DodgyCollation) nameCol.Collation = databaseType switch @@ -115,30 +116,38 @@ public void Load(DatabaseType databaseType, TestCase testCase) { case TestCase.WithNonPrimaryKeyIdentityColumn: { - tbl = db.CreateTable("MyTable",new [] + tbl = db.CreateTable("MyTable", new[] { - new DatabaseColumnRequest("ID",new DatabaseTypeRequest(typeof(int)),false){IsPrimaryKey = false,IsAutoIncrement = true}, - nameCol, - new DatabaseColumnRequest("DateOfBirth",new DatabaseTypeRequest(typeof(DateTime)),false){IsPrimaryKey = true}, - new DatabaseColumnRequest("FavouriteColour",new DatabaseTypeRequest(typeof(string))) + new DatabaseColumnRequest("ID", new DatabaseTypeRequest(typeof(int)), false) + { IsPrimaryKey = false, IsAutoIncrement = true }, + nameCol, + new DatabaseColumnRequest("DateOfBirth", new DatabaseTypeRequest(typeof(DateTime)), false) + { IsPrimaryKey = true }, + new DatabaseColumnRequest("FavouriteColour", new DatabaseTypeRequest(typeof(string))) }); - + using (var blk = tbl.BeginBulkInsert()) + { blk.Upload(dt); + } - Assert.AreEqual(1,tbl.DiscoverColumns().Count(c=>c.GetRuntimeName().Equals("ID",StringComparison.CurrentCultureIgnoreCase)),"Table created did not contain ID column"); + Assert.AreEqual(1, + tbl.DiscoverColumns().Count(c => + c.GetRuntimeName().Equals("ID", StringComparison.CurrentCultureIgnoreCase)), + "Table created did not contain ID column"); break; } case TestCase.AllPrimaryKeys: dt.PrimaryKey = dt.Columns.Cast().ToArray(); - tbl = db.CreateTable("MyTable",dt,new []{nameCol}); //upload the column as is + tbl = db.CreateTable("MyTable", dt, new[] { nameCol }); //upload the column as is Assert.IsTrue(tbl.DiscoverColumns().All(c => c.IsPrimaryKey)); break; default: tbl = db.CreateTable("MyTable", dt, new[] { nameCol, - new DatabaseColumnRequest("DateOfBirth",new DatabaseTypeRequest(typeof(DateTime)),false){IsPrimaryKey = true} + new DatabaseColumnRequest("DateOfBirth", new DatabaseTypeRequest(typeof(DateTime)), false) + { IsPrimaryKey = true } }); break; } @@ -148,18 +157,18 @@ public void Load(DatabaseType databaseType, TestCase testCase) //define a new load configuration var lmd = new LoadMetadata(CatalogueRepository, "MyLoad"); - if(testCase == TestCase.NoTrigger) + if (testCase == TestCase.NoTrigger) { lmd.IgnoreTrigger = true; lmd.SaveToDatabase(); } - var ti = Import(tbl, lmd,logManager); + var ti = Import(tbl, lmd, logManager); var projectDirectory = SetupLoadDirectory(lmd); - CreateCSVProcessTask(lmd,ti,"*.csv"); - + CreateCSVProcessTask(lmd, ti, "*.csv"); + //create a text file to load where we update Frank's favourite colour (it's a pk field) and we insert a new record (MrMurder) File.WriteAllText( Path.Combine(projectDirectory.ForLoading.FullName, "LoadMe.csv"), @@ -171,23 +180,30 @@ public void Load(DatabaseType databaseType, TestCase testCase) //the checks will probably need to be run as ddl admin because it involves creating _Archive table and trigger the first time //clean SetUp RAW / STAGING etc and generally accept proposed cleanup operations - var checker = new CheckEntireDataLoadProcess(lmd, new HICDatabaseConfiguration(lmd), new HICLoadConfigurationFlags(),CatalogueRepository.MEF); + var checker = new CheckEntireDataLoadProcess(lmd, new HICDatabaseConfiguration(lmd), + new HICLoadConfigurationFlags(), CatalogueRepository.MEF); checker.Check(new AcceptAllCheckNotifier()); //create a reader if (testCase == TestCase.LowPrivilegeLoaderAccount) { - SetupLowPrivilegeUserRightsFor(ti, TestLowPrivilegePermissions.Reader|TestLowPrivilegePermissions.Writer); - SetupLowPrivilegeUserRightsFor(db.Server.ExpectDatabase("DLE_STAGING"),TestLowPrivilegePermissions.All); + SetupLowPrivilegeUserRightsFor(ti, TestLowPrivilegePermissions.Reader | TestLowPrivilegePermissions.Writer); + SetupLowPrivilegeUserRightsFor(db.Server.ExpectDatabase("DLE_STAGING"), TestLowPrivilegePermissions.All); } - Assert.AreEqual(testCase != TestCase.NoTrigger, tbl.DiscoverColumns().Select(c=>c.GetRuntimeName()).Contains(SpecialFieldNames.DataLoadRunID), $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); - Assert.AreEqual(testCase != TestCase.NoTrigger, tbl.DiscoverColumns().Select(c=>c.GetRuntimeName()).Contains(SpecialFieldNames.ValidFrom), $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); + Assert.AreEqual(testCase != TestCase.NoTrigger, + tbl.DiscoverColumns().Select(c => c.GetRuntimeName()).Contains(SpecialFieldNames.DataLoadRunID), + $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); + Assert.AreEqual(testCase != TestCase.NoTrigger, + tbl.DiscoverColumns().Select(c => c.GetRuntimeName()).Contains(SpecialFieldNames.ValidFrom), + $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); - var dbConfig = new HICDatabaseConfiguration(lmd,testCase == TestCase.WithCustomTableNamer? new CustomINameDatabasesAndTablesDuringLoads():null); + var dbConfig = new HICDatabaseConfiguration(lmd, + testCase == TestCase.WithCustomTableNamer ? new CustomINameDatabasesAndTablesDuringLoads() : null); - if(testCase == TestCase.WithCustomTableNamer) - new PreExecutionChecker(lmd, dbConfig).Check(new AcceptAllCheckNotifier()); //handles staging database creation etc + if (testCase == TestCase.WithCustomTableNamer) + new PreExecutionChecker(lmd, dbConfig).Check( + new AcceptAllCheckNotifier()); //handles staging database creation etc if (testCase == TestCase.WithDiffColumnIgnoreRegex) dbConfig.UpdateButDoNotDiff = new Regex("^FavouriteColour"); //do not diff FavouriteColour @@ -206,60 +222,66 @@ public void Load(DatabaseType databaseType, TestCase testCase) var exe = loadFactory.Create(new ThrowImmediatelyDataLoadEventListener()); var exitCode = exe.Run( - new DataLoadJob(RepositoryLocator,"Go go go!", logManager, lmd, projectDirectory,new ThrowImmediatelyDataLoadEventListener(),dbConfig), + new DataLoadJob(RepositoryLocator, "Go go go!", logManager, lmd, projectDirectory, + new ThrowImmediatelyDataLoadEventListener(), dbConfig), new GracefulCancellationToken()); - Assert.AreEqual(ExitCodeType.Success,exitCode); + Assert.AreEqual(ExitCodeType.Success, exitCode); if (testCase == TestCase.AllPrimaryKeys) { Assert.AreEqual(4, tbl.GetRowCount()); //Bob, Frank, Frank (with also pk Neon) & MrMurder Assert.Pass(); } + if (testCase == TestCase.WithDiffColumnIgnoreRegex) { Assert.AreEqual(3, tbl.GetRowCount()); //Bob, Frank (original since the diff was skipped), & MrMurder //frank should be updated to like Neon instead of Orange Assert.AreEqual(3, tbl.GetRowCount()); - var frankOld = tbl.GetDataTable().Rows.Cast().Single(r => (string)r["Name"] == "Frank"); + var frankOld = tbl.GetDataTable().Rows.Cast().Single(r => (string)r["Name"] == "Frank"); Assert.AreEqual("Orange", frankOld["FavouriteColour"]); Assert.Pass(); } //frank should be updated to like Neon instead of Orange - Assert.AreEqual(3,tbl.GetRowCount()); + Assert.AreEqual(3, tbl.GetRowCount()); var result = tbl.GetDataTable(); - var frank = result.Rows.Cast().Single(r => (string) r["Name"] == "Frank"); - Assert.AreEqual("Neon",frank["FavouriteColour"]); - - if(testCase != TestCase.NoTrigger) + var frank = result.Rows.Cast().Single(r => (string)r["Name"] == "Frank"); + Assert.AreEqual("Neon", frank["FavouriteColour"]); + + if (testCase != TestCase.NoTrigger) AssertHasDataLoadRunId(frank); //MrMurder is a new person who likes Yella var mrmurder = result.Rows.Cast().Single(r => (string)r["Name"] == "MrMurder"); Assert.AreEqual("Yella", mrmurder["FavouriteColour"]); - Assert.AreEqual(new DateTime(2001,01,01), mrmurder["DateOfBirth"]); - - if(testCase != TestCase.NoTrigger) + Assert.AreEqual(new DateTime(2001, 01, 01), mrmurder["DateOfBirth"]); + + if (testCase != TestCase.NoTrigger) AssertHasDataLoadRunId(mrmurder); //bob should be untouched (same values as before and no dataloadrunID) var bob = result.Rows.Cast().Single(r => (string)r["Name"] == "Bob"); Assert.AreEqual("Pink", bob["FavouriteColour"]); Assert.AreEqual(new DateTime(2001, 01, 01), bob["DateOfBirth"]); - - if(testCase != TestCase.NoTrigger) + + if (testCase != TestCase.NoTrigger) { - Assert.AreEqual(DBNull.Value,bob[SpecialFieldNames.DataLoadRunID]); + Assert.AreEqual(DBNull.Value, bob[SpecialFieldNames.DataLoadRunID]); //MySql add default of now() on a table will auto populate all the column values with the the now() date while Sql Server will leave them as nulls - if(databaseType == DatabaseType.MicrosoftSQLServer) + if (databaseType == DatabaseType.MicrosoftSQLServer) Assert.AreEqual(DBNull.Value, bob[SpecialFieldNames.ValidFrom]); } - - Assert.AreEqual(testCase != TestCase.NoTrigger, tbl.DiscoverColumns().Select(c=>c.GetRuntimeName()).Contains(SpecialFieldNames.DataLoadRunID), $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); - Assert.AreEqual(testCase != TestCase.NoTrigger, tbl.DiscoverColumns().Select(c=>c.GetRuntimeName()).Contains(SpecialFieldNames.ValidFrom), $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); + + Assert.AreEqual(testCase != TestCase.NoTrigger, + tbl.DiscoverColumns().Select(c => c.GetRuntimeName()).Contains(SpecialFieldNames.DataLoadRunID), + $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); + Assert.AreEqual(testCase != TestCase.NoTrigger, + tbl.DiscoverColumns().Select(c => c.GetRuntimeName()).Contains(SpecialFieldNames.ValidFrom), + $"When running with NoTrigger there shouldn't be any additional columns added to table. Test case was {testCase}"); } finally { @@ -275,10 +297,10 @@ public void Load(DatabaseType databaseType, TestCase testCase) l.DeleteInDatabase(); } - if(testCase == TestCase.WithCustomTableNamer) + if (testCase == TestCase.WithCustomTableNamer) { var db2 = db.Server.ExpectDatabase("BB_STAGING"); - if(db.Exists()) + if (db.Exists()) db2.Drop(); } } @@ -294,10 +316,10 @@ public void DLELoadTwoTables(DatabaseType databaseType) var db = GetCleanedServer(databaseType); var dtParent = new DataTable(); - dtParent.Columns.Add("ID",typeof(int)); + dtParent.Columns.Add("ID", typeof(int)); dtParent.Columns.Add("Name"); dtParent.Columns.Add("Height"); - dtParent.PrimaryKey = new[] {dtParent.Columns[0]}; + dtParent.PrimaryKey = new[] { dtParent.Columns[0] }; dtParent.Rows.Add("1", "Dave", "3.5"); @@ -309,19 +331,19 @@ public void DLELoadTwoTables(DatabaseType databaseType) dtChild.Columns.Add("Age"); dtChild.Columns.Add("Height"); - dtChild.Rows.Add("1","1","Child1","2001-01-01","20","3.5"); - dtChild.Rows.Add("1","2","Child2","2002-01-01","19","3.4"); - - dtChild.PrimaryKey = new[] {dtChild.Columns[0], dtChild.Columns[1]}; + dtChild.Rows.Add("1", "1", "Child1", "2001-01-01", "20", "3.5"); + dtChild.Rows.Add("1", "2", "Child2", "2002-01-01", "19", "3.4"); + + dtChild.PrimaryKey = new[] { dtChild.Columns[0], dtChild.Columns[1] }; //create the parent table based on the DataTable - var parentTbl = db.CreateTable("Parent",dtParent); + var parentTbl = db.CreateTable("Parent", dtParent); //go find the primary key column created var pkParentID = parentTbl.DiscoverColumn("ID"); //forward declare this column as part of pk (will be used to specify foreign key - var fkParentID = new DatabaseColumnRequest("Parent_ID", "int"){IsPrimaryKey = true}; + var fkParentID = new DatabaseColumnRequest("Parent_ID", "int") { IsPrimaryKey = true }; var args = new CreateTableArgs( db, @@ -331,7 +353,7 @@ public void DLELoadTwoTables(DatabaseType databaseType) false, new Dictionary { - {fkParentID, pkParentID} + { fkParentID, pkParentID } }, true) { @@ -350,11 +372,11 @@ public void DLELoadTwoTables(DatabaseType databaseType) var lmd = new LoadMetadata(CatalogueRepository, "MyLoading2"); var childTableInfo = Import(childTbl, lmd, logManager); - var parentTableInfo = Import(parentTbl,lmd,logManager); + var parentTableInfo = Import(parentTbl, lmd, logManager); var projectDirectory = SetupLoadDirectory(lmd); - CreateCSVProcessTask(lmd,parentTableInfo,"parent.csv"); + CreateCSVProcessTask(lmd, parentTableInfo, "parent.csv"); CreateCSVProcessTask(lmd, childTableInfo, "child.csv"); //create a text file to load where we update Frank's favourite colour (it's a pk field) and we insert a new record (MrMurder) @@ -372,7 +394,8 @@ public void DLELoadTwoTables(DatabaseType databaseType) //clean SetUp RAW / STAGING etc and generally accept proposed cleanup operations - var checker = new CheckEntireDataLoadProcess(lmd, new HICDatabaseConfiguration(lmd), new HICLoadConfigurationFlags(), CatalogueRepository.MEF); + var checker = new CheckEntireDataLoadProcess(lmd, new HICDatabaseConfiguration(lmd), + new HICLoadConfigurationFlags(), CatalogueRepository.MEF); checker.Check(new AcceptAllCheckNotifier()); var config = new HICDatabaseConfiguration(lmd); @@ -389,7 +412,8 @@ public void DLELoadTwoTables(DatabaseType databaseType) var exe = loadFactory.Create(new ThrowImmediatelyDataLoadEventListener()); var exitCode = exe.Run( - new DataLoadJob(RepositoryLocator,"Go go go!", logManager, lmd, projectDirectory, new ThrowImmediatelyDataLoadEventListener(),config), + new DataLoadJob(RepositoryLocator, "Go go go!", logManager, lmd, projectDirectory, + new ThrowImmediatelyDataLoadEventListener(), config), new GracefulCancellationToken()); Assert.AreEqual(ExitCodeType.Success, exitCode); @@ -413,13 +437,13 @@ public void DLELoadTwoTables(DatabaseType databaseType) var newC1 = result.Rows.Cast().Single(r => (string)r["Name"] == "NewC1"); Assert.AreEqual(2, newC1["Parent_ID"]); Assert.AreEqual(1, newC1["ChildNumber"]); - Assert.AreEqual(DBNull.Value, newC1["Height"]); //the "null" in the input file should be DBNull.Value in the final database + Assert.AreEqual(DBNull.Value, + newC1["Height"]); //the "null" in the input file should be DBNull.Value in the final database AssertHasDataLoadRunId(newC1); - } finally { - Directory.Delete(lmd.LocationOfFlatFiles,true); + Directory.Delete(lmd.LocationOfFlatFiles, true); foreach (var c in RepositoryLocator.CatalogueRepository.GetAllObjects()) c.DeleteInDatabase(); @@ -431,10 +455,9 @@ public void DLELoadTwoTables(DatabaseType databaseType) l.DeleteInDatabase(); } } - } -internal class CustomINameDatabasesAndTablesDuringLoads:INameDatabasesAndTablesDuringLoads +internal class CustomINameDatabasesAndTablesDuringLoads : INameDatabasesAndTablesDuringLoads { public string GetDatabaseName(string rootDatabaseName, LoadBubble convention) { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseMergeCommandTest.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseMergeCommandTest.cs index c7a1817564..02e8e39dfa 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseMergeCommandTest.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/CrossDatabaseMergeCommandTest.cs @@ -26,7 +26,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.CrossDatabaseTypeTests; -public class CrossDatabaseMergeCommandTest:FromToDatabaseTests +public class CrossDatabaseMergeCommandTest : FromToDatabaseTests { [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] @@ -37,20 +37,20 @@ public void TestMerge(DatabaseType databaseType) SetupFromTo(databaseType); var dt = new DataTable(); - var colName = new DataColumn("Name",typeof(string)); - var colAge = new DataColumn("Age",typeof(int)); + var colName = new DataColumn("Name", typeof(string)); + var colAge = new DataColumn("Age", typeof(int)); dt.Columns.Add(colName); dt.Columns.Add(colAge); - dt.Columns.Add("Postcode",typeof(string)); + dt.Columns.Add("Postcode", typeof(string)); //Data in live awaiting toTbl be updated - dt.Rows.Add(new object[]{"Dave",18,"DD3 1AB"}); - dt.Rows.Add(new object[] {"Dave", 25, "DD1 1XS" }); - dt.Rows.Add(new object[] {"Mango", 32, DBNull.Value}); - dt.Rows.Add(new object[] { "Filli", 32,"DD3 78L" }); + dt.Rows.Add(new object[] { "Dave", 18, "DD3 1AB" }); + dt.Rows.Add(new object[] { "Dave", 25, "DD1 1XS" }); + dt.Rows.Add(new object[] { "Mango", 32, DBNull.Value }); + dt.Rows.Add(new object[] { "Filli", 32, "DD3 78L" }); dt.Rows.Add(new object[] { "Mandrake", 32, DBNull.Value }); - dt.PrimaryKey = new[]{colName,colAge}; + dt.PrimaryKey = new[] { colName, colAge }; var toTbl = To.CreateTable("ToTable", dt); @@ -59,7 +59,7 @@ public void TestMerge(DatabaseType databaseType) Assert.IsFalse(toTbl.DiscoverColumn("Postcode").IsPrimaryKey); dt.Rows.Clear(); - + //new data being loaded dt.Rows.Add(new object[] { "Dave", 25, "DD1 1PS" }); //update toTbl change postcode toTbl "DD1 1PS" dt.Rows.Add(new object[] { "Chutney", 32, DBNull.Value }); //new insert Chutney @@ -71,7 +71,7 @@ public void TestMerge(DatabaseType databaseType) var fromTbl = From.CreateTable($"{DatabaseName}_ToTable_STAGING", dt); //import the toTbl table as a TableInfo - var cata = Import(toTbl,out var ti, out var cis); + var cata = Import(toTbl, out var ti, out var cis); //put the backup trigger on the live table (this will also create the needed hic_ columns etc) var triggerImplementer = new TriggerImplementerFactory(databaseType).Create(toTbl); @@ -96,19 +96,19 @@ public void TestMerge(DatabaseType databaseType) { LoadMetadata = lmd, DataLoadInfo = dli, - RegularTablesToLoad = new List(new[]{ti}) + RegularTablesToLoad = new List(new[] { ti }) }; migrationHost.Migrate(job, new GracefulCancellationToken()); var resultantDt = toTbl.GetDataTable(); - Assert.AreEqual(7,resultantDt.Rows.Count); + Assert.AreEqual(7, resultantDt.Rows.Count); AssertRowEquals(resultantDt, "Dave", 25, "DD1 1PS"); AssertRowEquals(resultantDt, "Chutney", 32, DBNull.Value); AssertRowEquals(resultantDt, "Mango", 32, DBNull.Value); - AssertRowEquals(resultantDt,"Filli",32,DBNull.Value); + AssertRowEquals(resultantDt, "Filli", 32, DBNull.Value); AssertRowEquals(resultantDt, "Mandrake", 32, "DD1 1PS"); AssertRowEquals(resultantDt, "Mandrake", 31, "DD1 1PS"); @@ -119,15 +119,17 @@ public void TestMerge(DatabaseType databaseType) var log = archival.First(); - Assert.AreEqual(dli.ID,log.ID); - Assert.AreEqual(2,log.TableLoadInfos.Single().Inserts); + Assert.AreEqual(dli.ID, log.ID); + Assert.AreEqual(2, log.TableLoadInfos.Single().Inserts); Assert.AreEqual(3, log.TableLoadInfos.Single().Updates); } - private static void AssertRowEquals(DataTable resultantDt,string name,int age, object postcode) + private static void AssertRowEquals(DataTable resultantDt, string name, int age, object postcode) { Assert.AreEqual( - 1, resultantDt.Rows.Cast().Count(r => Equals(r["Name"], name) && Equals(r["Age"], age) && Equals(r["Postcode"], postcode)), - "Did not find expected record:" + string.Join(",",name,age,postcode)); + 1, + resultantDt.Rows.Cast().Count(r => + Equals(r["Name"], name) && Equals(r["Age"], age) && Equals(r["Postcode"], postcode)), + "Did not find expected record:" + string.Join(",", name, age, postcode)); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/HowDoWeAchieveMd5Test.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/HowDoWeAchieveMd5Test.cs index 8afe6660e5..d1b42209ed 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/HowDoWeAchieveMd5Test.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/CrossDatabaseTypeTests/HowDoWeAchieveMd5Test.cs @@ -12,16 +12,15 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.CrossDatabaseTypeTests; -internal class HowDoWeAchieveMd5Test:DatabaseTests +internal class HowDoWeAchieveMd5Test : DatabaseTests { - [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] public void TestMd5String(DatabaseType type) { var dt = new DataTable(); dt.Columns.Add("F"); - dt.Rows.Add(new[] {"Fish"}); + dt.Rows.Add(new[] { "Fish" }); var db = GetCleanedServer(type); var tbl = db.CreateTable("MD5Test", dt); @@ -42,9 +41,8 @@ public void TestMd5String(DatabaseType type) Console.WriteLine($"Value was:{value}"); Assert.IsNotNull(value); - Assert.AreNotEqual("Fish",value); - Assert.GreaterOrEqual(value.ToString().Length,32); - + Assert.AreNotEqual("Fish", value); + Assert.GreaterOrEqual(value.ToString().Length, 32); } } @@ -61,8 +59,9 @@ public void TestMd5Date(DatabaseType type) var col = tbl.DiscoverColumn("F"); - - Assert.AreEqual(typeof(DateTime),tbl.GetQuerySyntaxHelper().TypeTranslater.GetCSharpTypeForSQLDBType(col.DataType.SQLType)); + + Assert.AreEqual(typeof(DateTime), + tbl.GetQuerySyntaxHelper().TypeTranslater.GetCSharpTypeForSQLDBType(col.DataType.SQLType)); var sql = @@ -80,8 +79,6 @@ public void TestMd5Date(DatabaseType type) Assert.IsNotNull(value); Assert.GreaterOrEqual(value.ToString().Length, 32); - } } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadEngineTestsBase.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadEngineTestsBase.cs index 1ae6bd2deb..1629279e4e 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadEngineTestsBase.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadEngineTestsBase.cs @@ -30,16 +30,17 @@ protected static void AssertHasDataLoadRunId(DataRow row) var o = row[SpecialFieldNames.DataLoadRunID]; Assert.IsNotNull(o, "A row which was expected to have a hic_dataLoadRunID had null instead"); - Assert.AreNotEqual(DBNull.Value, o, "A row which was expected to have a hic_dataLoadRunID had DBNull.Value instead"); + Assert.AreNotEqual(DBNull.Value, o, + "A row which was expected to have a hic_dataLoadRunID had DBNull.Value instead"); Assert.GreaterOrEqual((int)o, 0); var d = row[SpecialFieldNames.ValidFrom]; Assert.IsNotNull(d, "A row which was expected to have a hic_validFrom had null instead"); - Assert.AreNotEqual(DBNull.Value, d, "A row which was expected to have a hic_validFrom had DBNull.Value instead"); + Assert.AreNotEqual(DBNull.Value, d, + "A row which was expected to have a hic_validFrom had DBNull.Value instead"); //expect validFrom to be after 2 hours ago (to handle UTC / BST nonsense) Assert.GreaterOrEqual((DateTime)d, DateTime.Now.Subtract(new TimeSpan(2, 0, 0))); - } protected void CreateCSVProcessTask(LoadMetadata lmd, ITableInfo ti, string regex) @@ -62,7 +63,9 @@ protected void CreateCSVProcessTask(LoadMetadata lmd, ITableInfo ti, string rege protected static LoadDirectory SetupLoadDirectory(LoadMetadata lmd) { - var projectDirectory = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "MyLoadDir", true); + var projectDirectory = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "MyLoadDir", true); lmd.LocationOfFlatFiles = projectDirectory.RootPath.FullName; lmd.SaveToDatabase(); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadProgressUpdateInfoTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadProgressUpdateInfoTests.cs index 185c4147f3..4578053588 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadProgressUpdateInfoTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataLoadProgressUpdateInfoTests.cs @@ -19,29 +19,32 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class DataLoadProgressUpdateInfoTests :DatabaseTests +public class DataLoadProgressUpdateInfoTests : DatabaseTests { private ScheduledDataLoadJob _job; #region Setup Methods + public DataLoadProgressUpdateInfoTests() { var cata = Mock.Of( - c=> c.LoggingDataTask == "NothingTask" && - c.GetTableInfoList(false) == Array.Empty() && - c.GetLookupTableInfoList() == Array.Empty()); + c => c.LoggingDataTask == "NothingTask" && + c.GetTableInfoList(false) == Array.Empty() && + c.GetLookupTableInfoList() == Array.Empty()); var lmd = Mock.Of(m => m.GetAllCatalogues() == new[] { cata }); - _job = new ScheduledDataLoadJob(null,"fish", Mock.Of(), lmd, null, new ThrowImmediatelyDataLoadJob(),null); + _job = new ScheduledDataLoadJob(null, "fish", Mock.Of(), lmd, null, + new ThrowImmediatelyDataLoadJob(), null); } + #endregion [Test] public void AddBasicNormalStrategy_NoDates() { var updateInfo = new DataLoadProgressUpdateInfo(); - var ex = Assert.Throws(()=>updateInfo.AddAppropriateDisposeStep(_job,null)); + var ex = Assert.Throws(() => updateInfo.AddAppropriateDisposeStep(_job, null)); Assert.IsTrue(ex.Message.StartsWith("Job does not have any DatesToRetrieve")); } @@ -49,13 +52,13 @@ public void AddBasicNormalStrategy_NoDates() public void AddBasicNormalStrategy_MaxDate() { var updateInfo = new DataLoadProgressUpdateInfo(); - Assert.AreEqual(DataLoadProgressUpdateStrategy.UseMaxRequestedDay,updateInfo.Strategy); + Assert.AreEqual(DataLoadProgressUpdateStrategy.UseMaxRequestedDay, updateInfo.Strategy); _job.DatesToRetrieve = new List { - new DateTime(2001, 1, 1), - new DateTime(2001, 1, 2), - new DateTime(2001, 1, 3) + new(2001, 1, 1), + new(2001, 1, 2), + new(2001, 1, 3) }; try { @@ -68,7 +71,6 @@ public void AddBasicNormalStrategy_MaxDate() { _job.DatesToRetrieve.Clear(); } - } [Test] @@ -79,7 +81,8 @@ public void AddRAWSQLStrategy_NoSQL() Strategy = DataLoadProgressUpdateStrategy.ExecuteScalarSQLInRAW }; - var ex = Assert.Throws(()=>updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); + var ex = Assert.Throws(() => + updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); Assert.IsTrue(ex.Message.StartsWith("Strategy is ExecuteScalarSQLInRAW but there is no ExecuteScalarSQL")); } @@ -93,7 +96,8 @@ public void AddRAWSQLStrategy_SQLDodgy_SqlCrashes() ExecuteScalarSQL = "SELECT Top 1 BarrelORum from CaptainMorgansSpicedRumBarrel" }; - var ex = Assert.Throws(() => updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); + var ex = Assert.Throws(() => + updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); Assert.IsTrue(ex.Message.StartsWith("Failed to execute the following SQL in the RAW database")); Assert.IsInstanceOf(ex.InnerException); @@ -108,7 +112,8 @@ public void AddRAWSQLStrategy_SQLDodgy_SqlReturnsNull() ExecuteScalarSQL = "SELECT null" }; - var ex = Assert.Throws(() => updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); + var ex = Assert.Throws(() => + updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); Assert.IsTrue(ex.Message.Contains("ExecuteScalarSQL")); Assert.IsTrue(ex.Message.Contains("returned null")); @@ -123,9 +128,12 @@ public void AddRAWSQLStrategy_SQLDodgy_SqlReturnsNonDate() ExecuteScalarSQL = "SELECT 'fishfish'" }; - var ex = Assert.Throws(() => updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); + var ex = Assert.Throws(() => + updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer))); - Assert.AreEqual("ExecuteScalarSQL specified for determining the maximum date of data loaded returned a value that was not a Date:fishfish",ex.Message); + Assert.AreEqual( + "ExecuteScalarSQL specified for determining the maximum date of data loaded returned a value that was not a Date:fishfish", + ex.Message); Assert.IsInstanceOf(ex.InnerException); } @@ -134,9 +142,9 @@ public void AddRAWSQLStrategy_SQLCorrect() { _job.DatesToRetrieve = new List { - new DateTime(2001, 1, 6), - new DateTime(2001, 1, 7), - new DateTime(2001, 1, 8) + new(2001, 1, 6), + new(2001, 1, 7), + new(2001, 1, 8) }; var updateInfo = new DataLoadProgressUpdateInfo @@ -145,8 +153,9 @@ public void AddRAWSQLStrategy_SQLCorrect() ExecuteScalarSQL = "SELECT '2001-01-07'" }; - var added = (UpdateProgressIfLoadsuccessful)updateInfo.AddAppropriateDisposeStep(_job, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); - + var added = (UpdateProgressIfLoadsuccessful)updateInfo.AddAppropriateDisposeStep(_job, + GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); + Assert.AreEqual(new DateTime(2001, 1, 7), added.DateToSetProgressTo); _job.DatesToRetrieve.Clear(); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataTableUploadDestinationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataTableUploadDestinationTests.cs index 58e385b7c4..973df406cf 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataTableUploadDestinationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DataTableUploadDestinationTests.cs @@ -21,7 +21,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class DataTableUploadDestinationTests:DatabaseTests +public class DataTableUploadDestinationTests : DatabaseTests { [Test] public void DataTableChangesLengths_NoReAlter() @@ -34,32 +34,32 @@ public void DataTableChangesLengths_NoReAlter() destination.PreInitialize(db, toConsole); var dt1 = new DataTable(); - dt1.Columns.Add("name", typeof (string)); - dt1.Rows.Add(new []{"Fish"}); + dt1.Columns.Add("name", typeof(string)); + dt1.Rows.Add(new[] { "Fish" }); dt1.TableName = "DataTableUploadDestinationTests"; var dt2 = new DataTable(); - dt2.Columns.Add("name", typeof (string)); - dt2.Rows.Add(new []{"BigFish"}); + dt2.Columns.Add("name", typeof(string)); + dt2.Rows.Add(new[] { "BigFish" }); dt2.TableName = "DataTableUploadDestinationTests"; - destination.ProcessPipelineData( dt1, toConsole,token); - var ex = Assert.Throws(()=>destination.ProcessPipelineData( dt2, toConsole,token)); + destination.ProcessPipelineData(dt1, toConsole, token); + var ex = Assert.Throws(() => destination.ProcessPipelineData(dt2, toConsole, token)); var expectedText = "BulkInsert failed on data row 1 the complaint was about source column <> which had value <> destination data type was <>"; Assert.IsNotNull(ex.InnerException); - StringAssert.Contains(expectedText,ex.InnerException.Message); + StringAssert.Contains(expectedText, ex.InnerException.Message); destination.Dispose(new ThrowImmediatelyDataLoadEventListener(), ex); } //RDMPDEV-653 [Test] - [TestCase(true,10)] - [TestCase(false,10)] - public void DataTableChangesLengths_RandomColumnOrder(bool createIdentity,int numberOfRandomisations) + [TestCase(true, 10)] + [TestCase(false, 10)] + public void DataTableChangesLengths_RandomColumnOrder(bool createIdentity, int numberOfRandomisations) { var token = new GracefulCancellationToken(); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -67,7 +67,7 @@ public void DataTableChangesLengths_RandomColumnOrder(bool createIdentity,int nu var tbl = db.ExpectTable("RandomOrderTable"); var random = new Random(); - for (var i =0;i> which had value <<{dt1.Rows[0][errorColumn]}>> destination data type was <>"; - StringAssert.Contains(expectedErrorMessage,interestingBit); + StringAssert.Contains(expectedErrorMessage, interestingBit); destination.Dispose(new ThrowImmediatelyDataLoadEventListener(), ex); tbl.Drop(); @@ -155,7 +157,6 @@ public void DataTableChangesLengths_RandomColumnOrder(bool createIdentity,int nu } - //RDMPDEV-653 [Test] public void DataTableChangesLengths_DropColumns() @@ -164,7 +165,7 @@ public void DataTableChangesLengths_DropColumns() var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); var tbl = db.ExpectTable("DroppedColumnsTable"); - if(tbl.Exists()) + if (tbl.Exists()) tbl.Drop(); var sql = @"CREATE TABLE DroppedColumnsTable ( @@ -199,7 +200,8 @@ ALTER TABLE DroppedColumnsTable add color varchar(1) dt1.Rows.Add("30", "blue", "Fish"); dt1.TableName = "DroppedColumnsTable"; - var ex = Assert.Throws(() => destination.ProcessPipelineData(dt1, new ThrowImmediatelyDataLoadEventListener(), token)); + var ex = Assert.Throws(() => + destination.ProcessPipelineData(dt1, new ThrowImmediatelyDataLoadEventListener(), token)); var exceptionMessage = ex.InnerException.Message; var interestingBit = exceptionMessage[(exceptionMessage.IndexOf(": <<") + ": ".Length)..]; @@ -209,7 +211,7 @@ ALTER TABLE DroppedColumnsTable add color varchar(1) destination.Dispose(new ThrowImmediatelyDataLoadEventListener(), ex); - if(tbl.Exists()) + if (tbl.Exists()) tbl.Drop(); } @@ -233,6 +235,7 @@ public void DataTableEmpty_ThrowHelpfulException() Assert.AreEqual("DataTable 'MyEmptyTable' had no Columns!", ex.Message); } + [Test] public void DataTableNoRows_ThrowHelpfulException() { @@ -252,6 +255,7 @@ public void DataTableNoRows_ThrowHelpfulException() Assert.AreEqual("DataTable 'MyEmptyTable' had no Rows!", ex.Message); } + [Test] public void DataTableChangesLengths_AllowAlter() { @@ -274,16 +278,14 @@ public void DataTableChangesLengths_AllowAlter() dt2.Rows.Add(new[] { "BigFish" }); dt2.TableName = "DataTableUploadDestinationTests"; - destination.ProcessPipelineData( dt1, toConsole, token); - Assert.DoesNotThrow(() => destination.ProcessPipelineData( dt2, toMemory, token)); + destination.ProcessPipelineData(dt1, toConsole, token); + Assert.DoesNotThrow(() => destination.ProcessPipelineData(dt2, toMemory, token)); Assert.IsTrue(toMemory.EventsReceivedBySender[destination].Any(msg => msg.Message.Contains("Resizing column"))); destination.Dispose(toConsole, null); Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); - Assert.AreEqual(2,db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); - - + Assert.AreEqual(2, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); } [Test] @@ -299,7 +301,7 @@ public void DoubleResizingBetweenIntAndDouble() var dt1 = new DataTable(); dt1.Columns.Add("mynum", typeof(double)); - dt1.Rows.Add(new object[] {1}); + dt1.Rows.Add(new object[] { 1 }); dt1.Rows.Add(new object[] { 5 }); dt1.Rows.Add(new object[] { 15 }); dt1.Rows.Add(new object[] { 2.5 }); @@ -312,13 +314,14 @@ public void DoubleResizingBetweenIntAndDouble() Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); Assert.AreEqual(5, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); - Assert.AreEqual("decimal(3,1)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); + Assert.AreEqual("decimal(3,1)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); } - [TestCase("varchar(3)", 1.5, "x")]//RDMPDEV-932 + [TestCase("varchar(3)", 1.5, "x")] //RDMPDEV-932 [TestCase("varchar(27)", "2001-01-01", "x")] //see Guesser.MinimumLengthRequiredForDateStringRepresentation - public void BatchResizing(string expectedDatatypeInDatabase,object batch1Value,object batch2Value) + public void BatchResizing(string expectedDatatypeInDatabase, object batch1Value, object batch2Value) { var token = new GracefulCancellationToken(); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -330,7 +333,7 @@ public void BatchResizing(string expectedDatatypeInDatabase,object batch1Value,o var dt1 = new DataTable(); dt1.Columns.Add("mycol"); - dt1.Rows.Add(new[] {batch1Value}); + dt1.Rows.Add(new[] { batch1Value }); dt1.TableName = "DataTableUploadDestinationTests"; try @@ -350,11 +353,13 @@ public void BatchResizing(string expectedDatatypeInDatabase,object batch1Value,o throw; } - Assert.AreEqual(expectedDatatypeInDatabase, db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mycol").DataType.SQLType); + Assert.AreEqual(expectedDatatypeInDatabase, + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mycol").DataType.SQLType); } [TestCase("varchar(24)", "2", "987styb4ih0r9h4322938476", "tinyint")] - public void BatchResizing_WithExplicitWriteTypes(string expectedDatatypeInDatabase, object batch1Value, object batch2Value, string batch1SqlType) + public void BatchResizing_WithExplicitWriteTypes(string expectedDatatypeInDatabase, object batch1Value, + object batch2Value, string batch1SqlType) { var token = new GracefulCancellationToken(); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -387,7 +392,8 @@ public void BatchResizing_WithExplicitWriteTypes(string expectedDatatypeInDataba throw; } - Assert.AreEqual(expectedDatatypeInDatabase, db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mycol").DataType.SQLType); + Assert.AreEqual(expectedDatatypeInDatabase, + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mycol").DataType.SQLType); } [Test] @@ -419,7 +425,8 @@ public void VeryLongStringIsVarcharMax() Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); Assert.AreEqual(1, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); - Assert.AreEqual("varchar(max)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("myText").DataType.SQLType); + Assert.AreEqual("varchar(max)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("myText").DataType.SQLType); } [Test] @@ -447,39 +454,51 @@ public void DecimalResizing(bool negative) dt2.Rows.Add(new[] { "00000.00000" }); dt2.Rows.Add(new[] { "0" }); dt2.Rows.Add(new string[] { null }); - dt2.Rows.Add(new [] { "" }); + dt2.Rows.Add(new[] { "" }); dt2.Rows.Add(new[] { DBNull.Value }); dt2.TableName = "DataTableUploadDestinationTests"; - destination.ProcessPipelineData( dt1, toConsole, token); - destination.ProcessPipelineData( dt2, toMemory, token); + destination.ProcessPipelineData(dt1, toConsole, token); + destination.ProcessPipelineData(dt2, toMemory, token); - Assert.IsTrue(toMemory.EventsReceivedBySender[destination].Any(msg => msg.Message.Contains("Resizing column "))); + Assert.IsTrue(toMemory.EventsReceivedBySender[destination] + .Any(msg => msg.Message.Contains("Resizing column "))); destination.Dispose(toConsole, null); Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); Assert.AreEqual(7, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); - Assert.AreEqual("decimal(5,2)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); + Assert.AreEqual("decimal(5,2)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); } - private static object[] _sourceLists = { - new object[] {"decimal(3,3)",new object[]{"0.001"}, new object[]{0.001}}, //case 1 - new object[] {"decimal(6,3)",new object[]{"19","0.001","123.001",32.0f}, new object[]{19,0.001,123.001,32.0f}}, //case 2 + private static object[] _sourceLists = + { + new object[] { "decimal(3,3)", new object[] { "0.001" }, new object[] { 0.001 } }, //case 1 + new object[] + { + "decimal(6,3)", new object[] { "19", "0.001", "123.001", 32.0f }, new object[] { 19, 0.001, 123.001, 32.0f } + }, //case 2 //Time tests - new object[] {"time",new object[]{"12:01"}, new object[]{new TimeSpan(12,1,0)}}, - new object[] {"time",new object[]{"13:00:00"}, new object[]{new TimeSpan(13,0,0)}}, + new object[] { "time", new object[] { "12:01" }, new object[] { new TimeSpan(12, 1, 0) } }, + new object[] { "time", new object[] { "13:00:00" }, new object[] { new TimeSpan(13, 0, 0) } }, //Send two dates expect datetime in database and resultant data to be legit dates - new object[] {"datetime2",new object[]{"2001-01-01 12:01","2010-01-01"}, new object[]{new DateTime(2001,01,01,12,1,0),new DateTime(2010,01,01,0,0,0)}}, + new object[] + { + "datetime2", new object[] { "2001-01-01 12:01", "2010-01-01" }, + new object[] { new DateTime(2001, 01, 01, 12, 1, 0), new DateTime(2010, 01, 01, 0, 0, 0) } + }, //Mixed data types going from time to date results in us falling back to string - new object[] {"varchar(10)",new object[]{"12:01","2001-01-01"}, new object[]{"12:01","2001-01-01"}} + new object[] { "varchar(10)", new object[] { "12:01", "2001-01-01" }, new object[] { "12:01", "2001-01-01" } } }; - [Test, TestCaseSource(nameof(_sourceLists))] - public void DataTypeEstimation(string expectedDatatypeInDatabase, object[] rowValues, object[] expectedValuesReadFromDatabase) + [Test] + [TestCaseSource(nameof(_sourceLists))] + public void DataTypeEstimation(string expectedDatatypeInDatabase, object[] rowValues, + object[] expectedValuesReadFromDatabase) { var token = new GracefulCancellationToken(); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -492,7 +511,7 @@ public void DataTypeEstimation(string expectedDatatypeInDatabase, object[] rowVa dt1.Columns.Add("myCol", typeof(string)); foreach (var rowValue in rowValues) - dt1.Rows.Add(new[] {rowValue}); + dt1.Rows.Add(new[] { rowValue }); dt1.TableName = "DataTableUploadDestinationTests"; @@ -500,23 +519,25 @@ public void DataTypeEstimation(string expectedDatatypeInDatabase, object[] rowVa destination.Dispose(toConsole, null); Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); - Assert.AreEqual(expectedDatatypeInDatabase, db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("myCol").DataType.SQLType); + Assert.AreEqual(expectedDatatypeInDatabase, + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("myCol").DataType.SQLType); using (var con = db.Server.GetConnection()) { con.Open(); - using(var cmd = DatabaseCommandHelper.GetCommand("Select * from DataTableUploadDestinationTests", con)) - using(var r = cmd.ExecuteReader()) + using (var cmd = DatabaseCommandHelper.GetCommand("Select * from DataTableUploadDestinationTests", con)) + using (var r = cmd.ExecuteReader()) + { foreach (var e in expectedValuesReadFromDatabase) { Assert.IsTrue(r.Read()); Assert.AreEqual(e, r["myCol"]); } + } } } - [Test] [TestCase(true)] [TestCase(false)] @@ -539,21 +560,22 @@ public void DecimalZeros(bool sendTheZero) dt1.TableName = "DataTableUploadDestinationTests"; - destination.ProcessPipelineData( dt1, toConsole, token); + destination.ProcessPipelineData(dt1, toConsole, token); destination.Dispose(toConsole, null); //table should exist Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); //should have 2 rows - Assert.AreEqual(sendTheZero?2:1, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); + Assert.AreEqual(sendTheZero ? 2 : 1, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); //should be decimal - Assert.AreEqual(sendTheZero ?"decimal(19,18)":"decimal(18,18)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); + Assert.AreEqual(sendTheZero ? "decimal(19,18)" : "decimal(18,18)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void TestResizing(DatabaseType dbType) { var db = GetCleanedServer(dbType); @@ -562,12 +584,12 @@ public void TestResizing(DatabaseType dbType) var table = db.CreateTable("TestResizing", new DatabaseColumnRequest[] { - new DatabaseColumnRequest("MyInteger",new DatabaseTypeRequest(typeof(int))), - new DatabaseColumnRequest("MyMaxString",new DatabaseTypeRequest(typeof(string),int.MaxValue)), - new DatabaseColumnRequest("Description",new DatabaseTypeRequest(typeof(string),int.MaxValue)), - new DatabaseColumnRequest("StringNotNull",new DatabaseTypeRequest(typeof(string),100),false), - new DatabaseColumnRequest("StringAllowNull",new DatabaseTypeRequest(typeof(string),100),true), - new DatabaseColumnRequest("StringPk",new DatabaseTypeRequest(typeof(string),50),true){IsPrimaryKey = true } + new("MyInteger", new DatabaseTypeRequest(typeof(int))), + new("MyMaxString", new DatabaseTypeRequest(typeof(string), int.MaxValue)), + new("Description", new DatabaseTypeRequest(typeof(string), int.MaxValue)), + new("StringNotNull", new DatabaseTypeRequest(typeof(string), 100), false), + new("StringAllowNull", new DatabaseTypeRequest(typeof(string), 100), true), + new("StringPk", new DatabaseTypeRequest(typeof(string), 50), true) { IsPrimaryKey = true } }); using (var con = server.GetConnection()) @@ -595,7 +617,7 @@ public void TestResizing(DatabaseType dbType) Assert.AreEqual(true, table.DiscoverColumn("StringAllowNull").AllowNulls); //we should have correct understanding prior to resize - AssertIsStringWithLength(table.DiscoverColumn("StringPk"),50); + AssertIsStringWithLength(table.DiscoverColumn("StringPk"), 50); Assert.AreEqual(true, table.DiscoverColumn("StringPk").IsPrimaryKey); Assert.AreEqual(false, table.DiscoverColumn("StringPk").AllowNulls); @@ -617,21 +639,21 @@ private static void AssertIsStringWithLength(DiscoveredColumn col, int expectedL { case DatabaseType.MicrosoftSQLServer: case DatabaseType.MySql: - Assert.AreEqual($"varchar({expectedLength})",col.DataType.SQLType); + Assert.AreEqual($"varchar({expectedLength})", col.DataType.SQLType); break; case DatabaseType.Oracle: - Assert.AreEqual($"varchar2({expectedLength})",col.DataType.SQLType); + Assert.AreEqual($"varchar2({expectedLength})", col.DataType.SQLType); break; case DatabaseType.PostgreSql: - Assert.AreEqual($"character varying({expectedLength})",col.DataType.SQLType); + Assert.AreEqual($"character varying({expectedLength})", col.DataType.SQLType); break; default: - throw new ArgumentOutOfRangeException(nameof(col.Table.Database.Server.DatabaseType), col.Table.Database.Server.DatabaseType, null); + throw new ArgumentOutOfRangeException(nameof(col.Table.Database.Server.DatabaseType), + col.Table.Database.Server.DatabaseType, null); } - } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void TestResizing_WithDetection(DatabaseType dbType) { var db = GetCleanedServer(dbType); @@ -639,12 +661,12 @@ public void TestResizing_WithDetection(DatabaseType dbType) var table = db.CreateTable("TestResizing", new DatabaseColumnRequest[] { - new DatabaseColumnRequest("MyInteger",new DatabaseTypeRequest(typeof(int))), - new DatabaseColumnRequest("MyMaxString",new DatabaseTypeRequest(typeof(string),int.MaxValue)), - new DatabaseColumnRequest("Description",new DatabaseTypeRequest(typeof(string),int.MaxValue)), - new DatabaseColumnRequest("StringNotNull",new DatabaseTypeRequest(typeof(string),10),false), - new DatabaseColumnRequest("StringAllowNull",new DatabaseTypeRequest(typeof(string),100),true), - new DatabaseColumnRequest("StringPk",new DatabaseTypeRequest(typeof(string),50),true){IsPrimaryKey = true } + new("MyInteger", new DatabaseTypeRequest(typeof(int))), + new("MyMaxString", new DatabaseTypeRequest(typeof(string), int.MaxValue)), + new("Description", new DatabaseTypeRequest(typeof(string), int.MaxValue)), + new("StringNotNull", new DatabaseTypeRequest(typeof(string), 10), false), + new("StringAllowNull", new DatabaseTypeRequest(typeof(string), 100), true), + new("StringPk", new DatabaseTypeRequest(typeof(string), 50), true) { IsPrimaryKey = true } }); Assert.AreEqual(10, table.DiscoverColumn("StringNotNull").DataType.GetLengthIfString()); @@ -657,45 +679,45 @@ public void TestResizing_WithDetection(DatabaseType dbType) dt.Columns.Add("StringAllowNull"); dt.Columns.Add("StringPk"); - dt.Rows.Add("1", //MyInteger - "fff", //MyMaxString - "fff2", //Description - "1234567891011",//StringNotNull - too long for the column, so it should resize - DBNull.Value, //StringAllowNull - "f" //StringPk + dt.Rows.Add("1", //MyInteger + "fff", //MyMaxString + "fff2", //Description + "1234567891011", //StringNotNull - too long for the column, so it should resize + DBNull.Value, //StringAllowNull + "f" //StringPk ); var dt2 = dt.Clone(); dt2.Rows.Clear(); - dt2.Rows.Add("1", //MyInteger - "fff", //MyMaxString - "fff2", //Description - "12345678910112",//StringNotNull - too long for the column, so it should resize - DBNull.Value, //StringAllowNull - "f2" //StringPk + dt2.Rows.Add("1", //MyInteger + "fff", //MyMaxString + "fff2", //Description + "12345678910112", //StringNotNull - too long for the column, so it should resize + DBNull.Value, //StringAllowNull + "f2" //StringPk ); var dest = new DataTableUploadDestination { AllowResizingColumnsAtUploadTime = true }; - dest.PreInitialize(db,new ThrowImmediatelyDataLoadEventListener()); + dest.PreInitialize(db, new ThrowImmediatelyDataLoadEventListener()); - dest.ProcessPipelineData(dt,new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + dest.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); dest.ProcessPipelineData(dt2, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - dest.Dispose(new ThrowImmediatelyDataLoadEventListener(),null); + dest.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); //it should have resized us. Assert.AreEqual(14, table.DiscoverColumn("StringNotNull").DataType.GetLengthIfString()); - } + [TestCase(DatabaseType.MicrosoftSQLServer, "didn�t")] [TestCase(DatabaseType.MySql, "didn�t")] [TestCase(DatabaseType.Oracle, "didn�t")] [TestCase(DatabaseType.MicrosoftSQLServer, "didn't")] [TestCase(DatabaseType.MySql, "didn't")] [TestCase(DatabaseType.Oracle, "didn't")] - public void Test_SingleQuote_InText(DatabaseType dbType,string testValue) + public void Test_SingleQuote_InText(DatabaseType dbType, string testValue) { var db = GetCleanedServer(dbType); @@ -713,7 +735,7 @@ public void Test_SingleQuote_InText(DatabaseType dbType,string testValue) var tbl = db.ExpectTable("TestFreeText"); Assert.IsTrue(tbl.Exists()); - Assert.AreEqual(1,tbl.GetRowCount()); + Assert.AreEqual(1, tbl.GetRowCount()); } [Test] @@ -734,7 +756,7 @@ public void DodgyTypes() dt1.Columns.Add("col4", typeof(byte)); dt1.Columns.Add("col5", typeof(byte[])); - dt1.Rows.Add(new object[] { 0.425,0.451,true,(byte)2,new byte[]{0x5,0xA}}); + dt1.Rows.Add(new object[] { 0.425, 0.451, true, (byte)2, new byte[] { 0x5, 0xA } }); dt1.TableName = "DataTableUploadDestinationTests"; @@ -749,12 +771,17 @@ public void DodgyTypes() Assert.AreEqual(1, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); //should be decimal - Assert.AreEqual("decimal(3,3)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col1").DataType.SQLType); - Assert.AreEqual("decimal(3,3)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col2").DataType.SQLType); - Assert.AreEqual("bit", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col3").DataType.SQLType); - Assert.AreEqual("tinyint", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col4").DataType.SQLType); - - Assert.AreEqual("varbinary(max)", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col5").DataType.SQLType); + Assert.AreEqual("decimal(3,3)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col1").DataType.SQLType); + Assert.AreEqual("decimal(3,3)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col2").DataType.SQLType); + Assert.AreEqual("bit", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col3").DataType.SQLType); + Assert.AreEqual("tinyint", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col4").DataType.SQLType); + + Assert.AreEqual("varbinary(max)", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("col5").DataType.SQLType); } @@ -783,12 +810,14 @@ public void TypeAlteringlResizing() destination.ProcessPipelineData(dt1, toConsole, token); destination.ProcessPipelineData(dt2, toMemory, token); - Assert.IsTrue(toMemory.EventsReceivedBySender[destination].Any(msg => msg.Message.Contains("Resizing column 'mynum' from 'bit' to 'int'"))); + Assert.IsTrue(toMemory.EventsReceivedBySender[destination] + .Any(msg => msg.Message.Contains("Resizing column 'mynum' from 'bit' to 'int'"))); destination.Dispose(toConsole, null); Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); Assert.AreEqual(2, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); - Assert.AreEqual("int", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); + Assert.AreEqual("int", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("mynum").DataType.SQLType); } [Test] @@ -807,16 +836,16 @@ public void MySqlTest_Simple() var dt = new DataTable(); dt.Columns.Add("mystringcol", typeof(string)); dt.Columns.Add("mynum", typeof(string)); - dt.Columns.Add("mydate", typeof (string)); + dt.Columns.Add("mydate", typeof(string)); dt.Columns.Add("myLegitDateTime", typeof(DateTime)); dt.Columns.Add("mynullcol", typeof(string)); //drop the millisecond part var now = DateTime.Now; - now = new DateTime(now.Year,now.Month,now.Day,now.Hour,now.Minute,now.Second); + now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); - dt.Rows.Add(new object[] { "Anhoy there \"mates\"", "999", "2001-01-01", now,null}); + dt.Rows.Add(new object[] { "Anhoy there \"mates\"", "999", "2001-01-01", now, null }); dt.TableName = "DataTableUploadDestinationTests"; destination.ProcessPipelineData(dt, toConsole, token); @@ -834,8 +863,8 @@ public void MySqlTest_Simple() Assert.IsTrue(r.Read()); Assert.AreEqual("Anhoy there \"mates\"", (string)r["mystringcol"]); - Assert.AreEqual(999,(int)r["mynum"]); - Assert.AreEqual(new DateTime(2001,1,1),(DateTime)r["mydate"]); + Assert.AreEqual(999, (int)r["mynum"]); + Assert.AreEqual(new DateTime(2001, 1, 1), (DateTime)r["mydate"]); Assert.AreEqual(now, (DateTime)r["myLegitDateTime"]); Assert.AreEqual(DBNull.Value, r["mynullcol"]); } @@ -884,7 +913,7 @@ public void MySqlTest_Resize() //technically these can come out in a random order var numbersRead = new List(); Assert.IsTrue(r.Read()); - numbersRead.Add((int) r["mynum"]); + numbersRead.Add((int)r["mynum"]); Assert.IsTrue(r.Read()); numbersRead.Add((int)r["mynum"]); @@ -900,18 +929,21 @@ public void TestDestinationAlreadyExistingIsOk(bool targetTableIsEmpty) { //create a table in the scratch database with a single column Name var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); - var tbl = db.CreateTable("TestDestinationAlreadyExistingIsOk",new[]{new DatabaseColumnRequest("Name","varchar(10)",false)}); + var tbl = db.CreateTable("TestDestinationAlreadyExistingIsOk", + new[] { new DatabaseColumnRequest("Name", "varchar(10)", false) }); try { - if(!targetTableIsEmpty) + if (!targetTableIsEmpty) { //upload a single row var dtAlreadyThereData = new DataTable(); dtAlreadyThereData.Columns.Add("Name"); - dtAlreadyThereData.Rows.Add(new[] {"Bob"}); + dtAlreadyThereData.Rows.Add(new[] { "Bob" }); - using(var bulk = tbl.BeginBulkInsert()) + using (var bulk = tbl.BeginBulkInsert()) + { bulk.Upload(dtAlreadyThereData); + } } //create the destination component (what we want to test) @@ -924,20 +956,20 @@ public void TestDestinationAlreadyExistingIsOk(bool targetTableIsEmpty) //create the simulated chunk that will be dispatched var dt = new DataTable("TestDestinationAlreadyExistingIsOk"); dt.Columns.Add("Name"); - dt.Rows.Add(new[] {"Bob"}); + dt.Rows.Add(new[] { "Bob" }); dt.Rows.Add(new[] { "Frank" }); dt.Rows.Add(new[] { "I've got a lovely bunch of coconuts" }); var listener = new ThrowImmediatelyDataLoadEventListener(); //pre initialzie with the database (which must be part of any pipeline use case involving a DataTableUploadDestination) - destinationComponent.PreInitialize(db ,listener); + destinationComponent.PreInitialize(db, listener); //tell the destination component to process the data - destinationComponent.ProcessPipelineData(dt, listener,new GracefulCancellationToken()); + destinationComponent.ProcessPipelineData(dt, listener, new GracefulCancellationToken()); - destinationComponent.Dispose(listener,null); - Assert.AreEqual(targetTableIsEmpty?3:4, tbl.GetRowCount()); + destinationComponent.Dispose(listener, null); + Assert.AreEqual(targetTableIsEmpty ? 3 : 4, tbl.GetRowCount()); } finally { @@ -956,7 +988,7 @@ public void DataTableUploadDestinationTests_PrimaryKeyDataTableWithAlterSizeLate AllowResizingColumnsAtUploadTime = true }; - destination.PreInitialize(db,new ThrowImmediatelyDataLoadEventListener()); + destination.PreInitialize(db, new ThrowImmediatelyDataLoadEventListener()); var dt1 = new DataTable { @@ -967,7 +999,8 @@ public void DataTableUploadDestinationTests_PrimaryKeyDataTableWithAlterSizeLate dt1.PrimaryKey = dt1.Columns.Cast().ToArray(); - destination.ProcessPipelineData(dt1, new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + destination.ProcessPipelineData(dt1, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); var dt2 = new DataTable { @@ -978,17 +1011,16 @@ public void DataTableUploadDestinationTests_PrimaryKeyDataTableWithAlterSizeLate dt2.PrimaryKey = dt2.Columns.Cast().ToArray(); - destination.ProcessPipelineData(dt2, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + destination.ProcessPipelineData(dt2, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); - destination.Dispose(new ThrowImmediatelyDataLoadEventListener(),null); + destination.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); var tbl = db.ExpectTable("MyTable"); - Assert.AreEqual(2,tbl.GetRowCount()); + Assert.AreEqual(2, tbl.GetRowCount()); Assert.IsTrue(tbl.DiscoverColumns().Single().IsPrimaryKey); - - } [Test] @@ -999,22 +1031,22 @@ public void TestDestinationAlreadyExisting_ColumnSubset() var tbl = db.CreateTable("TestDestinationAlreadyExisting_ColumnSubset", new[] { new DatabaseColumnRequest("Name", "varchar(10)", false), - new DatabaseColumnRequest("Age","int"), - new DatabaseColumnRequest("Address","varchar(1000)") - + new DatabaseColumnRequest("Age", "int"), + new DatabaseColumnRequest("Address", "varchar(1000)") }); try { - //upload a single row of already existing data var dtAlreadyThereData = new DataTable(); dtAlreadyThereData.Columns.Add("Name"); dtAlreadyThereData.Columns.Add("Age"); - dtAlreadyThereData.Rows.Add(new object[] { "Bob",5}); + dtAlreadyThereData.Rows.Add(new object[] { "Bob", 5 }); using (var bulk = tbl.BeginBulkInsert()) + { bulk.Upload(dtAlreadyThereData); + } //create the destination component (what we want to test) var destinationComponent = new DataTableUploadDestination @@ -1047,7 +1079,7 @@ public void TestDestinationAlreadyExisting_ColumnSubset() } } - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void Test_DataTableUploadDestination_ScientificNotation(DatabaseType dbType) { var db = GetCleanedServer(dbType); @@ -1057,26 +1089,25 @@ public void Test_DataTableUploadDestination_ScientificNotation(DatabaseType dbTy dt.Rows.Add("-4.10235746055587E-05"); //this string is untyped var dest = new DataTableUploadDestination(); - dest.PreInitialize(db,new ThrowImmediatelyDataLoadEventListener()); + dest.PreInitialize(db, new ThrowImmediatelyDataLoadEventListener()); try { - dest.ProcessPipelineData(dt,new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + dest.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); dest.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); } - catch(Exception ex) + catch (Exception ex) { - dest.Dispose(new ThrowImmediatelyDataLoadEventListener(),ex); + dest.Dispose(new ThrowImmediatelyDataLoadEventListener(), ex); throw; } //in the database it should be typed - Assert.AreEqual(typeof(decimal),db.ExpectTable("ff").DiscoverColumn("mycol").DataType.GetCSharpDataType()); + Assert.AreEqual(typeof(decimal), db.ExpectTable("ff").DiscoverColumn("mycol").DataType.GetCSharpDataType()); var dt2 = db.ExpectTable("ff").GetDataTable(); - Assert.IsTrue((decimal)dt2.Rows[0][0] == (decimal)-0.0000410235746055587); - + Assert.IsTrue((decimal)dt2.Rows[0][0] == (decimal)-0.0000410235746055587); } private class AdjustColumnDelegater : IDatabaseColumnRequestAdjuster @@ -1094,7 +1125,7 @@ public void AdjustColumns(List columns) /// as boolean instead /// /// - [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] + [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] public void Test_DataTableUploadDestination_ForceBool(DatabaseType dbType) { var db = GetCleanedServer(dbType); @@ -1140,8 +1171,8 @@ public void Test_DataTableUploadDestination_ForceBool(DatabaseType dbType) Assert.AreEqual(typeof(string), tbl.DiscoverColumn("hb_extract").DataType.GetCSharpDataType()); var dt2 = tbl.GetDataTable(); - Assert.Contains("T",dt2.Rows.Cast().Select(r=>r[0]).ToArray()); - Assert.Contains("F",dt2.Rows.Cast().Select(r =>r[0]).ToArray()); + Assert.Contains("T", dt2.Rows.Cast().Select(r => r[0]).ToArray()); + Assert.Contains("F", dt2.Rows.Cast().Select(r => r[0]).ToArray()); } else { @@ -1149,12 +1180,13 @@ public void Test_DataTableUploadDestination_ForceBool(DatabaseType dbType) Assert.AreEqual(typeof(bool), tbl.DiscoverColumn("hb_extract").DataType.GetCSharpDataType()); var dt2 = tbl.GetDataTable(); - Assert.Contains(true,dt2.Rows.Cast().Select(r=>r[0]).ToArray()); - Assert.Contains(false,dt2.Rows.Cast().Select(r =>r[0]).ToArray()); + Assert.Contains(true, dt2.Rows.Cast().Select(r => r[0]).ToArray()); + Assert.Contains(false, dt2.Rows.Cast().Select(r => r[0]).ToArray()); } } #region Two Batch Tests + [TestCase(DatabaseType.MySql, true)] [TestCase(DatabaseType.MySql, false)] [TestCase(DatabaseType.MicrosoftSQLServer, true)] @@ -1187,11 +1219,13 @@ public void TwoBatch_BooleanResizingTest(DatabaseType dbType, bool giveNullValue destination.ProcessPipelineData(dt1, toConsole, token); - Assert.AreEqual("bit", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("TestedCol").DataType.SQLType); + Assert.AreEqual("bit", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("TestedCol").DataType.SQLType); destination.ProcessPipelineData(dt2, toMemory, token); - Assert.IsTrue(toMemory.EventsReceivedBySender[destination].Any(msg => msg.Message.Contains("Resizing column "))); + Assert.IsTrue(toMemory.EventsReceivedBySender[destination] + .Any(msg => msg.Message.Contains("Resizing column "))); destination.Dispose(toConsole, null); Assert.IsTrue(db.ExpectTable("DataTableUploadDestinationTests").Exists()); @@ -1200,11 +1234,10 @@ public void TwoBatch_BooleanResizingTest(DatabaseType dbType, bool giveNullValue var tt = db.Server.GetQuerySyntaxHelper().TypeTranslater; Assert.AreEqual( - //if all we got are nulls we should have a DateTime otherwise we had 1/true so the only usable data type is string giveNullValuesOnly ? typeof(DateTime) : typeof(string), - - tt.GetCSharpTypeForSQLDBType(db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("TestedCol").DataType.SQLType)); + tt.GetCSharpTypeForSQLDBType(db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("TestedCol") + .DataType.SQLType)); } /// @@ -1218,16 +1251,18 @@ public void TwoBatch_BooleanResizingTest(DatabaseType dbType, bool giveNullValue /// The row value to send in batch 2 (after table creation) /// The Type you expect to be used to store the v1 /// The Type you expect after ALTER to support all values seen SetUp till now (i.e. v1) AND v2 - [TestCase(DatabaseType.MySql,null,"235", typeof(bool),typeof(int))] - [TestCase(DatabaseType.MySql, "123", "2001-01-01 12:00:00" ,typeof(int), typeof(string))] //123 cannot be converted to date so it becomes string - [TestCase(DatabaseType.MySql, "2001-01-01", "2001-01-01 12:00:00" , typeof(DateTime), typeof(DateTime) )] + [TestCase(DatabaseType.MySql, null, "235", typeof(bool), typeof(int))] + [TestCase(DatabaseType.MySql, "123", "2001-01-01 12:00:00", typeof(int), + typeof(string))] //123 cannot be converted to date so it becomes string + [TestCase(DatabaseType.MySql, "2001-01-01", "2001-01-01 12:00:00", typeof(DateTime), typeof(DateTime))] [TestCase(DatabaseType.MySql, "2001-01-01", "omg", typeof(DateTime), typeof(string))] - [TestCase(DatabaseType.MicrosoftSQLServer, null, "235", typeof(bool), typeof(int))] - [TestCase(DatabaseType.MicrosoftSQLServer, "123", "2001-01-01 12:00:00", typeof(int), typeof(string))] //123 cannot be converted to date so it becomes string + [TestCase(DatabaseType.MicrosoftSQLServer, "123", "2001-01-01 12:00:00", typeof(int), + typeof(string))] //123 cannot be converted to date so it becomes string [TestCase(DatabaseType.MicrosoftSQLServer, "2001-01-01", "2001-01-01 12:00:00", typeof(DateTime), typeof(DateTime))] [TestCase(DatabaseType.MicrosoftSQLServer, "2001-01-01", "omg", typeof(DateTime), typeof(string))] - public void TwoBatch_MiscellaneousTest(DatabaseType dbType, string v1,string v2,Type expectedTypeForBatch1,Type expectedTypeForBatch2) + public void TwoBatch_MiscellaneousTest(DatabaseType dbType, string v1, string v2, Type expectedTypeForBatch1, + Type expectedTypeForBatch2) { var token = new GracefulCancellationToken(); var db = GetCleanedServer(dbType); @@ -1265,7 +1300,7 @@ public void TwoBatch_MiscellaneousTest(DatabaseType dbType, string v1,string v2, destination.ProcessPipelineData(dt2, toMemory, token); destination.Dispose(toConsole, null); } - catch(Exception ex) + catch (Exception ex) { destination.Dispose(toConsole, ex); throw; @@ -1276,7 +1311,7 @@ public void TwoBatch_MiscellaneousTest(DatabaseType dbType, string v1,string v2, var colAfter = tbl.DiscoverColumn("TestedCol"); - Assert.AreEqual(v1 != null && v2 != null,colAfter.IsPrimaryKey); + Assert.AreEqual(v1 != null && v2 != null, colAfter.IsPrimaryKey); Assert.AreEqual(expectedTypeForBatch2, tt.GetCSharpTypeForSQLDBType(colAfter.DataType.SQLType)); } @@ -1293,7 +1328,7 @@ public void TwoBatch_ExplicitRealDataType() var destination = new DataTableUploadDestination(); destination.PreInitialize(db, toConsole); destination.AllowResizingColumnsAtUploadTime = true; - destination.AddExplicitWriteType("FloatCol","real"); + destination.AddExplicitWriteType("FloatCol", "real"); var dt1 = new DataTable(); dt1.Columns.Add("FloatCol", typeof(string)); @@ -1309,7 +1344,8 @@ public void TwoBatch_ExplicitRealDataType() destination.ProcessPipelineData(dt1, toConsole, token); - Assert.AreEqual("real", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("FloatCol").DataType.SQLType); + Assert.AreEqual("real", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("FloatCol").DataType.SQLType); destination.ProcessPipelineData(dt2, toMemory, token); @@ -1319,8 +1355,9 @@ public void TwoBatch_ExplicitRealDataType() Assert.AreEqual(2, db.ExpectTable("DataTableUploadDestinationTests").GetRowCount()); // should still be real - Assert.AreEqual("real", db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("FloatCol").DataType.SQLType); - + Assert.AreEqual("real", + db.ExpectTable("DataTableUploadDestinationTests").DiscoverColumn("FloatCol").DataType.SQLType); } + #endregion } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DatabaseOperationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DatabaseOperationTests.cs index 31c352f7b7..06f850de31 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DatabaseOperationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DatabaseOperationTests.cs @@ -35,7 +35,7 @@ public void CloneDatabaseAndTable() var testDb = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(testLiveDatabaseName); var raw = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase($"{testLiveDatabaseName}_RAW"); - foreach (var db in new[] { raw ,testDb}) + foreach (var db in new[] { raw, testDb }) if (db.Exists()) { foreach (var table in db.DiscoverTables(true)) @@ -43,20 +43,22 @@ public void CloneDatabaseAndTable() db.Drop(); } - + DiscoveredServerICanCreateRandomDatabasesAndTablesOn.CreateDatabase(testLiveDatabaseName); Assert.IsTrue(testDb.Exists()); - testDb.CreateTable("Table_1", new[] {new DatabaseColumnRequest("Id", "int")}); + testDb.CreateTable("Table_1", new[] { new DatabaseColumnRequest("Id", "int") }); //clone the builder - var builder = new SqlConnectionStringBuilder(DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Builder.ConnectionString) - { - InitialCatalog = testLiveDatabaseName - }; + var builder = + new SqlConnectionStringBuilder( + DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Builder.ConnectionString) + { + InitialCatalog = testLiveDatabaseName + }; - var dbConfiguration = new HICDatabaseConfiguration(new DiscoveredServer(builder),null,CatalogueRepository); + var dbConfiguration = new HICDatabaseConfiguration(new DiscoveredServer(builder), null, CatalogueRepository); var cloner = new DatabaseCloner(dbConfiguration); try @@ -68,15 +70,15 @@ public void CloneDatabaseAndTable() $"{testLiveDatabaseName}_RAW").Exists()); //now create a catalogue and wire it SetUp to the table TEST on the test database server - var cata = SetupATestCatalogue(builder, testLiveDatabaseName, "Table_1"); + var cata = SetupATestCatalogue(builder, testLiveDatabaseName, "Table_1"); //now clone the catalogue data structures to MachineName foreach (TableInfo tableInfo in cata.GetTableInfoList(false)) - cloner.CreateTablesInDatabaseFromCatalogueInfo(new ThrowImmediatelyDataLoadEventListener(), tableInfo, LoadBubble.Raw); - + cloner.CreateTablesInDatabaseFromCatalogueInfo(new ThrowImmediatelyDataLoadEventListener(), tableInfo, + LoadBubble.Raw); + Assert.IsTrue(raw.Exists()); Assert.IsTrue(raw.ExpectTable("Table_1").Exists()); - } finally { @@ -99,7 +101,8 @@ private Catalogue SetupATestCatalogue(SqlConnectionStringBuilder builder, string { //create a new catalogue for test data (in the test data catalogue) var cat = new Catalogue(CatalogueRepository, "DeleteMe"); - var importer = new TableInfoImporter(CatalogueRepository, builder.DataSource, database, table, DatabaseType.MicrosoftSQLServer, builder.UserID, builder.Password); + var importer = new TableInfoImporter(CatalogueRepository, builder.DataSource, database, table, + DatabaseType.MicrosoftSQLServer, builder.UserID, builder.Password); importer.DoImport(out var tableInfo, out var columnInfos); toCleanUp.Push(cat); @@ -108,15 +111,16 @@ private Catalogue SetupATestCatalogue(SqlConnectionStringBuilder builder, string var creds = (DataAccessCredentials)tableInfo.GetCredentialsIfExists(DataAccessContext.InternalDataProcessing); if (creds != null) toCleanUp.Push(creds); - + //and the TableInfo toCleanUp.Push(tableInfo); - + //for each column we will add a new one to the foreach (var col in columnInfos) { //create it with the same name - var cataItem = new CatalogueItem(CatalogueRepository, cat, col.Name[(col.Name.LastIndexOf(".") + 1)..].Trim('[', ']', '`')); + var cataItem = new CatalogueItem(CatalogueRepository, cat, + col.Name[(col.Name.LastIndexOf(".") + 1)..].Trim('[', ']', '`')); toCleanUp.Push(cataItem); cataItem.SetColumnInfo(col); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionCheckTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionCheckTests.cs index 166f489305..d55cacbff6 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionCheckTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionCheckTests.cs @@ -43,7 +43,7 @@ public void TestChecking_RoundDateToMiddleOfQuarter_WrongDataType(string incompa [TestCase("datetime")] public void TestChecking_RoundDateToMiddleOfQuarter_CompatibleDataType(string incompatibleType) { - var col = Mock.Of(p => p.SqlDataType==incompatibleType); + var col = Mock.Of(p => p.SqlDataType == incompatibleType); var dil = new RoundDateToMiddleOfQuarter { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationFactoryTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationFactoryTests.cs index 224a56585b..91a12f03af 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationFactoryTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationFactoryTests.cs @@ -27,25 +27,25 @@ public void NullColumn_Throws() [Test] public void NullOperation_Throws() { - var col = Mock.Of(p => p.Repository==CatalogueRepository); + var col = Mock.Of(p => p.Repository == CatalogueRepository); var factory = new DilutionOperationFactory(col); - Assert.Throws(()=>factory.Create(null)); + Assert.Throws(() => factory.Create(null)); } [Test] public void UnexpectedType_Throws() { - var col = Mock.Of(p => p.Repository==CatalogueRepository); + var col = Mock.Of(p => p.Repository == CatalogueRepository); var factory = new DilutionOperationFactory(col); - Assert.Throws(()=>factory.Create(typeof(Catalogue))); + Assert.Throws(() => factory.Create(typeof(Catalogue))); } [Test] public void ExpectedType_Created() { - var col = Mock.Of(p => p.Repository==CatalogueRepository); + var col = Mock.Of(p => p.Repository == CatalogueRepository); var factory = new DilutionOperationFactory(col); var i = factory.Create(typeof(ExcludeRight3OfUKPostcodes)); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationTests.cs index f30333ac7b..fed562622c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DilutionTests/DilutionOperationTests.cs @@ -21,7 +21,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.DilutionTests; -public class DilutionOperationTests:DatabaseTests +public class DilutionOperationTests : DatabaseTests { [TestCase("2001-01-03", "2001-02-15")] [TestCase("2001-03-31", "2001-02-15")] @@ -31,10 +31,8 @@ public class DilutionOperationTests:DatabaseTests [TestCase(null, null)] public void TestRoundDateToMiddleOfQuarter(string input, string expectedDilute) { - - - var tbl = Mock.Of(m => m.GetRuntimeName(LoadStage.AdjustStaging,null) == "DateRoundingTests"); - var col = Mock.Of(c=> + var tbl = Mock.Of(m => m.GetRuntimeName(LoadStage.AdjustStaging, null) == "DateRoundingTests"); + var col = Mock.Of(c => c.TableInfo == tbl && c.GetRuntimeName() == "TestField"); @@ -63,7 +61,7 @@ public void TestRoundDateToMiddleOfQuarter(string input, string expectedDilute) else Assert.AreEqual(DateTime.Parse(expectedDilute), result); } - finally + finally { con.ManagedTransaction.AbandonAndCloseConnection(); } @@ -81,17 +79,23 @@ public void TestRoundDateToMiddleOfQuarter(string input, string expectedDilute) [TestCase("!D!D!3!9TA!", "DD3")] //Random garbage [TestCase("EC4V_2AU", "EC4V")] //underscore instead of space [TestCase("EC4V2AU ", "EC4V")] //Trailing whitespace - [TestCase("??", "??")] //It's short and it's complete garbage but this is the kind of thing research datasets have :) - [TestCase("???????", "????")] //Return type is varchar(4) so while we reject the original value we still end SetUp truncating it + [TestCase("??", + "??")] //It's short and it's complete garbage but this is the kind of thing research datasets have :) + [TestCase("???????", + "????")] //Return type is varchar(4) so while we reject the original value we still end SetUp truncating it [TestCase("I<3Coffee Yay", "I3Co")] //What can you do?!, got to return varchar(4) - [TestCase("D3 9T", "D39T")]//39T isn't a valid suffix and the remainder (D) wouldn't be enough for a postcode prefix anyway so just return the original input minus dodgy characters - [TestCase("G 9TA", "G")]//9TA is the correct suffix pattern (Numeric Alpha Alpha) so can be chopped off and the remainder returned (G) - [TestCase("DD3 9T", "DD")] //Expected to get it wrong because the suffix check sees 39T but the remainder is long enough to make a legit postcode (2). We are currently deciding not to evaluate spaces/other dodgy characters when attempting to resolve postcodes - [TestCase(null,null)] + [TestCase("D3 9T", + "D39T")] //39T isn't a valid suffix and the remainder (D) wouldn't be enough for a postcode prefix anyway so just return the original input minus dodgy characters + [TestCase("G 9TA", + "G")] //9TA is the correct suffix pattern (Numeric Alpha Alpha) so can be chopped off and the remainder returned (G) + [TestCase("DD3 9T", + "DD")] //Expected to get it wrong because the suffix check sees 39T but the remainder is long enough to make a legit postcode (2). We are currently deciding not to evaluate spaces/other dodgy characters when attempting to resolve postcodes + [TestCase(null, null)] public void TestExcludeRight3OfUKPostcodes(string input, string expectedDilute) { - var tbl = Mock.Of(t=>t.GetRuntimeName(LoadStage.AdjustStaging,null) == "ExcludeRight3OfPostcodes"); - var col = Mock.Of(c=>c.TableInfo == tbl && c.GetRuntimeName() == "TestField"); + var tbl = Mock.Of( + t => t.GetRuntimeName(LoadStage.AdjustStaging, null) == "ExcludeRight3OfPostcodes"); + var col = Mock.Of(c => c.TableInfo == tbl && c.GetRuntimeName() == "TestField"); var o = new ExcludeRight3OfUKPostcodes { @@ -112,8 +116,8 @@ public void TestExcludeRight3OfUKPostcodes(string input, string expectedDilute) UsefulStuff.ExecuteBatchNonQuery(sql, con.Connection, con.Transaction); var result = server.GetCommand("SELECT * from ExcludeRight3OfPostcodes", con).ExecuteScalar(); - - if(expectedDilute == null) + + if (expectedDilute == null) Assert.AreEqual(DBNull.Value, result); else Assert.AreEqual(expectedDilute, result); @@ -122,23 +126,22 @@ public void TestExcludeRight3OfUKPostcodes(string input, string expectedDilute) { con.ManagedTransaction.AbandonAndCloseConnection(); } - } } - [TestCase("2001-01-03","datetime", true)] + [TestCase("2001-01-03", "datetime", true)] [TestCase("2001-01-03", "varchar(50)", true)] - [TestCase(null,"varchar(50)", false)] + [TestCase(null, "varchar(50)", false)] [TestCase(null, "bit", false)] [TestCase("1", "bit", true)] [TestCase("0", "bit", true)] - [TestCase("","varchar(1)", true)]//This data exists regardless of if it is blank so it still gets the 1 - public void DiluteToBitFlag(string input,string inputDataType, bool expectedDilute) + [TestCase("", "varchar(1)", true)] //This data exists regardless of if it is blank so it still gets the 1 + public void DiluteToBitFlag(string input, string inputDataType, bool expectedDilute) { - var tbl = Mock.Of(m => m.GetRuntimeName(LoadStage.AdjustStaging,null) == "DiluteToBitFlagTests"); - var col = Mock.Of(c=> - c.TableInfo == tbl && - c.GetRuntimeName() =="TestField"); + var tbl = Mock.Of(m => m.GetRuntimeName(LoadStage.AdjustStaging, null) == "DiluteToBitFlagTests"); + var col = Mock.Of(c => + c.TableInfo == tbl && + c.GetRuntimeName() == "TestField"); var o = new CrushToBitFlag { @@ -159,7 +162,7 @@ public void DiluteToBitFlag(string input,string inputDataType, bool expectedDilu UsefulStuff.ExecuteBatchNonQuery(sql, con.Connection, con.Transaction); var result = server.GetCommand("SELECT * from DiluteToBitFlagTests", con).ExecuteScalar(); - + Assert.AreEqual(expectedDilute, Convert.ToBoolean(result)); } finally @@ -168,7 +171,7 @@ public void DiluteToBitFlag(string input,string inputDataType, bool expectedDilu } } } - + [Test] public void Dilution_WithNamer_Test() { @@ -176,10 +179,10 @@ public void Dilution_WithNamer_Test() var dt = new DataTable(); dt.Columns.Add("Bob"); - dt.Rows.Add(new[] {"Fish"}); + dt.Rows.Add(new[] { "Fish" }); var tbl = db.CreateTable("DilutionNamerTest", dt); - Import(tbl,out var ti, out var cols); + Import(tbl, out var ti, out var cols); tbl.Rename("AAAA"); var namer = RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(db, "AAAA"); @@ -195,14 +198,14 @@ public void Dilution_WithNamer_Test() var dilution = new Dilution { ColumnToDilute = discarded, - Operation = typeof (CrushToBitFlag) + Operation = typeof(CrushToBitFlag) }; - dilution.Initialize(db,LoadStage.AdjustStaging); + dilution.Initialize(db, LoadStage.AdjustStaging); dilution.Check(new ThrowImmediatelyCheckNotifier()); - var job = new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(db.Server,namer),ti); - + var job = new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(db.Server, namer), ti); + dilution.Mutilate(job); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DistincterTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DistincterTests.cs index 2698f3bb90..4e08a6f4bb 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/DistincterTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/DistincterTests.cs @@ -45,7 +45,7 @@ public void TestDistincter_Duplicates(DatabaseType type) for (var i = 0; i < batchCount; i++) { var randInt = r.Next(int.MaxValue); - + dt.Rows.Add(new object[] { randInt, randInt, randInt, randInt, randInt }); dt.Rows.Add(new object[] { randInt, randInt, randInt, randInt, randInt }); } @@ -68,13 +68,15 @@ public void TestDistincter_Duplicates(DatabaseType type) }; distincter.Initialize(db, LoadStage.AdjustRaw); - var job = Mock.Of(p => p.RegularTablesToLoad==new List(new[] { tableInfo })&& p.Configuration==new HICDatabaseConfiguration(db.Server,null,null,null)); + var job = Mock.Of(p => + p.RegularTablesToLoad == new List(new[] { tableInfo }) && + p.Configuration == new HICDatabaseConfiguration(db.Server, null, null, null)); distincter.Mutilate(job); var rowsAfter = tbl.GetRowCount(); - Assert.AreEqual(rowsBefore/2,rowsAfter); + Assert.AreEqual(rowsBefore / 2, rowsAfter); db.Drop(); } @@ -102,7 +104,7 @@ public void TestDistincter_NoDuplicates(DatabaseType type) var randInt = r.Next(int.MaxValue); dt.Rows.Add(new object[] { randInt, randInt, randInt, randInt, randInt }); - dt.Rows.Add(new object[] { randInt, randInt, randInt, randInt, randInt+1 }); + dt.Rows.Add(new object[] { randInt, randInt, randInt, randInt, randInt + 1 }); } var tbl = db.CreateTable(dt.TableName, dt); @@ -123,7 +125,9 @@ public void TestDistincter_NoDuplicates(DatabaseType type) }; distincter.Initialize(db, LoadStage.AdjustRaw); - var job = Mock.Of(p => p.RegularTablesToLoad==new List(new[] { tableInfo }) && p.Configuration==new HICDatabaseConfiguration(db.Server,null,null,null)); + var job = Mock.Of(p => + p.RegularTablesToLoad == new List(new[] { tableInfo }) && + p.Configuration == new HICDatabaseConfiguration(db.Server, null, null, null)); distincter.Mutilate(job); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelConversionTest.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelConversionTest.cs index 912737f52f..09e8eb34bb 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelConversionTest.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelConversionTest.cs @@ -22,7 +22,7 @@ public class ExcelConversionTest { private readonly Stack _dirsToCleanUp = new(); private DirectoryInfo _parentDir; - + [OneTimeSetUp] protected virtual void OneTimeSetUp() { @@ -41,10 +41,10 @@ protected virtual void OneTimeTearDown() dir.Delete(true); } } - + private LoadDirectory CreateLoadDirectoryForTest(string directoryName) { - var loadDirectory = LoadDirectory.CreateDirectoryStructure(_parentDir, directoryName,true); + var loadDirectory = LoadDirectory.CreateDirectoryStructure(_parentDir, directoryName, true); _dirsToCleanUp.Push(loadDirectory.RootPath); return loadDirectory; } @@ -87,12 +87,13 @@ public void TestExcelFunctionality_DodgyFileExtension() fi.CopyTo(targetFile, true); - var ex = Assert.Throws(()=> TestConversionFor(targetFile, "*.fish", 1, LoadDirectory)); + var ex = Assert.Throws(() => TestConversionFor(targetFile, "*.fish", 1, LoadDirectory)); Assert.IsTrue(ex.Message.StartsWith("Did not find any files matching Pattern '*.fish' in directory")); } - - private static void TestConversionFor(string targetFile, string fileExtensionToConvert, int expectedNumberOfSheets, LoadDirectory directory) + + private static void TestConversionFor(string targetFile, string fileExtensionToConvert, int expectedNumberOfSheets, + LoadDirectory directory) { var f = new FileInfo(targetFile); @@ -103,17 +104,18 @@ private static void TestConversionFor(string targetFile, string fileExtensionToC var converter = new ExcelToCSVFilesConverter(); - var job = new ThrowImmediatelyDataLoadJob(new ThrowImmediatelyDataLoadEventListener {ThrowOnWarning = true, WriteToConsole = true}) - { - LoadDirectory = directory - }; + var job = new ThrowImmediatelyDataLoadJob(new ThrowImmediatelyDataLoadEventListener + { ThrowOnWarning = true, WriteToConsole = true }) + { + LoadDirectory = directory + }; converter.ExcelFilePattern = fileExtensionToConvert; converter.Fetch(job, new GracefulCancellationToken()); var filesCreated = directory.ForLoading.GetFiles("*.csv"); - Assert.AreEqual(expectedNumberOfSheets,filesCreated.Length); + Assert.AreEqual(expectedNumberOfSheets, filesCreated.Length); foreach (var fileCreated in filesCreated) { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs index c509233633..1374b12b07 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs @@ -28,10 +28,11 @@ public void TestLoadingFileWithTrailingDotsInHeader() // Create the 'out of the box' RDMP pipelines (which includes an excel bulk importer pipeline) var creator = new CataloguePipelinesAndReferencesCreation( RepositoryLocator, UnitTestLoggingConnectionString, DataQualityEngineConnectionString); - creator.CreatePipelines(); + creator.CreatePipelines(new PlatformDatabaseCreationOptions {}); // find the excel loading pipeline - var pipe = CatalogueRepository.GetAllObjects().OrderByDescending(p => p.ID).FirstOrDefault(p => p.Name.Contains("BULK INSERT: Excel File")); + var pipe = CatalogueRepository.GetAllObjects().OrderByDescending(p => p.ID) + .FirstOrDefault(p => p.Name.Contains("BULK INSERT: Excel File")); // run an import of the file using the pipeline var cmd = new ExecuteCommandCreateNewCatalogueByImportingFile( @@ -46,9 +47,9 @@ public void TestLoadingFileWithTrailingDotsInHeader() var cols = tbl.DiscoverColumns(); Assert.AreEqual(2, cols.Length); - Assert.AreEqual("Field1",cols[0].GetRuntimeName()); + Assert.AreEqual("Field1", cols[0].GetRuntimeName()); Assert.AreEqual("Field2", cols[1].GetRuntimeName()); - + Assert.AreEqual(2, tbl.GetRowCount()); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecutableProcessTaskTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecutableProcessTaskTests.cs index b510be4483..e402a338fb 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecutableProcessTaskTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecutableProcessTaskTests.cs @@ -42,10 +42,11 @@ public void TestConstructionFromProcessTaskUsingDatabase() var runtimeTask = new ExecutableRuntimeTask(processTask, args); Assert.AreEqual(expectedPath, runtimeTask.ExeFilepath); - + Assert.AreEqual(1, runtimeTask.RuntimeArguments.GetAllArgumentsOfType().Count()); - var dictionaryOfStringArguments = runtimeTask.RuntimeArguments.GetAllArgumentsOfType().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + var dictionaryOfStringArguments = runtimeTask.RuntimeArguments.GetAllArgumentsOfType() + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); Assert.IsNotNull(dictionaryOfStringArguments["DatabaseName"]); Assert.AreEqual("Foo_STAGING", dictionaryOfStringArguments["DatabaseName"]); } diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecuteSqlFileRuntimeTaskTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecuteSqlFileRuntimeTaskTests.cs index 6c90857cdb..9d09b90263 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecuteSqlFileRuntimeTaskTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExecuteSqlFileRuntimeTaskTests.cs @@ -27,7 +27,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -internal class ExecuteSqlFileRuntimeTaskTests:DatabaseTests +internal class ExecuteSqlFileRuntimeTaskTests : DatabaseTests { [TestCase(DatabaseType.MySql)] [TestCase(DatabaseType.MicrosoftSQLServer)] @@ -35,21 +35,23 @@ public void ExecuteSqlFileRuntimeTask_BasicScript(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); - dt.Rows.Add(new object []{2}); + dt.Rows.Add(new object[] { 2 }); var db = GetCleanedServer(dbType); - var tbl = db.CreateTable("Fish",dt); + var tbl = db.CreateTable("Fish", dt); - var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"Bob.sql")); + var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bob.sql")); - File.WriteAllText(f.FullName,@"UPDATE Fish Set Lawl = 1"); + File.WriteAllText(f.FullName, @"UPDATE Fish Set Lawl = 1"); - var pt = Mock.Of(x => x.Path==f.FullName); + var pt = Mock.Of(x => x.Path == f.FullName); - var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"ExecuteSqlFileRuntimeTaskTests", true); + var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "ExecuteSqlFileRuntimeTaskTests", true); - var task = new ExecuteSqlFileRuntimeTask(pt, new RuntimeArgumentCollection(Array.Empty(), new StageArgs(LoadStage.AdjustRaw, db, dir))); + var task = new ExecuteSqlFileRuntimeTask(pt, + new RuntimeArgumentCollection(Array.Empty(), new StageArgs(LoadStage.AdjustRaw, db, dir))); task.Check(new ThrowImmediatelyCheckNotifier()); @@ -57,7 +59,7 @@ public void ExecuteSqlFileRuntimeTask_BasicScript(DatabaseType dbType) task.Run(job, new GracefulCancellationToken()); - Assert.AreEqual(1,tbl.GetDataTable().Rows[0][0]); + Assert.AreEqual(1, tbl.GetDataTable().Rows[0][0]); tbl.Drop(); } @@ -74,32 +76,34 @@ public void ExecuteSqlFileRuntimeTask_InvalidID(DatabaseType dbType) var tbl = db.CreateTable("Fish", dt); - Import(tbl,out var ti, out var cols); + Import(tbl, out var ti, out var cols); var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bob.sql")); - - File.WriteAllText(f.FullName, @"UPDATE {T:0} Set {C:0} = 1"); - var pt = Mock.Of(x => x.Path==f.FullName); + File.WriteAllText(f.FullName, @"UPDATE {T:0} Set {C:0} = 1"); - var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"ExecuteSqlFileRuntimeTaskTests", true); + var pt = Mock.Of(x => x.Path == f.FullName); + var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "ExecuteSqlFileRuntimeTaskTests", true); - var task = new ExecuteSqlFileRuntimeTask(pt, new RuntimeArgumentCollection(Array.Empty(), new StageArgs(LoadStage.AdjustRaw, db, dir))); + var task = new ExecuteSqlFileRuntimeTask(pt, + new RuntimeArgumentCollection(Array.Empty(), new StageArgs(LoadStage.AdjustRaw, db, dir))); task.Check(new ThrowImmediatelyCheckNotifier()); var configuration = new HICDatabaseConfiguration(db.Server); var job = Mock.Of(x => - x.RegularTablesToLoad == new List {ti} && + x.RegularTablesToLoad == new List { ti } && x.LookupTablesToLoad == new List() && x.Configuration == configuration); - var ex = Assert.Throws(()=>task.Run(job, new GracefulCancellationToken())); - StringAssert.Contains("Failed to find a TableInfo in the load with ID 0",ex.Message); + var ex = Assert.Throws(() => + task.Run(job, new GracefulCancellationToken())); + StringAssert.Contains("Failed to find a TableInfo in the load with ID 0", ex.Message); - task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success,new ThrowImmediatelyDataLoadEventListener()); + task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); } [TestCase(DatabaseType.MySql)] @@ -114,17 +118,21 @@ public void ExecuteSqlRuntimeTask_InvalidID(DatabaseType dbType) var tbl = db.CreateTable("Fish", dt); - Import(tbl,out var ti, out var cols); + Import(tbl, out var ti, out var cols); var sql = @"UPDATE {T:0} Set {C:0} = 1"; - var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"ExecuteSqlFileRuntimeTaskTests", true); + var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "ExecuteSqlFileRuntimeTaskTests", true); #pragma warning disable CS0252, CS0253 // Spurious warning 'Possible unintended reference comparison; left hand side needs cast' since VS doesn't grok Moq fully - var sqlArg = new IArgument[]{Mock.Of(x => - x.Name == "Sql" && - x.Value == sql && - x.GetValueAsSystemType() == sql) }; + var sqlArg = new IArgument[] + { + Mock.Of(x => + x.Name == "Sql" && + x.Value == sql && + x.GetValueAsSystemType() == sql) + }; #pragma warning restore CS0252, CS0253 var args = new RuntimeArgumentCollection(sqlArg, new StageArgs(LoadStage.AdjustRaw, db, dir)); @@ -134,24 +142,24 @@ public void ExecuteSqlRuntimeTask_InvalidID(DatabaseType dbType) x.GetAllArguments() == sqlArg ); - IRuntimeTask task = new MutilateDataTablesRuntimeTask(pt,args,CatalogueRepository.MEF); + IRuntimeTask task = new MutilateDataTablesRuntimeTask(pt, args, CatalogueRepository.MEF); task.Check(new ThrowImmediatelyCheckNotifier()); var configuration = new HICDatabaseConfiguration(db.Server); var job = new ThrowImmediatelyDataLoadJob { - RegularTablesToLoad = new List {ti}, + RegularTablesToLoad = new List { ti }, LookupTablesToLoad = new List(), Configuration = configuration }; - var ex = Assert.Throws(()=>task.Run(job, new GracefulCancellationToken())); + var ex = Assert.Throws(() => task.Run(job, new GracefulCancellationToken())); - StringAssert.Contains("Mutilate failed",ex.Message); - StringAssert.Contains("Failed to find a TableInfo in the load with ID 0",ex.InnerException.Message); + StringAssert.Contains("Mutilate failed", ex.Message); + StringAssert.Contains("Failed to find a TableInfo in the load with ID 0", ex.InnerException.Message); - task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success,new ThrowImmediatelyDataLoadEventListener()); + task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); } [TestCase(DatabaseType.MySql)] @@ -179,21 +187,23 @@ public void ExecuteSqlFileRuntimeTask_ValidID_CustomNamer(DatabaseType dbType) //we renamed the table to simulate RAW, confirm TableInfo doesn't think it exists Assert.IsFalse(ti.Discover(DataAccessContext.InternalDataProcessing).Exists()); - var pt = Mock.Of(x => x.Path==f.FullName); + var pt = Mock.Of(x => x.Path == f.FullName); - var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"ExecuteSqlFileRuntimeTaskTests", true); + var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), + "ExecuteSqlFileRuntimeTaskTests", true); - var task = new ExecuteSqlFileRuntimeTask(pt, new RuntimeArgumentCollection(Array.Empty(), new StageArgs(LoadStage.AdjustRaw, db, dir))); + var task = new ExecuteSqlFileRuntimeTask(pt, + new RuntimeArgumentCollection(Array.Empty(), new StageArgs(LoadStage.AdjustRaw, db, dir))); task.Check(new ThrowImmediatelyCheckNotifier()); //create a namer that tells the user var namer = RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(db, tableName); - var configuration = new HICDatabaseConfiguration(db.Server,namer); + var configuration = new HICDatabaseConfiguration(db.Server, namer); var job = Mock.Of(x => - x.RegularTablesToLoad == new List { ti }&& + x.RegularTablesToLoad == new List { ti } && x.LookupTablesToLoad == new List() && x.Configuration == configuration); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/FixedWidthTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/FixedWidthTests.cs index 917208f1e3..d5948b72ae 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/FixedWidthTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/FixedWidthTests.cs @@ -19,14 +19,14 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class FixedWidthTests :DatabaseTests +public class FixedWidthTests : DatabaseTests { private static FixedWidthFormatFile CreateFormatFile() { - var fileInfo = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,@"FixedWidthFormat.csv")); + var fileInfo = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, @"FixedWidthFormat.csv")); File.WriteAllText(fileInfo.FullName, LoadDirectory.ExampleFixedWidthFormatFileContents); - + Assert.IsTrue(fileInfo.Exists); return new FixedWidthFormatFile(fileInfo); @@ -37,55 +37,63 @@ public void TestLoadingFormat() { var formatFile = CreateFormatFile(); - Assert.AreEqual(8,formatFile.FormatColumns.Length); + Assert.AreEqual(8, formatFile.FormatColumns.Length); - Assert.AreEqual("gmc",formatFile.FormatColumns[0].Field); + Assert.AreEqual("gmc", formatFile.FormatColumns[0].Field); Assert.AreEqual(1, formatFile.FormatColumns[0].From); Assert.AreEqual(7, formatFile.FormatColumns[0].To); - Assert.AreEqual(1+ formatFile.FormatColumns[0].To - formatFile.FormatColumns[0].From, formatFile.FormatColumns[0].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[0].To - formatFile.FormatColumns[0].From, + formatFile.FormatColumns[0].Size); Assert.AreEqual(7, formatFile.FormatColumns[0].Size); Assert.AreEqual("gp_code", formatFile.FormatColumns[1].Field); Assert.AreEqual(8, formatFile.FormatColumns[1].From); Assert.AreEqual(12, formatFile.FormatColumns[1].To); - Assert.AreEqual(1 + formatFile.FormatColumns[1].To - formatFile.FormatColumns[1].From, formatFile.FormatColumns[1].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[1].To - formatFile.FormatColumns[1].From, + formatFile.FormatColumns[1].Size); Assert.AreEqual(5, formatFile.FormatColumns[1].Size); Assert.AreEqual("surname", formatFile.FormatColumns[2].Field); Assert.AreEqual(13, formatFile.FormatColumns[2].From); Assert.AreEqual(32, formatFile.FormatColumns[2].To); - Assert.AreEqual(1 + formatFile.FormatColumns[2].To - formatFile.FormatColumns[2].From, formatFile.FormatColumns[2].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[2].To - formatFile.FormatColumns[2].From, + formatFile.FormatColumns[2].Size); Assert.AreEqual(20, formatFile.FormatColumns[2].Size); Assert.AreEqual("forename", formatFile.FormatColumns[3].Field); Assert.AreEqual(33, formatFile.FormatColumns[3].From); Assert.AreEqual(52, formatFile.FormatColumns[3].To); - Assert.AreEqual(1 + formatFile.FormatColumns[3].To - formatFile.FormatColumns[3].From, formatFile.FormatColumns[3].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[3].To - formatFile.FormatColumns[3].From, + formatFile.FormatColumns[3].Size); Assert.AreEqual(20, formatFile.FormatColumns[3].Size); Assert.AreEqual("initials", formatFile.FormatColumns[4].Field); Assert.AreEqual(53, formatFile.FormatColumns[4].From); Assert.AreEqual(55, formatFile.FormatColumns[4].To); - Assert.AreEqual(1 + formatFile.FormatColumns[4].To - formatFile.FormatColumns[4].From, formatFile.FormatColumns[4].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[4].To - formatFile.FormatColumns[4].From, + formatFile.FormatColumns[4].Size); Assert.AreEqual(3, formatFile.FormatColumns[4].Size); Assert.AreEqual("practice_code", formatFile.FormatColumns[5].Field); Assert.AreEqual(56, formatFile.FormatColumns[5].From); Assert.AreEqual(60, formatFile.FormatColumns[5].To); - Assert.AreEqual(1 + formatFile.FormatColumns[5].To - formatFile.FormatColumns[5].From, formatFile.FormatColumns[5].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[5].To - formatFile.FormatColumns[5].From, + formatFile.FormatColumns[5].Size); Assert.AreEqual(5, formatFile.FormatColumns[5].Size); - + Assert.AreEqual("date_into_practice", formatFile.FormatColumns[6].Field); Assert.AreEqual(61, formatFile.FormatColumns[6].From); Assert.AreEqual(68, formatFile.FormatColumns[6].To); - Assert.AreEqual(1 + formatFile.FormatColumns[6].To - formatFile.FormatColumns[6].From, formatFile.FormatColumns[6].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[6].To - formatFile.FormatColumns[6].From, + formatFile.FormatColumns[6].Size); Assert.AreEqual(8, formatFile.FormatColumns[6].Size); Assert.AreEqual("yyyyMMdd", formatFile.FormatColumns[6].DateFormat); Assert.AreEqual("date_out_of_practice", formatFile.FormatColumns[7].Field); Assert.AreEqual(69, formatFile.FormatColumns[7].From); Assert.AreEqual(76, formatFile.FormatColumns[7].To); - Assert.AreEqual(1 + formatFile.FormatColumns[7].To - formatFile.FormatColumns[7].From, formatFile.FormatColumns[7].Size); + Assert.AreEqual(1 + formatFile.FormatColumns[7].To - formatFile.FormatColumns[7].From, + formatFile.FormatColumns[7].Size); Assert.AreEqual(8, formatFile.FormatColumns[7].Size); Assert.AreEqual("yyyyMMdd", formatFile.FormatColumns[7].DateFormat); } @@ -95,7 +103,7 @@ public void TestLoadingFormatThenFile() { var formatFile = CreateFormatFile(); - var tempFileToCreate = Path.Combine(TestContext.CurrentContext.TestDirectory,"unitTestFixedWidthFile.txt"); + var tempFileToCreate = Path.Combine(TestContext.CurrentContext.TestDirectory, "unitTestFixedWidthFile.txt"); var streamWriter = File.CreateText(tempFileToCreate); try @@ -106,7 +114,7 @@ public void TestLoadingFormatThenFile() streamWriter.Close(); var dataTable = formatFile.GetDataTableFromFlatFile(new FileInfo(tempFileToCreate)); - Assert.AreEqual(dataTable.Rows.Count,2); + Assert.AreEqual(dataTable.Rows.Count, 2); Assert.AreEqual("0026440", dataTable.Rows[0]["gmc"]); Assert.AreEqual("99999", dataTable.Rows[0]["gp_code"]); Assert.AreEqual("Akerman", dataTable.Rows[0]["surname"]); @@ -114,9 +122,7 @@ public void TestLoadingFormatThenFile() Assert.AreEqual("FM", dataTable.Rows[0]["initials"]); Assert.AreEqual("38051", dataTable.Rows[0]["practice_code"]); Assert.AreEqual(new DateTime(2004, 4, 1), dataTable.Rows[0]["date_into_practice"]); - Assert.AreEqual(new DateTime(2009,5,1), dataTable.Rows[0]["date_out_of_practice"]); - - + Assert.AreEqual(new DateTime(2009, 5, 1), dataTable.Rows[0]["date_out_of_practice"]); } finally { @@ -143,7 +149,7 @@ public void TestHeaderMatching(FixedWidthTestCase testCase) if (testCase == FixedWidthTestCase.MisnamedHeaders) flatFileColumn = "chickenDippers"; - var formatFile = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"Format.csv")); + var formatFile = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Format.csv")); File.WriteAllText(formatFile.FullName, $@"From,To,Field,Size,DateFormat 1,5,{flatFileColumn},5"); @@ -181,7 +187,7 @@ public void TestHeaderMatching(FixedWidthTestCase testCase) } var table = db.ExpectTable("TestHeaderMatching_Compatible"); - + Assert.IsTrue(table.Exists()); Assert.AreEqual(0, table.GetRowCount()); try @@ -195,19 +201,21 @@ public void TestHeaderMatching(FixedWidthTestCase testCase) case FixedWidthTestCase.CompatibleHeaders: attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); Assert.AreEqual(2, table.GetRowCount()); - return;//Return + return; //Return //Error cases, set the expected error result case FixedWidthTestCase.MisnamedHeaders: errorRegex = new Regex( @"Format file \(.*Format.csv\) indicated there would be a header called 'chickenDippers' but the column did not appear in the RAW database table \(Columns in RAW were myNumber\)"); - ex = Assert.Throws(() => attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); + ex = Assert.Throws(() => + attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); break; case FixedWidthTestCase.InsufficientLengthOfCharactersInFileToLoad: errorRegex = new Regex( @"Error on line 2 of file file.txt, the format file \(.*Format.csv\) specified that a column myNumber would be found between character positions 1 and 5 but the current line is only 2 characters long"); - ex = Assert.Throws(() => attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); + ex = Assert.Throws(() => + attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); break; default: throw new ArgumentOutOfRangeException(nameof(testCase)); @@ -215,8 +223,6 @@ public void TestHeaderMatching(FixedWidthTestCase testCase) //Assert the expected error result is the real one Assert.IsTrue(errorRegex.IsMatch(ex.Message)); - - } finally { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/FlatFileAttacherTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/FlatFileAttacherTests.cs index 0b04d910f8..5c4ce326d4 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/FlatFileAttacherTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/FlatFileAttacherTests.cs @@ -46,30 +46,28 @@ protected override void SetUp() toCleanup?.Delete(true); LoadDirectory = LoadDirectory.CreateDirectoryStructure(parentDir, "Test_CSV_Attachment"); - + // create a separate builder for setting an initial catalog on (need to figure out how best to stop child classes changing ServerICan... as this then causes TearDown to fail) _database = GetCleanedServer(DatabaseType.MicrosoftSQLServer); - + using (var con = _database.Server.GetConnection()) { con.Open(); var cmdCreateTable = _database.Server.GetCommand( - $"CREATE Table {_database.GetRuntimeName()}..Bob([name] [varchar](500),[name2] [varchar](500))",con); + $"CREATE Table {_database.GetRuntimeName()}..Bob([name] [varchar](500),[name2] [varchar](500))", con); cmdCreateTable.ExecuteNonQuery(); } _table = _database.ExpectTable("Bob"); - } [Test] - [TestCase(",",false)] - [TestCase("|",false)]//wrong separator - [TestCase(",",true)] + [TestCase(",", false)] + [TestCase("|", false)] //wrong separator + [TestCase(",", true)] public void Test_CSV_Attachment(string separator, bool overrideHeaders) { - var filename = Path.Combine(LoadDirectory.ForLoading.FullName, "bob.csv"); var sw = new StreamWriter(filename); @@ -105,13 +103,15 @@ public void Test_CSV_Attachment(string separator, bool overrideHeaders) } //Case when you are using the wrong separator - if(separator == "|") + if (separator == "|") { + var ex = Assert.Throws(() => + attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); - var ex = Assert.Throws(()=>attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); - Assert.IsNotNull(ex.InnerException); - StringAssert.StartsWith("Your separator does not appear in the headers line of your file (bob.csv) but the separator ',' does", ex.InnerException.Message); + StringAssert.StartsWith( + "Your separator does not appear in the headers line of your file (bob.csv) but the separator ',' does", + ex.InnerException.Message); return; } @@ -126,29 +126,27 @@ public void Test_CSV_Attachment(string separator, bool overrideHeaders) using (var con = _database.Server.GetConnection()) { - con.Open(); var r = _database.Server.GetCommand("Select * from Bob", con).ExecuteReader(); Assert.IsTrue(r.Read()); - Assert.AreEqual("Bob",r["name"]); + Assert.AreEqual("Bob", r["name"]); Assert.AreEqual("Munchousain", r["name2"]); - + Assert.IsTrue(r.Read()); Assert.AreEqual("Franky", r["name"]); Assert.AreEqual("Hollyw9ood", r["name2"]); - + Assert.IsTrue(r.Read()); Assert.AreEqual("Manny2", r["name"]); Assert.AreEqual("Ok", r["name2"]); } - - attacher.LoadCompletedSoDispose(ExitCodeType.Success,new ThrowImmediatelyDataLoadEventListener()); + + attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); File.Delete(filename); } - [Test] public void Test_ExplicitDateTimeFormat_Attachment() { @@ -184,19 +182,18 @@ public void Test_ExplicitDateTimeFormat_Attachment() using (var con = _database.Server.GetConnection()) { - con.Open(); var r = _database.Server.GetCommand("Select * from Bob", con).ExecuteReader(); Assert.IsTrue(r.Read()); - Assert.AreEqual("Bob",r["name"]); - Assert.AreEqual(new DateTime(2001,01,13), r["name2"]); - + Assert.AreEqual("Bob", r["name"]); + Assert.AreEqual(new DateTime(2001, 01, 13), r["name2"]); + Assert.IsTrue(r.Read()); Assert.AreEqual("Franky", r["name"]); - Assert.AreEqual(new DateTime(2002,01,13), r["name2"]); + Assert.AreEqual(new DateTime(2002, 01, 13), r["name2"]); } - - attacher.LoadCompletedSoDispose(ExitCodeType.Success,new ThrowImmediatelyDataLoadEventListener()); + + attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); File.Delete(filename); } @@ -222,11 +219,10 @@ public void TabTestWithOverrideHeaders() attacher.ForceHeaders = "name\tname2"; var exitCode = attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); - Assert.AreEqual(ExitCodeType.Success,exitCode); + Assert.AreEqual(ExitCodeType.Success, exitCode); using (var con = _database.Server.GetConnection()) { - con.Open(); var r = _database.Server.GetCommand("Select name,name2 from Bob", con).ExecuteReader(); Assert.IsTrue(r.Read()); @@ -241,8 +237,6 @@ public void TabTestWithOverrideHeaders() attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); File.Delete(filename); - - } [TestCase(true)] @@ -260,7 +254,7 @@ public void TabTestWithOverrideHeaders_IncludePath(bool columnExistsInRaw) sw.Dispose(); if (columnExistsInRaw) - _table.AddColumn("FilePath",new DatabaseTypeRequest(typeof(string),500),true,30); + _table.AddColumn("FilePath", new DatabaseTypeRequest(typeof(string), 500), true, 30); var attacher = new AnySeparatorFileAttacher(); attacher.Initialize(LoadDirectory, _database); @@ -272,8 +266,10 @@ public void TabTestWithOverrideHeaders_IncludePath(bool columnExistsInRaw) if (!columnExistsInRaw) { - var ex = Assert.Throws(()=>attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); - Assert.AreEqual("AddFilenameColumnNamed is set to 'FilePath' but the column did not exist in RAW",ex.InnerException.Message); + var ex = Assert.Throws(() => + attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); + Assert.AreEqual("AddFilenameColumnNamed is set to 'FilePath' but the column did not exist in RAW", + ex.InnerException.Message); return; } @@ -283,7 +279,6 @@ public void TabTestWithOverrideHeaders_IncludePath(bool columnExistsInRaw) using (var con = _database.Server.GetConnection()) { - con.Open(); var r = _database.Server.GetCommand("Select name,name2,FilePath from Bob", con).ExecuteReader(); Assert.IsTrue(r.Read()); @@ -299,8 +294,6 @@ public void TabTestWithOverrideHeaders_IncludePath(bool columnExistsInRaw) attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); File.Delete(filename); - - } @@ -339,12 +332,12 @@ public void TestTableInfo(bool usenamer) var exitCode = attacher.Attach(job, new GracefulCancellationToken()); Assert.AreEqual(ExitCodeType.Success, exitCode); - + using (var con = _database.Server.GetConnection()) { - con.Open(); - var r = _database.Server.GetCommand($"Select name,name2 from {_table.GetRuntimeName()}", con).ExecuteReader(); + var r = _database.Server.GetCommand($"Select name,name2 from {_table.GetRuntimeName()}", con) + .ExecuteReader(); Assert.IsTrue(r.Read()); Assert.AreEqual("Bob", r["name"]); Assert.AreEqual("Munchousain", r["name2"]); @@ -357,7 +350,6 @@ public void TestTableInfo(bool usenamer) attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); File.Delete(filename); - } @@ -391,9 +383,9 @@ public void Test_FlatFileAttacher_IgnoreColumns() using (var con = _database.Server.GetConnection()) { - con.Open(); - var r = _database.Server.GetCommand($"Select name,name2 from {_table.GetRuntimeName()}", con).ExecuteReader(); + var r = _database.Server.GetCommand($"Select name,name2 from {_table.GetRuntimeName()}", con) + .ExecuteReader(); Assert.IsTrue(r.Read()); Assert.AreEqual("Bob", r["name"]); Assert.AreEqual("Munchousain", r["name2"]); @@ -406,26 +398,23 @@ public void Test_FlatFileAttacher_IgnoreColumns() attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); File.Delete(filename); - } - - [TestCase(DatabaseType.MySql,"27/01/2001","en-GB","en-GB")] - [TestCase(DatabaseType.MySql,"27/01/2001","en-GB","en-us")] - [TestCase(DatabaseType.MySql,"01/27/2001","en-us", "en-us")] - [TestCase(DatabaseType.MySql,"01/27/2001","en-us", "en-GB")] - - [TestCase(DatabaseType.MicrosoftSQLServer,"27/01/2001","en-GB","en-GB")] - [TestCase(DatabaseType.MicrosoftSQLServer,"27/01/2001","en-GB","en-us")] - [TestCase(DatabaseType.MicrosoftSQLServer,"01/27/2001","en-us","en-us")] - [TestCase(DatabaseType.MicrosoftSQLServer,"01/27/2001","en-us","en-GB")] - - [TestCase(DatabaseType.Oracle,"27/01/2001","en-GB","en-GB")] - [TestCase(DatabaseType.Oracle,"27/01/2001","en-GB","en-us")] - [TestCase(DatabaseType.Oracle,"01/27/2001","en-us","en-us")] - [TestCase(DatabaseType.Oracle,"01/27/2001","en-us","en-GB")] - - public void Test_FlatFileAttacher_AmbiguousDates(DatabaseType type,string val,string attacherCulture, string threadCulture) - { + + [TestCase(DatabaseType.MySql, "27/01/2001", "en-GB", "en-GB")] + [TestCase(DatabaseType.MySql, "27/01/2001", "en-GB", "en-us")] + [TestCase(DatabaseType.MySql, "01/27/2001", "en-us", "en-us")] + [TestCase(DatabaseType.MySql, "01/27/2001", "en-us", "en-GB")] + [TestCase(DatabaseType.MicrosoftSQLServer, "27/01/2001", "en-GB", "en-GB")] + [TestCase(DatabaseType.MicrosoftSQLServer, "27/01/2001", "en-GB", "en-us")] + [TestCase(DatabaseType.MicrosoftSQLServer, "01/27/2001", "en-us", "en-us")] + [TestCase(DatabaseType.MicrosoftSQLServer, "01/27/2001", "en-us", "en-GB")] + [TestCase(DatabaseType.Oracle, "27/01/2001", "en-GB", "en-GB")] + [TestCase(DatabaseType.Oracle, "27/01/2001", "en-GB", "en-us")] + [TestCase(DatabaseType.Oracle, "01/27/2001", "en-us", "en-us")] + [TestCase(DatabaseType.Oracle, "01/27/2001", "en-us", "en-GB")] + public void Test_FlatFileAttacher_AmbiguousDates(DatabaseType type, string val, string attacherCulture, + string threadCulture) + { Thread.CurrentThread.CurrentCulture = new CultureInfo(threadCulture); var filename = Path.Combine(LoadDirectory.ForLoading.FullName, "bob.csv"); @@ -440,13 +429,13 @@ public void Test_FlatFileAttacher_AmbiguousDates(DatabaseType type,string val,st var db = GetCleanedServer(type); - var tbl = + var tbl = db.CreateTable("AmbiguousDatesTestTable", - new []{new DatabaseColumnRequest("dob",new DatabaseTypeRequest(typeof(DateTime)))} + new[] { new DatabaseColumnRequest("dob", new DatabaseTypeRequest(typeof(DateTime))) } ); - Import(tbl,out var ti,out _); + Import(tbl, out var ti, out _); var attacher = new AnySeparatorFileAttacher { Separator = ",", @@ -456,14 +445,14 @@ public void Test_FlatFileAttacher_AmbiguousDates(DatabaseType type,string val,st }; attacher.Initialize(LoadDirectory, db); - var job = new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(_database.Server, null),ti); + var job = new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(_database.Server, null), ti); var exitCode = attacher.Attach(job, new GracefulCancellationToken()); Assert.AreEqual(ExitCodeType.Success, exitCode); - + attacher.LoadCompletedSoDispose(ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); - Assert.AreEqual(new DateTime(2001,1,27),tbl.GetDataTable().Rows[0][0]); + Assert.AreEqual(new DateTime(2001, 1, 27), tbl.GetDataTable().Rows[0][0]); File.Delete(filename); tbl.Drop(); @@ -474,19 +463,21 @@ public void Test_TableToLoad_IDNotInLoadMetadata() { var source = new AnySeparatorFileAttacher(); - var tiInLoad = new TableInfo(CatalogueRepository,"TableInLoad"); + var tiInLoad = new TableInfo(CatalogueRepository, "TableInLoad"); var tiNotInLoad = new TableInfo(CatalogueRepository, "TableNotInLoad"); source.TableToLoad = tiNotInLoad; - var job = new ThrowImmediatelyDataLoadJob(new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true}) - { - RegularTablesToLoad = new System.Collections.Generic.List(new []{tiInLoad }) - }; + var job = new ThrowImmediatelyDataLoadJob(new ThrowImmediatelyDataLoadEventListener { ThrowOnWarning = true }) + { + RegularTablesToLoad = new System.Collections.Generic.List(new[] { tiInLoad }) + }; - var ex = Assert.Throws(()=>source.Attach(job,new GracefulCancellationToken())); + var ex = Assert.Throws(() => source.Attach(job, new GracefulCancellationToken())); - StringAssert.IsMatch("FlatFileAttacher TableToLoad was 'TableNotInLoad' \\(ID=\\d+\\) but that table was not one of the tables in the load:'TableInLoad'", ex.Message); + StringAssert.IsMatch( + "FlatFileAttacher TableToLoad was 'TableNotInLoad' \\(ID=\\d+\\) but that table was not one of the tables in the load:'TableInLoad'", + ex.Message); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/HICPipelineTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/HICPipelineTests.cs index 7e08777b85..faf8560bf5 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/HICPipelineTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/HICPipelineTests.cs @@ -118,25 +118,25 @@ private void SetupLoadProcessTasks(ICatalogueRepository catalogueRepository) // Not assigned to a variable as they will be magically available through the repository var processTaskArgs = new List> { - new Tuple("FilePattern", "1.csv", typeof (string)), - new Tuple("TableName", "TestData", typeof (string)), - new Tuple("ForceHeaders", null, typeof (string)), - new Tuple("IgnoreQuotes", null, typeof (bool)), - new Tuple("IgnoreBlankLines", null, typeof (bool)), - new Tuple("ForceHeadersReplacesFirstLineInFile", null, typeof (bool)), - new Tuple("SendLoadNotRequiredIfFileNotFound", "false", typeof (bool)), - new Tuple("Separator", ",", typeof (string)), - new Tuple("TableToLoad", null, typeof (TableInfo)), - new Tuple("BadDataHandlingStrategy", BadDataHandlingStrategy.ThrowException.ToString(), typeof (BadDataHandlingStrategy)), - new Tuple("ThrowOnEmptyFiles", "true", typeof (bool)), - new Tuple("AttemptToResolveNewLinesInRecords", "true", typeof (bool)), - new Tuple("MaximumErrorsToReport", "0", typeof (int)), - new Tuple("IgnoreColumns", null, typeof (string)), - new Tuple("IgnoreBadReads", "false", typeof (bool)), - new Tuple("AddFilenameColumnNamed", null, typeof (string)) - + new("FilePattern", "1.csv", typeof(string)), + new("TableName", "TestData", typeof(string)), + new("ForceHeaders", null, typeof(string)), + new("IgnoreQuotes", null, typeof(bool)), + new("IgnoreBlankLines", null, typeof(bool)), + new("ForceHeadersReplacesFirstLineInFile", null, typeof(bool)), + new("SendLoadNotRequiredIfFileNotFound", "false", typeof(bool)), + new("Separator", ",", typeof(string)), + new("TableToLoad", null, typeof(TableInfo)), + new("BadDataHandlingStrategy", BadDataHandlingStrategy.ThrowException.ToString(), + typeof(BadDataHandlingStrategy)), + new("ThrowOnEmptyFiles", "true", typeof(bool)), + new("AttemptToResolveNewLinesInRecords", "true", typeof(bool)), + new("MaximumErrorsToReport", "0", typeof(int)), + new("IgnoreColumns", null, typeof(string)), + new("IgnoreBadReads", "false", typeof(bool)), + new("AddFilenameColumnNamed", null, typeof(string)) }; - + foreach (var tuple in processTaskArgs) { @@ -157,12 +157,13 @@ internal class DatabaseHelper : IDisposable public DiscoveredDatabase DatabaseToLoad { get; private set; } + public void SetUp(DiscoveredServer server) { _server = server; var databaseToLoadName = "HICPipelineTests"; - + // Create the databases server.ExpectDatabase(databaseToLoadName).Create(true); server.ChangeDatabase(databaseToLoadName); @@ -176,11 +177,15 @@ public void SetUp(DiscoveredServer server) "CREATE TABLE TestData ([Col1] [int], [hic_dataLoadRunID] [int] NULL, [hic_validFrom] [datetime] NULL, CONSTRAINT [PK_TestData] PRIMARY KEY CLUSTERED ([Col1] ASC))"; const string addValidFromDefault = "ALTER TABLE TestData ADD CONSTRAINT [DF_TestData__hic_validFrom] DEFAULT (getdate()) FOR [hic_validFrom]"; - using(var cmd = DatabaseCommandHelper.GetCommand(createDatasetTableQuery, con)) + using (var cmd = DatabaseCommandHelper.GetCommand(createDatasetTableQuery, con)) + { cmd.ExecuteNonQuery(); + } - using(var cmd = DatabaseCommandHelper.GetCommand(addValidFromDefault, con)) + using (var cmd = DatabaseCommandHelper.GetCommand(addValidFromDefault, con)) + { cmd.ExecuteNonQuery(); + } } // Ensure the dataset table has been created @@ -192,7 +197,7 @@ public void Dispose() { if (DatabaseToLoad == null) return; - + if (DatabaseToLoad.Exists()) DatabaseToLoad.Drop(); @@ -237,7 +242,7 @@ public void TestSingleJob(bool overrideRAW, bool sendDodgyCredentials) if (overrideRAW) { - external = new ExternalDatabaseServer(CatalogueRepository, "RAW Server",null); + external = new ExternalDatabaseServer(CatalogueRepository, "RAW Server", null); external.SetProperties(DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase("master")); if (sendDodgyCredentials) @@ -245,6 +250,7 @@ public void TestSingleJob(bool overrideRAW, bool sendDodgyCredentials) external.Username = "IveGotaLovely"; external.Password = "BunchOfCoconuts"; } + external.SaveToDatabase(); defaults.SetDefault(PermissableDefaults.RAWDataLoadServer, external); @@ -257,29 +263,36 @@ public void TestSingleJob(bool overrideRAW, bool sendDodgyCredentials) }; //run checks (with ignore errors if we are sending dodgy credentials) - RunnerFactory.CreateRunner(new ThrowImmediatelyActivator(RepositoryLocator),options).Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), - sendDodgyCredentials? - (ICheckNotifier) new IgnoreAllErrorsCheckNotifier(): new AcceptAllCheckNotifier(), new GracefulCancellationToken()); + RunnerFactory.CreateRunner(new ThrowImmediatelyActivator(RepositoryLocator), options).Run(RepositoryLocator, + new ThrowImmediatelyDataLoadEventListener(), + sendDodgyCredentials + ? (ICheckNotifier)new IgnoreAllErrorsCheckNotifier() + : new AcceptAllCheckNotifier(), new GracefulCancellationToken()); //run load options.Command = CommandLineActivity.run; - var runner = RunnerFactory.CreateRunner(new ThrowImmediatelyActivator(RepositoryLocator),options); + var runner = RunnerFactory.CreateRunner(new ThrowImmediatelyActivator(RepositoryLocator), options); if (sendDodgyCredentials) { - var ex = Assert.Throws(()=>runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new AcceptAllCheckNotifier(), new GracefulCancellationToken())); - Assert.IsTrue(ex.InnerException.Message.Contains("Login failed for user 'IveGotaLovely'"),"Error message did not contain expected text"); + var ex = Assert.Throws(() => runner.Run(RepositoryLocator, + new ThrowImmediatelyDataLoadEventListener(), new AcceptAllCheckNotifier(), + new GracefulCancellationToken())); + Assert.IsTrue(ex.InnerException.Message.Contains("Login failed for user 'IveGotaLovely'"), + "Error message did not contain expected text"); return; } else - runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new AcceptAllCheckNotifier(), new GracefulCancellationToken()); + { + runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new AcceptAllCheckNotifier(), + new GracefulCancellationToken()); + } - var archiveFile = loadDirectory.ForArchiving.EnumerateFiles("*.zip").MaxBy(f=>f.FullName); - Assert.NotNull(archiveFile,"Archive file has not been created by the load."); + var archiveFile = loadDirectory.ForArchiving.EnumerateFiles("*.zip").MaxBy(f => f.FullName); + Assert.NotNull(archiveFile, "Archive file has not been created by the load."); Assert.IsFalse(loadDirectory.ForLoading.EnumerateFileSystemInfos().Any()); - } finally { @@ -300,7 +313,6 @@ public class TestCacheFileRetriever : CachedFileRetriever { public override void Initialize(ILoadDirectory directory, DiscoveredDatabase dbInfo) { - } public override ExitCodeType Fetch(IDataLoadJob dataLoadJob, GracefulCancellationToken cancellationToken) diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/HousekeepingTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/HousekeepingTests.cs index 39749ae5ed..17fc0322df 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/HousekeepingTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/HousekeepingTests.cs @@ -18,20 +18,20 @@ internal class HousekeepingTests : DatabaseTests [Test] public void TestCheckUpdateTrigger() { - // set SetUp a test database const string tableName = "TestTable"; var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); var databaseName = db.GetRuntimeName(); - var table = db.CreateTable(tableName,new[] {new DatabaseColumnRequest("Id", "int") }); + var table = db.CreateTable(tableName, new[] { new DatabaseColumnRequest("Id", "int") }); var server = db.Server; using (var con = server.GetConnection()) { con.Open(); var cmd = server.GetCommand( - $"CREATE TRIGGER dbo.[TestTable_OnUpdate] ON [dbo].[{tableName}] AFTER DELETE AS RAISERROR('MESSAGE',16,10)", con); + $"CREATE TRIGGER dbo.[TestTable_OnUpdate] ON [dbo].[{tableName}] AFTER DELETE AS RAISERROR('MESSAGE',16,10)", + con); cmd.ExecuteNonQuery(); } @@ -44,14 +44,15 @@ public void TestCheckUpdateTrigger() var isEnabled = triggerImplementer.GetTriggerStatus(); Assert.AreEqual(TriggerStatus.Enabled, isEnabled); - + // disable the trigger and test correct reporting using (var con = new SqlConnection(dbInfo.Server.Builder.ConnectionString)) { con.Open(); var cmd = new SqlCommand( - $"USE [{databaseName}]; DISABLE TRIGGER TestTable_OnUpdate ON [{databaseName}]..[{tableName}]", con); + $"USE [{databaseName}]; DISABLE TRIGGER TestTable_OnUpdate ON [{databaseName}]..[{tableName}]", + con); cmd.ExecuteNonQuery(); } diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ImportFilesDataProviderTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ImportFilesDataProviderTests.cs index 750871ef3a..97c95bdedb 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ImportFilesDataProviderTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ImportFilesDataProviderTests.cs @@ -20,21 +20,21 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class ImportFilesDataProviderTests:DatabaseTests +public class ImportFilesDataProviderTests : DatabaseTests { [Test] public void CopyFiles() { var sourceDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory).CreateSubdirectory("subdir"); var targetDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory).CreateSubdirectory("loaddir"); - + //make sure target is empty foreach (var f in targetDir.GetFiles()) f.Delete(); var originpath = Path.Combine(sourceDir.FullName, "myFile.txt"); - File.WriteAllText(originpath,"fish"); + File.WriteAllText(originpath, "fish"); var job = new ThrowImmediatelyDataLoadJob(); var mockProjectDirectory = Mock.Of(p => p.ForLoading == targetDir); @@ -46,7 +46,7 @@ public void CopyFiles() //it doesn't know what to load yet Assert.Throws(() => provider.Check(new ThrowImmediatelyCheckNotifier())); - + //now it does provider.DirectoryPath = sourceDir.FullName; @@ -105,7 +105,5 @@ public void CopyFiles() //only forLoading file should exist (in real life that one would be handled by archivng already) Assert.AreEqual(1, targetDir.GetFiles().Length); Assert.AreEqual(0, sourceDir.GetFiles().Length); - } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/JobDateGenerationStrategyFactoryTestsIntegration.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/JobDateGenerationStrategyFactoryTestsIntegration.cs index 46cb08ba38..1d2878aa76 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/JobDateGenerationStrategyFactoryTestsIntegration.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/JobDateGenerationStrategyFactoryTestsIntegration.cs @@ -24,7 +24,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class JobDateGenerationStrategyFactoryTestsIntegration:DatabaseTests +public class JobDateGenerationStrategyFactoryTestsIntegration : DatabaseTests { private CacheProgress _cp; private LoadProgress _lp; @@ -58,8 +58,10 @@ protected override void SetUp() [Test] public void CacheProvider_None() { - var ex = Assert.Throws(() => _factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener())); - Assert.IsTrue(ex.Message.StartsWith("LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration does not have ANY process tasks of type ProcessTaskType.DataProvider")); + var ex = Assert.Throws(() => + _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); + Assert.IsTrue(ex.Message.StartsWith( + "LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration does not have ANY process tasks of type ProcessTaskType.DataProvider")); } @@ -68,14 +70,16 @@ public void CacheProvider_NonCachingOne() { var pt = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles) { - Path = typeof (DoNothingDataProvider).FullName, + Path = typeof(DoNothingDataProvider).FullName, ProcessTaskType = ProcessTaskType.DataProvider, Name = "DoNothing" }; pt.SaveToDatabase(); - var ex = Assert.Throws(() => _factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener())); - Assert.IsTrue(ex.Message.StartsWith("LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration has some DataProviders tasks but none of them wrap classes that implement ICachedDataProvider")); + var ex = Assert.Throws(() => + _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); + Assert.IsTrue(ex.Message.StartsWith( + "LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration has some DataProviders tasks but none of them wrap classes that implement ICachedDataProvider")); } @@ -98,8 +102,11 @@ public void CacheProvider_TwoCachingOnes() }; pt2.SaveToDatabase(); - var ex = Assert.Throws(() => _factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener())); - Assert.AreEqual("LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration has multiple cache DataProviders tasks (Cache1,Cache2), you are only allowed 1",ex.Message); + var ex = Assert.Throws(() => + _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); + Assert.AreEqual( + "LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration has multiple cache DataProviders tasks (Cache1,Cache2), you are only allowed 1", + ex.Message); } [Test] @@ -119,12 +126,14 @@ public void CacheProvider_NoPipeline() pt1.CreateArgumentsForClassIfNotExists(); - var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"delme", true); + var projDir = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", + true); _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _lmd.SaveToDatabase(); try { - var ex = Assert.Throws(() => _factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener())); + var ex = Assert.Throws(() => _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); Assert.AreEqual("CacheProgress MyTestCp does not have a Pipeline configured on it", ex.Message); } finally @@ -144,7 +153,9 @@ public void CacheProvider_NoCacheProgress() }; pt1.SaveToDatabase(); - var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", true); + var projDir = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", + true); _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _lmd.SaveToDatabase(); @@ -153,9 +164,11 @@ public void CacheProvider_NoCacheProgress() try { - var ex = Assert.Throws(()=>_factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener())); + var ex = Assert.Throws(() => + _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); Assert.AreEqual( - $"Caching has not begun for this CacheProgress ({_cp.ID}), so there is nothing to load and this strategy should not be used.",ex.Message); + $"Caching has not begun for this CacheProgress ({_cp.ID}), so there is nothing to load and this strategy should not be used.", + ex.Message); } finally { @@ -164,6 +177,7 @@ public void CacheProvider_NoCacheProgress() projDir.RootPath.Delete(true); } } + [Test] public void CacheProvider_Normal() { @@ -178,7 +192,9 @@ public void CacheProvider_Normal() _cp.CacheFillProgress = new DateTime(2010, 1, 1); _cp.SaveToDatabase(); - var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", true); + var projDir = + LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", + true); _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _lmd.SaveToDatabase(); @@ -187,22 +203,23 @@ public void CacheProvider_Normal() try { - var strategy = _factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener()); + var strategy = _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener()); Assert.AreEqual(typeof(SingleScheduleCacheDateTrackingStrategy), strategy.GetType()); var dates = strategy.GetDates(10, false); - Assert.AreEqual(0,dates.Count); //zero dates to load because no files in cache + Assert.AreEqual(0, dates.Count); //zero dates to load because no files in cache + + File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-02.zip"), + "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); + File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-03.zip"), + "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); + File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-05.zip"), + "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); - File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-02.zip"),"bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); - File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-03.zip"), "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); - File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-05.zip"), "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); - - strategy = _factory.Create(_lp,new ThrowImmediatelyDataLoadEventListener()); + strategy = _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener()); Assert.AreEqual(typeof(SingleScheduleCacheDateTrackingStrategy), strategy.GetType()); dates = strategy.GetDates(10, false); Assert.AreEqual(3, dates.Count); //zero dates to load because no files in cache - - } finally { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/KVPAttacherTest.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/KVPAttacherTest.cs index 439aaf3a0b..d362597475 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/KVPAttacherTest.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/KVPAttacherTest.cs @@ -21,9 +21,8 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class KVPAttacherTest:DatabaseTests +public class KVPAttacherTest : DatabaseTests { - public enum KVPAttacherTestCase { OneFileWithPrimaryKey, @@ -50,7 +49,8 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) var filepk2 = "kvpTestFilePK2.csv"; var fileNoPk = "kvpTestFile_NoPK.csv"; - if (testCase == KVPAttacherTestCase.OneFileWithPrimaryKey || testCase == KVPAttacherTestCase.TwoFilesWithPrimaryKey) + if (testCase == KVPAttacherTestCase.OneFileWithPrimaryKey || + testCase == KVPAttacherTestCase.TwoFilesWithPrimaryKey) CopyToBin(projectDir, filepk); if (testCase == KVPAttacherTestCase.TwoFilesWithPrimaryKey) @@ -58,12 +58,12 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) if (testCase == KVPAttacherTestCase.OneFileWithoutPrimaryKey) CopyToBin(projectDir, fileNoPk); - + if (tbl.Exists()) tbl.Drop(); - + //Create destination data table on server (where the data will ultimately end SetUp) - using (var con = (SqlConnection) tbl.Database.Server.GetConnection()) + using (var con = (SqlConnection)tbl.Database.Server.GetConnection()) { con.Open(); var sql = hasPk @@ -74,7 +74,8 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) } var remnantPipeline = - CatalogueRepository.GetAllObjects().SingleOrDefault(p=>p.Name.Equals("KVPAttacherTestPipeline")); + CatalogueRepository.GetAllObjects() + .SingleOrDefault(p => p.Name.Equals("KVPAttacherTestPipeline")); remnantPipeline?.DeleteInDatabase(); @@ -82,12 +83,14 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) var p = new Pipeline(CatalogueRepository, "KVPAttacherTestPipeline"); //With a CSV source - var flatFileLoad = new PipelineComponent(CatalogueRepository, p, typeof (DelimitedFlatFileDataFlowSource), 0,"Data Flow Source"); + var flatFileLoad = new PipelineComponent(CatalogueRepository, p, typeof(DelimitedFlatFileDataFlowSource), 0, + "Data Flow Source"); //followed by a Transpose that turns columns to rows (see how the test file grows right with new records instead of down, this is common in KVP input files but not always) - var transpose = new PipelineComponent(CatalogueRepository, p, typeof (Transposer), 1, "Transposer"); + var transpose = new PipelineComponent(CatalogueRepository, p, typeof(Transposer), 1, "Transposer"); - var saneHeaders = transpose.CreateArgumentsForClassIfNotExists(typeof (Transposer)).Single(a => a.Name.Equals("MakeHeaderNamesSane")); + var saneHeaders = transpose.CreateArgumentsForClassIfNotExists(typeof(Transposer)) + .Single(a => a.Name.Equals("MakeHeaderNamesSane")); saneHeaders.SetValue(false); saneHeaders.SaveToDatabase(); @@ -103,7 +106,7 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) p.SourcePipelineComponent_ID = flatFileLoad.ID; p.SaveToDatabase(); - + try { attacher.PipelineForReadingFromFlatFile = p; @@ -122,8 +125,8 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) attacher.TargetDataTableKeyColumnName = "Test"; attacher.TargetDataTableValueColumnName = "Result"; - - attacher.Initialize(projectDir,db); + + attacher.Initialize(projectDir, db); attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); @@ -135,7 +138,6 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) expectedRows += 54; Assert.AreEqual(expectedRows, tbl.GetRowCount()); - } finally { @@ -149,7 +151,9 @@ public void KVPAttacherTest_Attach(KVPAttacherTestCase testCase) public void KVPAttacherCheckTest_TableNameMissing() { var ex = Assert.Throws(() => new KVPAttacher().Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Either argument TableName or TableToLoad must be set Rdmp.Core.DataLoad.Modules.Attachers.KVPAttacher, you should specify this value.",ex.Message); + Assert.AreEqual( + "Either argument TableName or TableToLoad must be set Rdmp.Core.DataLoad.Modules.Attachers.KVPAttacher, you should specify this value.", + ex.Message); } [Test] @@ -160,12 +164,11 @@ public void KVPAttacherCheckTest_FilePathMissing() TableName = "MyTable" }; - var ex = Assert.Throws(()=>kvp.Check(new ThrowImmediatelyCheckNotifier())); + var ex = Assert.Throws(() => kvp.Check(new ThrowImmediatelyCheckNotifier())); Assert.IsTrue(ex.Message.StartsWith("Argument FilePattern has not been set")); } - [Test] [TestCase("PrimaryKeyColumns")] [TestCase("TargetDataTableKeyColumnName")] @@ -201,12 +204,14 @@ public void KVPAttacherCheckTest_Crossover(bool isKeyColumnDuplicate) TableName = "MyTable", FilePattern = "*.csv", PrimaryKeyColumns = "dave,bob", - TargetDataTableKeyColumnName = isKeyColumnDuplicate ?"dave":"Fish", + TargetDataTableKeyColumnName = isKeyColumnDuplicate ? "dave" : "Fish", TargetDataTableValueColumnName = isKeyColumnDuplicate ? "tron" : "dave" }; var ex = Assert.Throws(() => kvp.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("Field 'dave' is both a PrimaryKeyColumn and a TargetDataTable column, this is not allowed. Your fields Pk1,Pk2,Pketc,Key,Value must all be mutually exclusive", ex.Message); + Assert.AreEqual( + "Field 'dave' is both a PrimaryKeyColumn and a TargetDataTable column, this is not allowed. Your fields Pk1,Pk2,Pketc,Key,Value must all be mutually exclusive", + ex.Message); } [Test] @@ -222,13 +227,14 @@ public void KVPAttacherCheckTest_CrossoverKeyAndValue() }; var ex = Assert.Throws(() => kvp.Check(new ThrowImmediatelyCheckNotifier())); - Assert.AreEqual("TargetDataTableKeyColumnName cannot be the same as TargetDataTableValueColumnName", ex.Message); + Assert.AreEqual("TargetDataTableKeyColumnName cannot be the same as TargetDataTableValueColumnName", + ex.Message); } private static void CopyToBin(LoadDirectory projDir, string file) { - - var testFileLocation = Path.Combine(TestContext.CurrentContext.TestDirectory,"DataLoad","Engine","Resources" , file); + var testFileLocation = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataLoad", "Engine", "Resources", + file); Assert.IsTrue(File.Exists(testFileLocation)); File.Copy(testFileLocation, projDir.ForLoading.FullName + Path.DirectorySeparatorChar + file, true); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/MigrationStrategyTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/MigrationStrategyTests.cs index 83ecde4e57..4ae4040c78 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/MigrationStrategyTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/MigrationStrategyTests.cs @@ -23,7 +23,7 @@ public void OverwriteMigrationStrategy_NoPrimaryKey() { var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); - var from = db.CreateTable("Bob",new[] {new DatabaseColumnRequest("Field", "int")}); + var from = db.CreateTable("Bob", new[] { new DatabaseColumnRequest("Field", "int") }); var to = db.CreateTable("Frank", new[] { new DatabaseColumnRequest("Field", "int") }); var connection = Mock.Of(); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PayloadTest.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PayloadTest.cs index 9743176df1..42eb8f0a60 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PayloadTest.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PayloadTest.cs @@ -24,7 +24,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class PayloadTest:DatabaseTests +public class PayloadTest : DatabaseTests { public static object payload = new(); public static bool Success = false; @@ -32,13 +32,15 @@ public class PayloadTest:DatabaseTests [Test] public void TestPayloadInjection() { - var b = new BulkTestsData(CatalogueRepository,GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer),10); + var b = new BulkTestsData(CatalogueRepository, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer), 10); b.SetupTestData(); b.ImportAsCatalogue(); var lmd = new LoadMetadata(CatalogueRepository, "Loading") { - LocationOfFlatFiles = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory),"delme", true).RootPath.FullName + LocationOfFlatFiles = LoadDirectory + .CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", true) + .RootPath.FullName }; lmd.SaveToDatabase(); @@ -53,7 +55,7 @@ public void TestPayloadInjection() var pt = new ProcessTask(CatalogueRepository, lmd, LoadStage.Mounting) { - Path = typeof (TestPayloadAttacher).FullName, + Path = typeof(TestPayloadAttacher).FullName, ProcessTaskType = ProcessTaskType.Attacher }; pt.SaveToDatabase(); @@ -62,7 +64,8 @@ public void TestPayloadInjection() var factory = new HICDataLoadFactory(lmd, config, new HICLoadConfigurationFlags(), CatalogueRepository, lm); var execution = factory.Create(new ThrowImmediatelyDataLoadEventListener()); - var proceedure = new DataLoadProcess(RepositoryLocator, lmd, null, lm, new ThrowImmediatelyDataLoadEventListener(), execution, config); + var proceedure = new DataLoadProcess(RepositoryLocator, lmd, null, lm, + new ThrowImmediatelyDataLoadEventListener(), execution, config); proceedure.Run(new GracefulCancellationToken(), payload); @@ -70,7 +73,7 @@ public void TestPayloadInjection() } - public class TestPayloadAttacher : Attacher,IPluginAttacher + public class TestPayloadAttacher : Attacher, IPluginAttacher { public TestPayloadAttacher() : base(false) { @@ -78,7 +81,7 @@ public TestPayloadAttacher() : base(false) public override ExitCodeType Attach(IDataLoadJob job, GracefulCancellationToken cancellationToken) { - job.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information, $"Found Payload:{job.Payload}")); + job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"Found Payload:{job.Payload}")); Success = ReferenceEquals(payload, job.Payload); return ExitCodeType.OperationNotRequired; @@ -86,12 +89,10 @@ public override ExitCodeType Attach(IDataLoadJob job, GracefulCancellationToken public override void Check(ICheckNotifier notifier) { - } public override void LoadCompletedSoDispose(ExitCodeType exitCode, IDataLoadEventListener postLoadEventListener) { - } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ArchiveFilesTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ArchiveFilesTests.cs index fa8496b233..58bf658353 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ArchiveFilesTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ArchiveFilesTests.cs @@ -40,11 +40,11 @@ public void TestAllFilesAreArchived() var archiveComponent = new ArchiveFiles(new HICLoadConfigurationFlags()); - var dataLoadInfo = Mock.Of(info => info.ID==1); + var dataLoadInfo = Mock.Of(info => info.ID == 1); - var LoadDirectory = Mock.Of(d => d.ForArchiving==forArchiving && d.ForLoading==forLoading); + var LoadDirectory = Mock.Of(d => d.ForArchiving == forArchiving && d.ForLoading == forLoading); - var job = Mock.Of(j => j.DataLoadInfo==dataLoadInfo); + var job = Mock.Of(j => j.DataLoadInfo == dataLoadInfo); job.LoadDirectory = LoadDirectory; try @@ -58,7 +58,8 @@ public void TestAllFilesAreArchived() // there should be two entries using (var archive = ZipFile.Open(zipFilename, ZipArchiveMode.Read)) { - Assert.AreEqual(2, archive.Entries.Count, "There should be two entries in this archive: one from the root and one from the subdirectory"); + Assert.AreEqual(2, archive.Entries.Count, + "There should be two entries in this archive: one from the root and one from the subdirectory"); Assert.IsTrue(archive.Entries.Any(entry => entry.FullName.Equals(@"subdir/subdir.txt"))); Assert.IsTrue(archive.Entries.Any(entry => entry.FullName.Equals(@"test.txt"))); } @@ -68,7 +69,7 @@ public void TestAllFilesAreArchived() directoryHelper.TearDown(); } } - + [Test] public void CreateArchiveWithNoFiles_ShouldThrow() { @@ -80,7 +81,7 @@ public void CreateArchiveWithNoFiles_ShouldThrow() var archiveFiles = new ArchiveFiles(new HICLoadConfigurationFlags()); var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "dataset"); - var job = Mock.Of(j => j.DataLoadInfo==Mock.Of()); + var job = Mock.Of(j => j.DataLoadInfo == Mock.Of()); job.LoadDirectory = loadDirectory; try @@ -90,12 +91,12 @@ public void CreateArchiveWithNoFiles_ShouldThrow() foreach (var fileInfo in loadDirectory.ForArchiving.GetFiles("*.zip")) Console.WriteLine($"About to throw SetUp because of zip file:{fileInfo.FullName}"); - Assert.IsFalse(loadDirectory.ForArchiving.GetFiles("*.zip").Any(),"There should not be any zip files in the archive directory!"); + Assert.IsFalse(loadDirectory.ForArchiving.GetFiles("*.zip").Any(), + "There should not be any zip files in the archive directory!"); } finally { directoryHelper.TearDown(); } } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ComponentCompatibilityTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ComponentCompatibilityTests.cs index d3b5c171b8..10c4d62979 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ComponentCompatibilityTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/ComponentCompatibilityTests.cs @@ -14,7 +14,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests; -public class ComponentCompatibilityTests :UnitTests +public class ComponentCompatibilityTests : UnitTests { [OneTimeSetUp] protected override void OneTimeSetUp() diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/AliasHandlerTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/AliasHandlerTests.cs index 704e98cc98..9ed89e57e6 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/AliasHandlerTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/AliasHandlerTests.cs @@ -18,7 +18,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests.Components; -public class AliasHandlerTests : DatabaseTests +public class AliasHandlerTests : DatabaseTests { private ExternalDatabaseServer _server; private AliasHandler _handler; @@ -29,8 +29,8 @@ public class AliasHandlerTests : DatabaseTests protected override void SetUp() { base.SetUp(); - - _server = new ExternalDatabaseServer(CatalogueRepository, "AliasHandlerTestsServer",null); + + _server = new ExternalDatabaseServer(CatalogueRepository, "AliasHandlerTestsServer", null); _server.SetProperties(GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); _database = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); @@ -39,7 +39,8 @@ protected override void SetUp() { con.Open(); - s.GetCommand("CREATE TABLE AliasHandlerTests (input varchar(50), alias varchar(50))", con).ExecuteNonQuery(); + s.GetCommand("CREATE TABLE AliasHandlerTests (input varchar(50), alias varchar(50))", con) + .ExecuteNonQuery(); //Two names which are aliases of the same person s.GetCommand("INSERT INTO AliasHandlerTests VALUES ('freddie','craig')", con).ExecuteNonQuery(); @@ -65,18 +66,20 @@ protected override void SetUp() }; } - [Test] public void ThrowBecause_ColumnNotInInputDataTable() { var dt = new DataTable(); - dt.Columns.Add("cannonballer");//not the same as the expected input column name - dt.Rows.Add(new object[] { "yes"}); + dt.Columns.Add("cannonballer"); //not the same as the expected input column name + dt.Rows.Add(new object[] { "yes" }); - var ex = Assert.Throws(()=>_handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken())); - Assert.AreEqual("You asked to resolve aliases on a column called 'input' but no column by that name appeared in the DataTable being processed. Columns in that table were:cannonballer", + Assert.AreEqual( + "You asked to resolve aliases on a column called 'input' but no column by that name appeared in the DataTable being processed. Columns in that table were:cannonballer", ex.Message); } @@ -94,9 +97,10 @@ public void ThrowBecause_NameAndAliasSameValue() dt.Columns.Add("input"); dt.Rows.Add(new object[] { "candle" }); - var ex = Assert.Throws(()=>_handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken())); Assert.IsTrue(ex.Message.StartsWith("Alias table SQL should only return aliases not exact matches")); - } [Test] @@ -116,7 +120,9 @@ public void ThrowBecause_ThreeColumnAliasTable() dt.Rows.Add(new object[] { "dave", 100 }); dt.Rows.Add(new object[] { "frank", 100 }); - var ex = Assert.Throws(() => _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken())); Assert.IsTrue(ex.Message.Contains("Alias table SQL resulted in 3 fields being returned")); } @@ -128,12 +134,13 @@ public void NoAliases() dt.Columns.Add("input"); dt.Columns.Add("value"); - dt.Rows.Add(new object[] {"dave", 100}); - dt.Rows.Add(new object[] {"frank", 100}); + dt.Rows.Add(new object[] { "dave", 100 }); + dt.Rows.Add(new object[] { "frank", 100 }); - var result = _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var result = _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); - Assert.AreEqual(2,result.Rows.Count); + Assert.AreEqual(2, result.Rows.Count); } @@ -143,8 +150,10 @@ public void CrashStrategy() var dt = new DataTable(); dt.Columns.Add("input"); - dt.Rows.Add(new object[] { "paul"}); - Assert.Throws(()=> _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + dt.Rows.Add(new object[] { "paul" }); + Assert.Throws(() => + _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken())); } @@ -154,25 +163,27 @@ public void ResolveTwoNameAlias() _handler.ResolutionStrategy = AliasResolutionStrategy.MultiplyInputDataRowsByAliases; var dt = new DataTable(); - dt.Columns.Add("value1",typeof(int)); + dt.Columns.Add("value1", typeof(int)); dt.Columns.Add("input"); dt.Columns.Add("value2", typeof(int)); - dt.Rows.Add(new object[] { 99,"dave", 100 }); - dt.Rows.Add(new object[] { 199,"frank", 200 }); - dt.Rows.Add(new object[] { 299,"freddie", 300 }); //has a two name alias + dt.Rows.Add(new object[] { 99, "dave", 100 }); + dt.Rows.Add(new object[] { 199, "frank", 200 }); + dt.Rows.Add(new object[] { 299, "freddie", 300 }); //has a two name alias - var result = _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var result = _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(4, result.Rows.Count); - + Assert.AreEqual(299, result.Rows[2][0]); - Assert.AreEqual("freddie", result.Rows[2][1]);//the original input row which had an alias on it + Assert.AreEqual("freddie", result.Rows[2][1]); //the original input row which had an alias on it Assert.AreEqual(300, result.Rows[2][2]); Assert.AreEqual(299, result.Rows[3][0]); - Assert.AreEqual("craig", result.Rows[3][1]);//The new row that should have appeared to resolve the freddie=craig alias - Assert.AreEqual(300, result.Rows[3][2]);//value should match the input array + Assert.AreEqual("craig", + result.Rows[3][1]); //The new row that should have appeared to resolve the freddie=craig alias + Assert.AreEqual(300, result.Rows[3][2]); //value should match the input array } [Test] @@ -185,27 +196,29 @@ public void ResolveThreeNameAlias() dt.Columns.Add("input"); dt.Columns.Add("value2", typeof(int)); - dt.Rows.Add(new object[] { 99, "pepey", 100 });//has a three name alias + dt.Rows.Add(new object[] { 99, "pepey", 100 }); //has a three name alias dt.Rows.Add(new object[] { 199, "frank", 200 }); dt.Rows.Add(new object[] { 299, "anderson", 300 }); - var result = _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var result = _handler.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(5, result.Rows.Count); Assert.AreEqual(99, result.Rows[0][0]); - Assert.AreEqual("pepey", result.Rows[0][1]);//the original input row which had an alias on it + Assert.AreEqual("pepey", result.Rows[0][1]); //the original input row which had an alias on it Assert.AreEqual(100, result.Rows[0][2]); //new rows are added at the end of the DataTable Assert.AreEqual(99, result.Rows[3][0]); - Assert.AreEqual("paul", result.Rows[3][1]);//The new row that should have appeared to resolve the pepey=paul=peter alias - Assert.AreEqual(100, result.Rows[3][2]);//value should match the input array + Assert.AreEqual("paul", + result.Rows[3][1]); //The new row that should have appeared to resolve the pepey=paul=peter alias + Assert.AreEqual(100, result.Rows[3][2]); //value should match the input array Assert.AreEqual(99, result.Rows[4][0]); - Assert.AreEqual("peter", result.Rows[4][1]);//The new row that should have appeared to resolve the pepey=paul=peter alias - Assert.AreEqual(100, result.Rows[4][2]);//value should match the input array + Assert.AreEqual("peter", + result.Rows[4][1]); //The new row that should have appeared to resolve the pepey=paul=peter alias + Assert.AreEqual(100, result.Rows[4][2]); //value should match the input array } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/ColumnSwapperTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/ColumnSwapperTests.cs index 491517ac7c..040787e6f6 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/ColumnSwapperTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/ColumnSwapperTests.cs @@ -25,7 +25,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests.Components; -internal class ColumnSwapperTests:DatabaseTests +internal class ColumnSwapperTests : DatabaseTests { [TestCase(true)] [TestCase(false)] @@ -39,11 +39,12 @@ public void TestColumnSwapper_NormalUseCase(bool keepInputColumnToo) dt.Rows.Add("B", 2); dt.Rows.Add("C", 3); dt.Rows.Add("D", 4); - dt.Rows.Add("D", 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter + dt.Rows.Add("D", + 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); - - Import(db.CreateTable("Map", dt),out var map, out var mapCols); + + Import(db.CreateTable("Map", dt), out var map, out var mapCols); var swapper = new ColumnSwapper { @@ -64,7 +65,8 @@ public void TestColumnSwapper_NormalUseCase(bool keepInputColumnToo) dtToSwap.Rows.Add("A", "Dave", 30); dtToSwap.Rows.Add("B", "Frank", 50); - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); //in should be there or not depending on the setting KeepInputColumnToo Assert.AreEqual(keepInputColumnToo, resultDt.Columns.Contains("In")); @@ -98,7 +100,8 @@ public void TestColumnSwapper_AlternateColumnNames(bool keepInputColumnToo) dtMap.Rows.Add("B", 2); dtMap.Rows.Add("C", 3); dtMap.Rows.Add("D", 4); - dtMap.Rows.Add("D", 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter + dtMap.Rows.Add("D", + 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -124,14 +127,16 @@ public void TestColumnSwapper_AlternateColumnNames(bool keepInputColumnToo) dtToSwap.Rows.Add("B", "Frank", 50); // Our pipeline data does not have a column called In but instead it is called In2 - var ex = Assert.Throws(() => swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => swapper.ProcessPipelineData(dtToSwap, + new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); Assert.AreEqual("DataTable did not contain a field called 'In'", ex.Message); - + // Tell the swapper about the new name swapper.InputFromColumn = "In2"; swapper.OutputToColumn = "Out2"; - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); //in should be there or not depending on the setting KeepInputColumnToo Assert.AreEqual(keepInputColumnToo, resultDt.Columns.Contains("In2")); @@ -166,7 +171,8 @@ public void TestColumnSwapper_InPlaceSwapNoNewCols(bool keepInputColumnToo) dtMap.Rows.Add("B", 2); dtMap.Rows.Add("C", 3); dtMap.Rows.Add("D", 4); - dtMap.Rows.Add("D", 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter + dtMap.Rows.Add("D", + 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -195,7 +201,8 @@ public void TestColumnSwapper_InPlaceSwapNoNewCols(bool keepInputColumnToo) swapper.InputFromColumn = "In2"; swapper.OutputToColumn = "In2"; - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); // in ALWAYS be there, because it is an in place update - ignore KeepInputColumnToo Assert.True(resultDt.Columns.Contains("In2")); @@ -222,7 +229,8 @@ public void TestColumnSwapper_Aliases(AliasResolutionStrategy strategy) dt.Rows.Add("B", 2); dt.Rows.Add("C", 3); dt.Rows.Add("D", 4); - dt.Rows.Add("D", 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter + dt.Rows.Add("D", + 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -249,15 +257,17 @@ public void TestColumnSwapper_Aliases(AliasResolutionStrategy strategy) switch (strategy) { case AliasResolutionStrategy.CrashIfAliasesFound: - Assert.Throws(()=>swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + Assert.Throws(() => swapper.ProcessPipelineData(dtToSwap, + new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); break; case AliasResolutionStrategy.MultiplyInputDataRowsByAliases: - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); AreBasicallyEquals(1, resultDt.Rows[0]["Out"]); Assert.AreEqual("Dave", resultDt.Rows[0]["Name"]); - + //we get the first alias (4) AreBasicallyEquals(4, resultDt.Rows[1]["Out"]); Assert.AreEqual("Dandy", resultDt.Rows[1]["Name"]); @@ -271,7 +281,6 @@ public void TestColumnSwapper_Aliases(AliasResolutionStrategy strategy) default: throw new ArgumentOutOfRangeException(nameof(strategy)); } - } [TestCase(true)] @@ -286,7 +295,8 @@ public void TestColumnSwapper_MissingMappings(bool crashIfNoMappingsFound) dt.Rows.Add("B", 2); dt.Rows.Add("C", 3); dt.Rows.Add("D", 4); - dt.Rows.Add("D", 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter + dt.Rows.Add("D", + 5); //oh dear D maps to 2 out values that's a violation! but if we don't see a D it doesn't matter var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -311,11 +321,15 @@ public void TestColumnSwapper_MissingMappings(bool crashIfNoMappingsFound) dtToSwap.Rows.Add("A", "Dave", 30); dtToSwap.Rows.Add("B", "Frank", 50); - if(crashIfNoMappingsFound) - Assert.Throws(() => swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), null)); + if (crashIfNoMappingsFound) + { + Assert.Throws(() => + swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), null)); + } else { - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(1, resultDt.Rows.Count); AreBasicallyEquals(1, resultDt.Rows[0]["Out"]); @@ -332,10 +346,10 @@ public void TestColumnSwapper_ProjectSpecificMappings() dt.Columns.Add("Proj"); //Anonymise A and B differently depending on ProjectNumber (valid project numbers are 1 and 2) - dt.Rows.Add("A", 1,1); - dt.Rows.Add("A", 2,2); - dt.Rows.Add("B", 3,1); - dt.Rows.Add("B", 4,2); + dt.Rows.Add("A", 1, 1); + dt.Rows.Add("A", 2, 2); + dt.Rows.Add("B", 3, 1); + dt.Rows.Add("B", 4, 2); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); @@ -362,7 +376,8 @@ public void TestColumnSwapper_ProjectSpecificMappings() dtToSwap.Rows.Add("A", "Dave", 30); dtToSwap.Rows.Add("B", "Frank", 50); - using var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + using var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(2, resultDt.Rows.Count); @@ -387,7 +402,7 @@ public void TestColumnSwapper_InputTableNulls() dt.Rows.Add(2, 2); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); - + Import(db.CreateTable("Map", dt), out var map, out var mapCols); var swapper = new ColumnSwapper @@ -400,24 +415,24 @@ public void TestColumnSwapper_InputTableNulls() using var dtToSwap = new DataTable(); - dtToSwap.Columns.Add("In",typeof(int)); + dtToSwap.Columns.Add("In", typeof(int)); dtToSwap.Columns.Add("Name"); dtToSwap.Columns.Add("Age"); dtToSwap.Rows.Add(1, "Dave", 30); dtToSwap.Rows.Add(null, "Bob", 30); - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(2, resultDt.Rows.Count); AreBasicallyEquals(1, resultDt.Rows[0]["Out"]); Assert.AreEqual("Dave", resultDt.Rows[0]["Name"]); - + AreBasicallyEquals(DBNull.Value, resultDt.Rows[1]["Out"]); Assert.AreEqual("Bob", resultDt.Rows[1]["Name"]); - - } + /// /// Tests ColumnSwapper when there are null values in the database mapping table /// @@ -446,7 +461,7 @@ public void TestColumnSwapper_MappingTableNulls() using var dtToSwap = new DataTable(); - dtToSwap.Columns.Add("In",typeof(int)); + dtToSwap.Columns.Add("In", typeof(int)); dtToSwap.Columns.Add("Name"); dtToSwap.Columns.Add("Age"); @@ -455,18 +470,20 @@ public void TestColumnSwapper_MappingTableNulls() var toMem = new ToMemoryDataLoadEventListener(true); - var resultDt = swapper.ProcessPipelineData(dtToSwap,toMem , new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, toMem, new GracefulCancellationToken()); //this is the primary thing we are testing here - Assert.Contains("Discarded 1 Null key values read from mapping table",toMem.GetAllMessagesByProgressEventType()[ProgressEventType.Warning].Select(m=>m.Message).ToArray()); + Assert.Contains("Discarded 1 Null key values read from mapping table", + toMem.GetAllMessagesByProgressEventType()[ProgressEventType.Warning].Select(m => m.Message).ToArray()); Assert.AreEqual(2, resultDt.Rows.Count); AreBasicallyEquals(1, resultDt.Rows[0]["Out"]); Assert.AreEqual("Dave", resultDt.Rows[0]["Name"]); - + AreBasicallyEquals(DBNull.Value, resultDt.Rows[1]["Out"]); Assert.AreEqual("Bob", resultDt.Rows[1]["Name"]); } + /// /// Tests the systems ability to compare an integer in the input data table with a string in the database /// @@ -488,7 +505,8 @@ public void TestColumnSwapper_MixedDatatypes_StringInDatabase() Import(mapTbl = db.CreateTable("Map", dt), out var map, out var mapCols); - Assert.AreEqual(typeof(string),mapTbl.DiscoverColumn("In").DataType.GetCSharpDataType(), "Expected map to be of string datatype"); + Assert.AreEqual(typeof(string), mapTbl.DiscoverColumn("In").DataType.GetCSharpDataType(), + "Expected map to be of string datatype"); var swapper = new ColumnSwapper { @@ -504,14 +522,15 @@ public void TestColumnSwapper_MixedDatatypes_StringInDatabase() dtToSwap.Columns.Add("Name"); dtToSwap.Rows.Add(1 /*int*/, "Dave"); - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(1, resultDt.Rows.Count); AreBasicallyEquals(2, resultDt.Rows[0]["Out"]); Assert.AreEqual("Dave", resultDt.Rows[0]["Name"]); } - + /// /// Tests the systems ability to compare a string input data table with an integer in the database /// @@ -527,12 +546,13 @@ public void TestColumnSwapper_MixedDatatypes_IntegerInDatabase() dt.Rows.Add(3, 4); var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer); - + DiscoveredTable mapTbl; Import(mapTbl = db.CreateTable("Map", dt), out var map, out var mapCols); - Assert.AreEqual(typeof(int),mapTbl.DiscoverColumn("In").DataType.GetCSharpDataType(), "Expected map to be of int datatype"); + Assert.AreEqual(typeof(int), mapTbl.DiscoverColumn("In").DataType.GetCSharpDataType(), + "Expected map to be of int datatype"); var swapper = new ColumnSwapper { @@ -548,7 +568,8 @@ public void TestColumnSwapper_MixedDatatypes_IntegerInDatabase() dtToSwap.Columns.Add("Name"); dtToSwap.Rows.Add("1" /*string*/, "Dave"); - var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var resultDt = swapper.ProcessPipelineData(dtToSwap, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(1, resultDt.Rows.Count); AreBasicallyEquals(2, resultDt.Rows[0]["Out"]); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/RemoveDuplicatesTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/RemoveDuplicatesTests.cs index 84fe664247..9a13e8b637 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/RemoveDuplicatesTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/RemoveDuplicatesTests.cs @@ -20,15 +20,15 @@ public void TestRemovingDuplicatesFromDataTable() { var dt = new DataTable(); dt.Columns.Add("Col1"); - dt.Columns.Add("Col2",typeof(int)); + dt.Columns.Add("Col2", typeof(int)); dt.Rows.Add("Fish", 123); dt.Rows.Add("Fish", 123); dt.Rows.Add("Fish", 123); - Assert.AreEqual(3,dt.Rows.Count); - - + Assert.AreEqual(3, dt.Rows.Count); + + Assert.AreEqual(123, dt.Rows[0]["Col2"]); var receiver = new ToMemoryDataLoadEventListener(true); @@ -36,7 +36,7 @@ public void TestRemovingDuplicatesFromDataTable() var result = new RemoveDuplicates().ProcessPipelineData(dt, receiver, new GracefulCancellationToken()); //should have told us that it processed 3 rows - Assert.AreEqual(3,receiver.LastProgressRecieivedByTaskName["Evaluating For Duplicates"].Progress.Value); + Assert.AreEqual(3, receiver.LastProgressRecieivedByTaskName["Evaluating For Duplicates"].Progress.Value); //and discarded 2 of them as duplicates Assert.AreEqual(2, receiver.LastProgressRecieivedByTaskName["Discarding Duplicates"].Progress.Value); @@ -49,7 +49,9 @@ public void TestRemovingDuplicatesFromDataTable() [Test] public void TestEmptyDataTable() { - Assert.AreEqual(0,new RemoveDuplicates().ProcessPipelineData(new DataTable(),new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()).Rows.Count); + Assert.AreEqual(0, + new RemoveDuplicates().ProcessPipelineData(new DataTable(), new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()).Rows.Count); } [Test] @@ -71,13 +73,17 @@ public void TestMultipleBatches() dt2.Rows.Add("Haddock", 123); - var remover = new RemoveDuplicates(); + var remover = new RemoveDuplicates(); //send it the batch with the duplication it will return 1 row - Assert.AreEqual(1,remover.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count); + Assert.AreEqual(1, + remover.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()).Rows.Count); //now send it the second batch which contains 2 records, one duplication against first batch and one new one, expect only 1 row to come back - Assert.AreEqual(1, remover.ProcessPipelineData(dt2, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count); + Assert.AreEqual(1, + remover.ProcessPipelineData(dt2, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()).Rows.Count); } [Test] @@ -96,11 +102,11 @@ public void TestNulls() var remover = new RemoveDuplicates(); - Assert.AreEqual(6,dt.Rows.Count); + Assert.AreEqual(6, dt.Rows.Count); //send it the batch with the duplication it will return 5 rows (the only duplicate is the double null) - Assert.AreEqual(5, remover.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count); - - + Assert.AreEqual(5, + remover.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()).Rows.Count); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/TransposerTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/TransposerTests.cs index ecd41bc70e..c310515340 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/TransposerTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Components/TransposerTests.cs @@ -37,15 +37,20 @@ public void TransposerTest_ThrowOnDualBatches() { var transposer = new Transposer(); transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); - var ex = Assert.Throws(()=>transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); - Assert.AreEqual("Error, we received multiple batches, Transposer only works when all the data arrives in a single DataTable",ex.Message); + var ex = Assert.Throws(() => + transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); + Assert.AreEqual( + "Error, we received multiple batches, Transposer only works when all the data arrives in a single DataTable", + ex.Message); } [Test] public void TransposerTest_ThrowOnEmptyDataTable() { var transposer = new Transposer(); - var ex = Assert.Throws(()=>transposer.ProcessPipelineData(new DataTable(), new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + transposer.ProcessPipelineData(new DataTable(), new ThrowImmediatelyDataLoadJob(), + new GracefulCancellationToken())); Assert.AreEqual("DataTable toProcess had 0 rows and 0 columns, thus it cannot be transposed", ex.Message); } @@ -54,7 +59,8 @@ public void TransposerTest_ThrowOnEmptyDataTable() public void TransposerTest_TableTransposed() { var transposer = new Transposer(); - var actual = transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); + var actual = + transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); var expectedResult = new DataTable(); @@ -73,24 +79,22 @@ public void TransposerTest_TableTransposed() for (var i = 0; i < expectedResult.Rows.Count; i++) for (var j = 0; j < actual.Columns.Count; j++) Assert.AreEqual(expectedResult.Rows[i][j], actual.Rows[i][j]); - } [Test] public void TestTransposerDodgyHeaders() { - var dr = dt.Rows.Add("32 GramMax", "55", "0", "5"); var transposer = new Transposer { MakeHeaderNamesSane = true }; - var actual = transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); - + var actual = + transposer.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); + Assert.IsTrue(actual.Columns.Contains("_32GramMax")); dt.Rows.Remove(dr); - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineArgumentTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineArgumentTests.cs index 7352259a32..11fee3a17c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineArgumentTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineArgumentTests.cs @@ -11,41 +11,38 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests; -public class PipelineArgumentTests:DatabaseTests +public class PipelineArgumentTests : DatabaseTests { [Test] - [TestCase(typeof(int?),null)] + [TestCase(typeof(int?), null)] [TestCase(typeof(float?), null)] [TestCase(typeof(double?), null)] [TestCase(typeof(char?), null)] [TestCase(typeof(DateTime?), null)] - - [TestCase(typeof(int?), 3)] [TestCase(typeof(float?), 10.01f)] [TestCase(typeof(double?), 10.999)] [TestCase(typeof(char?), 'K')] [TestCase(typeof(DateTime?), "now")] //sadly can't pass DateTime.Now - - public void TestIArgumentsForNullableTypes(Type nullableType,object value) + public void TestIArgumentsForNullableTypes(Type nullableType, object value) { if (string.Equals(value as string, "now")) //sadly can't pass DateTime.Now - value = new DateTime(2001, 01, 01, 3, 20, 11); //hey btw when you put in milliseconds into DateTime IArgument it drops them... due to DateTime.Parse? or DateTime.ToString()? + value = new DateTime(2001, 01, 01, 3, 20, + 11); //hey btw when you put in milliseconds into DateTime IArgument it drops them... due to DateTime.Parse? or DateTime.ToString()? var p = new Pipeline(CatalogueRepository); - var pc = new PipelineComponent(CatalogueRepository,p, + var pc = new PipelineComponent(CatalogueRepository, p, GetType() //Normally this would be the PipelineComponent hosted class which would be a proper class declared as a MEF export with DemandsInitialization etc but we don't need all that - ,0 - ,"My imaginary Pipe Component"); - var arg = new PipelineComponentArgument(CatalogueRepository,pc); + , 0 + , "My imaginary Pipe Component"); + var arg = new PipelineComponentArgument(CatalogueRepository, pc); try { arg.SetType(nullableType); arg.SetValue(value); - Assert.AreEqual(nullableType,arg.GetSystemType()); - Assert.AreEqual(value,arg.GetValueAsSystemType()); - + Assert.AreEqual(nullableType, arg.GetSystemType()); + Assert.AreEqual(value, arg.GetValueAsSystemType()); } finally { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineReadPerformanceTest.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineReadPerformanceTest.cs index b8c9744f9e..492eab2387 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineReadPerformanceTest.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/PipelineReadPerformanceTest.cs @@ -12,10 +12,10 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests; -public class PipelineReadPerformanceTest:DatabaseTests +public class PipelineReadPerformanceTest : DatabaseTests { private BulkTestsData _bulkTestData; - + [OneTimeSetUp] protected override void OneTimeSetUp() { @@ -23,9 +23,8 @@ protected override void OneTimeSetUp() _bulkTestData = new BulkTestsData(CatalogueRepository, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); _bulkTestData.SetupTestData(); - } - + [Test] public void BulkTestDataContainsExpectedNumberOfRows() { @@ -38,7 +37,7 @@ public void BulkTestDataContainsExpectedNumberOfRows() var manualCount = Convert.ToInt32(cmd.ExecuteScalar()); //manual count matches expected - Assert.AreEqual(_bulkTestData.ExpectedNumberOfRowsInTestData,manualCount); + Assert.AreEqual(_bulkTestData.ExpectedNumberOfRowsInTestData, manualCount); //now get the fast approximate rowcount var fastRowcount = _bulkTestData.BulkDataDatabase @@ -46,7 +45,7 @@ public void BulkTestDataContainsExpectedNumberOfRows() .GetRowCount(); //it should also match - Assert.AreEqual(_bulkTestData.ExpectedNumberOfRowsInTestData,fastRowcount); + Assert.AreEqual(_bulkTestData.ExpectedNumberOfRowsInTestData, fastRowcount); } } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests.cs index a7e5945661..f7b50a6bcd 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests.cs @@ -30,7 +30,7 @@ public void SetUp() { filename = Path.Combine(TestContext.CurrentContext.TestDirectory, "DelimitedFileSourceTests.txt"); - if(File.Exists(filename)) + if (File.Exists(filename)) File.Delete(filename); var sb = new StringBuilder(); @@ -45,18 +45,22 @@ public void SetUp() public void FileToLoadNotSet_Throws() { var source = new DelimitedFlatFileDataFlowSource(); - var ex = Assert.Throws(()=>source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); - StringAssert.Contains("_fileToLoad was not set",ex.Message); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + StringAssert.Contains("_fileToLoad was not set", ex.Message); } + [Test] public void SeparatorNotSet_Throws() { var testFile = new FileInfo(filename); var source = new DelimitedFlatFileDataFlowSource(); - source.PreInitialize(new FlatFileToLoad(testFile),new ThrowImmediatelyDataLoadEventListener() ); - var ex = Assert.Throws(()=>source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + source.PreInitialize(new FlatFileToLoad(testFile), new ThrowImmediatelyDataLoadEventListener()); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); StringAssert.Contains("Separator has not been set", ex.Message); } + [Test] public void LoadCSVWithCorrectDatatypes_ForceHeadersWhitespace() { @@ -67,7 +71,7 @@ public void LoadCSVWithCorrectDatatypes_ForceHeadersWhitespace() source.Separator = ","; source.ForceHeaders = "chi ,Study ID\t ,Date"; source.ForceHeadersReplacesFirstLineInFile = true; - source.StronglyTypeInput = true;//makes the source interpret the file types properly + source.StronglyTypeInput = true; //makes the source interpret the file types properly var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); @@ -75,26 +79,28 @@ public void LoadCSVWithCorrectDatatypes_ForceHeadersWhitespace() $"Resulting columns were:{string.Join(",", chunk.Columns.Cast().Select(c => c.ColumnName))}"); Assert.IsTrue(chunk.Columns.Contains("chi")); //notice the lack of whitespace! - Assert.IsTrue(chunk.Columns.Contains("study ID")); //whitespace is allowed in the middle though... because we like a challenge! + Assert.IsTrue( + chunk.Columns + .Contains("study ID")); //whitespace is allowed in the middle though... because we like a challenge! - Assert.AreEqual(3,chunk.Columns.Count); + Assert.AreEqual(3, chunk.Columns.Count); Assert.AreEqual(1, chunk.Rows.Count); Assert.AreEqual("0101010101", chunk.Rows[0][0]); Assert.AreEqual(5, chunk.Rows[0][1]); - Assert.AreEqual(new DateTime(2001 , 1 , 5), chunk.Rows[0][2]);//notice the strong typing (we are not looking for strings here) - + Assert.AreEqual(new DateTime(2001, 1, 5), + chunk.Rows[0][2]); //notice the strong typing (we are not looking for strings here) + source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); } [Test] public void LoadCSVWithCorrectDatatypes_DatatypesAreCorrect() { - var testFile = new FileInfo(filename); var source = new DelimitedFlatFileDataFlowSource(); source.PreInitialize(new FlatFileToLoad(testFile), new ThrowImmediatelyDataLoadEventListener()); source.Separator = ","; - source.StronglyTypeInput = true;//makes the source interpret the file types properly + source.StronglyTypeInput = true; //makes the source interpret the file types properly var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); @@ -102,22 +108,23 @@ public void LoadCSVWithCorrectDatatypes_DatatypesAreCorrect() Assert.AreEqual(1, chunk.Rows.Count); Assert.AreEqual("0101010101", chunk.Rows[0][0]); Assert.AreEqual(5, chunk.Rows[0][1]); - Assert.AreEqual(new DateTime(2001, 1, 5), chunk.Rows[0][2]);//notice the strong typing (we are not looking for strings here) + Assert.AreEqual(new DateTime(2001, 1, 5), + chunk.Rows[0][2]); //notice the strong typing (we are not looking for strings here) source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); } + [Test] public void OverrideDatatypes_ForcedFreakyTypesCorrect() { - var testFile = new FileInfo(filename); var source = new DelimitedFlatFileDataFlowSource(); source.PreInitialize(new FlatFileToLoad(testFile), new ThrowImmediatelyDataLoadEventListener()); source.Separator = ","; - source.StronglyTypeInput = true;//makes the source interpret the file types properly - + source.StronglyTypeInput = true; //makes the source interpret the file types properly + source.ExplicitlyTypedColumns = new ExplicitTypingCollection(); - source.ExplicitlyTypedColumns.ExplicitTypesCSharp.Add("StudyID",typeof(string)); + source.ExplicitlyTypedColumns.ExplicitTypesCSharp.Add("StudyID", typeof(string)); //preview should be correct var preview = source.TryGetPreview(); @@ -154,14 +161,14 @@ public void TestIgnoreQuotes() source.Separator = ","; source.IgnoreQuotes = true; source.MaxBatchSize = 10000; - source.StronglyTypeInput = true;//makes the source interpret the file types properly + source.StronglyTypeInput = true; //makes the source interpret the file types properly var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.AreEqual(3, dt.Rows.Count); Assert.AreEqual("\"Sick\" headaches", dt.Rows[0][1]); Assert.AreEqual("2\" length of wood", dt.Rows[1][1]); Assert.AreEqual("\"\"The bends\"\"", dt.Rows[2][1]); - source.Dispose(new ThrowImmediatelyDataLoadEventListener(),null); + source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); } @@ -191,29 +198,33 @@ public void BadDataTestExtraColumns(BadDataHandlingStrategy strategy) source.MaxBatchSize = 10000; - source.StronglyTypeInput = true;//makes the source interpret the file types properly + source.StronglyTypeInput = true; //makes the source interpret the file types properly source.BadDataHandlingStrategy = strategy; try { switch (strategy) { case BadDataHandlingStrategy.ThrowException: - var ex = Assert.Throws(() => source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); - StringAssert.Contains("line 4",ex.Message); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + StringAssert.Contains("line 4", ex.Message); break; case BadDataHandlingStrategy.IgnoreRows: - var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.IsNotNull(dt); - Assert.AreEqual(4,dt.Rows.Count); + Assert.AreEqual(4, dt.Rows.Count); break; case BadDataHandlingStrategy.DivertRows: - var dt2 = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var dt2 = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(4, dt2.Rows.Count); Assert.IsNotNull(source.EventHandlers.DivertErrorsFile); - Assert.AreEqual($"0101010101,5,2001-01-05,fish,watafak{Environment.NewLine}", File.ReadAllText(source.EventHandlers.DivertErrorsFile.FullName)); + Assert.AreEqual($"0101010101,5,2001-01-05,fish,watafak{Environment.NewLine}", + File.ReadAllText(source.EventHandlers.DivertErrorsFile.FullName)); break; default: @@ -222,9 +233,8 @@ public void BadDataTestExtraColumns(BadDataHandlingStrategy strategy) } finally { - source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); + source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); } - } [Test] @@ -236,7 +246,8 @@ public void DelimitedFlatFileDataFlowSource_ProperQuoteEscaping() var sb = new StringBuilder(); sb.AppendLine("CHI,Name,SomeInterestingFacts,Date"); sb.AppendLine("0101010101,Dave,Dave is over 1000 years old,2001-01-05"); - sb.AppendLine("0101010101,Dave,\"Dave is \"\"over\"\" 1000 years old\",2001-01-05"); //https://tools.ietf.org/html/rfc4180 (to properly include quotes in escaped text you need to use "") + sb.AppendLine( + "0101010101,Dave,\"Dave is \"\"over\"\" 1000 years old\",2001-01-05"); //https://tools.ietf.org/html/rfc4180 (to properly include quotes in escaped text you need to use "") File.WriteAllText(filename, sb.ToString()); @@ -300,10 +311,11 @@ public void DelimitedFlatFileDataFlowSource_LoadDataWithQuotesInMiddle_IgnoreBad try { var chunk = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); - Assert.AreEqual(5,chunk.Rows.Count); + Assert.AreEqual(5, chunk.Rows.Count); Assert.AreEqual("Dave is \"over\" 1000 years old", chunk.Rows[1][2]); Assert.AreEqual($"Dave is {Environment.NewLine}over 1000 years old", chunk.Rows[2][2]); - Assert.AreEqual("Dave is over\" 1000 years old\"", chunk.Rows[3][2]); //notice this line drops some of the quotes, we just have to live with that + Assert.AreEqual("Dave is over\" 1000 years old\"", + chunk.Rows[3][2]); //notice this line drops some of the quotes, we just have to live with that } finally { @@ -343,9 +355,9 @@ public void DelimitedFlatFileDataFlowSource_TrashFile_IgnoreBadReads() try { - var ex = Assert.Throws(()=>source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); Assert.AreEqual("Bad data found on line 3", ex.Message); - } finally { @@ -382,7 +394,8 @@ public void DelimitedFlatFileDataFlowSource_LoadDataWithQuotesInMiddle_WithMulti source.BadDataHandlingStrategy = BadDataHandlingStrategy.ThrowException; try { - var ex = Assert.Throws(() => source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); Assert.AreEqual("Bad data found on line 3", ex.Message); } finally @@ -419,29 +432,33 @@ public void BadDataTestExtraColumns_ErrorIsOnLastLine(BadDataHandlingStrategy st source.MaxBatchSize = 10000; - source.StronglyTypeInput = true;//makes the source interpret the file types properly + source.StronglyTypeInput = true; //makes the source interpret the file types properly source.BadDataHandlingStrategy = strategy; try { switch (strategy) { case BadDataHandlingStrategy.ThrowException: - var ex = Assert.Throws(() => source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); StringAssert.Contains("line 6", ex.Message); break; case BadDataHandlingStrategy.IgnoreRows: - var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.IsNotNull(dt); Assert.AreEqual(4, dt.Rows.Count); break; case BadDataHandlingStrategy.DivertRows: - var dt2 = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var dt2 = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(4, dt2.Rows.Count); Assert.IsNotNull(source.EventHandlers.DivertErrorsFile); - Assert.AreEqual($"0101010101,5,2001-01-05,fish,watafak{Environment.NewLine}", File.ReadAllText(source.EventHandlers.DivertErrorsFile.FullName)); + Assert.AreEqual($"0101010101,5,2001-01-05,fish,watafak{Environment.NewLine}", + File.ReadAllText(source.EventHandlers.DivertErrorsFile.FullName)); break; default: @@ -451,7 +468,7 @@ public void BadDataTestExtraColumns_ErrorIsOnLastLine(BadDataHandlingStrategy st finally { source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); - } + } } [Test] @@ -478,16 +495,15 @@ public void NewLinesInConstantString_EscapedCorrectly() source.Separator = ","; source.MaxBatchSize = 10000; - source.StronglyTypeInput = true;//makes the source interpret the file types properly - + source.StronglyTypeInput = true; //makes the source interpret the file types properly + try { var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.IsNotNull(dt); Assert.AreEqual(5, dt.Rows.Count); Assert.AreEqual(@"5 - The first",dt.Rows[0][1]); - + The first", dt.Rows[0][1]); } finally { @@ -521,24 +537,27 @@ public void NewLinesInConstantString_NotEscaped(BadDataHandlingStrategy strategy source.Separator = ","; source.MaxBatchSize = 10000; - source.StronglyTypeInput = true;//makes the source interpret the file types properly + source.StronglyTypeInput = true; //makes the source interpret the file types properly source.BadDataHandlingStrategy = strategy; try { switch (strategy) { case BadDataHandlingStrategy.ThrowException: - var ex = Assert.Throws(() => source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); + var ex = Assert.Throws(() => + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken())); StringAssert.Contains("line 2", ex.Message); break; case BadDataHandlingStrategy.IgnoreRows: - var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.IsNotNull(dt); Assert.AreEqual(4, dt.Rows.Count); break; case BadDataHandlingStrategy.DivertRows: - var dt2 = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); + var dt2 = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), + new GracefulCancellationToken()); Assert.AreEqual(4, dt2.Rows.Count); Assert.IsNotNull(source.EventHandlers.DivertErrorsFile); @@ -555,9 +574,9 @@ public void NewLinesInConstantString_NotEscaped(BadDataHandlingStrategy strategy finally { source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); - } + } } - + [Test] public void OverrideHeadersAndTab() @@ -568,14 +587,15 @@ public void OverrideHeadersAndTab() var sb = new StringBuilder(); sb.AppendLine("0101010101\t5\t2001-01-05"); sb.AppendLine("0101010101\t5\t2001-01-05"); - File.WriteAllText(filename,sb.ToString()); + File.WriteAllText(filename, sb.ToString()); var testFile = new FileInfo(filename); var source = new DelimitedFlatFileDataFlowSource(); source.PreInitialize(new FlatFileToLoad(testFile), new ThrowImmediatelyDataLoadEventListener()); - source.Separator = "\\t"; //<-- Important this is the string value SLASH T not an actual escaped tab as C# understands it. This reflects the user pressing slash and t on his keyboard for the Separator argument in the UI + source.Separator = + "\\t"; //<-- Important this is the string value SLASH T not an actual escaped tab as C# understands it. This reflects the user pressing slash and t on his keyboard for the Separator argument in the UI source.ForceHeaders = "CHI\tStudyID\tDate"; source.MaxBatchSize = 10000; @@ -583,13 +603,13 @@ public void OverrideHeadersAndTab() Assert.NotNull(dt); - Assert.AreEqual(3,dt.Columns.Count); + Assert.AreEqual(3, dt.Columns.Count); Assert.AreEqual("CHI", dt.Columns[0].ColumnName); Assert.AreEqual("StudyID", dt.Columns[1].ColumnName); Assert.AreEqual("Date", dt.Columns[2].ColumnName); - Assert.AreEqual(2,dt.Rows.Count); + Assert.AreEqual(2, dt.Rows.Count); source.Dispose(new ThrowImmediatelyDataLoadJob(), null); @@ -611,7 +631,8 @@ public void Test_IgnoreColumns() var source = new DelimitedFlatFileDataFlowSource(); source.PreInitialize(new FlatFileToLoad(testFile), new ThrowImmediatelyDataLoadEventListener()); - source.Separator = "\\t"; //<-- Important this is the string value SLASH T not an actual escaped tab as C# understands it. This reflects the user pressing slash and t on his keyboard for the Separator argument in the UI + source.Separator = + "\\t"; //<-- Important this is the string value SLASH T not an actual escaped tab as C# understands it. This reflects the user pressing slash and t on his keyboard for the Separator argument in the UI source.ForceHeaders = "CHI\tStudyID\tDate\tSomeText"; source.MaxBatchSize = 10000; source.IgnoreColumns = "StudyID\tDate\t"; @@ -630,25 +651,28 @@ public void Test_IgnoreColumns() source.Dispose(new ThrowImmediatelyDataLoadJob(), null); File.Delete(filename); - } [TestCase("Fish In Barrel", "FishInBarrel")] - [TestCase("32 Fish In Barrel","_32FishInBarrel")]//Column names can't start with numbers so underscore prefix applies - [TestCase("once upon a time","onceUponATime")]//where spaces are removed cammel case the next symbol if it's a character - [TestCase("once _ upon a time", "once_UponATime")]//where spaces are removed cammel case the next symbol if it's a character + [TestCase("32 Fish In Barrel", + "_32FishInBarrel")] //Column names can't start with numbers so underscore prefix applies + [TestCase("once upon a time", + "onceUponATime")] //where spaces are removed cammel case the next symbol if it's a character + [TestCase("once _ upon a time", + "once_UponATime")] //where spaces are removed cammel case the next symbol if it's a character [TestCase("once#upon a", "onceuponA")] - [TestCase("once #upon", "onceUpon")] //Dodgy characters are stripped before cammel casing after spaces so 'u' gets cammeled even though it has a symbol before it. + [TestCase("once #upon", + "onceUpon")] //Dodgy characters are stripped before cammel casing after spaces so 'u' gets cammeled even though it has a symbol before it. public void TestMakingHeaderNamesSane(string bad, string expectedGood) { - Assert.AreEqual(expectedGood,QuerySyntaxHelper.MakeHeaderNameSensible(bad)); + Assert.AreEqual(expectedGood, QuerySyntaxHelper.MakeHeaderNameSensible(bad)); } [Test] public void Test_ScientificNotation_StronglyTyped() { - var f = Path.Combine(TestContext.CurrentContext.WorkDirectory,"meee.csv"); + var f = Path.Combine(TestContext.CurrentContext.WorkDirectory, "meee.csv"); var sb = new StringBuilder(); @@ -658,13 +682,13 @@ public void Test_ScientificNotation_StronglyTyped() sb.AppendLine("-4.10235746055587E-05"); //500 lines of random stuff to force 2 batches - for (var i =0;i< DelimitedFlatFileDataFlowSource.MinimumStronglyTypeInputBatchSize; i++) + for (var i = 0; i < DelimitedFlatFileDataFlowSource.MinimumStronglyTypeInputBatchSize; i++) sb.AppendLine("5"); //a scientific notation in batch 2 sb.AppendLine("-4.10235746055587E-05"); - File.WriteAllText(f,sb.ToString()); + File.WriteAllText(f, sb.ToString()); var source = new DelimitedFlatFileDataFlowSource(); source.PreInitialize(new FlatFileToLoad(new FileInfo(f)), new ThrowImmediatelyDataLoadEventListener()); @@ -673,14 +697,14 @@ public void Test_ScientificNotation_StronglyTyped() source.StronglyTypeInputBatchSize = DelimitedFlatFileDataFlowSource.MinimumStronglyTypeInputBatchSize; source.StronglyTypeInput = true; - var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(),new GracefulCancellationToken()); + var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.AreEqual(typeof(decimal), dt.Columns.Cast().Single().DataType); Assert.AreEqual(DelimitedFlatFileDataFlowSource.MinimumStronglyTypeInputBatchSize, dt.Rows.Count); - + dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.AreEqual(typeof(decimal), dt.Columns.Cast().Single().DataType); Assert.AreEqual(2, dt.Rows.Count); - + dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.IsNull(dt); @@ -692,9 +716,9 @@ public void Test_ScientificNotation_StronglyTyped() [Test] public void Test_IgnoreQuotes() { - var f = Path.Combine(TestContext.CurrentContext.WorkDirectory,"talk.csv"); - - File.WriteAllText(f,@"Field1,Field2 + var f = Path.Combine(TestContext.CurrentContext.WorkDirectory, "talk.csv"); + + File.WriteAllText(f, @"Field1,Field2 1,Watch out guys its Billie ""The Killer"" Cole 2,""The Killer""? I've heard of him hes a bad un"); @@ -706,8 +730,8 @@ public void Test_IgnoreQuotes() source.StronglyTypeInput = true; var toMem = new ToMemoryDataLoadEventListener(true); - var ex = Assert.Throws(()=>source.GetChunk(toMem,new GracefulCancellationToken())); + var ex = Assert.Throws(() => source.GetChunk(toMem, new GracefulCancellationToken())); Assert.AreEqual("Bad data found on line 2", ex.Message); - source.Dispose(new ThrowImmediatelyDataLoadEventListener(),null); + source.Dispose(new ThrowImmediatelyDataLoadEventListener(), null); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTestsBase.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTestsBase.cs index 8a0d2944fc..4950a59439 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTestsBase.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTestsBase.cs @@ -34,7 +34,7 @@ protected static void AssertDivertFileIsExactly(string expectedContents) { var filename = Path.Combine(TestContext.CurrentContext.TestDirectory, "DelimitedFileSourceTests_Errors.txt"); - if(!File.Exists(filename)) + if (!File.Exists(filename)) Assert.Fail($"No Divert file was generated at expected path {filename}"); var contents = File.ReadAllText(filename); @@ -42,7 +42,7 @@ protected static void AssertDivertFileIsExactly(string expectedContents) } - protected static DataTable RunGetChunk(FlatFileToLoad file,BadDataHandlingStrategy strategy, bool throwOnEmpty) + protected static DataTable RunGetChunk(FlatFileToLoad file, BadDataHandlingStrategy strategy, bool throwOnEmpty) { return RunGetChunk(file, s => { @@ -56,7 +56,7 @@ protected static DataTable RunGetChunk(FlatFileToLoad file, Action { s.ForceHeaders = "CHI ,,StudyID,Date,,"; + dt = RunGetChunk(file, s => + { + s.ForceHeaders = "CHI ,,StudyID,Date,,"; s.ForceHeadersReplacesFirstLineInFile = true; }); else diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_ResolvedAccordingToStrategy.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_ResolvedAccordingToStrategy.cs index a1fdae2bc4..b6ae6cabcb 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_ResolvedAccordingToStrategy.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_ResolvedAccordingToStrategy.cs @@ -21,7 +21,8 @@ public void EmptyFile_TotallyEmpty(bool throwOnEmpty) if (throwOnEmpty) { - var ex = Assert.Throws(() => RunGetChunk(file, BadDataHandlingStrategy.ThrowException, throwOnEmpty)); + var ex = Assert.Throws(() => + RunGetChunk(file, BadDataHandlingStrategy.ThrowException, throwOnEmpty)); Assert.AreEqual("File DelimitedFileSourceTests.txt is empty", ex.Message); } else @@ -38,14 +39,15 @@ public void EmptyFile_AllWhitespace(bool throwOnEmpty) "); - if(throwOnEmpty) + if (throwOnEmpty) { - var ex = Assert.Throws(() => RunGetChunk(file, BadDataHandlingStrategy.ThrowException, throwOnEmpty)); + var ex = Assert.Throws(() => + RunGetChunk(file, BadDataHandlingStrategy.ThrowException, throwOnEmpty)); StringAssert.StartsWith("File DelimitedFileSourceTests.txt is empty", ex.Message); } else { - Assert.IsNull(RunGetChunk(file, BadDataHandlingStrategy.ThrowException,throwOnEmpty)); + Assert.IsNull(RunGetChunk(file, BadDataHandlingStrategy.ThrowException, throwOnEmpty)); } } @@ -62,12 +64,12 @@ public void EmptyFile_HeaderOnly(bool throwOnEmpty) if (throwOnEmpty) { - var ex = Assert.Throws(() => RunGetChunk(file, s=>s.ThrowOnEmptyFiles = true)); + var ex = Assert.Throws(() => RunGetChunk(file, s => s.ThrowOnEmptyFiles = true)); Assert.AreEqual("File DelimitedFileSourceTests.txt is empty", ex.Message); } else { - Assert.IsNull(RunGetChunk(file,s => s.ThrowOnEmptyFiles = false)); + Assert.IsNull(RunGetChunk(file, s => s.ThrowOnEmptyFiles = false)); } } @@ -80,17 +82,27 @@ public void EmptyFile_ForceHeader(bool throwOnEmpty) "); - + if (throwOnEmpty) { var ex = Assert.Throws(() => RunGetChunk(file, - s =>{ s.ThrowOnEmptyFiles = true; s.ForceHeaders="Name,Address"; s.ForceHeadersReplacesFirstLineInFile = true;})); + s => + { + s.ThrowOnEmptyFiles = true; + s.ForceHeaders = "Name,Address"; + s.ForceHeadersReplacesFirstLineInFile = true; + })); Assert.AreEqual("File DelimitedFileSourceTests.txt is empty", ex.Message); } else { Assert.IsNull(RunGetChunk(file, - s =>{ s.ThrowOnEmptyFiles = false; s.ForceHeaders="Name,Address"; s.ForceHeadersReplacesFirstLineInFile = true;})); + s => + { + s.ThrowOnEmptyFiles = false; + s.ForceHeaders = "Name,Address"; + s.ForceHeadersReplacesFirstLineInFile = true; + })); } } @@ -113,11 +125,11 @@ public void BadCSV_TooManyCellsInRow(BadDataHandlingStrategy strategy) break; case BadDataHandlingStrategy.IgnoreRows: var dt = RunGetChunk(file, strategy, true); - Assert.AreEqual(2,dt.Rows.Count); + Assert.AreEqual(2, dt.Rows.Count); break; case BadDataHandlingStrategy.DivertRows: var dt2 = RunGetChunk(file, strategy, true); - Assert.AreEqual(2,dt2.Rows.Count); + Assert.AreEqual(2, dt2.Rows.Count); AssertDivertFileIsExactly( $"Bob,He's also dynamite, seen him do a lot of good work,30{Environment.NewLine}"); @@ -149,11 +161,11 @@ public void BadCSV_TooManyCellsInRow_TwoBadRows(BadDataHandlingStrategy strategy break; case BadDataHandlingStrategy.IgnoreRows: var dt = RunGetChunk(file, strategy, true); - Assert.AreEqual(2,dt.Rows.Count); + Assert.AreEqual(2, dt.Rows.Count); break; case BadDataHandlingStrategy.DivertRows: var dt2 = RunGetChunk(file, strategy, true); - Assert.AreEqual(2,dt2.Rows.Count); + Assert.AreEqual(2, dt2.Rows.Count); AssertDivertFileIsExactly( $"Frank,Is the greatest,100,Frank,Is the greatest,100{Environment.NewLine}Bob,He's also dynamite, seen him do a lot of good work,30{Environment.NewLine}Bob2,He's also dynamite2, seen him do a lot of good work2,30{Environment.NewLine}"); @@ -164,11 +176,11 @@ public void BadCSV_TooManyCellsInRow_TwoBadRows(BadDataHandlingStrategy strategy } } - [TestCase(BadDataHandlingStrategy.DivertRows,true)] - [TestCase(BadDataHandlingStrategy.ThrowException,false)] - [TestCase(BadDataHandlingStrategy.ThrowException,true)] - [TestCase(BadDataHandlingStrategy.IgnoreRows,false)] - public void BadCSV_TooFewCellsInRow(BadDataHandlingStrategy strategy,bool tryToResolve) + [TestCase(BadDataHandlingStrategy.DivertRows, true)] + [TestCase(BadDataHandlingStrategy.ThrowException, false)] + [TestCase(BadDataHandlingStrategy.ThrowException, true)] + [TestCase(BadDataHandlingStrategy.IgnoreRows, false)] + public void BadCSV_TooFewCellsInRow(BadDataHandlingStrategy strategy, bool tryToResolve) { var file = CreateTestFile( "Name,Description,Age", @@ -258,7 +270,7 @@ not too bad to be honest,20", "Dennis,Hes ok,35"); - var dt = RunGetChunk(file,s=> { s.AttemptToResolveNewLinesInRecords = true; }); + var dt = RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true; }); Assert.AreEqual(3, dt.Rows.Count); Assert.AreEqual($"He's{Environment.NewLine}not too bad{Environment.NewLine}to be honest", dt.Rows[1][1]); } @@ -274,11 +286,16 @@ not too bad to be honest,Bob,20", "Hes ok,Dennis,35"); - var ex = Assert.Throws(()=> RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true; })); - Assert.AreEqual("Bad data found on line 3",ex.Message); + var ex = Assert.Throws(() => + RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true; })); + Assert.AreEqual("Bad data found on line 3", ex.Message); //looks like a good record followed by 2 bad records - var dt = RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true; s.BadDataHandlingStrategy = BadDataHandlingStrategy.IgnoreRows; }); + var dt = RunGetChunk(file, s => + { + s.AttemptToResolveNewLinesInRecords = true; + s.BadDataHandlingStrategy = BadDataHandlingStrategy.IgnoreRows; + }); Assert.AreEqual(3, dt.Rows.Count); Assert.AreEqual("to be honest", dt.Rows[1][0]); Assert.AreEqual("Bob", dt.Rows[1][1]); @@ -296,15 +313,18 @@ not too bad to be honest", "Dennis,35,Hes ok"); - var ex = Assert.Throws(()=> RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true; })); - Assert.AreEqual("Bad data found on line 4",ex.Message); + var ex = Assert.Throws(() => + RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true; })); + Assert.AreEqual("Bad data found on line 4", ex.Message); //looks like a good record followed by 2 bad records - var dt = RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = true;s.BadDataHandlingStrategy = BadDataHandlingStrategy.IgnoreRows; }); - Assert.AreEqual(3,dt.Rows.Count); + var dt = RunGetChunk(file, s => + { + s.AttemptToResolveNewLinesInRecords = true; + s.BadDataHandlingStrategy = BadDataHandlingStrategy.IgnoreRows; + }); + Assert.AreEqual(3, dt.Rows.Count); Assert.AreEqual("He's", dt.Rows[1][2]); - - } [Test] @@ -315,7 +335,8 @@ public void BadCSV_ForceHeaders() "Thomas,100", "Frank,300"); - var ex = Assert.Throws(() => RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = false; })); + var ex = Assert.Throws(() => + RunGetChunk(file, s => { s.AttemptToResolveNewLinesInRecords = false; })); Assert.AreEqual("Bad data found on line 2", ex.Message); @@ -326,11 +347,10 @@ public void BadCSV_ForceHeaders() s.ForceHeadersReplacesFirstLineInFile = true; }); - Assert.AreEqual(2,dt.Rows.Count); + Assert.AreEqual(2, dt.Rows.Count); Assert.AreEqual(2, dt.Columns.Count); Assert.AreEqual("Thomas", dt.Rows[0]["Name"]); Assert.AreEqual(100, dt.Rows[0]["BloodGlucose"]); - } [Test] @@ -346,11 +366,9 @@ public void BadCSV_ForceHeaders_NoReplace() s.ForceHeaders = "Name,BloodGlucose"; }); - Assert.AreEqual(2,dt.Rows.Count); + Assert.AreEqual(2, dt.Rows.Count); Assert.AreEqual(2, dt.Columns.Count); Assert.AreEqual("Thomas", dt.Rows[0]["Name"]); Assert.AreEqual(100, dt.Rows[0]["BloodGlucose"]); - } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_Unresolveable.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_Unresolveable.cs index 2c64f9de09..18b3ac826c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_Unresolveable.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/DelimitedFileSourceTests_Unresolveable.cs @@ -11,9 +11,8 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests.Sources; -internal class DelimitedFileSourceTests_Unresolveable: DelimitedFileSourceTestsBase +internal class DelimitedFileSourceTests_Unresolveable : DelimitedFileSourceTestsBase { - [TestCase(BadDataHandlingStrategy.DivertRows)] [TestCase(BadDataHandlingStrategy.ThrowException)] [TestCase(BadDataHandlingStrategy.IgnoreRows)] @@ -44,14 +43,15 @@ void adjust(DelimitedFlatFileDataFlowSource a) break; case BadDataHandlingStrategy.IgnoreRows: var dt = RunGetChunk(file, adjust); - Assert.AreEqual(2, dt.Rows.Count); //reads first 2 rows and chucks the rest! + Assert.AreEqual(2, dt.Rows.Count); //reads first 2 rows and chucks the rest! break; case BadDataHandlingStrategy.DivertRows: //read 2 rows and rejected the rest var dt2 = RunGetChunk(file, adjust); Assert.AreEqual(2, dt2.Rows.Count); - AssertDivertFileIsExactly($"Frank,\"Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}"); + AssertDivertFileIsExactly( + $"Frank,\"Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}Frank,Is the greatest,100{Environment.NewLine}"); break; default: diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/SourceTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/SourceTests.cs index 36ab7a84c7..303c16ea03 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/SourceTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PipelineTests/Sources/SourceTests.cs @@ -20,15 +20,17 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration.PipelineTests.Sources; -public class SourceTests:DatabaseTests +public class SourceTests : DatabaseTests { private ICatalogueRepository mockRepo = new MemoryCatalogueRepository(); [Test] public void RetrieveChunks() { - var source = new DbDataCommandDataFlowSource("Select top 3 * from master.sys.tables", "Query Sys tables", DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Builder, 30); - Assert.AreEqual(3, source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count); + var source = new DbDataCommandDataFlowSource("Select top 3 * from master.sys.tables", "Query Sys tables", + DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Builder, 30); + Assert.AreEqual(3, + source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count); } @@ -36,12 +38,12 @@ public void RetrieveChunks() public void TestPipelineContextInitialization() { var contextFactory = new DataFlowPipelineContextFactory(); - var context = contextFactory.Create(PipelineUsage.FixedDestination |PipelineUsage.LoadsSingleTableInfo); + var context = contextFactory.Create(PipelineUsage.FixedDestination | PipelineUsage.LoadsSingleTableInfo); var component = new TestObject_RequiresTableInfo(); var ti = new TableInfo(CatalogueRepository, "TestTableInfo"); context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, ti); - + Assert.AreEqual(component.PreInitToThis, ti); ti.DeleteInDatabase(); } @@ -69,8 +71,9 @@ public void TestPipelineContextInitialization_UnexpectedType() Name = "ColumnInfo" // because we passed a stubbed repository, the name won't be set }; - var ex = Assert.Throws(()=>context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, ci)); - StringAssert.Contains("The following expected types were not passed to PreInitialize:TableInfo",ex.Message); + var ex = Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, ci)); + StringAssert.Contains("The following expected types were not passed to PreInitialize:TableInfo", ex.Message); } [Test] @@ -81,8 +84,11 @@ public void TestPipelineContextInitialization_ForbiddenType() var component = new TestObject_RequiresTableInfo(); var ti = new TableInfo(new MemoryCatalogueRepository(), "Foo"); - var ex = Assert.Throws(()=>context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, ti)); - StringAssert.Contains("Type TableInfo is not an allowable PreInitialize parameters type under the current DataFlowPipelineContext (check which flags you passed to the DataFlowPipelineContextFactory and the interfaces IPipelineRequirement<> that your components implement) ",ex.Message); + var ex = Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, ti)); + StringAssert.Contains( + "Type TableInfo is not an allowable PreInitialize parameters type under the current DataFlowPipelineContext (check which flags you passed to the DataFlowPipelineContextFactory and the interfaces IPipelineRequirement<> that your components implement) ", + ex.Message); } [Test] @@ -99,15 +105,19 @@ public void TestPipelineContextInitialization_UninitializedInterface() Name = "Test Table Info" }; - var ex = Assert.Throws(()=>context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, testTableInfo)); - StringAssert.Contains($"The following expected types were not passed to PreInitialize:LoadModuleAssembly{Environment.NewLine}The object types passed were:{Environment.NewLine}Rdmp.Core.Curation.Data.TableInfo:Test Table Info",ex.Message); + var ex = Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadEventListener(), component, testTableInfo)); + StringAssert.Contains( + $"The following expected types were not passed to PreInitialize:LoadModuleAssembly{Environment.NewLine}The object types passed were:{Environment.NewLine}Rdmp.Core.Curation.Data.TableInfo:Test Table Info", + ex.Message); } [Test] public void TestPipelineContextIsAllowable() { var contextFactory = new DataFlowPipelineContextFactory(); - var context = contextFactory.Create(PipelineUsage.FixedSource | PipelineUsage.FixedDestination | PipelineUsage.LoadsSingleTableInfo); + var context = contextFactory.Create(PipelineUsage.FixedSource | PipelineUsage.FixedDestination | + PipelineUsage.LoadsSingleTableInfo); var pipeline = new Pipeline(CatalogueRepository, "DeleteMePipeline"); var component = new PipelineComponent(CatalogueRepository, pipeline, typeof(TestObject_RequiresTableInfo), 0); @@ -126,18 +136,20 @@ public void TestPipelineContextIsNOTAllowable() var pipeline = new Pipeline(CatalogueRepository, "DeleteMePipeline"); var component = new PipelineComponent(CatalogueRepository, pipeline, typeof(TestObject_RequiresTableInfo), 0) - { - Name = "TestPipeComponent" - }; + { + Name = "TestPipeComponent" + }; component.SaveToDatabase(); var rejection = context.IsAllowable(pipeline, out var reason); Console.WriteLine(reason); - Assert.IsFalse(rejection,reason); + Assert.IsFalse(rejection, reason); - Assert.AreEqual("Component TestPipeComponent implements a forbidden type (IPipelineRequirement) under the pipeline usage context",reason); + Assert.AreEqual( + "Component TestPipeComponent implements a forbidden type (IPipelineRequirement) under the pipeline usage context", + reason); pipeline.DeleteInDatabase(); } @@ -149,10 +161,12 @@ public void TestSuspiciousPipelineRequirements() var context = contextFactory.Create(PipelineUsage.FixedDestination); var suspiciousComponent = new TestObject_Suspicious(); - var ex = Assert.Throws(() => context.PreInitialize(new ThrowImmediatelyDataLoadJob(), suspiciousComponent, 5, "fish")); + var ex = Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadJob(), suspiciousComponent, 5, "fish")); Console.WriteLine($"Exception was:{ex.Message}"); } + [Test] public void TestExtraSuspiciousPipelineRequirements() { @@ -160,7 +174,8 @@ public void TestExtraSuspiciousPipelineRequirements() var context = contextFactory.Create(PipelineUsage.FixedDestination); var suspiciousComponent = new TestObject_ExtraSuspicious(); - Assert.Throws(() => context.PreInitialize(new ThrowImmediatelyDataLoadJob(), suspiciousComponent, "5")); + Assert.Throws(() => + context.PreInitialize(new ThrowImmediatelyDataLoadJob(), suspiciousComponent, "5")); } #region Test objects that have an assortment of IPipelineRequirements @@ -168,10 +183,9 @@ public void TestExtraSuspiciousPipelineRequirements() public class TestObject_RequiresTableInfo : IDataFlowComponent, IPipelineRequirement { public TableInfo PreInitToThis { get; private set; } - public DataTable ProcessPipelineData( DataTable toProcess, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) - { - throw new NotImplementedException(); - } + + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -187,16 +201,16 @@ public void PreInitialize(TableInfo value, IDataLoadEventListener listener) { PreInitToThis = value; } - } - public class TestObject_RequiresTableInfoAndFreakyObject : IDataFlowComponent, IPipelineRequirement, IPipelineRequirement + + public class TestObject_RequiresTableInfoAndFreakyObject : IDataFlowComponent, + IPipelineRequirement, IPipelineRequirement { public TableInfo PreInitToThis { get; private set; } - public DataTable ProcessPipelineData( DataTable toProcess, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - + + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); + public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { throw new NotImplementedException(); @@ -222,10 +236,8 @@ public void PreInitialize(LoadModuleAssembly value, IDataLoadEventListener liste public class TestObjectNoRequirements : IDataFlowComponent { - public DataTable ProcessPipelineData( DataTable toProcess, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) - { - throw new NotImplementedException(); - } + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -241,11 +253,10 @@ public void Abort(IDataLoadEventListener listener) public class TestObject_Suspicious : IDataFlowComponent, IPipelineRequirement { public object Object { get; set; } + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, - GracefulCancellationToken cancellationToken) - { + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); - } public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -263,14 +274,14 @@ public void PreInitialize(object value, IDataLoadEventListener listener) } } -public class TestObject_ExtraSuspicious : IDataFlowComponent, IPipelineRequirement, IPipelineRequirement +public class TestObject_ExtraSuspicious : IDataFlowComponent, IPipelineRequirement, + IPipelineRequirement { public object Object { get; set; } + public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, - GracefulCancellationToken cancellationToken) - { + GracefulCancellationToken cancellationToken) => throw new NotImplementedException(); - } public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) { @@ -292,4 +303,5 @@ public void PreInitialize(string value, IDataLoadEventListener listener) Object = value; } } + #endregion \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrematureLoadEnderTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrematureLoadEnderTests.cs index 6c13f56ae8..949a189e31 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrematureLoadEnderTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrematureLoadEnderTests.cs @@ -15,15 +15,15 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -internal class PrematureLoadEnderTests:DatabaseTests +internal class PrematureLoadEnderTests : DatabaseTests { [TestCase(DatabaseType.MySql)] [TestCase(DatabaseType.MicrosoftSQLServer)] public void TestEndLoadBecause_NoTables(DatabaseType type) { var database = GetCleanedServer(type); - - Assert.AreEqual(0,database.DiscoverTables(false).Length); + + Assert.AreEqual(0, database.DiscoverTables(false).Length); var ender = new PrematureLoadEnder { @@ -31,9 +31,9 @@ public void TestEndLoadBecause_NoTables(DatabaseType type) ExitCodeToReturnIfConditionMet = ExitCodeType.OperationNotRequired }; - ender.Initialize(database,LoadStage.AdjustRaw); + ender.Initialize(database, LoadStage.AdjustRaw); - Assert.AreEqual(ExitCodeType.OperationNotRequired ,ender.Mutilate(new ThrowImmediatelyDataLoadJob())); + Assert.AreEqual(ExitCodeType.OperationNotRequired, ender.Mutilate(new ThrowImmediatelyDataLoadJob())); } [TestCase(DatabaseType.MySql)] diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrimaryKeyCollisionResolverTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrimaryKeyCollisionResolverTests.cs index b2e53fc3fc..92817dc79d 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrimaryKeyCollisionResolverTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/PrimaryKeyCollisionResolverTests.cs @@ -16,7 +16,6 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; public class PrimaryKeyCollisionResolverTests : DatabaseTests { - [Test] public void PrimaryKeyCollisionResolverMultilation_Check_Passes() { @@ -40,7 +39,6 @@ public void PrimaryKeyCollisionResolverMultilation_Check_Passes() c3.SaveToDatabase(); Assert.DoesNotThrow(() => mutilation.Check(new ThrowImmediatelyCheckNotifier())); - } finally { @@ -52,7 +50,7 @@ public void PrimaryKeyCollisionResolverMultilation_Check_Passes() [Test] public void PrimaryKeyCollisionResolverMultilation_Check_ThrowsBecauseNoColumnOrderConfigured() { - SetupTableInfos(out var t, out ColumnInfo c1, out ColumnInfo c2, out ColumnInfo c3); + SetupTableInfos(out var t, out var c1, out var c2, out var c3); try { var mutilation = new PrimaryKeyCollisionResolverMutilation @@ -61,14 +59,16 @@ public void PrimaryKeyCollisionResolverMultilation_Check_ThrowsBecauseNoColumnOr }; try { - mutilation.Check(new ThrowImmediatelyCheckNotifier()); Assert.Fail("Should have crashed before here"); } catch (Exception e) { - Assert.AreEqual("Failed to check PrimaryKeyCollisionResolver on PrimaryKeyCollisionResolverTests", e.Message); - Assert.AreEqual("TableInfo PrimaryKeyCollisionResolverTests does not have any primary keys defined so cannot resolve primary key collisions",e.InnerException.Message); + Assert.AreEqual("Failed to check PrimaryKeyCollisionResolver on PrimaryKeyCollisionResolverTests", + e.Message); + Assert.AreEqual( + "TableInfo PrimaryKeyCollisionResolverTests does not have any primary keys defined so cannot resolve primary key collisions", + e.InnerException.Message); } } finally @@ -82,8 +82,10 @@ public void PrimaryKeyCollisionResolverMultilation_Check_ThrowsBecauseNotInitial { var mutilation = new PrimaryKeyCollisionResolverMutilation(); - var ex = Assert.Throws(()=>mutilation.Check(new ThrowImmediatelyCheckNotifier())); - StringAssert.Contains("Target table is null, a table must be specified upon which to resolve primary key duplication (that TableInfo must have a primary key collision resolution order)",ex.Message); + var ex = Assert.Throws(() => mutilation.Check(new ThrowImmediatelyCheckNotifier())); + StringAssert.Contains( + "Target table is null, a table must be specified upon which to resolve primary key duplication (that TableInfo must have a primary key collision resolution order)", + ex.Message); } [Test] @@ -126,15 +128,17 @@ public void GenerateSQL_OrderCorrect() [Test] public void NoColumnOrdersConfigured_ThrowsException() { - SetupTableInfos(out var t, out var c1, out ColumnInfo c2, out ColumnInfo c3); + SetupTableInfos(out var t, out var c1, out var c2, out var c3); try { c1.IsPrimaryKey = true; c1.SaveToDatabase(); var resolver = new PrimaryKeyCollisionResolver(t); - var ex = Assert.Throws(()=>Console.WriteLine(resolver.GenerateSQL())); - StringAssert.Contains("The ColumnInfos of TableInfo PrimaryKeyCollisionResolverTests do not have primary key resolution orders configured (do not know which order to use non primary key column values in to resolve collisions). Fix this by right clicking a TableInfo in CatalogueManager and selecting 'Configure Primary Key Collision Resolution'.",ex.Message); + var ex = Assert.Throws(() => Console.WriteLine(resolver.GenerateSQL())); + StringAssert.Contains( + "The ColumnInfos of TableInfo PrimaryKeyCollisionResolverTests do not have primary key resolution orders configured (do not know which order to use non primary key column values in to resolve collisions). Fix this by right clicking a TableInfo in CatalogueManager and selecting 'Configure Primary Key Collision Resolution'.", + ex.Message); } finally { @@ -145,13 +149,14 @@ public void NoColumnOrdersConfigured_ThrowsException() [Test] public void NoPrimaryKeys_ThrowsException() { - SetupTableInfos(out var t, out ColumnInfo c1, out ColumnInfo c2, out ColumnInfo c3); + SetupTableInfos(out var t, out var c1, out var c2, out var c3); try { var resolver = new PrimaryKeyCollisionResolver(t); - var ex = Assert.Throws(()=>Console.WriteLine(resolver.GenerateSQL())); - StringAssert.Contains("does not have any primary keys defined so cannot resolve primary key collisions",ex.Message); + var ex = Assert.Throws(() => Console.WriteLine(resolver.GenerateSQL())); + StringAssert.Contains("does not have any primary keys defined so cannot resolve primary key collisions", + ex.Message); } finally { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/RemoteDatabaseAttacherTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/RemoteDatabaseAttacherTests.cs index ae9dbdeff7..78ba28f66c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/RemoteDatabaseAttacherTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/RemoteDatabaseAttacherTests.cs @@ -23,7 +23,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class RemoteDatabaseAttacherTests:DatabaseTests +public class RemoteDatabaseAttacherTests : DatabaseTests { [TestCase(DatabaseType.MicrosoftSQLServer, Scenario.AllRawColumns)] [TestCase(DatabaseType.MySql, Scenario.AllRawColumns)] @@ -41,32 +41,34 @@ public void TestRemoteDatabaseAttach(DatabaseType dbType, Scenario scenario) dt.Rows.Add("123", 11); - var tbl = db.CreateTable("MyTable",dt); + var tbl = db.CreateTable("MyTable", dt); Assert.AreEqual(1, tbl.GetRowCount()); Import(tbl, out var ti, out var cols); //Create a virtual RAW column - if (scenario == Scenario.MissingPreLoadDiscardedColumn || scenario == Scenario.MissingPreLoadDiscardedColumnButSelectStar) + if (scenario == Scenario.MissingPreLoadDiscardedColumn || + scenario == Scenario.MissingPreLoadDiscardedColumnButSelectStar) new PreLoadDiscardedColumn(CatalogueRepository, ti, "MyMissingCol"); - var externalServer = new ExternalDatabaseServer(CatalogueRepository, "MyFictionalRemote",null); + var externalServer = new ExternalDatabaseServer(CatalogueRepository, "MyFictionalRemote", null); externalServer.SetProperties(db); var attacher = new RemoteDatabaseAttacher(); - attacher.Initialize(null,db); + attacher.Initialize(null, db); - attacher.LoadRawColumnsOnly = scenario == Scenario.AllRawColumns || scenario == Scenario.MissingPreLoadDiscardedColumn; + attacher.LoadRawColumnsOnly = + scenario == Scenario.AllRawColumns || scenario == Scenario.MissingPreLoadDiscardedColumn; attacher.RemoteSource = externalServer; var lm = new LogManager(CatalogueRepository.GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID)); lm.CreateNewLoggingTaskIfNotExists("amagad"); var dli = lm.CreateDataLoadInfo("amagad", "p", "a", "", true); - var job = Mock.Of(p => - p.RegularTablesToLoad==new List {ti} && - p.LookupTablesToLoad==new List() && p.DataLoadInfo==dli); - + var job = Mock.Of(p => + p.RegularTablesToLoad == new List { ti } && + p.LookupTablesToLoad == new List() && p.DataLoadInfo == dli); + switch (scenario) { case Scenario.AllRawColumns: @@ -74,22 +76,25 @@ public void TestRemoteDatabaseAttach(DatabaseType dbType, Scenario scenario) case Scenario.AllColumns: break; case Scenario.MissingPreLoadDiscardedColumn: - var ex = Assert.Throws(() => attacher.Attach(job, new GracefulCancellationToken())); + var ex = Assert.Throws(() => + attacher.Attach(job, new GracefulCancellationToken())); - Assert.AreEqual("Invalid column name 'MyMissingCol'.", ex.InnerException.InnerException.InnerException.Message); + Assert.AreEqual("Invalid column name 'MyMissingCol'.", + ex.InnerException.InnerException.InnerException.Message); return; case Scenario.MissingPreLoadDiscardedColumnButSelectStar: break; default: throw new ArgumentOutOfRangeException(nameof(scenario)); } + attacher.Attach(job, new GracefulCancellationToken()); - Assert.AreEqual(2,tbl.GetRowCount()); + Assert.AreEqual(2, tbl.GetRowCount()); dt = tbl.GetDataTable(); - VerifyRowExist(dt,123,11); + VerifyRowExist(dt, 123, 11); if (scenario == Scenario.AllRawColumns) VerifyRowExist(dt, 123, DBNull.Value); @@ -98,7 +103,7 @@ public void TestRemoteDatabaseAttach(DatabaseType dbType, Scenario scenario) externalServer.DeleteInDatabase(); } - + public enum Scenario { /// diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/RuntimeTaskFactoryTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/RuntimeTaskFactoryTests.cs index 6ab988aa8e..c7ca311acf 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/RuntimeTaskFactoryTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/RuntimeTaskFactoryTests.cs @@ -22,27 +22,27 @@ public class RuntimeTaskFactoryTests : DatabaseTests [TestCase("Rdmp.Core.DataLoad.Modules.DataProvider.FlatFileManipulation.ExcelToCSVFilesConverter")] public void RuntimeTaskFactoryTest(string className) { - var lmd = new LoadMetadata(CatalogueRepository); - var task = new ProcessTask(CatalogueRepository, lmd,LoadStage.GetFiles); + var task = new ProcessTask(CatalogueRepository, lmd, LoadStage.GetFiles); var f = new RuntimeTaskFactory(CatalogueRepository); task.Path = className; task.ProcessTaskType = ProcessTaskType.DataProvider; task.SaveToDatabase(); - + try { - var ex = Assert.Throws(() => f.Create(task, new StageArgs(LoadStage.AdjustRaw, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer), Mock.Of()))); - Assert.IsTrue(ex.InnerException.Message.Contains("marked with DemandsInitialization but no corresponding argument was provided in ArgumentCollection")); + var ex = Assert.Throws(() => f.Create(task, + new StageArgs(LoadStage.AdjustRaw, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer), + Mock.Of()))); + Assert.IsTrue(ex.InnerException.Message.Contains( + "marked with DemandsInitialization but no corresponding argument was provided in ArgumentCollection")); } - finally + finally { task.DeleteInDatabase(); lmd.DeleteInDatabase(); } - - } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/SafePrimaryKeyCollisionResolverMutilationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/SafePrimaryKeyCollisionResolverMutilationTests.cs index ad7ee2fa66..2d642558ef 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/SafePrimaryKeyCollisionResolverMutilationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/SafePrimaryKeyCollisionResolverMutilationTests.cs @@ -17,13 +17,14 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class SafePrimaryKeyCollisionResolverMutilationTests:DatabaseTests +public class SafePrimaryKeyCollisionResolverMutilationTests : DatabaseTests { - [TestCase(DatabaseType.MicrosoftSQLServer,true)] - [TestCase(DatabaseType.MySql,true)] + [TestCase(DatabaseType.MicrosoftSQLServer, true)] + [TestCase(DatabaseType.MySql, true)] [TestCase(DatabaseType.MicrosoftSQLServer, false)] [TestCase(DatabaseType.MySql, false)] - public void SafePrimaryKeyCollisionResolverMutilationTests_NoDifference_NoRecordsDeleted(DatabaseType dbType,bool bothNull) + public void SafePrimaryKeyCollisionResolverMutilationTests_NoDifference_NoRecordsDeleted(DatabaseType dbType, + bool bothNull) { var db = GetCleanedServer(dbType); @@ -31,15 +32,15 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_NoDifference_NoRecord dt.Columns.Add("PK"); dt.Columns.Add("ResolveOn"); dt.Columns.Add("AnotherCol"); - - dt.Rows.Add(1, bothNull?null:"fish", "cat"); + + dt.Rows.Add(1, bothNull ? null : "fish", "cat"); dt.Rows.Add(1, bothNull ? null : "fish", "flop"); dt.Rows.Add(2, "fish", "flop"); dt.Rows.Add(3, "dave", "franl"); var tbl = db.CreateTable("MyTable", dt); - Import(tbl,out var ti, out var cis); + Import(tbl, out var ti, out var cis); var pk = cis.Single(c => c.GetRuntimeName().Equals("PK")); pk.IsPrimaryKey = true; @@ -57,13 +58,15 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_NoDifference_NoRecord mutilation.Initialize(db, LoadStage.AdjustRaw); mutilation.Mutilate(new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(db.Server))); - Assert.AreEqual(4,tbl.GetRowCount()); + Assert.AreEqual(4, tbl.GetRowCount()); } - [TestCase(DatabaseType.MicrosoftSQLServer,false)] - [TestCase(DatabaseType.MySql,false)] + + [TestCase(DatabaseType.MicrosoftSQLServer, false)] + [TestCase(DatabaseType.MySql, false)] [TestCase(DatabaseType.MicrosoftSQLServer, true)] [TestCase(DatabaseType.MySql, true)] - public void SafePrimaryKeyCollisionResolverMutilationTests_PreferNull_RecordsDeleted(DatabaseType dbType,bool preferNulls) + public void SafePrimaryKeyCollisionResolverMutilationTests_PreferNull_RecordsDeleted(DatabaseType dbType, + bool preferNulls) { var db = GetCleanedServer(dbType); @@ -99,13 +102,18 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_PreferNull_RecordsDel Assert.AreEqual(3, tbl.GetRowCount()); var result = tbl.GetDataTable(); - + //if you prefer nulls you shouldn't want this one - Assert.AreEqual(preferNulls? 0:1 ,result.Rows.Cast().Count(r=>(int)r["PK"] == 1 && r["ResolveOn"] as string == "fish" && r["AnotherCol"] as string == "flop" )); + Assert.AreEqual(preferNulls ? 0 : 1, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] as string == "fish" && r["AnotherCol"] as string == "flop")); //if you prefer nulls you should have this one - Assert.AreEqual(preferNulls ? 1 : 0, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); + Assert.AreEqual(preferNulls ? 1 : 0, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); } + [TestCase(DatabaseType.MicrosoftSQLServer)] [TestCase(DatabaseType.MySql)] public void SafePrimaryKeyCollisionResolverMutilationTests_WithDatabaseNamer_RecordsDeleted(DatabaseType dbType) @@ -127,7 +135,7 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_WithDatabaseNamer_Rec Import(tbl, out var ti, out var cis); tbl.Rename("AAAA"); - var namer = RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(db,"AAAA"); + var namer = RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(db, "AAAA"); var pk = cis.Single(c => c.GetRuntimeName().Equals("PK")); pk.IsPrimaryKey = true; @@ -143,16 +151,20 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_WithDatabaseNamer_Rec }; mutilation.Initialize(db, LoadStage.AdjustRaw); - mutilation.Mutilate(new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(db.Server,namer), ti)); + mutilation.Mutilate(new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(db.Server, namer), ti)); Assert.AreEqual(3, tbl.GetRowCount()); var result = tbl.GetDataTable(); //if you prefer nulls you shouldn't want this one - Assert.AreEqual( 0 , result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] as string == "fish" && r["AnotherCol"] as string == "flop")); + Assert.AreEqual(0, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] as string == "fish" && r["AnotherCol"] as string == "flop")); //if you prefer nulls you should have this one - Assert.AreEqual(1, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); + Assert.AreEqual(1, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); } @@ -160,7 +172,8 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_WithDatabaseNamer_Rec [TestCase(DatabaseType.MySql, false)] [TestCase(DatabaseType.MicrosoftSQLServer, true)] [TestCase(DatabaseType.MySql, true)] - public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_RecordsDeleted(DatabaseType dbType, bool preferLarger) + public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_RecordsDeleted(DatabaseType dbType, + bool preferLarger) { var db = GetCleanedServer(dbType); @@ -199,20 +212,26 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_RecordsD var result = tbl.GetDataTable(); //if you like larger values (alphabetically) then you want the 'b' - Assert.AreEqual(preferLarger ? 1 : 0, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] as string == "b" && r["AnotherCol"] as string == "flop")); - Assert.AreEqual(preferLarger ? 0 : 1, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] as string == "a" && r["AnotherCol"] as string == "flop")); + Assert.AreEqual(preferLarger ? 1 : 0, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] as string == "b" && r["AnotherCol"] as string == "flop")); + Assert.AreEqual(preferLarger ? 0 : 1, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] as string == "a" && r["AnotherCol"] as string == "flop")); //either way you shouldn't have the null one - Assert.AreEqual(0, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); + Assert.AreEqual(0, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); } - [TestCase(DatabaseType.MicrosoftSQLServer, false)] [TestCase(DatabaseType.MySql, false)] [TestCase(DatabaseType.MicrosoftSQLServer, true)] [TestCase(DatabaseType.MySql, true)] - public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_Dates_RecordsDeleted(DatabaseType dbType, bool preferLarger) + public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_Dates_RecordsDeleted(DatabaseType dbType, + bool preferLarger) { var db = GetCleanedServer(dbType); @@ -222,7 +241,7 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_Dates_Re dt.Columns.Add("AnotherCol"); dt.Rows.Add(1, null, "cat"); - dt.Rows.Add(1, new DateTime(2001,01,01), "flop"); + dt.Rows.Add(1, new DateTime(2001, 01, 01), "flop"); dt.Rows.Add(1, new DateTime(2002, 01, 01), "flop"); dt.Rows.Add(2, null, "flop"); dt.Rows.Add(3, null, "franl"); @@ -251,18 +270,27 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_Dates_Re var result = tbl.GetDataTable(); //if you like larger values then you want 2002 thats larger than 2001 - Assert.AreEqual(preferLarger ? 1 : 0, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && Equals(r["ResolveOn"], new DateTime(2002,01,01)) && r["AnotherCol"] as string == "flop")); - Assert.AreEqual(preferLarger ? 0 : 1, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && Equals(r["ResolveOn"], new DateTime(2001,01,01)) && r["AnotherCol"] as string == "flop")); + Assert.AreEqual(preferLarger ? 1 : 0, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && Equals(r["ResolveOn"], new DateTime(2002, 01, 01)) && + r["AnotherCol"] as string == "flop")); + Assert.AreEqual(preferLarger ? 0 : 1, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && Equals(r["ResolveOn"], new DateTime(2001, 01, 01)) && + r["AnotherCol"] as string == "flop")); //either way you shouldn't have the null one - Assert.AreEqual(0, result.Rows.Cast().Count(r => (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); + Assert.AreEqual(0, + result.Rows.Cast().Count(r => + (int)r["PK"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); } [TestCase(DatabaseType.MicrosoftSQLServer, false)] [TestCase(DatabaseType.MySql, false)] [TestCase(DatabaseType.MicrosoftSQLServer, true)] [TestCase(DatabaseType.MySql, true)] - public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_ComboKey_RecordsDeleted(DatabaseType dbType, bool preferLarger) + public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_ComboKey_RecordsDeleted(DatabaseType dbType, + bool preferLarger) { var db = GetCleanedServer(dbType); @@ -272,17 +300,17 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_ComboKey dt.Columns.Add("ResolveOn"); dt.Columns.Add("AnotherCol"); - dt.Rows.Add(1,1, null, "cat"); - dt.Rows.Add(1,1, new DateTime(2001, 01, 01), "flop"); - dt.Rows.Add(1,1, new DateTime(2002, 01, 01), "flop"); + dt.Rows.Add(1, 1, null, "cat"); + dt.Rows.Add(1, 1, new DateTime(2001, 01, 01), "flop"); + dt.Rows.Add(1, 1, new DateTime(2002, 01, 01), "flop"); dt.Rows.Add(1, 2, null, "cat"); dt.Rows.Add(1, 2, null, "cat"); dt.Rows.Add(1, 3, new DateTime(2001, 01, 01), "flop"); dt.Rows.Add(1, 4, new DateTime(2002, 01, 01), "flop"); - dt.Rows.Add(2,1, null, "flop"); - dt.Rows.Add(3,1, null, "franl"); + dt.Rows.Add(2, 1, null, "flop"); + dt.Rows.Add(3, 1, null, "franl"); var tbl = db.CreateTable("MyTable", dt); @@ -312,10 +340,19 @@ public void SafePrimaryKeyCollisionResolverMutilationTests_PreferLarger_ComboKey var result = tbl.GetDataTable(); //if you like larger values then you want 2002 thats larger than 2001 - Assert.AreEqual(preferLarger ? 1 : 0, result.Rows.Cast().Count(r => (int)r["PK1"] == 1 && (int)r["PK2"] == 1 && Equals(r["ResolveOn"], new DateTime(2002, 01, 01)) && r["AnotherCol"] as string == "flop")); - Assert.AreEqual(preferLarger ? 0 : 1, result.Rows.Cast().Count(r => (int)r["PK1"] == 1 && (int)r["PK2"] == 1 && Equals(r["ResolveOn"], new DateTime(2001, 01, 01)) && r["AnotherCol"] as string == "flop")); + Assert.AreEqual(preferLarger ? 1 : 0, + result.Rows.Cast().Count(r => + (int)r["PK1"] == 1 && (int)r["PK2"] == 1 && Equals(r["ResolveOn"], new DateTime(2002, 01, 01)) && + r["AnotherCol"] as string == "flop")); + Assert.AreEqual(preferLarger ? 0 : 1, + result.Rows.Cast().Count(r => + (int)r["PK1"] == 1 && (int)r["PK2"] == 1 && Equals(r["ResolveOn"], new DateTime(2001, 01, 01)) && + r["AnotherCol"] as string == "flop")); //either way you shouldn't have the null one - Assert.AreEqual(0, result.Rows.Cast().Count(r => (int)r["PK1"] == 1 && (int)r["PK2"] == 1 && r["ResolveOn"] == DBNull.Value && r["AnotherCol"] as string == "cat")); + Assert.AreEqual(0, + result.Rows.Cast().Count(r => + (int)r["PK1"] == 1 && (int)r["PK2"] == 1 && r["ResolveOn"] == DBNull.Value && + r["AnotherCol"] as string == "cat")); } } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/SingleJobPipelineTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/SingleJobPipelineTests.cs index 2f29f8e0d3..2920f88e5c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/SingleJobPipelineTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/SingleJobPipelineTests.cs @@ -22,7 +22,7 @@ public static void LoadNotRequiredStopsPipelineGracefully() { var component = new NotRequiredComponent(); - var pipeline = new SingleJobExecution(new List {component}); + var pipeline = new SingleJobExecution(new List { component }); var job = Mock.Of(); var jobTokenSource = new GracefulCancellationTokenSource(); @@ -32,10 +32,8 @@ public static void LoadNotRequiredStopsPipelineGracefully() internal class NotRequiredComponent : DataLoadComponent { - public override ExitCodeType Run(IDataLoadJob job, GracefulCancellationToken cancellationToken) - { - return ExitCodeType.OperationNotRequired; - } + public override ExitCodeType Run(IDataLoadJob job, GracefulCancellationToken cancellationToken) => + ExitCodeType.OperationNotRequired; public override void LoadCompletedSoDispose(ExitCodeType exitCode, IDataLoadEventListener postDataLoadEventListener) { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableInfoJoiningQueryBuilderTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableInfoJoiningQueryBuilderTests.cs index 006ed1b3a5..e553e344c9 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableInfoJoiningQueryBuilderTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableInfoJoiningQueryBuilderTests.cs @@ -15,7 +15,7 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; -public class TableInfoJoiningQueryBuilderTests:DatabaseTests +public class TableInfoJoiningQueryBuilderTests : DatabaseTests { [Test] public void OpportunisticJoinRequired() @@ -23,8 +23,8 @@ public void OpportunisticJoinRequired() var memory = new MemoryRepository(); //tables and columns - var head = new TableInfo(CatalogueRepository,"Head"); - var col1 = new ColumnInfo(CatalogueRepository,"TestResultSetNumber","int",head); + var head = new TableInfo(CatalogueRepository, "Head"); + var col1 = new ColumnInfo(CatalogueRepository, "TestResultSetNumber", "int", head); var col2 = new ColumnInfo(CatalogueRepository, "PK", "int", head); var result = new TableInfo(CatalogueRepository, "[biochemistry]..[Result]"); @@ -33,33 +33,33 @@ public void OpportunisticJoinRequired() var col5 = new ColumnInfo(CatalogueRepository, "[biochemistry]..[Result].[OmgBob]", "varchar(10)", result); //we can join on col2 = col3 - new JoinInfo(CatalogueRepository,col3, col2, ExtractionJoinType.Right, ""); + new JoinInfo(CatalogueRepository, col3, col2, ExtractionJoinType.Right, ""); //CASE 1 : Only 1 column used so no join needed var queryBuilder = new QueryBuilder(null, null); - var icol1 = new ColumnInfoToIColumn(memory,col1) + var icol1 = new ColumnInfoToIColumn(memory, col1) { Order = 1 }; queryBuilder.AddColumn(icol1); - var tablesUsed = SqlQueryBuilderHelper.GetTablesUsedInQuery(queryBuilder, out var primary,null); - - Assert.AreEqual(1,tablesUsed.Count); - Assert.AreEqual(head,tablesUsed[0]); + var tablesUsed = SqlQueryBuilderHelper.GetTablesUsedInQuery(queryBuilder, out var primary, null); + + Assert.AreEqual(1, tablesUsed.Count); + Assert.AreEqual(head, tablesUsed[0]); //CASE 2 : 2 columns used one from each table so join is needed queryBuilder = new QueryBuilder(null, null); - queryBuilder.AddColumn(new ColumnInfoToIColumn(memory,col1)); + queryBuilder.AddColumn(new ColumnInfoToIColumn(memory, col1)); - var icol4 = new ColumnInfoToIColumn(memory,col4) + var icol4 = new ColumnInfoToIColumn(memory, col4) { Order = 2 }; queryBuilder.AddColumn(icol4); tablesUsed = SqlQueryBuilderHelper.GetTablesUsedInQuery(queryBuilder, out primary, null); - + Assert.AreEqual(2, tablesUsed.Count); Assert.AreEqual(head, tablesUsed[0]); Assert.AreEqual(result, tablesUsed[1]); @@ -72,21 +72,23 @@ public void OpportunisticJoinRequired() var memoryRepository = new MemoryCatalogueRepository(); - var spontContainer = new SpontaneouslyInventedFilterContainer(memoryRepository,null, null, FilterContainerOperation.AND); + var spontContainer = + new SpontaneouslyInventedFilterContainer(memoryRepository, null, null, FilterContainerOperation.AND); - var spontFilter = new SpontaneouslyInventedFilter(memoryRepository,spontContainer, "[biochemistry]..[Result].[OmgBob] = 'T'", + var spontFilter = new SpontaneouslyInventedFilter(memoryRepository, spontContainer, + "[biochemistry]..[Result].[OmgBob] = 'T'", "My Filter", "Causes spontaneous requirement for joining compeltely", null); spontContainer.AddChild(spontFilter); //CASE 3 : Only 1 column from Head but filter contains a reference to Result column queryBuilder = new QueryBuilder(null, null); - queryBuilder.AddColumn(new ColumnInfoToIColumn(memory,col1)); + queryBuilder.AddColumn(new ColumnInfoToIColumn(memory, col1)); //without the filter tablesUsed = SqlQueryBuilderHelper.GetTablesUsedInQuery(queryBuilder, out primary, null); Assert.AreEqual(1, tablesUsed.Count); - + //set the filter queryBuilder.RootFilterContainer = spontContainer; @@ -95,11 +97,7 @@ public void OpportunisticJoinRequired() queryBuilder.ParameterManager.ClearNonGlobals(); //with the filter - tablesUsed = SqlQueryBuilderHelper.GetTablesUsedInQuery(queryBuilder, out primary,null); + tablesUsed = SqlQueryBuilderHelper.GetTablesUsedInQuery(queryBuilder, out primary, null); Assert.AreEqual(2, tablesUsed.Count); - - - } - } \ No newline at end of file diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableVarcharMaxerTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableVarcharMaxerTests.cs index 7b8f9478bc..535e4f7b56 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableVarcharMaxerTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/TableVarcharMaxerTests.cs @@ -24,18 +24,18 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; public class TableVarcharMaxerTests : DatabaseTests { - [TestCase(DatabaseType.MySql,true)] + [TestCase(DatabaseType.MySql, true)] [TestCase(DatabaseType.MySql, false)] - [TestCase(DatabaseType.MicrosoftSQLServer,true)] - [TestCase(DatabaseType.MicrosoftSQLServer,false)] - public void TestTableVarcharMaxer(DatabaseType dbType,bool allDataTypes) + [TestCase(DatabaseType.MicrosoftSQLServer, true)] + [TestCase(DatabaseType.MicrosoftSQLServer, false)] + public void TestTableVarcharMaxer(DatabaseType dbType, bool allDataTypes) { var db = GetCleanedServer(dbType); - var tbl = db.CreateTable("Fish",new[] + var tbl = db.CreateTable("Fish", new[] { - new DatabaseColumnRequest("Dave",new DatabaseTypeRequest(typeof(string),100)), - new DatabaseColumnRequest("Frank",new DatabaseTypeRequest(typeof(int))) + new DatabaseColumnRequest("Dave", new DatabaseTypeRequest(typeof(string), 100)), + new DatabaseColumnRequest("Frank", new DatabaseTypeRequest(typeof(int))) }); Import(tbl, out var ti, out var cols); @@ -44,30 +44,31 @@ public void TestTableVarcharMaxer(DatabaseType dbType,bool allDataTypes) { AllDataTypes = allDataTypes, TableRegexPattern = new Regex(".*"), - DestinationType = db.Server.GetQuerySyntaxHelper().TypeTranslater.GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string),int.MaxValue)) + DestinationType = db.Server.GetQuerySyntaxHelper().TypeTranslater + .GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string), int.MaxValue)) }; - maxer.Initialize(db,LoadStage.AdjustRaw); - maxer.Check(new ThrowImmediatelyCheckNotifier {ThrowOnWarning = true}); + maxer.Initialize(db, LoadStage.AdjustRaw); + maxer.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); - var job = Mock.Of(x => - x.RegularTablesToLoad==new List {ti} && - x.Configuration==new HICDatabaseConfiguration(db.Server,null,null,null)); + var job = Mock.Of(x => + x.RegularTablesToLoad == new List { ti } && + x.Configuration == new HICDatabaseConfiguration(db.Server, null, null, null)); maxer.Mutilate(job); switch (dbType) { case DatabaseType.MicrosoftSQLServer: - Assert.AreEqual("varchar(max)",tbl.DiscoverColumn("Dave").DataType.SQLType); + Assert.AreEqual("varchar(max)", tbl.DiscoverColumn("Dave").DataType.SQLType); Assert.AreEqual(allDataTypes ? "varchar(max)" : "int", tbl.DiscoverColumn("Frank").DataType.SQLType); break; case DatabaseType.MySql: - Assert.AreEqual("text",tbl.DiscoverColumn("Dave").DataType.SQLType); + Assert.AreEqual("text", tbl.DiscoverColumn("Dave").DataType.SQLType); Assert.AreEqual(allDataTypes ? "text" : "int", tbl.DiscoverColumn("Frank").DataType.SQLType); break; case DatabaseType.Oracle: - Assert.AreEqual("varchar(max)",tbl.DiscoverColumn("Dave").DataType.SQLType); + Assert.AreEqual("varchar(max)", tbl.DiscoverColumn("Dave").DataType.SQLType); Assert.AreEqual(allDataTypes ? "varchar(max)" : "int", tbl.DiscoverColumn("Frank").DataType.SQLType); break; default: @@ -81,10 +82,10 @@ public void VarcharMaxer_BadTableNames(DatabaseType dbType) { var db = GetCleanedServer(dbType); - var tbl = db.CreateTable("Fi ; '`sh",new[] + var tbl = db.CreateTable("Fi ; '`sh", new[] { - new DatabaseColumnRequest("Da' ,,;ve",new DatabaseTypeRequest(typeof(string),100)), - new DatabaseColumnRequest("Frrrrr ##' ank",new DatabaseTypeRequest(typeof(int))) + new DatabaseColumnRequest("Da' ,,;ve", new DatabaseTypeRequest(typeof(string), 100)), + new DatabaseColumnRequest("Frrrrr ##' ank", new DatabaseTypeRequest(typeof(int))) }); Import(tbl, out var ti, out var cols); @@ -92,16 +93,17 @@ public void VarcharMaxer_BadTableNames(DatabaseType dbType) var maxer = new TableVarcharMaxer { TableRegexPattern = new Regex(".*"), - DestinationType = db.Server.GetQuerySyntaxHelper().TypeTranslater.GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string),int.MaxValue)) + DestinationType = db.Server.GetQuerySyntaxHelper().TypeTranslater + .GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string), int.MaxValue)) }; - maxer.Initialize(db,LoadStage.AdjustRaw); - maxer.Check(new ThrowImmediatelyCheckNotifier {ThrowOnWarning = true}); + maxer.Initialize(db, LoadStage.AdjustRaw); + maxer.Check(new ThrowImmediatelyCheckNotifier { ThrowOnWarning = true }); var job = new ThrowImmediatelyDataLoadJob { - RegularTablesToLoad = new List {ti}, - Configuration = new HICDatabaseConfiguration(db.Server,null,null,null) + RegularTablesToLoad = new List { ti }, + Configuration = new HICDatabaseConfiguration(db.Server, null, null, null) }; maxer.Mutilate(job); @@ -109,13 +111,13 @@ public void VarcharMaxer_BadTableNames(DatabaseType dbType) switch (dbType) { case DatabaseType.MicrosoftSQLServer: - Assert.AreEqual("varchar(max)",tbl.DiscoverColumn("Da' ,,;ve").DataType.SQLType); + Assert.AreEqual("varchar(max)", tbl.DiscoverColumn("Da' ,,;ve").DataType.SQLType); break; case DatabaseType.MySql: - Assert.AreEqual("text",tbl.DiscoverColumn("Da' ,,;ve").DataType.SQLType); + Assert.AreEqual("text", tbl.DiscoverColumn("Da' ,,;ve").DataType.SQLType); break; case DatabaseType.Oracle: - Assert.AreEqual("varchar(max)",tbl.DiscoverColumn("Da' ,,;ve").DataType.SQLType); + Assert.AreEqual("varchar(max)", tbl.DiscoverColumn("Da' ,,;ve").DataType.SQLType); break; default: throw new ArgumentOutOfRangeException(nameof(dbType)); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/TestTemporalTables.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/TestTemporalTables.cs index 08aef55bc4..2a555beaaa 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/TestTemporalTables.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/TestTemporalTables.cs @@ -50,10 +50,10 @@ public void TestTemporalTable(bool ignoreWithGlobalPattern) var dbtype = FAnsi.DatabaseType.MicrosoftSQLServer; var db = GetCleanedServer(dbtype); - using(var con = db.Server.GetConnection()) + using (var con = db.Server.GetConnection()) { con.Open(); - db.Server.GetCommand(sql,con).ExecuteNonQuery(); + db.Server.GetCommand(sql, con).ExecuteNonQuery(); } var tbl = db.ExpectTable("Employee"); @@ -63,7 +63,7 @@ public void TestTemporalTable(bool ignoreWithGlobalPattern) var logManager = new LogManager(logServer); var raw = db.Server.ExpectDatabase($"{db.GetRuntimeName()}_RAW"); - if(raw.Exists()) + if (raw.Exists()) raw.Drop(); //define a new load configuration @@ -73,12 +73,12 @@ public void TestTemporalTable(bool ignoreWithGlobalPattern) }; lmd.SaveToDatabase(); - var ti = Import(tbl, lmd,logManager); + var ti = Import(tbl, lmd, logManager); var projectDirectory = SetupLoadDirectory(lmd); - CreateCSVProcessTask(lmd,ti,"*.csv"); - + CreateCSVProcessTask(lmd, ti, "*.csv"); + //create a text file to load where we update Frank's favourite colour (it's a pk field) and we insert a new record (MrMurder) File.WriteAllText( Path.Combine(projectDirectory.ForLoading.FullName, "LoadMe.csv"), @@ -90,10 +90,11 @@ public void TestTemporalTable(bool ignoreWithGlobalPattern) //the checks will probably need to be run as ddl admin because it involves creating _Archive table and trigger the first time //clean SetUp RAW / STAGING etc and generally accept proposed cleanup operations - var checker = new CheckEntireDataLoadProcess(lmd, new HICDatabaseConfiguration(lmd), new HICLoadConfigurationFlags(),CatalogueRepository.MEF); + var checker = new CheckEntireDataLoadProcess(lmd, new HICDatabaseConfiguration(lmd), + new HICLoadConfigurationFlags(), CatalogueRepository.MEF); checker.Check(new AcceptAllCheckNotifier()); - if(ignoreWithGlobalPattern) + if (ignoreWithGlobalPattern) { var regex = new StandardRegex(RepositoryLocator.CatalogueRepository) { @@ -105,16 +106,16 @@ public void TestTemporalTable(bool ignoreWithGlobalPattern) } else { - var col = ti.ColumnInfos.Single(c=>c.GetRuntimeName().Equals("ValidFrom")); + var col = ti.ColumnInfos.Single(c => c.GetRuntimeName().Equals("ValidFrom")); col.IgnoreInLoads = true; col.SaveToDatabase(); - col = ti.ColumnInfos.Single(c=>c.GetRuntimeName().Equals("ValidTo")); + col = ti.ColumnInfos.Single(c => c.GetRuntimeName().Equals("ValidTo")); col.IgnoreInLoads = true; col.SaveToDatabase(); } - var dbConfig = new HICDatabaseConfiguration(lmd,null); + var dbConfig = new HICDatabaseConfiguration(lmd, null); var loadFactory = new HICDataLoadFactory( lmd, @@ -127,17 +128,18 @@ public void TestTemporalTable(bool ignoreWithGlobalPattern) var exe = loadFactory.Create(new ThrowImmediatelyDataLoadEventListener()); var exitCode = exe.Run( - new DataLoadJob(RepositoryLocator,"Go go go!", logManager, lmd, projectDirectory,new ThrowImmediatelyDataLoadEventListener(),dbConfig), + new DataLoadJob(RepositoryLocator, "Go go go!", logManager, lmd, projectDirectory, + new ThrowImmediatelyDataLoadEventListener(), dbConfig), new GracefulCancellationToken()); - Assert.AreEqual(ExitCodeType.Success,exitCode); + Assert.AreEqual(ExitCodeType.Success, exitCode); //frank should be updated to his new departement and role - Assert.AreEqual(2,tbl.GetRowCount()); + Assert.AreEqual(2, tbl.GetRowCount()); var result = tbl.GetDataTable(); - var frank = result.Rows.Cast().Single(r => (string) r["Name"] == "Frank"); - Assert.AreEqual("Department of F'Tang",frank["Department"]); - Assert.AreEqual("Boss",frank["Position"]); + var frank = result.Rows.Cast().Single(r => (string)r["Name"] == "Frank"); + Assert.AreEqual("Department of F'Tang", frank["Department"]); + Assert.AreEqual("Boss", frank["Position"]); //post test cleanup foreach (var regex in RepositoryLocator.CatalogueRepository.GetAllObjects()) diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ToMemoryDataLoadJob.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ToMemoryDataLoadJob.cs index cfd83d79fc..b47269a44c 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ToMemoryDataLoadJob.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ToMemoryDataLoadJob.cs @@ -23,10 +23,11 @@ namespace Rdmp.Core.Tests.DataLoad.Engine.Integration; public class ToMemoryDataLoadJob : ToMemoryDataLoadEventListener, IDataLoadJob { private List _crashAtEnd = new(); + /// public IReadOnlyCollection CrashAtEndMessages => _crashAtEnd.AsReadOnly(); - public ToMemoryDataLoadJob(bool throwOnErrorEvents = true): base(throwOnErrorEvents) + public ToMemoryDataLoadJob(bool throwOnErrorEvents = true) : base(throwOnErrorEvents) { } @@ -37,8 +38,8 @@ public ToMemoryDataLoadJob(bool throwOnErrorEvents = true): base(throwOnErrorEve public ILoadMetadata LoadMetadata { get; private set; } public bool DisposeImmediately { get; private set; } public string ArchiveFilepath { get; private set; } - public List RegularTablesToLoad { get; private set; } = new List(); - public List LookupTablesToLoad { get; private set; } = new List(); + public List RegularTablesToLoad { get; private set; } = new(); + public List LookupTablesToLoad { get; private set; } = new(); public IRDMPPlatformRepositoryServiceLocator RepositoryLocator => null; public void StartLogging() @@ -65,10 +66,13 @@ public void PushForDisposal(IDisposeAfterDataLoad disposeable) public void LoadCompletedSoDispose(ExitCodeType exitCode, IDataLoadEventListener postLoadEventsListener) { } + public ColumnInfo[] GetAllColumns() { - return RegularTablesToLoad.SelectMany(t=>t.ColumnInfos).Union(LookupTablesToLoad.SelectMany(t=>t.ColumnInfos)).Distinct().ToArray(); + return RegularTablesToLoad.SelectMany(t => t.ColumnInfos) + .Union(LookupTablesToLoad.SelectMany(t => t.ColumnInfos)).Distinct().ToArray(); } + /// public void CrashAtEnd(NotifyEventArgs because) { diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/WebServiceConfigurationTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/WebServiceConfigurationTests.cs index 18dbde6bff..cb817aa26d 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/WebServiceConfigurationTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/WebServiceConfigurationTests.cs @@ -15,7 +15,7 @@ public class WebServiceConfigurationTests : DatabaseTests [Test] public void TestXmlSerialization() { - var config = new WebServiceConfiguration(CatalogueRepository) {Username = "foo", Password = "bar"}; + var config = new WebServiceConfiguration(CatalogueRepository) { Username = "foo", Password = "bar" }; var state = config.SaveStateToString(); config.RestoreStateFrom(state); } diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Resources/XmlTestForExcel.xml b/Rdmp.Core.Tests/DataLoad/Engine/Resources/XmlTestForExcel.xml index ed0027ebbb..b9e416f6c7 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Resources/XmlTestForExcel.xml +++ b/Rdmp.Core.Tests/DataLoad/Engine/Resources/XmlTestForExcel.xml @@ -1,145 +1,210 @@  + - - Marie Pitkethly - Thomas Nind - 2014-10-15T13:59:26Z - 2014-10-15T13:56:39Z - 14.00 - - - - - - 10005 - 10005 - 120 - 135 - False - False - - - - - - - - - - -
- - - Node - HealthBoard Area - Organisation Name - PracticeCode - Address1 - Address2 - Address3 - Address4 - PostCode - Practice Managers - Practice Manager Emails - - - East - Fife - Airlie Medical Practice - 11111 - The Health Centre - Victoria Road - Leven - Fife - KY8 4ET - Captain Morgan - fishsticks@nhs.net - - - East - Fife - Anstruther Medical Practice - 22222 - Skeith Health Centre - Crail Road, Cellardyke - Anstruther - KY10 3FF - Thomas Nind - t.z.nind@nhs.net - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-