sharee.bike-App/TestTINKLib/Fixtures/ObjectTests/Logging/TestLoggingDirectoryManager.cs

76 lines
2.5 KiB
C#
Raw Normal View History

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;
2021-07-12 21:31:46 +02:00
using TINK.Model.Logging;
namespace TestTINKLib.Fixtures.ObjectTests
{
[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" },
2022-08-30 15:42:25 +02:00
(name) => false,
2021-07-12 21:31:46 +02:00
(name) => { },
(name) => { },
"abc",
'\\',
0));
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));
}
[Test]
public void TestDeleteObsoleteLogs()
{
var l_oDeletedFilesList = new List<string>();
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);
l_oManger.DeleteObsoleteLogs();
Assert.AreEqual(2, l_oDeletedFilesList.Count);
Assert.IsTrue(l_oDeletedFilesList.Contains("2018_02_06_22_18_00"));
Assert.IsTrue(l_oDeletedFilesList.Contains("2018_02_06_22_19_00"));
}
[Test]
public void TestDeleteObsoleteLogs_EmptyDirectory()
{
var l_oDeletedFilesList = new List<string>();
var l_oManger = new LoggingDirectoryManager(
(name) => new List<string>(),
(name) => false,
(name) => { },
(name) => { l_oDeletedFilesList.Add(name); },
"abc",
'\\',
3);
l_oManger.DeleteObsoleteLogs();
Assert.AreEqual(0, l_oDeletedFilesList.Count);
}
}
}