Browse Source

Implemented a test entity without Id property.

pull/194/head
Halil İbrahim Kalkan 9 years ago
parent
commit
d2da1f5a55
  1. 29
      src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs
  2. 18
      src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs
  3. 17
      src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs
  4. 15
      src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs
  5. 8
      src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs
  6. 5
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs
  7. 2
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs
  8. 4
      test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs
  9. 5
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs
  10. 3
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto2.cs
  11. 5
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs
  12. 10
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs
  13. 5
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs
  14. 5
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PhoneDto.cs
  15. 2
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs
  16. 6
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs
  17. 2
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs

29
src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/EntityDto.cs

@ -1,33 +1,14 @@
using System;
namespace Volo.Abp.Application.Dtos namespace Volo.Abp.Application.Dtos
{ {
public class EntityDto : EntityDto<Guid>, IEntityDto public class EntityDto : IEntityDto //TODO: Consider to delete this class
{ {
/// <summary> public override string ToString()
/// Creates a new <see cref="EntityDto"/> object.
/// </summary>
public EntityDto()
{
}
/// <summary>
/// Creates a new <see cref="EntityDto"/> object.
/// </summary>
/// <param name="id">Id of the entity</param>
public EntityDto(Guid id)
: base(id)
{ {
return $"[DTO: {GetType().Name}]";
} }
} }
/// <summary> public class EntityDto<TPrimaryKey> : EntityDto, IEntityDto<TPrimaryKey>
/// Implements common properties for entity based DTOs.
/// </summary>
/// <typeparam name="TPrimaryKey">Type of the primary key</typeparam>
public class EntityDto<TPrimaryKey> : IEntityDto<TPrimaryKey>
{ {
/// <summary> /// <summary>
/// Id of the entity. /// Id of the entity.
@ -53,7 +34,7 @@ namespace Volo.Abp.Application.Dtos
public override string ToString() public override string ToString()
{ {
return $"[{GetType().Name}] Id = {Id}"; return $"[DTO: {GetType().Name}] Id = {Id}";
} }
} }
} }

18
src/Volo.Abp.Ddd/Volo/Abp/Application/Dtos/IEntityDto.cs

@ -1,24 +1,12 @@
using System; namespace Volo.Abp.Application.Dtos
namespace Volo.Abp.Application.Dtos
{ {
/// <summary> public interface IEntityDto
/// A shortcut of <see cref="IEntityDto{TPrimaryKey}"/> for default primary key type (<see cref="Guid"/>).
/// </summary>
public interface IEntityDto : IEntityDto<Guid>
{ {
} }
/// <summary> public interface IEntityDto<TPrimaryKey> : IEntityDto
/// Defines common properties for entity based DTOs.
/// </summary>
/// <typeparam name="TPrimaryKey"></typeparam>
public interface IEntityDto<TPrimaryKey>
{ {
/// <summary>
/// Id of the entity.
/// </summary>
TPrimaryKey Id { get; set; } TPrimaryKey Id { get; set; }
} }
} }

17
src/Volo.Abp.Ddd/Volo/Abp/Application/Services/AsyncCrudAppService.cs

@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -8,18 +7,6 @@ using Volo.Abp.Linq;
namespace Volo.Abp.Application.Services namespace Volo.Abp.Application.Services
{ {
public abstract class AsyncCrudAppService<TEntity, TEntityDto>
: AsyncCrudAppService<TEntity, TEntityDto, Guid>
where TEntity : class, IEntity<Guid>
where TEntityDto : IEntityDto<Guid>
{
protected AsyncCrudAppService(IQueryableRepository<TEntity, Guid> repository)
: base(repository)
{
}
}
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey> public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey>
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto> : AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
@ -49,7 +36,7 @@ namespace Volo.Abp.Application.Services
where TGetAllInput : IPagedAndSortedResultRequest where TGetAllInput : IPagedAndSortedResultRequest
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey> where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey> where TCreateInput : IEntityDto<TPrimaryKey>
{ {
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository) protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository) : base(repository)

15
src/Volo.Abp.Ddd/Volo/Abp/Application/Services/CrudAppService.cs

@ -1,23 +1,10 @@
using System; using System.Linq;
using System.Linq;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.Application.Services namespace Volo.Abp.Application.Services
{ {
public abstract class CrudAppService<TEntity, TEntityDto>
: CrudAppService<TEntity, TEntityDto, Guid>
where TEntity : class, IEntity<Guid>
where TEntityDto : IEntityDto<Guid>
{
protected CrudAppService(IQueryableRepository<TEntity, Guid> repository)
: base(repository)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey> public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey>
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto> : CrudAppService<TEntity, TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>

8
src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs

@ -5,7 +5,11 @@ namespace Volo.Abp.Domain.Entities
/// <inheritdoc/> /// <inheritdoc/>
public abstract class Entity : IEntity public abstract class Entity : IEntity
{ {
/// <inheritdoc/>
public override string ToString()
{
return $"[ENTITY: {GetType().Name}]";
}
} }
/// <inheritdoc cref="IEntity{TPrimaryKey}" /> /// <inheritdoc cref="IEntity{TPrimaryKey}" />
@ -75,7 +79,7 @@ namespace Volo.Abp.Domain.Entities
/// <inheritdoc/> /// <inheritdoc/>
public override string ToString() public override string ToString()
{ {
return $"[{GetType().Name} {Id}]"; return $"[ENTITY: {GetType().Name}] Id = {Id}";
} }
} }
} }

5
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs

@ -1,8 +1,9 @@
using Volo.Abp.Application.Dtos; using System;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
public class IdentityRoleDto : EntityDto public class IdentityRoleDto : EntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }
} }

