You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
using CoreLibrary.Exceptions;
|
|
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
|
|
using Xunit;
|
|
|
|
namespace UnitTesting
|
|
{
|
|
public class CodeInvalideExceptionUT
|
|
{
|
|
[Fact]
|
|
public void ExceptionDefaut()
|
|
{
|
|
Assert.ThrowsAsync<CodeInvalideException>(() => throw new CodeInvalideException());
|
|
}
|
|
|
|
[Fact]
|
|
public void ExceptionAttributs()
|
|
{
|
|
Assert.ThrowsAsync<CodeInvalideException>(() => throw new CodeInvalideException(3, 4));
|
|
|
|
try
|
|
{
|
|
throw new CodeInvalideException(3, 4);
|
|
}
|
|
catch (CodeInvalideException e)
|
|
{
|
|
Assert.Contains("3", e.Message);
|
|
Assert.Contains("4", e.Message);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ExceptionMessage()
|
|
{
|
|
string message = "Mon super gros problème.";
|
|
|
|
Assert.ThrowsAsync<CodeInvalideException>(() => throw new CodeInvalideException(message));
|
|
|
|
try
|
|
{
|
|
throw new CodeInvalideException(message);
|
|
}
|
|
catch(CodeInvalideException 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<CodeInvalideException>(() => throw new CodeInvalideException(message, parent));
|
|
|
|
try
|
|
{
|
|
throw new CodeInvalideException(message, parent);
|
|
}
|
|
catch (CodeInvalideException e)
|
|
{
|
|
Assert.Equal(message, e.Message);
|
|
Assert.NotNull(e.InnerException);
|
|
Assert.IsType<InvalidOperationException>(e.InnerException);
|
|
Assert.Equal(message2, e.InnerException.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|