Browse Source

Implement IQueryable for IQueryableRepository

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent
commit
fcaa050af2
  1. 7
      src/AbpDesk/AbpDesk.Application.Contracts/AbpDesk/Tickets/Dtos/GetAllTicketsInput.cs
  2. 2
      src/AbpDesk/AbpDesk.Application.Contracts/AbpDesk/Tickets/ITicketAppService.cs
  3. 14
      src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs
  4. 3
      src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/TicketLister.cs
  5. 5
      src/AbpDesk/AbpDesk.UI/Controllers/TicketsController.cs
  6. 13
      src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/ILimitedResultRequest.cs
  7. 13
      src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/IPagedResultRequest.cs
  8. 3
      src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs
  9. 35
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs
  10. 36
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  11. 16
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs
  12. 1
      src/Volo.Abp.TestBase/AbpIntegratedTest.cs
  13. 49
      src/Volo.Abp/Volo/Abp/Domain/Repositories/IQueryableRepository.cs
  14. 11
      src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs
  15. 7
      src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepositoryMarker.cs
  16. 41
      src/Volo.Abp/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs
  17. 10
      src/Volo.Abp/Volo/Abp/Domain/Repositories/RepositoryBase.cs
  18. 68
      src/Volo.Abp/Volo/Abp/Linq/Extensions/QueryableExtensions.cs
  19. 3
      src/Volo.Abp/project.json
  20. 6
      test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestModule.cs
  21. 17
      test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/Tickets/TicketAppService_Tests.cs

7
src/AbpDesk/AbpDesk.Application.Contracts/AbpDesk/Tickets/Dtos/GetAllTicketsInput.cs

@ -0,0 +1,7 @@
namespace AbpDesk.Tickets.Dtos
{
public class GetAllTicketsInput
{
public string Filter { get; set; }
}
}

2
src/AbpDesk/AbpDesk.Application.Contracts/AbpDesk/Tickets/ITicketAppService.cs

@ -6,6 +6,6 @@ namespace AbpDesk.Tickets
{
public interface ITicketAppService : IApplicationService
{
ListResultDto<TicketDto> GetAll();
ListResultDto<TicketDto> GetAll(GetAllTicketsInput input);
}
}

14
src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs

