Apply R# clean-up for reliability (#877)
* Apply R# clean-up for reliability - Migrate to NUnit4 Assert.That - Update dependencise versions - Fix LangVersion to 9.0 (until net core migration) - Reformat code - Apply 'var' style (easier for refactoring) - Remove redundant parentheses - Add braces on every condition blocks (1 line) - Uses new null checking patterns - Uses AutoProperties when possible - Uses string scalar type instead of class - Clean usings - Add .orig files in git ignore - Rename some properties to respect defined conventions and US format definition - ID -> Id - BPM -> Bpm - Finish -> End * Update R# settings according to the clean-up made
This commit is contained in:
1 parent
b9b0f7c8df
commit
6ffa63b923
236 files changed
+14194
-7278
No files matched your search
@@ -15,7 +15,6 @@
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using VocaluxeLib.Log;
|
||||
@@ -28,7 +27,6 @@ namespace Tests.VocaluxeLib.Log
|
||||
private string _TestFolder;
|
||||
|
||||
#region Setup methods
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
@@ -40,18 +38,16 @@ namespace Tests.VocaluxeLib.Log
|
||||
{
|
||||
Directory.Delete(_TestFolder, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tests
|
||||
|
||||
[Test]
|
||||
public void BenchmarkTimeTest()
|
||||
{
|
||||
const string testMessage = "BenchmarkTime Test";
|
||||
string testFileName = Path.GetRandomFileName();
|
||||
string testFileSongName = Path.GetRandomFileName();
|
||||
string testFileMarkerName = Path.GetRandomFileName();
|
||||
var testFileName = Path.GetRandomFileName();
|
||||
var testFileSongName = Path.GetRandomFileName();
|
||||
var testFileMarkerName = Path.GetRandomFileName();
|
||||
const string versionTag = "Test Version (1.2.4)";
|
||||
|
||||
// Init Log
|
||||
@@ -68,59 +64,59 @@ namespace Tests.VocaluxeLib.Log
|
||||
CLog.Close();
|
||||
|
||||
// Check log
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileName)), "Mainlog file is missing.");
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileSongName)), "Songlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileName)), Is.True, "Mainlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileSongName)), Is.True, "Songlog file is missing.");
|
||||
|
||||
string mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
string songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
var mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
var songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
|
||||
StringAssert.Contains($"[Information] Started \"{ testMessage }\"", mainLogContent, "Start entry wrong");
|
||||
StringAssert.Contains($"[Information] Finished \"{ testMessage }\" successfully in ", mainLogContent, "Finish entry wrong");
|
||||
StringAssert.AreEqualIgnoringCase("", songLogContent, "Benchmark should not create song log entries");
|
||||
Assert.That(mainLogContent, Contains.Substring($"[Information] Started \"{testMessage}\""), "Start entry wrong");
|
||||
Assert.That(mainLogContent, Contains.Substring($"[Information] Finished \"{testMessage}\" successfully in "), "Finish entry wrong");
|
||||
Assert.That(songLogContent, Is.Empty, "Benchmark should not create song log entries");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BenchmarkBeginTest()
|
||||
{
|
||||
const string testMessage = "BenchmarkBegin Test";
|
||||
string testFileName = Path.GetRandomFileName();
|
||||
string testFileSongName = Path.GetRandomFileName();
|
||||
string testFileMarkerName = Path.GetRandomFileName();
|
||||
var testFileName = Path.GetRandomFileName();
|
||||
var testFileSongName = Path.GetRandomFileName();
|
||||
var testFileMarkerName = Path.GetRandomFileName();
|
||||
const string versionTag = "Test Version (1.2.4)";
|
||||
|
||||
// Init Log
|
||||
CLog.Init(_TestFolder, testFileName, testFileSongName, testFileMarkerName, versionTag,
|
||||
(crash, cont, tag, log, error) => { Assert.Fail("Benchmarks should not show the reporter."); },
|
||||
ELogLevel.Verbose);
|
||||
|
||||
|
||||
using (var token = CBenchmark.Begin(testMessage))
|
||||
{
|
||||
System.Threading.Thread.Sleep(1);
|
||||
token.End();
|
||||
}
|
||||
|
||||
|
||||
// Close logfile
|
||||
CLog.Close();
|
||||
|
||||
// Check log
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileName)), "Mainlog file is missing.");
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileSongName)), "Songlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileName)), Is.True, "Mainlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileSongName)), Is.True, "Songlog file is missing.");
|
||||
|
||||
string mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
string songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
var mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
var songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
|
||||
StringAssert.Contains($"[Information] Started \"{ testMessage }\"", mainLogContent, "Start entry wrong");
|
||||
StringAssert.Contains($"[Information] Finished \"{ testMessage }\" successfully in ", mainLogContent, "Finish entry wrong");
|
||||
StringAssert.AreEqualIgnoringCase("", songLogContent, "Benchmark should not create song log entries");
|
||||
Assert.That(mainLogContent, Contains.Substring($"[Information] Started \"{testMessage}\""), "Start entry wrong");
|
||||
Assert.That(mainLogContent, Contains.Substring($"[Information] Finished \"{testMessage}\" successfully in "), "Finish entry wrong");
|
||||
Assert.That(songLogContent, Is.Empty, "Benchmark should not create song log entries");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BenchmarkBeginWithoutEndTest()
|
||||
{
|
||||
const string testMessage = "BenchmarkBegin Test";
|
||||
string testFileName = Path.GetRandomFileName();
|
||||
string testFileSongName = Path.GetRandomFileName();
|
||||
string testFileMarkerName = Path.GetRandomFileName();
|
||||
var testFileName = Path.GetRandomFileName();
|
||||
var testFileSongName = Path.GetRandomFileName();
|
||||
var testFileMarkerName = Path.GetRandomFileName();
|
||||
const string versionTag = "Test Version (1.2.4)";
|
||||
|
||||
// Init Log
|
||||
@@ -137,28 +133,25 @@ namespace Tests.VocaluxeLib.Log
|
||||
CLog.Close();
|
||||
|
||||
// Check log
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileName)), "Mainlog file is missing.");
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileSongName)), "Songlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileName)), Is.True, "Mainlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileSongName)), Is.True, "Songlog file is missing.");
|
||||
|
||||
string mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
string songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
var mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
var songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
|
||||
StringAssert.Contains($"[Information] Started \"{ testMessage }\"", mainLogContent, "Start entry wrong");
|
||||
StringAssert.Contains($"[Information] Failed \"{ testMessage }\" in ", mainLogContent, "Finish entry wrong");
|
||||
StringAssert.AreEqualIgnoringCase("", songLogContent, "Benchmark should not create song log entries");
|
||||
Assert.That(mainLogContent, Contains.Substring($"[Information] Started \"{testMessage}\""), "Start entry wrong");
|
||||
Assert.That(mainLogContent, Contains.Substring($"[Information] Failed \"{testMessage}\" in "), "Finish entry wrong");
|
||||
Assert.That(songLogContent, Is.Empty, "Benchmark should not create song log entries");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper methods
|
||||
|
||||
private string _GetTemporaryDirectory()
|
||||
{
|
||||
string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(tempDirectory);
|
||||
return tempDirectory;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
+566
-579
File diff suppressed because it is too large.
Load diff
@@ -92,16 +92,16 @@ namespace Tests.VocaluxeLib.Log
|
||||
(crash, cont, tag, log, error) =>
|
||||
{
|
||||
messageShown = true;
|
||||
Assert.IsTrue(show);
|
||||
Assert.IsFalse(crash);
|
||||
Assert.IsTrue(cont);
|
||||
Assert.AreEqual(versionTag, tag);
|
||||
Assert.That(show, Is.True);
|
||||
Assert.That(crash, Is.False);
|
||||
Assert.That(cont, Is.True);
|
||||
Assert.That(tag, Is.EqualTo(versionTag));
|
||||
|
||||
StringAssert.Contains("[Information] Starting to log", log, "Main log start entry wrong");
|
||||
StringAssert.Contains("Version = " + versionTag, log, "Main log version tag entry wrong");
|
||||
StringAssert.Contains("[<#= LogLevel #>] " + <#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>, log, "Main log entry wrong");
|
||||
Assert.That(log, Contains.Substring("[Information] Starting to log"), "Main log start entry wrong");
|
||||
Assert.That(log, Contains.Substring("Version = " + versionTag), "Main log version tag entry wrong");
|
||||
Assert.That(log, Contains.Substring("[<#= LogLevel #>] " + <#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>), "Main log entry wrong");
|
||||
|
||||
StringAssert.Contains(<#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>, error, "Error message wrong");
|
||||
Assert.That(error, Contains.Substring(<#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>), "Error message wrong");
|
||||
},
|
||||
ELogLevel.Verbose);
|
||||
|
||||
@@ -115,27 +115,27 @@ namespace Tests.VocaluxeLib.Log
|
||||
CLog.Close();
|
||||
|
||||
// Check log
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileName)), "Mainlog file is missing.");
|
||||
Assert.IsTrue(File.Exists(Path.Combine(_TestFolder, testFileSongName)), "Songlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileName)), Is.True, "Mainlog file is missing.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, testFileSongName)), Is.True, "Songlog file is missing.");
|
||||
|
||||
string mainLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileName));
|
||||
string songLogContent = File.ReadAllText(Path.Combine(_TestFolder, testFileSongName));
|
||||
|
||||
StringAssert.Contains("[Information] Starting to log", mainLogContent, "Main log start entry wrong");
|
||||
StringAssert.Contains("Version = " + versionTag, mainLogContent, "Main log version tag entry wrong");
|
||||
StringAssert.Contains("[<#= LogLevel #>] " +<#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>, mainLogContent, "Main log entry wrong");
|
||||
Assert.That(mainLogContent, Contains.Substring("[Information] Starting to log"), "Main log start entry wrong");
|
||||
Assert.That(mainLogContent, Contains.Substring("Version = " + versionTag), "Main log version tag entry wrong");
|
||||
Assert.That(mainLogContent, Contains.Substring("[<#= LogLevel #>] " +<#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>), "Main log entry wrong");
|
||||
<# if(WithException) { #>
|
||||
StringAssert.Contains(_TestExceptionMessage, mainLogContent, "Exception is missing");
|
||||
Assert.That(mainLogContent, Contains.Substring(_TestExceptionMessage), "Exception is missing");
|
||||
<# } #>
|
||||
<# if(WithData) { #>
|
||||
StringAssert.Contains(_SecondParam, mainLogContent, "Second data field is missing");
|
||||
Assert.That(mainLogContent, Contains.Substring(_SecondParam), "Second data field is missing");
|
||||
<# } #>
|
||||
<# if(LogLevel!="Fatal") { #>
|
||||
StringAssert.Contains(<#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>, songLogContent, "Song log entry wrong");
|
||||
Assert.That(songLogContent, Contains.Substring(<#= WithData?"_TestMessageWithResolvedData":"_TestMessage" #>), "Song log entry wrong");
|
||||
<# } #>
|
||||
if(!show)
|
||||
{
|
||||
Assert.IsFalse(messageShown);
|
||||
Assert.That(messageShown, Is.False);
|
||||
}
|
||||
}
|
||||
<# } #>
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace Tests.VocaluxeLib.Log.Rolling
|
||||
private string _TestFolder;
|
||||
|
||||
#region Setup methods
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
@@ -41,20 +40,18 @@ namespace Tests.VocaluxeLib.Log.Rolling
|
||||
{
|
||||
Directory.Delete(_TestFolder, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tests
|
||||
|
||||
[Test]
|
||||
public void RollFilesTest([Range(0,4)] int numFilesExisting, [Range(0, 3)] int numOldFilesToKeep)
|
||||
public void RollFilesTest([Range(0, 4)] int numFilesExisting, [Range(0, 3)] int numOldFilesToKeep)
|
||||
{
|
||||
// Create existing files
|
||||
if (numFilesExisting > 0)
|
||||
{
|
||||
CreateFile(_TestFolder, _TestFileName, 0);
|
||||
}
|
||||
|
||||
|
||||
for (var i = 1; i < numFilesExisting; i++)
|
||||
{
|
||||
CreateFile(_TestFolder, GetFileName(i), i);
|
||||
@@ -63,33 +60,31 @@ namespace Tests.VocaluxeLib.Log.Rolling
|
||||
|
||||
// Roll the files
|
||||
CLogFileRoller.RollLogs(Path.Combine(_TestFolder, _TestFileName), numOldFilesToKeep);
|
||||
|
||||
|
||||
|
||||
// Check main file
|
||||
Assert.IsFalse(File.Exists(Path.Combine(_TestFolder, _TestFileName)), "Main file was not deleted.");
|
||||
Assert.That(File.Exists(Path.Combine(_TestFolder, _TestFileName)), Is.False, "Main file was not deleted.");
|
||||
//Check other files
|
||||
for (int i = 1; i <= Math.Max(numOldFilesToKeep, numFilesExisting); i++)
|
||||
for (var i = 1; i <= Math.Max(numOldFilesToKeep, numFilesExisting); i++)
|
||||
{
|
||||
var fileToCheck = Path.Combine(_TestFolder, GetFileName(i));
|
||||
if (i <= Math.Min(numFilesExisting,numOldFilesToKeep))
|
||||
if (i <= Math.Min(numFilesExisting, numOldFilesToKeep))
|
||||
{
|
||||
Assert.IsTrue(File.Exists(fileToCheck), $"File {GetFileName(i)} is missing.");
|
||||
Assert.AreEqual((i - 1).ToString(), File.ReadAllText(fileToCheck), "Rotation is wrong");
|
||||
Assert.That(File.Exists(fileToCheck), Is.True, $"File {GetFileName(i)} is missing.");
|
||||
Assert.That(File.ReadAllText(fileToCheck), Is.EqualTo((i - 1).ToString()), "Rotation is wrong");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(File.Exists(fileToCheck));
|
||||
Assert.That(File.Exists(fileToCheck), Is.False);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper methods
|
||||
|
||||
private string _GetTemporaryDirectory()
|
||||
{
|
||||
string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(tempDirectory);
|
||||
return tempDirectory;
|
||||
}
|
||||
@@ -103,8 +98,6 @@ namespace Tests.VocaluxeLib.Log.Rolling
|
||||
{
|
||||
return _TestFileName.Replace(".", $"_{i}.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user