Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
Fix: Another round of SonarQube fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapellman committed Aug 13, 2024
1 parent 229c9cb commit 8662828
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 84 deletions.
18 changes: 9 additions & 9 deletions src/MLIDS.UnitTests/lib/DAL/JsonFileDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class JsonDAL
[TestMethod]
public async Task JsonDAL_NullTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await jsonDal.GetHostPacketsAsync(null);

Expand All @@ -22,7 +22,7 @@ public async Task JsonDAL_NullTestAsync()
[TestMethod]
public async Task JsonDAL_StringTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await jsonDal.GetHostPacketsAsync("test");

Expand All @@ -33,7 +33,7 @@ public async Task JsonDAL_StringTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task JsonDAL_WriteNullTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

await jsonDal.WritePacketAsync(null);
}
Expand All @@ -42,15 +42,15 @@ public async Task JsonDAL_WriteNullTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task JsonDAL_QueryNullTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

await jsonDal.QueryPacketsAsync(null);
}

[TestMethod]
public async Task JsonDAL_QueryEmptyTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await jsonDal.QueryPacketsAsync(a => a.Label);

Expand All @@ -60,7 +60,7 @@ public async Task JsonDAL_QueryEmptyTestAsync()
[TestMethod]
public void JsonDAL_InitializeTest()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = jsonDal.Initialize();

