diff --git a/Sieve/Services/SieveProcessor.cs b/Sieve/Services/SieveProcessor.cs index 8d998dd..fd295f1 100644 --- a/Sieve/Services/SieveProcessor.cs +++ b/Sieve/Services/SieveProcessor.cs @@ -309,8 +309,8 @@ namespace Sieve.Services } catch (ArgumentException) // name matched with custom method for a differnt type { - var expected = typeof(TEntity); - var actual = ((IQueryable)customMethod.ReturnParameter).ElementType; + var expected = typeof(IQueryable); + 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}"); } diff --git a/Sieve/Sieve.nuspec b/Sieve/Sieve.nuspec index 868358a..99fb397 100644 --- a/Sieve/Sieve.nuspec +++ b/Sieve/Sieve.nuspec @@ -13,7 +13,7 @@ Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries. Documentation available on GitHub: https://github.com/Biarity/Sieve/ - Custom method case-insensitivity + Custom method case-insensitivity, new custom exceptions Copyright 2018 aspnetcore filter sort page paginate sieve search diff --git a/SieveUnitTests/Entities/Comment.cs b/SieveUnitTests/Entities/Comment.cs new file mode 100644 index 0000000..b34e945 --- /dev/null +++ b/SieveUnitTests/Entities/Comment.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Sieve.Attributes; + +namespace SieveUnitTests.Entities +{ + public class Comment + { + public int Id { get; set; } + + public string Text { get; set; } + } +} diff --git a/SieveUnitTests/General.cs b/SieveUnitTests/General.cs index a54ae60..11117e6 100644 --- a/SieveUnitTests/General.cs +++ b/SieveUnitTests/General.cs @@ -6,6 +6,7 @@ using SieveUnitTests.Services; using System; using System.Linq; using System.Collections.Generic; +using Sieve.Exceptions; namespace SieveUnitTests { @@ -101,6 +102,28 @@ namespace SieveUnitTests Assert.IsFalse(result.Any(p => p.Id == 0)); Assert.IsTrue(result.Count() == 2); } + + [TestMethod] + public void MethodNotFoundExceptionWork() + { + var model = new SieveModel() + { + Filters = "does not exist", + }; + + Assert.ThrowsException(() => _processor.ApplyFiltering(model, _posts)); + } + + [TestMethod] + public void IncompatibleMethodExceptionsWork() + { + var model = new SieveModel() + { + Filters = "TestComment", + }; + + Assert.ThrowsException(() => _processor.ApplyFiltering(model, _posts)); + } } } diff --git a/SieveUnitTests/Mapper.cs b/SieveUnitTests/Mapper.cs index baadc22..f97be42 100644 --- a/SieveUnitTests/Mapper.cs +++ b/SieveUnitTests/Mapper.cs @@ -6,6 +6,7 @@ using SieveUnitTests.Services; using System; using System.Linq; using System.Collections.Generic; +using Sieve.Exceptions; namespace SieveUnitTests { @@ -68,7 +69,9 @@ namespace SieveUnitTests Sorts = "OnlySortableViaFluentApi" }; - var result = _processor.ApplyAll(model, _posts); + var result = _processor.ApplySorting(model, _posts); + + Assert.ThrowsException(() => _processor.ApplyAll(model, _posts)); Assert.AreEqual(result.First().Id, 3); diff --git a/SieveUnitTests/Services/SieveCustomFilterMethods.cs b/SieveUnitTests/Services/SieveCustomFilterMethods.cs index 85b56e8..0ebce79 100644 --- a/SieveUnitTests/Services/SieveCustomFilterMethods.cs +++ b/SieveUnitTests/Services/SieveCustomFilterMethods.cs @@ -15,5 +15,10 @@ namespace SieveUnitTests.Services return result; } + + public IQueryable TestComment(IQueryable source, string op, string value) + { + return source; + } } }