﻿using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Meadow.Tests.Meadow
{
    [SuppressMessage("ReSharper", "ExceptionNotDocumented")]
    public partial class EnumExtensionTest
    {
        private enum EMetadataTest
        {
            [EnumMetadata(nameof(ValueA))]
            ValueA,

            [EnumMetadata(nameof(ValueB), Alias = "B")]
            ValueB,

            ValueC
        }

        [TestMethod]
        public void Enum_GetMetadata()
        {
            // Name attribute with implied Alias.
            Assert.AreEqual(nameof(EMetadataTest.ValueA), EMetadataTest.ValueA.GetMetadata().Name, false);
            Assert.AreEqual(nameof(EMetadataTest.ValueA), EMetadataTest.ValueA.GetMetadata().Alias, false);

            // Name attribute with explicit Alias.
            Assert.AreEqual(nameof(EMetadataTest.ValueB), EMetadataTest.ValueB.GetMetadata().Name, false);
            Assert.AreEqual("B", EMetadataTest.ValueB.GetMetadata().Alias, false);

            // No attribute.
            Assert.ThrowsException<NullReferenceException>(() => EMetadataTest.ValueC.GetMetadata().Name);

            // Invalid type.
            Assert.ThrowsException<AssertionException>(() => 42.GetMetadata().Name);
        }
    }
}
