Tested CRUD service and refactored.

pull/96/head
Halil İbrahim Kalkan 8 years ago
parent 92354378d0
commit 863a65f0db

@ -118,13 +118,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AutoMapper", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AutoMapper.Tests", "test\Volo.Abp.AutoMapper.Tests\Volo.Abp.AutoMapper.Tests.csproj", "{8343BE23-6A7B-4C58-BF0D-95188B11B180}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.Tests", "test\Volo.Abp.AspNetCore.Mvc.Tests\Volo.Abp.AspNetCore.Mvc.Tests.csproj", "{27D76546-6091-4AEE-9079-1FE3991C81BC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Mvc.Tests", "test\Volo.Abp.AspNetCore.Mvc.Tests\Volo.Abp.AspNetCore.Mvc.Tests.csproj", "{27D76546-6091-4AEE-9079-1FE3991C81BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.TestApp", "test\Volo.Abp.TestApp\Volo.Abp.TestApp.csproj", "{DE160F1A-92FB-44BA-87E2-B8AD7A938AC7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.TestApp", "test\Volo.Abp.TestApp\Volo.Abp.TestApp.csproj", "{DE160F1A-92FB-44BA-87E2-B8AD7A938AC7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.MemoryDb", "src\Volo.Abp.MemoryDb\Volo.Abp.MemoryDb.csproj", "{CF564447-8E0B-4A07-B0D2-396E00A8E437}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.MemoryDb", "src\Volo.Abp.MemoryDb\Volo.Abp.MemoryDb.csproj", "{CF564447-8E0B-4A07-B0D2-396E00A8E437}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.MemoryDb.Tests", "test\Volo.Abp.MemoryDb.Tests\Volo.Abp.MemoryDb.Tests.csproj", "{D0279C94-E9A3-4A1B-968B-D3BBF3E06FD8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.MemoryDb.Tests", "test\Volo.Abp.MemoryDb.Tests\Volo.Abp.MemoryDb.Tests.csproj", "{D0279C94-E9A3-4A1B-968B-D3BBF3E06FD8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.TestApp.Tests", "test\Volo.Abp.TestApp.Tests\Volo.Abp.TestApp.Tests.csproj", "{4C2F7B03-C598-4432-A43A-B065D9D0712F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -312,6 +314,10 @@ Global
{D0279C94-E9A3-4A1B-968B-D3BBF3E06FD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0279C94-E9A3-4A1B-968B-D3BBF3E06FD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0279C94-E9A3-4A1B-968B-D3BBF3E06FD8}.Release|Any CPU.Build.0 = Release|Any CPU
{4C2F7B03-C598-4432-A43A-B065D9D0712F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C2F7B03-C598-4432-A43A-B065D9D0712F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C2F7B03-C598-4432-A43A-B065D9D0712F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C2F7B03-C598-4432-A43A-B065D9D0712F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -371,6 +377,7 @@ Global
{DE160F1A-92FB-44BA-87E2-B8AD7A938AC7} = {37087D1B-3693-4E96-983D-A69F210BDE53}
{CF564447-8E0B-4A07-B0D2-396E00A8E437} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8}
{D0279C94-E9A3-4A1B-968B-D3BBF3E06FD8} = {37087D1B-3693-4E96-983D-A69F210BDE53}
{4C2F7B03-C598-4432-A43A-B065D9D0712F} = {37087D1B-3693-4E96-983D-A69F210BDE53}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

@ -0,0 +1,19 @@
using System;
using AutoMapper;
namespace Volo.Abp.AutoMapper
{
public class AbpAutoMapperConfigurationContext : IAbpAutoMapperConfigurationContext
{
public IMapperConfigurationExpression MapperConfiguration { get; }
public IServiceProvider ServiceProvider { get; }
public AbpAutoMapperConfigurationContext(
IMapperConfigurationExpression mapperConfigurationExpression,
IServiceProvider serviceProvider)
{
MapperConfiguration = mapperConfigurationExpression;
ServiceProvider = serviceProvider;
}
}
}

