146 lines
4.4 KiB
VB.net
146 lines
4.4 KiB
VB.net
Imports System.Text
|
|
Imports System.IO
|
|
Imports Microsoft.VisualStudio.TestTools.UnitTesting
|
|
Imports DigitalData.Modules.Filesystem
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Filesystem.FileContainerOld
|
|
|
|
<TestClass()> 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
|
|
|
|
<AssemblyInitialize()>
|
|
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
|
|
|
|
<AssemblyCleanup()>
|
|
Public Shared Sub Cleanup()
|
|
IO.File.Delete(FILENAME_VALID)
|
|
End Sub
|
|
|
|
<TestCleanup()>
|
|
Public Sub TestCleanup()
|
|
IO.File.Delete(CONTAINER_FILE_VALID)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
<ExpectedException(GetType(ArgumentNullException))>
|
|
Public Sub TestConstructorPasswordNothing()
|
|
Dim oContainer = New FileContainerOld(_logConfig, Nothing)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
Public Sub TestConstructorValidPassword()
|
|
Dim oContainer = New FileContainerOld(_logConfig, "foobar")
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
<ExpectedException(GetType(FileNotFoundException))>
|
|
Public Sub TestAddFileNonExistentFilePath()
|
|
Dim oContainer As New FileContainerOld(_logConfig, PASSWORD)
|
|
|
|
oContainer.AddFile(FILENAME_NONEXISTENT)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
<ExpectedException(GetType(ArgumentNullException))>
|
|
Public Sub TestAddFileNothingFilePath()
|
|
Dim oContainer As New FileContainerOld(_logConfig, PASSWORD)
|
|
|
|
oContainer.AddFile(Nothing)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
Public Sub TestAddFileValidFilePath()
|
|
Dim oContainer As New FileContainerOld(_logConfig, PASSWORD)
|
|
|
|
oContainer.AddFile(FILENAME_VALID)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
Public Sub TestFilesPropertyCount()
|
|
Dim oContainer As New FileContainerOld(_logConfig, PASSWORD)
|
|
|
|
oContainer.AddFile(FILENAME_VALID)
|
|
Assert.AreEqual(1, oContainer.Files.Count)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
Public Sub TestFilesPropertyType()
|
|
Dim oContainer As New FileContainerOld(_logConfig, PASSWORD)
|
|
|
|
oContainer.AddFile(FILENAME_VALID)
|
|
Assert.IsInstanceOfType(oContainer.Files.First(), GetType(FileEntry))
|
|
End Sub
|
|
|
|
|
|
<TestMethod()>
|
|
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
|
|
|
|
<TestMethod()>
|
|
<ExpectedException(GetType(UnauthorizedAccessException))>
|
|
Public Sub TestSavePathNotWritable()
|
|
Dim oContainer As New FileContainerOld(_logConfig, PASSWORD)
|
|
|
|
oContainer.AddFile(FILENAME_VALID)
|
|
oContainer.Save(CONTAINER_FILE_NOWRITE)
|
|
End Sub
|
|
|
|
<TestMethod()>
|
|
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 |