Made excepton handling optional, off by default

This commit is contained in:
Biarity 2018-02-14 08:52:13 +10:00
parent ce5da2a573
commit e83f647945
3 changed files with 14 additions and 6 deletions

View File

@ -10,5 +10,7 @@ namespace Sieve.Models
public bool CaseSensitive { get; set; } = false;
public int DefaultPageSize { get; set; } = 0;
public bool ThrowExceptions { get; set; } = false;
}
}

View File

@ -309,13 +309,16 @@ namespace Sieve.Services
}
catch (ArgumentException) // name matched with custom method for a differnt type
{
var expected = typeof(IQueryable<TEntity>);
var actual = customMethod.ReturnType;
throw new SieveIncompatibleMethodException(name, expected, actual,
$"{name} failed. Expected a custom method for type {expected} but only found for type {actual}");
if (_options.Value.ThrowExceptions)
{
var expected = typeof(IQueryable<TEntity>);
var actual = customMethod.ReturnType;
throw new SieveIncompatibleMethodException(name, expected, actual,
$"{name} failed. Expected a custom method for type {expected} but only found for type {actual}");
}
}
}
else
else if (_options.Value.ThrowExceptions)
{
throw new SieveMethodNotFoundException(name,
$"{name} not found.");

View File

@ -20,7 +20,10 @@ namespace SieveUnitTests
public SieveOptionsAccessor()
{
_value = new SieveOptions();
_value = new SieveOptions()
{
ThrowExceptions = true
};
}
}
}