Tested exception handling (#7)

This commit is contained in:
Biarity
2018-02-14 08:43:33 +10:00
parent ce4da673d9
commit b70eb3471d
6 changed files with 50 additions and 4 deletions

View 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; }
}
}

View File

@@ -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<SieveMethodNotFoundException>(() => _processor.ApplyFiltering(model, _posts));
}
[TestMethod]
public void IncompatibleMethodExceptionsWork()
{
var model = new SieveModel()
{
Filters = "TestComment",
};
Assert.ThrowsException<SieveIncompatibleMethodException>(() => _processor.ApplyFiltering(model, _posts));
}
}
}

View File

@@ -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<SieveMethodNotFoundException>(() => _processor.ApplyAll(model, _posts));
Assert.AreEqual(result.First().Id, 3);

View File

@@ -15,5 +15,10 @@ namespace SieveUnitTests.Services
return result;
}
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string value)
{
return source;
}
}
}