Imports System.Text Imports System.IO Imports Microsoft.VisualStudio.TestTools.UnitTesting Imports DigitalData.Modules.Filesystem Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Filesystem.FileContainerOld Public Class FileContainerTest Const PASSWORD = "foobar" Const FILENAME_VALID = "Textfile.txt" Const FILENAME_NONEXISTENT = "Nonexistent.txt" Const CONTAINER_FILE_VALID = "Container.enc" Const CONTAINER_FILE_NOWRITE = "C:\Windows\System32\Container.enc" Private Shared _logger As Logger Private Shared _logConfig As LogConfig Public Shared Sub Init(ctx As TestContext) _logConfig = New LogConfig(LogConfig.PathType.CurrentDirectory) _logger = _logConfig.GetLogger() Dim oContents As String = "" For oIndex As Integer = 0 To 10000 oContents = oContents & PASSWORD Next IO.File.WriteAllText(FILENAME_VALID, oContents) End Sub Public Shared Sub Cleanup() IO.File.Delete(FILENAME_VALID) End Sub Public Sub TestCleanup() IO.File.Delete(CONTAINER_FILE_VALID) End Sub Public Sub TestConstructorPasswordNothing() Dim oContainer = New FileContainerOld(_logConfig, Nothing) End Sub Public Sub TestConstructorValidPassword() Dim oContainer = New FileContainerOld(_logConfig, "foobar") End Sub Public Sub TestAddFileNonExistentFilePath() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(FILENAME_NONEXISTENT) End Sub Public Sub TestAddFileNothingFilePath() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(Nothing) End Sub Public Sub TestAddFileValidFilePath() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(FILENAME_VALID) End Sub Public Sub TestFilesPropertyCount() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(FILENAME_VALID) Assert.AreEqual(1, oContainer.Files.Count) End Sub Public Sub TestFilesPropertyType() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(FILENAME_VALID) Assert.IsInstanceOfType(oContainer.Files.First(), GetType(FileEntry)) End Sub Public Sub TestSaveValidPath() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(FILENAME_VALID) oContainer.Save(CONTAINER_FILE_VALID) Assert.IsTrue(IO.File.Exists(CONTAINER_FILE_VALID)) End Sub Public Sub TestSavePathNotWritable() Dim oContainer As New FileContainerOld(_logConfig, PASSWORD) oContainer.AddFile(FILENAME_VALID) oContainer.Save(CONTAINER_FILE_NOWRITE) End Sub Public Sub TestSaveLoadSameContents() Dim oContainer As FileContainerOld Dim oFileContents As String = "dasisteintest" ' Test String in Textdatei schreiben IO.File.WriteAllText(FILENAME_VALID, oFileContents) oContainer = New FileContainerOld(_logConfig, PASSWORD) ' Textdatei zu einem Container hinzufügen oContainer.AddFile(FILENAME_VALID) ' Container speichern oContainer.Save(CONTAINER_FILE_VALID) Assert.IsTrue(IO.File.Exists(CONTAINER_FILE_VALID)) ' Textdatei löschen IO.File.Delete(FILENAME_VALID) oContainer = Nothing oContainer = New FileContainerOld(_logConfig, PASSWORD) ' Container wieder laden oContainer.Load(CONTAINER_FILE_VALID) ' Textdatei-Inhalt aus Container in Textdatei schreiben IO.File.WriteAllBytes(FILENAME_VALID, oContainer.Files.First().Contents) ' Textdatei-Inhalt aus Textdatei lesen Dim oFileContents2 = IO.File.ReadAllText(FILENAME_VALID) Assert.AreEqual(oFileContents, oFileContents2) End Sub End Class