mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
When multiple builds had to run, these tests would sometimes fail due to the file system being a shared resource. Each test now creates its own random folder and cleans it up after the test runs
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.IO;
|
|
using System.Threading;
|
|
using mRemoteNG.Config.DataProviders;
|
|
using mRemoteNGTests.TestHelpers;
|
|
using NUnit.Framework;
|
|
|
|
namespace mRemoteNGTests.Config.DataProviders
|
|
{
|
|
public class FileDataProviderWithRollingBackupTests
|
|
{
|
|
private FileDataProviderWithRollingBackup _dataProvider;
|
|
private string _testFilePath;
|
|
private string _testFileDirectory;
|
|
private string _testFileRollingBackup;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_testFilePath = FileTestHelpers.NewTempFilePath();
|
|
_testFileDirectory = Path.GetDirectoryName(_testFilePath);
|
|
_testFileRollingBackup = Path.GetFileName(_testFilePath) + ".*-*.backup";
|
|
_dataProvider = new FileDataProviderWithRollingBackup(_testFilePath);
|
|
}
|
|
|
|
[TearDown]
|
|
public void Teardown()
|
|
{
|
|
if (Directory.Exists(_testFileDirectory))
|
|
Directory.Delete(_testFileDirectory, true);
|
|
}
|
|
|
|
[Test]
|
|
public void RollingBackupCreatedIfRegularBackupExists()
|
|
{
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
_dataProvider.Save("");
|
|
Thread.Sleep(100);
|
|
}
|
|
|
|
var rollingBackupFiles = Directory.GetFiles(_testFileDirectory, _testFileRollingBackup);
|
|
Assert.That(rollingBackupFiles.Length, Is.EqualTo(2));
|
|
}
|
|
|
|
[Test]
|
|
public void NoRollingBackupCreatedIfRegularFileDoesntExists()
|
|
{
|
|
_dataProvider.Save("");
|
|
var rollingBackupFiles = Directory.GetFiles(_testFileDirectory, _testFileRollingBackup);
|
|
Assert.That(rollingBackupFiles.Length, Is.EqualTo(0));
|
|
}
|
|
}
|
|
} |