Imports System.Data
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports FluentAssertions
Imports DigitalData.Modules.Logging

Namespace Global_Indexer.Test
    <TestClass>
    Public Class ClassPostprocessingTest

        Private LogConfig As LogConfig
        Private PostProcessing As ClassPostprocessing

        <TestInitialize()>
        Sub Init()
            LogConfig = New LogConfig(LogPath:=LogConfig.PathType.Temp)
            PostProcessing = New ClassPostprocessing(LogConfig)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBSPLIT_INDEX_0()
            Dim oTable = GetDataTable(ClassPostprocessing.VBSPLIT, ",", "0")
            Dim oString = "1,2,3,4"
            Dim oExpected = "1"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBSPLIT_INDEX_3()
            Dim oTable = GetDataTable(ClassPostprocessing.VBSPLIT, ",", "3")
            Dim oString = "1,2,3,4"
            Dim oExpected = "4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBSPLIT_INDEX_5()
            Dim oTable = GetDataTable(ClassPostprocessing.VBSPLIT, ",", "5")
            Dim oString = "1,2,3,4"
            Dim oExpected = "1,2,3,4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBREPLACE()
            Dim oTable = GetDataTable(ClassPostprocessing.VBREPLACE, ",", "_")
            Dim oString = "1,2,3,4"
            Dim oExpected = "1_2_3_4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBREPLACE_NOT_EXISTING()
            Dim oTable = GetDataTable(ClassPostprocessing.VBREPLACE, ";", "_")
            Dim oString = "1,2,3,4"
            Dim oExpected = "1,2,3,4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBREPLACE_EMPTY_STRING()
            Dim oTable = GetDataTable(ClassPostprocessing.VBREPLACE, "", "_")
            Dim oString = "1,2,3,4"
            Dim oExpected = "1,2,3,4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBREPLACE_NOTHING1()
            Dim oTable = GetDataTable(ClassPostprocessing.VBREPLACE, ",", Nothing)
            Dim oString = "1,2,3,4"
            Dim oExpected = "1,2,3,4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub
        <TestMethod>
        Sub Get_Nachbearbeitung_Wert_VBREPLACE_NOTHING2()
            Dim oTable = GetDataTable(ClassPostprocessing.VBREPLACE, Nothing, "_")
            Dim oString = "1,2,3,4"
            Dim oExpected = "1,2,3,4"

            Dim rString = PostProcessing.Get_Nachbearbeitung_Wert(oString, oTable)
            rString.Should.Be(oExpected)
        End Sub

        Private Function GetDataTable(pType As String, pText1 As String, Optional pText2 As String = "") As DataTable
            Dim oTable As New DataTable()
            oTable.Columns.Add("TYPE", GetType(String))
            oTable.Columns.Add("TEXT1", GetType(String))
            oTable.Columns.Add("TEXT2", GetType(String))
            oTable.Rows.Add(pType, pText1, pText2)
            oTable.AcceptChanges()

            Return oTable
        End Function
    End Class


End Namespace

