using CoreLibrary.Exceptions;
using Xunit;

namespace UnitTesting
{
    public class TailleGrilleExceptionUT
    {
        [Fact]
        public void ExceptionDefaut()
        {
            Assert.ThrowsAsync<TailleGrilleException>(() => throw new TailleGrilleException());
        }

        [Fact]
        public void ExceptionAttributs()
        {
            Assert.ThrowsAsync<TailleGrilleException>(() => throw new TailleGrilleException(0));

            try
            {
                throw new TailleCodeException(0);
            }
            catch (TailleCodeException e)
            {
                Assert.Contains("0", e.Message);
            }
        }

        [Fact]
        public void ExceptionMessage()
        {
            string message = "Mon super gros problème.";

            Assert.ThrowsAsync<TailleGrilleException>(() => throw new TailleGrilleException(message));

            try
            {
                throw new TailleGrilleException(message);
            }
            catch(TailleGrilleException e)
            {
                Assert.Equal(message, e.Message);
            }
        }

        [Fact]
        public void ExceptionMessageEtException()
        {
            string message = "Mon super gros problème.";
            string message2 = "Pas de chance...";
            InvalidOperationException parent = new InvalidOperationException(message2);

            Assert.ThrowsAsync<TailleGrilleException>(() => throw new TailleGrilleException(message, parent));

            try
            {
                throw new TailleGrilleException(message, parent);
            }
            catch (TailleGrilleException e)
            {
                Assert.Equal(message, e.Message);
                Assert.NotNull(e.InnerException);
                Assert.IsType<InvalidOperationException>(e.InnerException);
                Assert.Equal(message2, e.InnerException.Message);
            }
        }

    }
}
