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

Fixed TRX file overwrite in certain circumstances #2508

Merged
16 commits merged into from
Aug 7, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactored some tests.
  • Loading branch information
Haplois committed Aug 7, 2020
commit c67c60232e2e255e971d12203bbb827a755fcd8e
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public void DefaultTrxFileNameVerification()

var time = DateTime.Now;
var internalFileHelper = new InternalFileHelper(() => time);

testableTrxLogger = new TestableTrxLogger(new FileHelper(), internalFileHelper);
testableTrxLogger.Initialize(this.events.Object, this.parameters);

Expand All @@ -657,7 +657,7 @@ public void DefaultTrxFileNameVerification()
var expectedName = $"{DefaultLogFilePrefixParameterValue}{time:_yyyyMMddHHmmss}.trx";

Assert.AreEqual(expectedName, fileName, "Trx file name pattern has changed. It should be in the form of prefix_yyyyMMddHHmmss.trx");
Haplois marked this conversation as resolved.
Show resolved Hide resolved
}
}

[TestMethod]
public void DefaultTrxFileShouldIterateIfLogFileNameParameterNotPassed()
Expand Down Expand Up @@ -690,7 +690,7 @@ public void TrxPrefixFileNameShouldIterate()

private string[] TestMultipleTrxLoggers()
{
string[] files = null;
var files = new string[2];

try
{
Expand All @@ -704,20 +704,23 @@ private string[] TestMultipleTrxLoggers()
trxLogger2.Initialize(this.events.Object, this.parameters);

MakeTestRunComplete(trxLogger1);
MakeTestRunComplete(trxLogger2);
files[0] = trxLogger1.trxFile;

files = (new[] { trxLogger1.trxFile, trxLogger2.trxFile }).Distinct().ToArray();
MakeTestRunComplete(trxLogger2);
files[1] = trxLogger2.trxFile;
}
finally
{
if (files != null)
files = files
.Where(i => !string.IsNullOrWhiteSpace(i))
.Distinct()
.ToArray();

foreach (var file in files)
{
foreach (var file in files)
if (!string.IsNullOrEmpty(file) && File.Exists(file))
{
if (!string.IsNullOrEmpty(file) && File.Exists(file))
{
File.Delete(file);
}
File.Delete(file);
}
}
}
Expand Down