sharee.bike-App/SharedBusinessLogic.Tests/Model/Logging/TestLoggingDirectoryManager.cs
2024-04-09 12:53:23 +02:00

75 lines
2 KiB
C#

using System;
using System.Collections.Generic;
using NUnit.Framework;
using ShareeBike.Model.Logging;
namespace SharedBusinessLogic.Tests.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" },
(name) => false,
(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.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);
}
[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.That(l_oDeletedFilesList.Count, Is.EqualTo(0));
}
}
}