Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeQL fixups #2134

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)

private void newFindToolStripMenuItem_Click(object sender, EventArgs e)
{
var focusItem = _windowManager.GetAllWindows<RDMPUserControl>().Where(c => c.ContainsFocus).FirstOrDefault();
var nf = new NewfindUI(Activator, false,focusItem);
var focusItem = _windowManager.GetAllWindows<RDMPUserControl>().FirstOrDefault(c => c.ContainsFocus);
var nf = new NewfindUI(Activator, false, focusItem);
nf.ShowDialog();
}

private void newReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
var nf = new NewfindUI(Activator, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ private T Activate<T, T2>(T2 databaseObject, Image<Rgba32> tabImage)
var floatable = WindowFactory.Create(this, RefreshBus, uiInstance, tabImage, databaseObject);

int? insertIndex = null;
var panel = _mainDockPanel.Panes.Where(p => p.IsActiveDocumentPane).SingleOrDefault();
var panel = _mainDockPanel.Panes.SingleOrDefault(static p => p.IsActiveDocumentPane);
if (panel is not null)
{
var contents = panel.Contents;
insertIndex = contents.IndexOf(panel.ActiveContent)+1;
insertIndex = contents.IndexOf(panel.ActiveContent) + 1;
}

floatable.Show(_mainDockPanel, DockState.Document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace ResearchDataManagementPlatform.WindowManagement.WindowArranging;

/// <inheritdoc/>
public class WindowArranger : IArrangeWindows
public partial class WindowArranger : IArrangeWindows
{
private readonly IActivateItems _activator;
private readonly WindowManager _windowManager;
Expand Down Expand Up @@ -57,10 +57,12 @@ public void Setup(WindowLayout target)

private static bool AreBasicallyTheSameLayout(string oldXml, string newXml)
{
var patStripActive = @"Active.*=[""\-\d]*";
oldXml = Regex.Replace(oldXml, patStripActive, "");
newXml = Regex.Replace(newXml, patStripActive, "");
oldXml = StripActive().Replace(oldXml, "");
newXml = StripActive().Replace(newXml, "");

return oldXml.Equals(newXml, StringComparison.CurrentCultureIgnoreCase);
return oldXml.Equals(newXml, StringComparison.OrdinalIgnoreCase);
}

[GeneratedRegex(@"Active.*=[""\-\d]*")]
private static partial Regex StripActive();
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void ImportCatalogueWithMandatoryFilter()
[TestCase(false)]
public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalOverrideBeforeHand)
{
var parameterSQL = "DECLARE @dragonCount as varchar(100)";
const string parameterSQL = "DECLARE @dragonCount as varchar(100)";

var filter = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ public void TestCloneLoadMetadata()
};
pt1.SaveToDatabase();

pt1.CreateArgumentsForClassIfNotExists(typeof(AnySeparatorFileAttacher));
var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "Separator");
pt1.CreateArgumentsForClassIfNotExists<AnySeparatorFileAttacher>();
var pta = pt1.ProcessTaskArguments.Single(static pt => pt.Name == "Separator");
pta.SetValue(",");
pta.SaveToDatabase();
LoadMetadata clonedLmd;
clonedLmd = lmd1.Clone();
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
var clonedLmd = lmd1.Clone();
Assert.Multiple(() =>
{
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ public void TestCreateLoadMetadataVersion()
};
pt1.SaveToDatabase();

pt1.CreateArgumentsForClassIfNotExists(typeof(AnySeparatorFileAttacher));
var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "Separator");
pt1.CreateArgumentsForClassIfNotExists<AnySeparatorFileAttacher>();
var pta = pt1.ProcessTaskArguments.Single(static pt => pt.Name == "Separator");
pta.SetValue(",");
pta.SaveToDatabase();
LoadMetadata clonedLmd;
clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
var clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.Multiple(() =>
{
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ public void TestRestoreLoadMetadataVersion()
};
pt1.SaveToDatabase();

pt1.CreateArgumentsForClassIfNotExists(typeof(AnySeparatorFileAttacher));
var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "Separator");
pt1.CreateArgumentsForClassIfNotExists<AnySeparatorFileAttacher>();
var pta = pt1.ProcessTaskArguments.Single(static pt => pt.Name == "Separator");
pta.SetValue(",");
pta.SaveToDatabase();
LoadMetadata clonedLmd;
clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
var clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.Multiple(() =>
{
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
});
pt1.DeleteInDatabase();
var fetchedlmd = CatalogueRepository.GetObjectByID<LoadMetadata>(lmd1.ID);
Assert.That(fetchedlmd.ProcessTasks.Count(), Is.EqualTo(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ private DataTable GetRedactionTestDataTable()
var ei = new ExtractionInformation(CatalogueRepository, ci, columnInfo, "");
ei.SaveToDatabase();
}

return (catalogue, _columnInfos);
}

private DataTable Retrieve(DiscoveredDatabase db)
private static DataTable Retrieve(DiscoveredDatabase db)
{
var retrieveSQL = @"select [Condition2] from [RedactionTest]";
const string retrieveSQL = @"select [Condition2] from [RedactionTest]";
var dt = new DataTable();
dt.BeginLoadData();
using (var fetchCmd = db.Server.GetCommand(retrieveSQL, db.Server.GetConnection()))
{
using var da = db.Server.GetDataAdapter(fetchCmd);
da.Fill(dt);
}
using var fetchCmd = db.Server.GetCommand(retrieveSQL, db.Server.GetConnection());
using var da = db.Server.GetDataAdapter(fetchCmd);
da.Fill(dt);
return dt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ private void CreateDatabase()
{
RemoteDatabase = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(RemoteDatabaseName);
RemoteDatabase.Create(true);
using (var dt = new DataTable())
{
dt.Columns.Add("Column1", typeof(string));
dt.Columns.Add("Column2", typeof(int));

var dr = dt.NewRow();
dr["Column1"] = "d";
dr["Column2"] = 100;
dt.Rows.Add(dr);
RemoteTable = RemoteDatabase.CreateTable("SomeTable", dt);
}
using var dt = new DataTable();
dt.Columns.Add("Column1", typeof(string));
dt.Columns.Add("Column2", typeof(int));

var dr = dt.NewRow();
dr["Column1"] = "d";
dr["Column2"] = 100;
dt.Rows.Add(dr);
RemoteTable = RemoteDatabase.CreateTable("SomeTable", dt);
}

private void CreateCatalogue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public void Test_ImportTableInfo_MalformedArgument()
[Test]
public void Test_ImportTableInfo_NoTable()
{
var tbl =
"Table:MyTable:DatabaseType:MicrosoftSQLServer:Server=myServerAddress;Database=myDataBase;Trusted_Connection=True";
const string tbl = "Table:MyTable:DatabaseType:MicrosoftSQLServer:Server=myServerAddress;Database=myDataBase;Trusted_Connection=True";

var ex = Assert.Throws<Exception>(() => GetInvoker().ExecuteCommand(typeof(ExecuteCommandImportTableInfo),
new CommandLineObjectPicker(new string[] { tbl, "true" }, GetActivator())));
Expand Down
109 changes: 55 additions & 54 deletions Rdmp.Core.Tests/Curation/DublinCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,60 +72,61 @@ public void TestWritingDocument()
[Test]
public void TestReadingDocument()
{
var xml =
@"<?xml version=""1.0""?>

<metadata
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xsi:schemaLocation=""http://example.org/myapp/ http://example.org/myapp/schema.xsd""
xmlns:dc=""http://purl.org/dc/elements/1.1/""
xmlns:dcterms=""http://purl.org/dc/terms/"">

<dc:title>
UKOLN
</dc:title>
<dcterms:alternative>
UK Office for Library and Information Networking
</dcterms:alternative>
<dc:subject>
national centre, network information support, library
community, awareness, research, information services,public
library networking, bibliographic management, distributed
library systems, metadata, resource discovery,
conferences,lectures, workshops
</dc:subject>
<dc:subject xsi:type=""dcterms:DDC"">
062
</dc:subject>
<dc:subject xsi:type=""dcterms:UDC"">
061(410)
</dc:subject>
<dc:description>
UKOLN is a national focus of expertise in digital information
management. It provides policy, research and awareness services
to the UK library, information and cultural heritage communities.
UKOLN is based at the University of Bath.
</dc:description>
<dc:description xml:lang=""fr"">
UKOLN est un centre national d'expertise dans la gestion de l'information
digitale.
</dc:description>
<dc:publisher>
UKOLN, University of Bath
</dc:publisher>
<dcterms:isPartOf xsi:type=""dcterms:URI"">
http://www.bath.ac.uk/
</dcterms:isPartOf>
<dc:identifier xsi:type=""dcterms:URI"">
http://www.ukoln.ac.uk/
</dc:identifier>
<dcterms:modified xsi:type=""dcterms:W3CDTF"">
2001-07-18
</dcterms:modified>
<dc:format xsi:type=""dcterms:IMT"">
text/html
</dc:format>
</metadata>";
const string xml = """
<?xml version="1.0"?>

<metadata
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.org/myapp/ http://example.org/myapp/schema.xsd"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/">

<dc:title>
UKOLN
</dc:title>
<dcterms:alternative>
UK Office for Library and Information Networking
</dcterms:alternative>
<dc:subject>
national centre, network information support, library
community, awareness, research, information services,public
library networking, bibliographic management, distributed
library systems, metadata, resource discovery,
conferences,lectures, workshops
</dc:subject>
<dc:subject xsi:type="dcterms:DDC">
062
</dc:subject>
<dc:subject xsi:type="dcterms:UDC">
061(410)
</dc:subject>
<dc:description>
UKOLN is a national focus of expertise in digital information
management. It provides policy, research and awareness services
to the UK library, information and cultural heritage communities.
UKOLN is based at the University of Bath.
</dc:description>
<dc:description xml:lang="fr">
UKOLN est un centre national d'expertise dans la gestion de l'information
digitale.
</dc:description>
<dc:publisher>
UKOLN, University of Bath
</dc:publisher>
<dcterms:isPartOf xsi:type="dcterms:URI">
http://www.bath.ac.uk/
</dcterms:isPartOf>
<dc:identifier xsi:type="dcterms:URI">
http://www.ukoln.ac.uk/
</dc:identifier>
<dcterms:modified xsi:type="dcterms:W3CDTF">
2001-07-18
</dcterms:modified>
<dc:format xsi:type="dcterms:IMT">
text/html
</dc:format>
</metadata>
""";

var fi = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "dublinTestReading.xml"));
File.WriteAllText(fi.FullName, xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,40 +182,42 @@ public void SingleParameterTest_Template_TemplateValuesUsed()
b=@b")]
public void ReplaceParametersSQL(string haystack, string needle, string replacement, string expectedOutput)
{
var output = ParameterCreator.RenameParameterInSQL(haystack, needle, replacement);
Assert.That(output, Is.EqualTo(expectedOutput));
var output = ParameterCreator.RenameParameterInSQL(haystack, needle, replacement);
Assert.That(output, Is.EqualTo(expectedOutput));
}

[Test]
public void SequentialReplacementSQL()
{
var haystack =
@"/*Paracetamol*/
[test]..[prescribing].[approved_name] LIKE @drugName
OR
/*Ketamine*/
[test]..[prescribing].[approved_name] LIKE @drugName2
OR
/*Approved Name Like*/
[test]..[prescribing].[approved_name] LIKE @drugName3";


var newString = ParameterCreator.RenameParameterInSQL(haystack, "@drugName", "@drugName_2");
newString = ParameterCreator.RenameParameterInSQL(newString, "@drugName2", "@drugName2_2");
newString = ParameterCreator.RenameParameterInSQL(newString, "@drugName3", "@drugName3_2");


var expectedoutput =
@"/*Paracetamol*/
[test]..[prescribing].[approved_name] LIKE @drugName_2
OR
/*Ketamine*/
[test]..[prescribing].[approved_name] LIKE @drugName2_2
OR
/*Approved Name Like*/
[test]..[prescribing].[approved_name] LIKE @drugName3_2";


Assert.That(newString, Is.EqualTo(expectedoutput));
const string haystack = """
/*Paracetamol*/
[test]..[prescribing].[approved_name] LIKE @drugName
OR
/*Ketamine*/
[test]..[prescribing].[approved_name] LIKE @drugName2
OR
/*Approved Name Like*/
[test]..[prescribing].[approved_name] LIKE @drugName3
""";


var newString = ParameterCreator.RenameParameterInSQL(haystack, "@drugName", "@drugName_2");
newString = ParameterCreator.RenameParameterInSQL(newString, "@drugName2", "@drugName2_2");
newString = ParameterCreator.RenameParameterInSQL(newString, "@drugName3", "@drugName3_2");


const string expectedoutput = """
/*Paracetamol*/
[test]..[prescribing].[approved_name] LIKE @drugName_2
OR
/*Ketamine*/
[test]..[prescribing].[approved_name] LIKE @drugName2_2
OR
/*Approved Name Like*/
[test]..[prescribing].[approved_name] LIKE @drugName3_2
""";


Assert.That(newString, Is.EqualTo(expectedoutput));
}
}
Loading