@ -2,23 +2,27 @@
using AbpDesk.Tickets.Dtos;
using Volo.Abp.Application.Services.Dtos;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Linq.Extensions;
using Volo.ExtensionMethods;
namespace AbpDesk.Tickets
{
public class TicketAppService : ITicketAppService
{
private readonly IRepository<Ticket, int> _ticketRepository;
private readonly IQueryableRepository<Ticket, int> _ticketRepository;
public TicketAppService(IRepository<Ticket, int> ticketRepository)
public TicketAppService(IQueryableRepository<Ticket, int> ticketRepository)
{
_ticketRepository = ticketRepository;
}
public ListResultDto<TicketDto> GetAll()
public ListResultDto<TicketDto> GetAll(GetAllTicketsInput input)
{
var tickets = _ticketRepository
.GetList()
.Select(t => new TicketDto { Id = t.Id, Title = t.Title, Body = t.Body })
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
t => t.Title.Contains(input.Filter) || t.Body.Contains(input.Filter)
).Select(t => new TicketDto { Id = t.Id, Title = t.Title, Body = t.Body })
.ToList();
return new ListResultDto<TicketDto>(tickets);

3
src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/TicketLister.cs

@ -1,5 +1,6 @@
using System;
using AbpDesk.Tickets;
using AbpDesk.Tickets.Dtos;
using Volo.DependencyInjection;
namespace AbpDesk.ConsoleDemo
@ -15,7 +16,7 @@ namespace AbpDesk.ConsoleDemo
public void List()
{
var result = _ticketAppService.GetAll();
var result = _ticketAppService.GetAll(new GetAllTicketsInput());
foreach (var ticket in result.Items)
{

5
src/AbpDesk/AbpDesk.UI/Controllers/TicketsController.cs

@ -1,5 +1,6 @@
using AbpDesk.Models.Tickets;
using AbpDesk.Tickets;
using AbpDesk.Tickets.Dtos;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
@ -14,9 +15,9 @@ namespace AbpDesk.Controllers
_ticketAppService = ticketAppService;
}
public IActionResult Index()
public IActionResult Index(GetAllTicketsInput input)
{
var result = _ticketAppService.GetAll();
var result = _ticketAppService.GetAll(input);
var model = new IndexViewModel
{

13
src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/ILimitedResultRequest.cs

@ -0,0 +1,13 @@
namespace Volo.Abp.Application.Services.Dtos
{
/// <summary>
/// This interface is defined to standardize to request a limited result.
/// </summary>
public interface ILimitedResultRequest
{
/// <summary>
/// Max expected result count.
/// </summary>
int MaxResultCount { get; set; }
}
}

13
src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/IPagedResultRequest.cs

@ -0,0 +1,13 @@
namespace Volo.Abp.Application.Services.Dtos
{
/// <summary>
/// This interface is defined to standardize to request a paged result.
/// </summary>
public interface IPagedResultRequest : ILimitedResultRequest
{
/// <summary>
/// Skip count (beginning of the page).
/// </summary>
int SkipCount { get; set; }
}
}

3
src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs

@ -18,10 +18,13 @@ namespace Microsoft.Extensions.DependencyInjection
foreach (var entityType in DbContextHelper.GetEntityTypes(dbContextType))
{
var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityType);
var repositoryInterfaceType = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType);
var queryableRepositoryInterfaceType = typeof(IQueryableRepository<,>).MakeGenericType(entityType, primaryKeyType);
var repositoryImplementationType = typeof(EfCoreRepository<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType);
services.TryAddTransient(repositoryInterfaceType, repositoryImplementationType);
services.TryAddTransient(queryableRepositoryInterfaceType, repositoryImplementationType);
}
return services;

35
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs

@ -0,0 +1,35 @@
using System;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Repositories.EntityFrameworkCore;
namespace Volo.Abp.Repositories
{
public static class EfCoreRepositoryExtensions
{
public static DbContext GetDbContext<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository)
where TEntity : class, IEntity<TPrimaryKey>, new()
{
var efCoreRepository = repository as IEfCoreRepository;
if (efCoreRepository == null)
{
throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository));
}
return efCoreRepository.DbContext;
}
public static DbSet<TEntity> GetDbSet<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository)
where TEntity : class, IEntity<TPrimaryKey>, new()
{
var efCoreRepository = repository as IEfCoreRepository<TEntity, TPrimaryKey>;
if (efCoreRepository == null)
{
throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName, nameof(repository));
}
return efCoreRepository.DbSet;
}
}
}

