Imports System
Imports System.Text
Imports System.Security.Cryptography
Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Mercury.Mobile.Security.Cryptography

<TestClass()> Public Class HashUtil_specs

    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = Value
        End Set
    End Property

#Region "Additional test attributes"
    '
    ' You can use the following additional attributes as you write your tests:
    '
    ' Use ClassInitialize to run code before running the first test in the class
    ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    ' End Sub
    '
    ' Use ClassCleanup to run code after all tests in a class have run
    ' <ClassCleanup()> Public Shared Sub MyClassCleanup()
    ' End Sub
    '
    ' Use TestInitialize to run code before running each test
    ' <TestInitialize()> Public Sub MyTestInitialize()
    ' End Sub
    '
    ' Use TestCleanup to run code after each test has run
    ' <TestCleanup()> Public Sub MyTestCleanup()
    ' End Sub
    '
#End Region

    <TestMethod()> _
    Public Sub Can_generate_hash()
        Dim validHash = "2D5C86E6550C22E0F4BE06DDD825B78058FDEB47"
        Dim username = "Cmankin"
        Dim password = "1234"
        Dim salt = -419651312
        Dim enc = New ASCIIEncoding()
        Dim alg = SHA1.Create()

        Dim test = HashUtil.GetHash(alg, enc, username + password, salt, True)
        Assert.IsNotNull(test)
        Assert.AreEqual(validHash, test)
    End Sub

    <TestMethod()> _
    Public Sub Can_generate_hash_defined_by_hash_info()
        Dim validHash = "2D5C86E6550C22E0F4BE06DDD825B78058FDEB47"
        Dim username = "Cmankin"
        Dim password = "1234"
        Dim salt = -419651312
        Dim info = New HashInfo(SHA1.Create(), New ASCIIEncoding(), 0, True)

        Dim test = HashUtil.GetHash(username + password, salt, info)
        Assert.IsNotNull(test)
        Assert.AreEqual(test, validHash)
    End Sub

End Class