2
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs

@ -3,7 +3,7 @@ using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
public class IdentityUserDto : EntityDto public class IdentityUserDto : EntityDto<Guid>
{ {
public string UserName { get; set; } public string UserName { get; set; }

4
test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs

@ -163,10 +163,10 @@ namespace Volo.Abp.AspNetCore.Mvc
var douglas = _personRepository.First(p => p.Name == "Douglas"); var douglas = _personRepository.First(p => p.Name == "Douglas");
var firstPhone = douglas.Phones.First(); var firstPhone = douglas.Phones.First();
await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones/{firstPhone.Id}"); await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones?number={firstPhone.Number}");
douglas = _personRepository.First(p => p.Name == "Douglas"); douglas = _personRepository.First(p => p.Name == "Douglas");
douglas.Phones.Any(p => p.Id == firstPhone.Id).ShouldBeFalse(); douglas.Phones.Any(p => p.Number == firstPhone.Number).ShouldBeFalse();
} }
} }
} }

5
test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs

@ -1,9 +1,10 @@
using Volo.Abp.Application.Dtos; using System;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.AutoMapper.SampleClasses namespace Volo.Abp.AutoMapper.SampleClasses
{ {
[AutoMap(typeof(MyEntity))] [AutoMap(typeof(MyEntity))]
public class MyEntityDto : EntityDto public class MyEntityDto : EntityDto<Guid>
{ {
public int Number { get; set; } public int Number { get; set; }
} }

3
test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto2.cs

@ -1,8 +1,9 @@
using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Volo.Abp.AutoMapper.SampleClasses namespace Volo.Abp.AutoMapper.SampleClasses
{ {
public class MyEntityDto2 : EntityDto public class MyEntityDto2 : EntityDto<Guid>
{ {
public int Number { get; set; } public int Number { get; set; }
} }

5
test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs

@ -1,8 +1,9 @@
using Volo.Abp.Application.Dtos; using System;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.AutoMapper.SampleClasses namespace Volo.Abp.AutoMapper.SampleClasses
{ {
public class MyNotMappedDto : EntityDto public class MyNotMappedDto : EntityDto<Guid>
{ {
public int Number { get; set; } public int Number { get; set; }
} }

10
test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs

@ -16,5 +16,15 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
{ {
} }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Phone>(b =>
{
b.HasKey(p => new {p.PersonId, p.Number});
});
}
} }
} }

5
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs

@ -1,8 +1,9 @@
using Volo.Abp.Application.Dtos; using System;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.TestApp.Application.Dto namespace Volo.Abp.TestApp.Application.Dto
{ {
public class PersonDto : EntityDto public class PersonDto : EntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }

5
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PhoneDto.cs

@ -1,9 +1,8 @@
using Volo.Abp.Application.Dtos; using Volo.Abp.TestApp.Domain;
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.Application.Dto namespace Volo.Abp.TestApp.Application.Dto
{ {
public class PhoneDto : EntityDto<long> public class PhoneDto
{ {
public string Number { get; set; } public string Number { get; set; }

2
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.TestApp.Application
Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto); Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto);
Task RemovePhone(Guid id, long phoneId); Task RemovePhone(Guid id, string number);
Task<GetWithComplexTypeInput> GetWithComplexType(GetWithComplexTypeInput input); Task<GetWithComplexTypeInput> GetWithComplexType(GetWithComplexTypeInput input);
} }

6
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs

@ -10,7 +10,7 @@ using Volo.Abp.TestApp.Application.Dto;
namespace Volo.Abp.TestApp.Application namespace Volo.Abp.TestApp.Application
{ {
public class PeopleAppService : AsyncCrudAppService<Person, PersonDto>, IPeopleAppService public class PeopleAppService : AsyncCrudAppService<Person, PersonDto, Guid>, IPeopleAppService
{ {
public PeopleAppService(IQueryableRepository<Person, Guid> repository) public PeopleAppService(IQueryableRepository<Person, Guid> repository)
: base(repository) : base(repository)
@ -39,10 +39,10 @@ namespace Volo.Abp.TestApp.Application
return ObjectMapper.Map<Phone, PhoneDto>(phone); return ObjectMapper.Map<Phone, PhoneDto>(phone);
} }
public async Task RemovePhone(Guid id, long phoneId) public async Task RemovePhone(Guid id, string number)
{ {
var person = await GetEntityByIdAsync(id); var person = await GetEntityByIdAsync(id);
person.Phones.RemoveAll(p => p.Id == phoneId); person.Phones.RemoveAll(p => p.Number == number);
} }
public Task<GetWithComplexTypeInput> GetWithComplexType(GetWithComplexTypeInput input) public Task<GetWithComplexTypeInput> GetWithComplexType(GetWithComplexTypeInput input)

2
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs

@ -5,7 +5,7 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain namespace Volo.Abp.TestApp.Domain
{ {
[Table("AppPhones")] [Table("AppPhones")]
public class Phone : Entity<long> public class Phone : Entity
{ {
public virtual Guid PersonId { get; set; } public virtual Guid PersonId { get; set; }

Loading…
Cancel
Save