mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-22 05:22:57 +01:00
Tested exception handling (#7)
This commit is contained in:
parent
ce4da673d9
commit
b70eb3471d
@ -309,8 +309,8 @@ namespace Sieve.Services
|
|||||||
}
|
}
|
||||||
catch (ArgumentException) // name matched with custom method for a differnt type
|
catch (ArgumentException) // name matched with custom method for a differnt type
|
||||||
{
|
{
|
||||||
var expected = typeof(TEntity);
|
var expected = typeof(IQueryable<TEntity>);
|
||||||
var actual = ((IQueryable)customMethod.ReturnParameter).ElementType;
|
var actual = customMethod.ReturnType;
|
||||||
throw new SieveIncompatibleMethodException(name, expected, actual,
|
throw new SieveIncompatibleMethodException(name, expected, actual,
|
||||||
$"{name} failed. Expected a custom method for type {expected} but only found for type {actual}");
|
$"{name} failed. Expected a custom method for type {expected} but only found for type {actual}");
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<description>
|
<description>
|
||||||
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/
|
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/
|
||||||
</description>
|
</description>
|
||||||
<releaseNotes>Custom method case-insensitivity</releaseNotes>
|
<releaseNotes>Custom method case-insensitivity, new custom exceptions</releaseNotes>
|
||||||
<copyright>Copyright 2018</copyright>
|
<copyright>Copyright 2018</copyright>
|
||||||
<tags>aspnetcore filter sort page paginate sieve search</tags>
|
<tags>aspnetcore filter sort page paginate sieve search</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
15
SieveUnitTests/Entities/Comment.cs
Normal file
15
SieveUnitTests/Entities/Comment.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using SieveUnitTests.Services;
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Sieve.Exceptions;
|
||||||
|
|
||||||
namespace SieveUnitTests
|
namespace SieveUnitTests
|
||||||
{
|
{
|
||||||
@ -101,6 +102,28 @@ namespace SieveUnitTests
|
|||||||
Assert.IsFalse(result.Any(p => p.Id == 0));
|
Assert.IsFalse(result.Any(p => p.Id == 0));
|
||||||
Assert.IsTrue(result.Count() == 2);
|
Assert.IsTrue(result.Count() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MethodNotFoundExceptionWork()
|
||||||
|
{
|
||||||
|
var model = new SieveModel()
|
||||||
|
{
|
||||||
|
Filters = "does not exist",
|
||||||
|
};
|
||||||
|
|
||||||
|
Assert.ThrowsException<SieveMethodNotFoundException>(() => _processor.ApplyFiltering(model, _posts));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void IncompatibleMethodExceptionsWork()
|
||||||
|
{
|
||||||
|
var model = new SieveModel()
|
||||||
|
{
|
||||||
|
Filters = "TestComment",
|
||||||
|
};
|
||||||
|
|
||||||
|
Assert.ThrowsException<SieveIncompatibleMethodException>(() => _processor.ApplyFiltering(model, _posts));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ using SieveUnitTests.Services;
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Sieve.Exceptions;
|
||||||
|
|
||||||
namespace SieveUnitTests
|
namespace SieveUnitTests
|
||||||
{
|
{
|
||||||
@ -68,7 +69,9 @@ namespace SieveUnitTests
|
|||||||
Sorts = "OnlySortableViaFluentApi"
|
Sorts = "OnlySortableViaFluentApi"
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = _processor.ApplyAll(model, _posts);
|
var result = _processor.ApplySorting(model, _posts);
|
||||||
|
|
||||||
|
Assert.ThrowsException<SieveMethodNotFoundException>(() => _processor.ApplyAll(model, _posts));
|
||||||
|
|
||||||
Assert.AreEqual(result.First().Id, 3);
|
Assert.AreEqual(result.First().Id, 3);
|
||||||
|
|
||||||
|
@ -15,5 +15,10 @@ namespace SieveUnitTests.Services
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string value)
|
||||||
|
{
|
||||||
|
return source;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user