36
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
@ -10,24 +8,24 @@ using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.Repositories.EntityFrameworkCore
{
//TODO: Override async versions and others
public class EfCoreRepository<TDbContext, TEntity, TPrimaryKey> : QueryableRepositoryBase<TEntity, TPrimaryKey>
public class EfCoreRepository<TDbContext, TEntity, TPrimaryKey> : QueryableRepositoryBase<TEntity, TPrimaryKey>, IEfCoreRepository<TEntity, TPrimaryKey>
where TDbContext : AbpDbContext<TDbContext>
where TEntity : class, IEntity<TPrimaryKey>
{
protected virtual TDbContext DbContext { get; }
protected virtual DbSet<TEntity> DbSet => DbContext.Set<TEntity>();
public virtual TDbContext DbContext { get; }
public virtual DbSet<TEntity> DbSet => DbContext.Set<TEntity>();
DbContext IEfCoreRepository.DbContext => DbContext;
public EfCoreRepository(TDbContext dbContext)
{
DbContext = dbContext;
}
public override IQueryable<TEntity> GetQueryable()
protected override IQueryable<TEntity> GetQueryable()
{
return DbSet;
return DbSet.AsQueryable();
}
public override Task<List<TEntity>> GetListAsync()
@ -37,7 +35,7 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore
public override async Task<TEntity> GetAsync(TPrimaryKey id)
{
var entity = await FirstOrDefaultAsync(id);
var entity = await FindAsync(id);
if (entity == null)
{
throw new EntityNotFoundException(typeof(TEntity), id);
@ -46,21 +44,16 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore
return entity;
}
public override TEntity FirstOrDefault(TPrimaryKey id)
public override TEntity Find(TPrimaryKey id)
{
return DbSet.Find(id);
}
public override Task<TEntity> FirstOrDefaultAsync(TPrimaryKey id)
public override Task<TEntity> FindAsync(TPrimaryKey id)
{
return DbSet.FindAsync(id);
}
public override Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate)
{
return GetQueryable().FirstOrDefaultAsync(predicate);
}
public override TEntity Insert(TEntity entity)
{
return DbSet.Add(entity).Entity;
@ -94,10 +87,5 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore
{
return DbSet.CountAsync();
}
public override Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate)
{
return DbSet.CountAsync(predicate);
}
}
}

16
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs

@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Repositories.EntityFrameworkCore
{
public interface IEfCoreRepository
{
DbContext DbContext { get; }
}
public interface IEfCoreRepository<TEntity, TPrimaryKey> : IEfCoreRepository
where TEntity : class, IEntity<TPrimaryKey>
{
DbSet<TEntity> DbSet { get; }
}
}

1
src/Volo.Abp.TestBase/AbpIntegratedTest.cs

