convertible tests.
This commit is contained in:
parent
18540a672d
commit
a4a1e8b9a6
84
PoweredSoft.DynamicQuery.Test/ConvertibleInterceptorTests.cs
Normal file
84
PoweredSoft.DynamicQuery.Test/ConvertibleInterceptorTests.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using PoweredSoft.DynamicQuery.Core;
|
||||
using PoweredSoft.DynamicQuery.Test.Mock;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace PoweredSoft.DynamicQuery.Test
|
||||
{
|
||||
public class QueryConvertInterceptorTests
|
||||
{
|
||||
private class CustomerModel
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string FullName => $"{FirstName} {LastName}";
|
||||
}
|
||||
|
||||
private class MockQueryConvertInterceptor : IQueryConvertInterceptor
|
||||
{
|
||||
public object InterceptResultTo(object entity)
|
||||
{
|
||||
var customer = entity as Customer;
|
||||
var personModel = new CustomerModel
|
||||
{
|
||||
Id = customer.Id,
|
||||
FirstName = customer.FirstName,
|
||||
LastName = customer.LastName
|
||||
};
|
||||
return personModel;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockQueryConvertGenericInterceptor :
|
||||
IQueryConvertInterceptor<Customer>,
|
||||
IQueryConvertInterceptor<Order>
|
||||
{
|
||||
public object InterceptResultTo(Customer entity)
|
||||
{
|
||||
var customer = entity;
|
||||
var personModel = new CustomerModel
|
||||
{
|
||||
Id = customer.Id,
|
||||
FirstName = customer.FirstName,
|
||||
LastName = customer.LastName
|
||||
};
|
||||
return personModel;
|
||||
}
|
||||
|
||||
public object InterceptResultTo(Order entity)
|
||||
{
|
||||
// leave the throw, its on purpose to match the type testing.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NonGeneric()
|
||||
{
|
||||
MockContextFactory.SeedAndTestContextFor("QueryConvertInterceptorTests_NonGeneric", TestSeeders.SimpleSeedScenario, ctx =>
|
||||
{
|
||||
var criteria = new QueryCriteria();
|
||||
var queryHandler = new QueryHandler();
|
||||
queryHandler.AddInterceptor(new MockQueryConvertInterceptor());
|
||||
var result = queryHandler.Execute(ctx.Customers, criteria);
|
||||
Assert.All(result.Data, t => Assert.IsType<CustomerModel>(t));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generic()
|
||||
{
|
||||
MockContextFactory.SeedAndTestContextFor("ConvertibleIntereceptorTests_Generic", TestSeeders.SimpleSeedScenario, ctx =>
|
||||
{
|
||||
var criteria = new QueryCriteria();
|
||||
var queryHandler = new QueryHandler();
|
||||
queryHandler.AddInterceptor(new MockQueryConvertGenericInterceptor());
|
||||
var result = queryHandler.Execute(ctx.Customers, criteria);
|
||||
Assert.All(result.Data, t => Assert.IsType<CustomerModel>(t));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -107,5 +107,5 @@ IAggregateInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IAgg
|
||||
|
||||
Interceptor | Interface | Example | Description
|
||||
----------------------------------|---------------------------------------------------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------
|
||||
IQueryConvertInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to replace the object that is being returned by the query, by another object instance
|
||||
IQueryConvertInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to replace the object that is being returned by the query, by another object instance
|
||||
IQueryConvertInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/ConvertibleInterceptorTests.cs) | This interceptor allows you to replace the object that is being returned by the query, by another object instance
|
||||
IQueryConvertInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/ConvertibleInterceptorTests.cs#L72) | This interceptor allows you to replace the object that is being returned by the query, by another object instance
|
||||
|
Loading…
Reference in New Issue
Block a user