@ -81,6 +81,8 @@ namespace Volo.Abp.AutoMapper
private void FindAndAutoMapTypes(IAbpAutoMapperConfigurationContext context)
{
//TODO: AutoMapping (by attributes) can be optionally enabled/disabled.
var typeFinder = context.ServiceProvider.GetRequiredService<ITypeFinder>();
var logger = context.ServiceProvider.GetRequiredService<ILogger<AbpAutoMapperModule>>();

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using AutoMapper;
namespace Volo.Abp.AutoMapper
{
@ -16,25 +15,4 @@ namespace Volo.Abp.AutoMapper
Configurators = new List<Action<IAbpAutoMapperConfigurationContext>>();
}
}
public interface IAbpAutoMapperConfigurationContext
{
IMapperConfigurationExpression MapperConfiguration { get; }
IServiceProvider ServiceProvider { get; }
}
public class AbpAutoMapperConfigurationContext : IAbpAutoMapperConfigurationContext
{
public IMapperConfigurationExpression MapperConfiguration { get; }
public IServiceProvider ServiceProvider { get; }
public AbpAutoMapperConfigurationContext(
IMapperConfigurationExpression mapperConfigurationExpression,
IServiceProvider serviceProvider)
{
MapperConfiguration = mapperConfigurationExpression;
ServiceProvider = serviceProvider;
}
}
}

@ -0,0 +1,12 @@
using System;
using AutoMapper;
namespace Volo.Abp.AutoMapper
{
public interface IAbpAutoMapperConfigurationContext
{
IMapperConfigurationExpression MapperConfiguration { get; }
IServiceProvider ServiceProvider { get; }
}
}

