using CoreLibrary.Exceptions;
using Xunit;

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

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

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

            try
            {
                throw new PartieNonCommenceeException(message);
            }
            catch(PartieNonCommenceeException 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<PartieNonCommenceeException>(() => throw new PartieNonCommenceeException(message, parent));

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

    }
}