@ -7,7 +7,6 @@ namespace Volo.Abp.TestBase
public class AbpIntegratedTest<TStartupModule> : IDisposable
where TStartupModule : IAbpModule
{
protected AbpApplication Application { get; }
protected IServiceProvider ServiceProvider => Application.ServiceProvider;

49
src/Volo.Abp/Volo/Abp/Domain/Repositories/IQueryableRepository.cs

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
@ -7,41 +6,9 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public interface IQueryableRepository<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
public interface IQueryableRepository<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>, IQueryable<TEntity>
where TEntity : class, IEntity<TPrimaryKey>
{
/// <summary>
/// Used to get a IQueryable that is used to retrieve entities from entire table.
/// </summary>
/// <returns>IQueryable to be used to select entities from database</returns>
IQueryable<TEntity> GetQueryable();
/// <summary>
/// Used to get all entities based on given <paramref name="predicate"/>.
/// </summary>
/// <param name="predicate">A condition to filter entities</param>
/// <returns>List of all entities</returns>
List<TEntity> GetList(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Used to get all entities based on given <paramref name="predicate"/>.
/// </summary>
/// <param name="predicate">A condition to filter entities</param>
/// <returns>List of all entities</returns>
Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Gets an entity with given given predicate or null if not found.
/// </summary>
/// <param name="predicate">Predicate to filter entities</param>
TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Gets an entity with given given predicate or null if not found.
/// </summary>
/// <param name="predicate">Predicate to filter entities</param>
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Deletes many entities by function.
/// Notice that: All entities fits to given predicate are retrieved and deleted.
@ -59,19 +26,5 @@ namespace Volo.Abp.Domain.Repositories
/// </summary>
/// <param name="predicate">A condition to filter entities</param>
Task DeleteAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Gets count of all entities in this repository based on given <paramref name="predicate"/>.
/// </summary>
/// <param name="predicate">A method to filter count</param>
/// <returns>Count of entities</returns>
int Count(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Gets count of all entities in this repository based on given <paramref name="predicate"/>.
/// </summary>
/// <param name="predicate">A method to filter count</param>
/// <returns>Count of entities</returns>
Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate);
}
}

11
src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs

@ -7,7 +7,12 @@ namespace Volo.Abp.Domain.Repositories
{
//TODO: Didn't get all members from ABP 1.x
public interface IRepository<TEntity, TPrimaryKey> : IRepositoryMarker, ITransientDependency
public interface IRepository : ITransientDependency
{
}
public interface IRepository<TEntity, TPrimaryKey> : IRepository
where TEntity : class, IEntity<TPrimaryKey>
{
/// <summary>
@ -41,14 +46,14 @@ namespace Volo.Abp.Domain.Repositories
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns>
TEntity FirstOrDefault(TPrimaryKey id);
TEntity Find(TPrimaryKey id);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns>
Task<TEntity> FirstOrDefaultAsync(TPrimaryKey id);
Task<TEntity> FindAsync(TPrimaryKey id);
/// <summary>
/// Inserts a new entity.

7
src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepositoryMarker.cs

@ -1,7 +0,0 @@
namespace Volo.Abp.Domain.Repositories
{
public interface IRepositoryMarker
{
}
}

41
src/Volo.Abp/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@ -10,36 +11,32 @@ namespace Volo.Abp.Domain.Repositories
public abstract class QueryableRepositoryBase<TEntity, TPrimaryKey> : RepositoryBase<TEntity, TPrimaryKey>, IQueryableRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
{
public abstract IQueryable<TEntity> GetQueryable();
public virtual Type ElementType => GetQueryable().ElementType;
public override List<TEntity> GetList()
{
return GetQueryable().ToList();
}
public virtual Expression Expression => GetQueryable().Expression;
public virtual List<TEntity> GetList(Expression<Func<TEntity, bool>> predicate)
{
return GetQueryable().Where(predicate).ToList();
}
public virtual IQueryProvider Provider => GetQueryable().Provider;
public virtual Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate)
IEnumerator IEnumerable.GetEnumerator()
{
return Task.FromResult(GetList(predicate));
return GetEnumerator();
}
public override TEntity FirstOrDefault(TPrimaryKey id)
public IEnumerator<TEntity> GetEnumerator()
{
return FirstOrDefault(CreateEqualityExpressionForId(id));
return GetQueryable().GetEnumerator();
}
public virtual TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate)
protected abstract IQueryable<TEntity> GetQueryable();
public override List<TEntity> GetList()
{
return GetQueryable().FirstOrDefault(predicate);
return GetQueryable().ToList();
}
public virtual Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate)
public override TEntity Find(TPrimaryKey id)
{
return Task.FromResult(FirstOrDefault(predicate));
return GetQueryable().FirstOrDefault(CreateEqualityExpressionForId(id));
}
public virtual void Delete(Expression<Func<TEntity, bool>> predicate)
@ -60,15 +57,5 @@ namespace Volo.Abp.Domain.Repositories
{
return GetQueryable().Count();
}
public virtual int Count(Expression<Func<TEntity, bool>> predicate)
{
return GetQueryable().Count(predicate);
}
public virtual Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate)
{
return Task.FromResult(Count(predicate));
}
}
}

10
src/Volo.Abp/Volo/Abp/Domain/Repositories/RepositoryBase.cs