@ -13,7 +13,7 @@ namespace Abp.Application.Services
where TEntity : class, IEntity<Guid>
where TEntityDto : IEntityDto<Guid>
{
protected AsyncCrudAppService(IRepository<TEntity, Guid> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, Guid> repository)
: base(repository)
{
@ -25,7 +25,7 @@ namespace Abp.Application.Services
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -37,7 +37,7 @@ namespace Abp.Application.Services
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -51,7 +51,7 @@ namespace Abp.Application.Services
where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -64,7 +64,7 @@ namespace Abp.Application.Services
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -78,7 +78,7 @@ namespace Abp.Application.Services
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -96,7 +96,7 @@ namespace Abp.Application.Services
{
public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; }
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
:base(repository)
{
AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance;

@ -11,7 +11,7 @@ namespace Abp.Application.Services
where TEntity : class, IEntity<Guid>
where TEntityDto : IEntityDto<Guid>
{
protected CrudAppService(IRepository<TEntity, Guid> repository)
protected CrudAppService(IQueryableRepository<TEntity, Guid> repository)
: base(repository)
{
@ -23,7 +23,7 @@ namespace Abp.Application.Services
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -35,7 +35,7 @@ namespace Abp.Application.Services
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -48,7 +48,7 @@ namespace Abp.Application.Services
where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -61,7 +61,7 @@ namespace Abp.Application.Services
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -75,7 +75,7 @@ namespace Abp.Application.Services
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
@ -91,7 +91,7 @@ namespace Abp.Application.Services
where TGetInput : IEntityDto<TPrimaryKey>
where TDeleteInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{

@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Linq.Dynamic.Core;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Entities;
@ -18,7 +17,7 @@ namespace Abp.Application.Services
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
protected IRepository<TEntity, TPrimaryKey> Repository { get; }
protected IQueryableRepository<TEntity, TPrimaryKey> Repository { get; }
protected virtual string GetPermissionName { get; set; }
@ -30,7 +29,7 @@ namespace Abp.Application.Services
protected virtual string DeletePermissionName { get; set; }
protected CrudAppServiceBase(IRepository<TEntity, TPrimaryKey> repository)
protected CrudAppServiceBase(IQueryableRepository<TEntity, TPrimaryKey> repository)
{
Repository = repository;
}
@ -96,13 +95,7 @@ namespace Abp.Application.Services
/// <param name="input">The input.</param>
protected virtual IQueryable<TEntity> CreateFilteredQuery(TGetAllInput input)
{
var queryableRepository = Repository as IQueryableRepository<TEntity, TPrimaryKey>;
if (queryableRepository == null)
{
throw new AbpException("Repository should be IQueryableRepository in order to call CreateFilteredQuery, but it's not. It's type: " + Repository.GetType().AssemblyQualifiedName);
}
return queryableRepository;
return Repository;
}
/// <summary>

@ -1,6 +1,6 @@
using Volo.Abp.TestBase;
namespace Volo.Abp.MemoryDb.Repositories
namespace Volo.Abp.MemoryDb
{
public abstract class MemoryDbTestBase : AbpIntegratedTest<AbpMemoryDbTestModule>
{

@ -31,7 +31,7 @@ namespace Volo.Abp.MemoryDb.Repositories
var name = Guid.NewGuid().ToString();
//Act
_personRepository.Insert(new Person(name, 42));
_personRepository.Insert(new Person(Guid.NewGuid(), name, 42));
//Assert
UseUnitOfWork(() =>

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Volo.Abp.TestApp.Tests</AssemblyName>
<PackageId>Volo.Abp.TestApp.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.MemoryDb.Tests\Volo.Abp.MemoryDb.Tests.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,25 @@
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Xunit;
namespace Volo.Abp.TestApp.Application
{
public class PersonAppService_Tests : TestAppTestBase
{
private readonly IPersonAppService _personAppService;
public PersonAppService_Tests()
{
_personAppService = ServiceProvider.GetRequiredService<IPersonAppService>();
}
[Fact]
public async Task GetAll()
{
var people = await _personAppService.GetAll(new PagedAndSortedResultRequestDto());
people.Items.Count.ShouldBeGreaterThan(0);
}
}
}

@ -0,0 +1,12 @@
using Volo.Abp.TestBase;
namespace Volo.Abp.TestApp
{
public class TestAppTestBase : AbpIntegratedTest<TestAppTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.MemoryDb;
using Volo.Abp.Modularity;
namespace Volo.Abp.TestApp
{
[DependsOn(typeof(AbpMemoryDbTestModule))]
public class TestAppTestModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<TestAppTestModule>();
}
}
}

@ -12,11 +12,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp\Volo.Abp.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
</ItemGroup>
</Project>

@ -0,0 +1,8 @@
using Abp.Application.Services;
namespace Volo.Abp.TestApp.Application
{
public interface IPersonAppService : IAsyncCrudAppService<PersonDto>
{
}
}

@ -0,0 +1,14 @@
using Abp.Application.Services;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.TestApp.Application
{
public class PersonAppService : AsyncCrudAppService<Person, PersonDto>, IPersonAppService
{
public PersonAppService(IQueryableRepository<Person> repository)
: base(repository)
{
}
}
}

@ -0,0 +1,11 @@
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.TestApp.Application
{
public class PersonDto : EntityDto
{
public string Name { get; set; }
public int Age { get; set; }
}
}

@ -1,3 +1,4 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
@ -8,8 +9,9 @@ namespace Volo.Abp.TestApp.Domain
public int Age { get; set; }
public Person(string name, int age)
public Person(Guid id, string name, int age)
{
Id = id;
Name = name;
Age = age;
}

@ -1,17 +0,0 @@
using System.Collections.Generic;
using Volo.Abp.Application.Services;
namespace Volo.Abp.TestApp.Domain
{
public class PersonAppService : ApplicationService
{
public List<Person> GetAll()
{
return new List<Person>
{
new Person("John", 33),
new Person("Dougles", 42),
};
}
}
}

@ -1,23 +1,36 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.AutoMapper;
using Volo.Abp.TestApp.Application;
namespace Volo.Abp.TestApp
{
[DependsOn(typeof(AbpAutoMapperModule))]
public class TestAppModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<AbpAutoMapperOptions>(options =>
{
options.Configurators.Add((IAbpAutoMapperConfigurationContext ctx) =>
{
ctx.MapperConfiguration.CreateMap<Person, PersonDto>();
});
});
services.AddAssemblyOf<TestAppModule>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
//TODO: Refactor to a seed class!
using(IServiceScope scope = context.ServiceProvider.CreateScope())
{
var personRepository = scope.ServiceProvider.GetRequiredService<IRepository<Person>>();
personRepository.Insert(new Person("Douglas", 42));
personRepository.Insert(new Person(Guid.NewGuid(), "Douglas", 42));
}
}
}

Loading…
Cancel
Save