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

<TestClass()> Public Class Enumeration_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_create_custom_enumeration()
        Dim enm = MockEnum.Original
        Assert.IsNotNull(enm)
        Assert.IsInstanceOfType(enm, GetType(MockEnum))
        Assert.IsTrue(enm.Value = 0)
        Assert.IsTrue(enm.DisplayName = "Original")
    End Sub

    <TestMethod()> _
    Public Sub Can_get_values_of_enumeration_by_type()
        Dim valueList = Enumeration.GetAll(GetType(MockEnum))
        Dim enumerator = valueList.GetEnumerator()
        enumerator.MoveNext()
        Assert.IsTrue(enumerator.Current.DisplayName = "Original")
        Assert.IsTrue(enumerator.Current.Value = 0)
        enumerator.MoveNext()
        Assert.IsTrue(enumerator.Current.DisplayName = "Artificial")
        Assert.IsTrue(enumerator.Current.Value = 1)
        enumerator.MoveNext()
        Assert.IsTrue(enumerator.Current.DisplayName = "Mocked")
        Assert.IsTrue(enumerator.Current.Value = 2)
        enumerator.MoveNext()
        Assert.IsTrue(enumerator.Current.DisplayName = "Undefined Value")
        Assert.IsTrue(enumerator.Current.Value = 3)
        Dim flag = enumerator.MoveNext()
        Assert.IsFalse(flag)
    End Sub

    <TestMethod()> _
    Public Sub Can_retrieve_value_by_display_name()
        Dim dispName = "Undefined Value"
        Dim test1 = Enumeration.FromDisplayName(Of MockEnum)(dispName)
        Assert.IsNotNull(test1)
        Assert.IsTrue(test1.Value = 3)
        Assert.IsTrue(test1.DisplayName = dispName)

        dispName = "Mocked"
        Dim test2 = Enumeration.FromDisplayName(GetType(MockEnum), dispName)
        Assert.IsNotNull(test2)
        Assert.IsTrue(test2.Value = 2)
        Assert.IsTrue(test2.DisplayName = dispName)
    End Sub

End Class