Expand All @@ -71,7 +71,7 @@ public void JsonDAL_InitializeTest()
[ExpectedException(typeof(ArgumentNullException))]
public async Task JSONDAL_NullFileNameTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem());
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await jsonDal.WritePacketAsync(new MLIDS.lib.ML.Objects.PayloadItem
{
Expand All @@ -98,7 +98,7 @@ public async Task JSONDAL_NullFileNameTestAsync()
[TestMethod]
public async Task JSONDAL_WriteNotEmptyTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem
{
DAL_FileName = "Testo.json"
});
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task JSONDAL_WriteNotEmptyTestAsync()
[TestMethod]
public async Task JSONDAL_QueryTestAsync()
{
var jsonDal = new MLIDS.lib.DAL.JsonFileDAL(new MLIDS.lib.Containers.SettingsItem
var jsonDal = new MLIDS.lib.DAL.JsonFileDal(new MLIDS.lib.Containers.SettingsItem
{
DAL_FileName = "Testo.json"
});
Expand Down
14 changes: 7 additions & 7 deletions src/MLIDS.UnitTests/lib/DAL/LiteDBDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class LiteDBDAL
[ExpectedException(typeof(ArgumentNullException))]
public void LiteDBDAL_NullTest()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(null);
var litedb = new MLIDS.lib.DAL.LiteDbdal(null);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public async Task LiteDBDAL_StringTestAsync()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(new MLIDS.lib.Containers.SettingsItem());
var litedb = new MLIDS.lib.DAL.LiteDbdal(new MLIDS.lib.Containers.SettingsItem());

await litedb.GetHostPacketsAsync("test");
}
Expand All @@ -29,15 +29,15 @@ public async Task LiteDBDAL_StringTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task LiteDBDAL_WriteNullTestAsync()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(new MLIDS.lib.Containers.SettingsItem());
var litedb = new MLIDS.lib.DAL.LiteDbdal(new MLIDS.lib.Containers.SettingsItem());

await litedb.WritePacketAsync(null);
}

[TestMethod]
public async Task LiteDBDAL_WriteEmptyTestAsync()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(new MLIDS.lib.Containers.SettingsItem
var litedb = new MLIDS.lib.DAL.LiteDbdal(new MLIDS.lib.Containers.SettingsItem
{
DAL_FileName = "testo.db"
});
Expand All @@ -55,7 +55,7 @@ public async Task LiteDBDAL_WriteEmptyTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task LiteDBDAL_QueryNullTestAsync()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(new MLIDS.lib.Containers.SettingsItem());
var litedb = new MLIDS.lib.DAL.LiteDbdal(new MLIDS.lib.Containers.SettingsItem());

await litedb.QueryPacketsAsync(null);
}
Expand All @@ -64,7 +64,7 @@ public async Task LiteDBDAL_QueryNullTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task LiteDBDAL_QueryEmptyTestAsync()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(new MLIDS.lib.Containers.SettingsItem());
var litedb = new MLIDS.lib.DAL.LiteDbdal(new MLIDS.lib.Containers.SettingsItem());

var result = await litedb.QueryPacketsAsync(a => a.Label);

Expand All @@ -74,7 +74,7 @@ public async Task LiteDBDAL_QueryEmptyTestAsync()
[TestMethod]
public void LiteDBDAL_Initialize()
{
var litedb = new MLIDS.lib.DAL.LiteDBDAL(new MLIDS.lib.Containers.SettingsItem());
var litedb = new MLIDS.lib.DAL.LiteDbdal(new MLIDS.lib.Containers.SettingsItem());

var result = litedb.Initialize();

Expand Down
10 changes: 5 additions & 5 deletions src/MLIDS.UnitTests/lib/DAL/MongoDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MongoDAL
[TestMethod]
public async Task MongoDAL_NullTestAsync()
{
var mongo = new MLIDS.lib.DAL.MongoDAL(new MLIDS.lib.Containers.SettingsItem());
var mongo = new MLIDS.lib.DAL.MongoDal(new MLIDS.lib.Containers.SettingsItem());

mongo.Initialize();

Expand All @@ -25,7 +25,7 @@ public async Task MongoDAL_NullTestAsync()
[TestMethod]
public async Task MongoDAL_StringTestAsync()
{
var mongo = new MLIDS.lib.DAL.MongoDAL(new MLIDS.lib.Containers.SettingsItem());
var mongo = new MLIDS.lib.DAL.MongoDal(new MLIDS.lib.Containers.SettingsItem());

mongo.Initialize();

Expand All @@ -38,7 +38,7 @@ public async Task MongoDAL_StringTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task MongoDAL_WriteNullTestAsync()
{
var mongo = new MLIDS.lib.DAL.MongoDAL(new MLIDS.lib.Containers.SettingsItem());
var mongo = new MLIDS.lib.DAL.MongoDal(new MLIDS.lib.Containers.SettingsItem());

await mongo.WritePacketAsync(null);
}
Expand All @@ -47,15 +47,15 @@ public async Task MongoDAL_WriteNullTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task MongoDAL_QueryNullTestAsync()
{
var mongo = new MLIDS.lib.DAL.MongoDAL(new MLIDS.lib.Containers.SettingsItem());
var mongo = new MLIDS.lib.DAL.MongoDal(new MLIDS.lib.Containers.SettingsItem());

await mongo.QueryPacketsAsync(null);
}

[TestMethod]
public async Task MongoDAL_QueryEmptyTestAsync()
{
var mongo = new MLIDS.lib.DAL.MongoDAL(new MLIDS.lib.Containers.SettingsItem());
var mongo = new MLIDS.lib.DAL.MongoDal(new MLIDS.lib.Containers.SettingsItem());

mongo.Initialize();

Expand Down
4 changes: 2 additions & 2 deletions src/MLIDS.UnitTests/lib/Helpers/DALHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class DALHelper
[ExpectedException(typeof(ArgumentNullException))]
public void DALHelperTests_NullSettings()
{
_ = MLIDS.lib.Helpers.DALHelper.GetAvailableDALs(null);
_ = MLIDS.lib.Helpers.DalHelper.GetAvailableDALs(null);
}

[TestMethod]
public void DALHelperTests_EmptySettings()
{
var result = MLIDS.lib.Helpers.DALHelper.GetAvailableDALs(new MLIDS.lib.Containers.SettingsItem());
var result = MLIDS.lib.Helpers.DalHelper.GetAvailableDALs(new MLIDS.lib.Containers.SettingsItem());

Assert.IsTrue(result.Count == 5);
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.UnitTests/lib/ML/Trainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Trainer_NullTest()
[ExpectedException(typeof(FileNotFoundException))]
public async Task Trainer_ModelNotFoundTest()
{
await new MLIDS.lib.ML.Trainer().GenerateModel(new MongoDAL(new MLIDS.lib.Containers.SettingsItem()), "test");
await new MLIDS.lib.ML.Trainer().GenerateModel(new MongoDal(new MLIDS.lib.Containers.SettingsItem()), "test");
}
}
}
12 changes: 6 additions & 6 deletions src/MLIDS.lib.Windows/ViewModels/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public bool StopBtnEnabled
}
}

private List<MLIDSDevice> _deviceList = new();
private List<MlidsDevice> _deviceList = new();

public List<MLIDSDevice> DeviceList
public List<MlidsDevice> DeviceList
{
get => _deviceList;

Expand All @@ -119,9 +119,9 @@ public List<MLIDSDevice> DeviceList
}
}

private MLIDSDevice _selectedDevice;
private MlidsDevice _selectedDevice;

public MLIDSDevice SelectedDevice
public MlidsDevice SelectedDevice
{
get => _selectedDevice;

Expand Down Expand Up @@ -179,7 +179,7 @@ public string SettingsJSON

protected BaseViewModel()
{
DeviceList = CaptureDeviceList.Instance.Where(a => a is PcapDevice).OrderBy(a => a.Description).Select(b => new MLIDSDevice(b)).ToList();
DeviceList = CaptureDeviceList.Instance.Where(a => a is PcapDevice).OrderBy(a => a.Description).Select(b => new MlidsDevice(b)).ToList();

SelectedDevice = DeviceList.FirstOrDefault();

Expand All @@ -192,7 +192,7 @@ protected BaseViewModel()

SettingsJSON = JsonSerializer.Serialize(Settings);

DataLayers = DALHelper.GetAvailableDALs(Settings);
DataLayers = DalHelper.GetAvailableDALs(Settings);

SelectedDataLayer = DataLayers.First(a => !a.IsSelectable);
}
Expand Down
25 changes: 8 additions & 17 deletions src/MLIDS.lib/DAL/CSVFileDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@

namespace MLIDS.lib.DAL
{
public class CsvFileDal : BaseDal
public class CsvFileDal(SettingsItem settingsItem) : BaseDal(settingsItem)
{
public class CSVWriter
public class CsvWriter(string filePath)
{
private string Filepath { get; set; }

public CSVWriter(string filePath)
{
Filepath = filePath;
}
private string Filepath { get; set; } = filePath;

public async Task WriteToFileAsync(string text)
{
Expand All @@ -33,19 +28,15 @@ public async Task WriteToFileAsync(string text)
}
}

private CSVWriter _writer;
private CsvWriter _writer;

private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();

private const string DEFAULT_CSV_FILE = "db.csv";

private string _fileName;

public CsvFileDal(SettingsItem settingsItem) : base(settingsItem)
{
}

public override string Description => "CSV";
public override string Description => "Csv";

public override bool IsSelectable => true;

Expand Down Expand Up @@ -82,7 +73,7 @@ public override bool Initialize()
{
_fileName = settingsItem.DAL_FileName ?? DEFAULT_CSV_FILE;

_writer = new CSVWriter(_fileName);
_writer = new CsvWriter(_fileName);

return File.Exists(_fileName);
}
Expand All @@ -98,7 +89,7 @@ public override async Task<List<PayloadItem>> QueryPacketsAsync(Expression<Func<

if (!File.Exists(_fileName))
{
return new List<PayloadItem>();
return [];
}

var lines = await File.ReadAllLinesAsync(_fileName);
Expand All @@ -110,7 +101,7 @@ public override async Task<List<PayloadItem>> QueryPacketsAsync(Expression<Func<
data.Add(line.FromCSV<PayloadItem>());
}

return data.AsQueryable().Where(queryExpression).ToList();
return [.. data.AsQueryable().Where(queryExpression)];
}

public override async Task<bool> WritePacketAsync(PayloadItem packet)
Expand Down
4 changes: 2 additions & 2 deletions src/MLIDS.lib/DAL/EmptyDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

namespace MLIDS.lib.DAL
{
public class EmptyDAL : BaseDal
public class EmptyDal : BaseDal
{
public override string Description => "--Select a Data Layer--";

public override bool IsSelectable => false;

public EmptyDAL(SettingsItem settings) : base(settings) { }
public EmptyDal(SettingsItem settings) : base(settings) { }

public override Task<List<PayloadItem>> GetHostPacketsAsync(string hostName)
{
Expand Down
8 changes: 4 additions & 4 deletions src/MLIDS.lib/DAL/JsonFileDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MLIDS.lib.DAL
{
public class JsonFileDAL : BaseDal
public class JsonFileDal : BaseDal
{
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();

Expand All @@ -22,7 +22,7 @@ public class JsonFileDAL : BaseDal

public override string Description => "JSON";

public JsonFileDAL(SettingsItem settings) : base(settings) { }
public JsonFileDal(SettingsItem settings) : base(settings) { }

public override bool IsSelectable => true;

Expand All @@ -44,7 +44,7 @@ public override async Task<List<PayloadItem>> QueryPacketsAsync(Expression<Func<
{
if (queryExpression == null)
{
Log.Error($"JsonFileDAL::QueryPacketsAsync - Query Expression was null");
Log.Error($"JsonFileDal::QueryPacketsAsync - Query Expression was null");

throw new ArgumentNullException(nameof(queryExpression));
}
Expand All @@ -65,7 +65,7 @@ public override async Task<bool> WritePacketAsync(PayloadItem packet)
{
if (packet == null)
{
Log.Error($"JsonFileDAL::WritePacketAsync - packet was null");
Log.Error($"JsonFileDal::WritePacketAsync - packet was null");

throw new ArgumentNullException(nameof(packet));
}
Expand Down
Loading

0 comments on commit 8662828

Please sign in to comment.