Imports System.Text
Imports System.IO
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports DigitalData.Modules.Logging

''' <summary>
''' Test creating the log path in various configurations
''' </summary>
<TestClass()> Public Class ConstructorUnitTest
    Private Shared _currentDirectoryLogPath = Path.Combine(Directory.GetCurrentDirectory(), "Log")
    Private Shared _appdataDirectoryLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Digital Data", "Modules.Logging", "Log")
    Private Shared _customDirectoryLogPath = Path.Combine(Directory.GetCurrentDirectory(), "CustomLogFolder")
    Private Shared _restrictedDirectoryLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "ShouldNotBeCreated")
    Private Shared _nonsenseDirectoryLogPath = "X:\FOO\BAR\BAZ\QUUX"

    <TestMethod()> Public Sub TestConstructorCurrentDirectory()
        Assert.ThrowsException(Of ArgumentException)(Sub()
                                                         Dim oLogConfig As New LogConfig(LogConfig.PathType.Temp)
                                                     End Sub)
    End Sub

    <TestMethod()> Public Sub TestConstructorApplicationDirectory()
        Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "Modules.Logging")

        Assert.AreEqual(_appdataDirectoryLogPath, oLogConfig.LogDirectory)
    End Sub

    <TestMethod()> Public Sub TestConstructorCustomDirectory()
        Dim oLogConfig As New LogConfig(LogConfig.PathType.CustomPath, _customDirectoryLogPath)

        Assert.AreEqual(_customDirectoryLogPath, oLogConfig.LogDirectory)
    End Sub

    <TestMethod()> Public Sub TestConstructorRestrictedDirectory()
        Dim oLogConfig As New LogConfig(LogConfig.PathType.CustomPath, _restrictedDirectoryLogPath)

        Assert.AreEqual(Path.GetTempPath, oLogConfig.LogDirectory)
    End Sub

    <TestMethod()> Public Sub TestConstructorNonsenseDirectory()
        Dim oLogConfig As New LogConfig(LogConfig.PathType.CustomPath, _nonsenseDirectoryLogPath)

        Assert.AreEqual(Path.GetTempPath, oLogConfig.LogDirectory)
    End Sub

    <ClassCleanup()> Public Shared Sub Cleanup()
        Directory.Delete(_currentDirectoryLogPath, True)
        Directory.Delete(_appdataDirectoryLogPath, True)
        Directory.Delete(_customDirectoryLogPath, True)
    End Sub

End Class