@ -18,7 +18,7 @@ namespace Volo.Abp.Domain.Repositories
public virtual TEntity Get(TPrimaryKey id)
{
var entity = FirstOrDefault(id);
var entity = Find(id);
if (entity == null)
{
throw new EntityNotFoundException(typeof(TEntity), id);
@ -32,11 +32,11 @@ namespace Volo.Abp.Domain.Repositories
return Task.FromResult(Get(id));
}
public abstract TEntity FirstOrDefault(TPrimaryKey id);
public abstract TEntity Find(TPrimaryKey id);
public virtual Task<TEntity> FirstOrDefaultAsync(TPrimaryKey id)
public virtual Task<TEntity> FindAsync(TPrimaryKey id)
{
return Task.FromResult(FirstOrDefault(id));
return Task.FromResult(Find(id));
}
public abstract TEntity Insert(TEntity entity);
@ -73,7 +73,7 @@ namespace Volo.Abp.Domain.Repositories
public virtual void Delete(TPrimaryKey id)
{
var entity = FirstOrDefault(id);
var entity = Find(id);
if (entity == null)
{
return;

68
src/Volo.Abp/Volo/Abp/Linq/Extensions/QueryableExtensions.cs

@ -0,0 +1,68 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Volo.Abp.Application.Services.Dtos;
namespace Volo.Abp.Linq.Extensions
{
/// <summary>
/// Some useful extension methods for <see cref="IQueryable{T}"/>.
/// </summary>
public static class QueryableExtensions
{
/// <summary>
/// Used for paging. Can be used as an alternative to Skip(...).Take(...) chaining.
/// </summary>
public static IQueryable<T> PageBy<T>([NotNull] this IQueryable<T> query, int skipCount, int maxResultCount)
{
Check.NotNull(query, nameof(query));
return query.Skip(skipCount).Take(maxResultCount);
}
/// <summary>
/// Used for paging with an <see cref="IPagedResultRequest"/> object.
/// </summary>
/// <param name="query">Queryable to apply paging</param>
/// <param name="pagedResultRequest">An object implements <see cref="IPagedResultRequest"/> interface</param>
public static IQueryable<T> PageBy<T>([NotNull] this IQueryable<T> query, IPagedResultRequest pagedResultRequest)
{
Check.NotNull(query, nameof(query));
return query.PageBy(pagedResultRequest.SkipCount, pagedResultRequest.MaxResultCount);
}
/// <summary>
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
/// </summary>
/// <param name="query">Queryable to apply filtering</param>
/// <param name="condition">A boolean value</param>
/// <param name="predicate">Predicate to filter the query</param>
/// <returns>Filtered or not filtered query based on <paramref name="condition"/></returns>
public static IQueryable<T> WhereIf<T>([NotNull] this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
{
Check.NotNull(query, nameof(query));
return condition
? query.Where(predicate)
: query;
}
/// <summary>
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
/// </summary>
/// <param name="query">Queryable to apply filtering</param>
/// <param name="condition">A boolean value</param>
/// <param name="predicate">Predicate to filter the query</param>
/// <returns>Filtered or not filtered query based on <paramref name="condition"/></returns>
public static IQueryable<T> WhereIf<T>([NotNull] this IQueryable<T> query, bool condition, Expression<Func<T, int, bool>> predicate)
{
Check.NotNull(query, nameof(query));
return condition
? query.Where(predicate)
: query;
}
}
}

3
src/Volo.Abp/project.json

@ -9,7 +9,8 @@
"Newtonsoft.Json": "9.0.1",
"Nito.AsyncEx.Context": "1.1.0",
"System.Runtime.Loader": "4.3.0",
"System.Linq.Queryable": "4.3.0"
"System.Linq.Queryable": "4.3.0",
"Volo.Abp.ApplicationContracts": "1.0.0-*"
},
"frameworks": {

6
test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestModule.cs

@ -1,4 +1,5 @@
using AbpDesk.EntityFrameworkCore;
using System;
using AbpDesk.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
@ -11,10 +12,9 @@ namespace AbpDesk
public override void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkInMemoryDatabase();
services.AddDbContext<AbpDeskDbContext>(options =>
{
options.UseInMemoryDatabase();
options.UseInMemoryDatabase(Guid.NewGuid().ToString());
});
}
}

17
test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/Tickets/TicketAppService_Tests.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using AbpDesk.Tickets.Dtos;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
@ -18,11 +19,23 @@ namespace AbpDesk.Tickets
{
//Act
var result = _ticketAppService.GetAll();
var result = _ticketAppService.GetAll(new GetAllTicketsInput());
//Assert
result.Items.Count.ShouldBe(1);
}
[Fact]
public void GetAll_Filtered_Test()
{
//Act
var result = _ticketAppService.GetAll(new GetAllTicketsInput { Filter = "non-existing-text" });
//Assert
result.Items.Count.ShouldBe(0);
}
}
}

Loading…
Cancel
Save