2022-08-30 15:42:25 +02:00
|
|
|
|
using System;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
using System.Collections.Generic;
|
2022-08-30 15:42:25 +02:00
|
|
|
|
using NUnit.Framework;
|
2024-04-09 12:53:23 +02:00
|
|
|
|
using ShareeBike.Model.Logging;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
|
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestLoggingDirectoryManager
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestConstructInvalidArgs()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<ArgumentException>(
|
|
|
|
|
() => new LoggingDirectoryManager(
|
|
|
|
|
(name) => new List<string> { "2018_02_06_22_18_00" /* oldest */, "2018_02_06_23_10_00" /*youngest*/ , "2018_02_06_22_19_00", "2018_02_06_22_20_00" },
|
|
|
|
|
(name) => false,
|
|
|
|
|
(name) => { },
|
|
|
|
|
(name) => { },
|
|
|
|
|
"abc",
|
|
|
|
|
'\\',
|
|
|
|
|
0));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.Throws<ArgumentException>(
|
|
|
|
|
() => new LoggingDirectoryManager(
|
|
|
|
|
(name) => new List<string> { "2018_02_06_22_18_00" /* oldest */, "2018_02_06_23_10_00" /*youngest*/ , "2018_02_06_22_19_00", "20180206222000" },
|
|
|
|
|
(name) => false,
|
|
|
|
|
(name) => { },
|
|
|
|
|
(name) => { },
|
|
|
|
|
"",
|
|
|
|
|
'\\',
|
|
|
|
|
3));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDeleteObsoleteLogs()
|
|
|
|
|
{
|
|
|
|
|
var l_oDeletedFilesList = new List<string>();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
var l_oManger = new LoggingDirectoryManager(
|
|
|
|
|
(name) => new List<string> { "2018_02_06_22_18_00" /* oldest */, "2018_02_06_23_10_00" /*youngest*/ , "2018_02_06_22_19_00", "20180206222000" },
|
|
|
|
|
(name) => false,
|
|
|
|
|
(name) => { },
|
|
|
|
|
(name) => { l_oDeletedFilesList.Add(name); },
|
|
|
|
|
"abc",
|
|
|
|
|
'\\',
|
|
|
|
|
3);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oManger.DeleteObsoleteLogs();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(l_oDeletedFilesList.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(l_oDeletedFilesList.Contains("2018_02_06_22_18_00"), Is.True);
|
|
|
|
|
Assert.That(l_oDeletedFilesList.Contains("2018_02_06_22_19_00"), Is.True);
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDeleteObsoleteLogs_EmptyDirectory()
|
|
|
|
|
{
|
|
|
|
|
var l_oDeletedFilesList = new List<string>();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
var l_oManger = new LoggingDirectoryManager(
|
|
|
|
|
(name) => new List<string>(),
|
|
|
|
|
(name) => false,
|
|
|
|
|
(name) => { },
|
|
|
|
|
(name) => { l_oDeletedFilesList.Add(name); },
|
|
|
|
|
"abc",
|
|
|
|
|
'\\',
|
|
|
|
|
3);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oManger.DeleteObsoleteLogs();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(l_oDeletedFilesList.Count, Is.EqualTo(0));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
}
|