-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Resulted in move of interface (which was wrongly placed from the beginning)
- Loading branch information
1 parent
edf29f1
commit 08d860c
Showing
3 changed files
with
160 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using EnsureThat; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace UnitTests | ||
{ | ||
public class ExceptionFactoryTests : UnitTestBase | ||
{ | ||
private const string DefaultMessage = "54a170d6997c400487c177768f72aa7a"; | ||
private const string CustomMessage = "3b3e6082d4c1482fbc775abc11a2e415"; | ||
private const string DummyValue = "61927e885db34e08b9a7211c7eb74c36"; | ||
private readonly Exception _exceptionFactoryException = new KeyNotFoundException(); | ||
private readonly Exception _customException = new("036859e6693848b199575feffe17bd46"); | ||
private readonly ExceptionFactory _sut = new(); | ||
|
||
[Fact] | ||
public void ArgumentException_UsesDefaults_WhenNoOptionsAreProvided() | ||
=> _sut.ArgumentException( | ||
DefaultMessage, | ||
ParamName) | ||
.Should() | ||
.BeEquivalentTo(new ArgumentException(DefaultMessage, ParamName)); | ||
|
||
[Fact] | ||
public void ArgumentException_UsesExceptionFactory_WhenOptionsAlsoContainsCustomExceptionAndCustomMessage() | ||
=> _sut.ArgumentException( | ||
DefaultMessage, | ||
ParamName, | ||
o => o | ||
.WithMessage(CustomMessage) | ||
.WithException(_customException) | ||
.WithExceptionFactory((_, __) => _exceptionFactoryException)) | ||
.Should() | ||
.Be(_exceptionFactoryException); | ||
|
||
[Fact] | ||
public void ArgumentException_UsesCustomException_WhenOptionsAlsoContainsCustomMessage() | ||
=> _sut.ArgumentException( | ||
DefaultMessage, | ||
ParamName, | ||
o => o | ||
.WithMessage(CustomMessage) | ||
.WithException(_customException)) | ||
.Should() | ||
.Be(_customException); | ||
|
||
[Fact] | ||
public void ArgumentException_UsesCustomMessage_WhenOptionsHasNoOtherConfig() | ||
=> _sut.ArgumentException( | ||
DefaultMessage, | ||
ParamName, | ||
o => o | ||
.WithMessage(CustomMessage)) | ||
.Should() | ||
.BeEquivalentTo(new ArgumentException(CustomMessage, ParamName)); | ||
|
||
[Fact] | ||
public void ArgumentNullException_UsesDefaults_WhenNoOptionsAreProvided() | ||
=> _sut.ArgumentNullException( | ||
DefaultMessage, | ||
ParamName) | ||
.Should() | ||
.BeEquivalentTo(new ArgumentNullException(ParamName, DefaultMessage)); | ||
|
||
[Fact] | ||
public void ArgumentNullException_UsesExceptionFactory_WhenOptionsAlsoContainsCustomExceptionAndCustomMessage() | ||
=> _sut.ArgumentNullException( | ||
DefaultMessage, | ||
ParamName, | ||
o => o | ||
.WithMessage(CustomMessage) | ||
.WithException(_customException) | ||
.WithExceptionFactory((_, __) => _exceptionFactoryException)) | ||
.Should() | ||
.Be(_exceptionFactoryException); | ||
|
||
[Fact] | ||
public void ArgumentNullException_UsesCustomException_WhenOptionsAlsoContainsCustomMessage() | ||
=> _sut.ArgumentNullException( | ||
DefaultMessage, | ||
ParamName, | ||
o => o | ||
.WithMessage(CustomMessage) | ||
.WithException(_customException)) | ||
.Should() | ||
.Be(_customException); | ||
|
||
[Fact] | ||
public void ArgumentNullException_UsesCustomMessage_WhenOptionsHasNoOtherConfig() | ||
=> _sut.ArgumentNullException( | ||
DefaultMessage, | ||
ParamName, | ||
o => o | ||
.WithMessage(CustomMessage)) | ||
.Should() | ||
.BeEquivalentTo(new ArgumentNullException(ParamName, CustomMessage)); | ||
|
||
[Fact] | ||
public void ArgumentOutOfRangeException_UsesDefaults_WhenNoOptionsAreProvided() | ||
=> _sut.ArgumentOutOfRangeException( | ||
DefaultMessage, | ||
ParamName, | ||
DummyValue) | ||
.Should() | ||
.BeEquivalentTo(new ArgumentOutOfRangeException(ParamName, DummyValue, DefaultMessage)); | ||
|
||
[Fact] | ||
public void ArgumentOutOfRangeException_UsesExceptionFactory_WhenOptionsAlsoContainsCustomExceptionAndCustomMessage() | ||
=> _sut.ArgumentOutOfRangeException( | ||
DefaultMessage, | ||
ParamName, | ||
DummyValue, | ||
o => o | ||
.WithMessage(CustomMessage) | ||
.WithException(_customException) | ||
.WithExceptionFactory((_, __) => _exceptionFactoryException)) | ||
.Should() | ||
.Be(_exceptionFactoryException); | ||
|
||
[Fact] | ||
public void ArgumentOutOfRangeException_UsesCustomException_WhenOptionsAlsoContainsCustomMessage() | ||
=> _sut.ArgumentOutOfRangeException( | ||
DefaultMessage, | ||
ParamName, | ||
DummyValue, | ||
o => o | ||
.WithMessage(CustomMessage) | ||
.WithException(_customException)) | ||
.Should() | ||
.Be(_customException); | ||
|
||
[Fact] | ||
public void ArgumentOutOfRangeException_UsesCustomMessage_WhenOptionsHasNoOtherConfig() | ||
=> _sut.ArgumentOutOfRangeException( | ||
DefaultMessage, | ||
ParamName, | ||
DummyValue, | ||
o => o | ||
.WithMessage(CustomMessage)) | ||
.Should() | ||
.BeEquivalentTo(new ArgumentOutOfRangeException(ParamName, DummyValue, CustomMessage)); | ||
} | ||
} |