Base solution for your next web application
Open Closed

PhoneBookDemo "AddPhone and DeletePhone Method" fails Tests. #4934


User avatar
0
timmackey created

Acme.PhoneBookDemo-Angular, "AddPhone and DeletePhone Methods" section... When implementing changes as specified, plus per explanation this:

[AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook)]
public class PersonAppService : PhoneBookDemoAppServiceBase, IPersonAppService
{
    private readonly IRepository<Person> _personRepository;
    private readonly IRepository<Phone, long> _phoneRepository;

    public PersonAppService(IRepository<Person> personRepository,
                            IRepository<Phone, long> phoneRepository)
    {
        _personRepository = personRepository;
        _phoneRepository = phoneRepository;
    }
    ...
}

...two Tests fail:

Test Name: PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Get_All_People_Without_Any_Filter Test FullName: PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Get_All_People_Without_Any_Filter Test Source: C:\PhoneBookDemo\PhoneBookDemo\aspnet-core\test\PhoneBookDemo.Tests\People\PersonAppService_Tests.cs : line 21 Test Outcome: Failed Test Duration: 0:00:03.093

Result StackTrace: at AutoMapper.Mapper.get_Instance() at AutoMapper.Mapper.Map[TDestination](Object source) at Abp.AutoMapper.AutoMapExtensions.MapTo[TDestination](Object source) at PhoneBookDemo.Persons.PersonAppService.GetPeople(GetPeopleInput input) at Castle.Proxies.PersonAppServiceProxy.GetPeople_callback(GetPeopleInput input) at Castle.Proxies.Invocations.IPersonAppService_GetPeople.InvokeMethodOnTarget() at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Authorization.AuthorizationInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Auditing.AuditingInterceptor.PerformSyncAuditing(IInvocation invocation, AuditInfo auditInfo) at Abp.Auditing.AuditingInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Runtime.Validation.Interception.ValidationInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.PersonAppServiceProxy.GetPeople(GetPeopleInput input) at PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Get_All_People_Without_Any_Filter() Result Message: System.InvalidOperationException : Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.

...and...

Test Name: PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Get_People_With_Filter Test FullName: PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Get_People_With_Filter Test Source: C:\PhoneBookDemo\PhoneBookDemo\aspnet-core\test\PhoneBookDemo.Tests\People\PersonAppService_Tests.cs : line 31 Test Outcome: Failed Test Duration: 0:00:07.733

Result StackTrace: at AutoMapper.Mapper.get_Instance() at AutoMapper.Mapper.Map[TDestination](Object source) at Abp.AutoMapper.AutoMapExtensions.MapTo[TDestination](Object source) at PhoneBookDemo.Persons.PersonAppService.GetPeople(GetPeopleInput input) at Castle.Proxies.PersonAppServiceProxy.GetPeople_callback(GetPeopleInput input) at Castle.Proxies.Invocations.IPersonAppService_GetPeople.InvokeMethodOnTarget() at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Authorization.AuthorizationInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Auditing.AuditingInterceptor.PerformSyncAuditing(IInvocation invocation, AuditInfo auditInfo) at Abp.Auditing.AuditingInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Abp.Runtime.Validation.Interception.ValidationInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.PersonAppServiceProxy.GetPeople(GetPeopleInput input) at PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Get_People_With_Filter() Result Message: System.InvalidOperationException : Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.


12 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    Please double check all the steps.

  • User Avatar
    0
    timmackey created

    First of all, please note that I corrected the title.

    To your point to double check all the steps...

    The instructions are a bit cryptic at this point, i.e. "(Note: We injected IRepository<Phone, long> in the constructor and set to _personRepository field, as similar to _personRepository)"

    I included in the previous post the code that I wrote so that someone could verify if it follows the above instruction. Please refer to the attached .zip file for the changed code. Thank you. AddPhone-and-DeletePhone-Method-Error.zip

  • User Avatar
    0
    aaron created
    Support Team

    First of all, please note that I corrected the title.

    First of all, please don't change the original post after someone has answered it. Post a new topic instead.

    The instructions are a bit cryptic at this point, i.e. "(Note: We injected IRepository<Phone, long> in the constructor and set to _personRepository field, as similar to _personRepository)"

    It should be: "(Note: We injected IRepository<Phone, long> in the constructor and set to _phoneRepository field, as similar to _personRepository)"

    I included in the previous post the code that I wrote so that someone could verify if it follows the above instruction. Please refer to the attached .zip file for the changed code.

    There's nothing about AddPhone or DeletePhone "included in the previous post". Referring to the attached .zip file, this is the contents of your PersonAppService.cs:

    namespace PhoneBookDemo.Persons.Dto
    {
        public class GetPeopleInput
        {
            // ...
        }
    
        public class PersonListDto : FullAuditedEntityDto
        {
            // ...
        }
    
        public class PhoneInPersonListDto : CreationAuditedEntityDto<long>
        {
            // ...
        }
    
        public class AddPhoneInput
        {
            // ...
        }
    }
    

    Please double check.

  • User Avatar
    0
    timmackey created

    There's nothing about AddPhone or DeletePhone "included in the previous post".

    Actually if you give it a read again there is code starting at the 3rd line, and it is how I implemented the constructor of PersonAppService, My apologies for not using the code tags to highlight it. But that is beside the main points, which I will get to in a moment. It does appear that I have implemented it correctly. Thank you for correcting the instructions.

    Also, it was my intent to reference a section in the developer instructions page... [https://aspnetzero.com/Documents/Developing-Step-By-Step-Angular#creating-a-new-person]) ...when I said "Acme.PhoneBookDemo-Angular, "AddPhone and DeletePhone Methods" section..." - I was not referring to the AddPhone or DeletePhone methods.

    In the same page at section "Creating Person Application Service" the instructions say... "Application service interface and DTOs are located in .Application.Shared project." This makes sense given most other DTOs are located in the project. However, going to the github repository ... [https://github.com/aspnetzero/aspnet-zero-samples/tree/master/PhoneBook-Angular]) ... to double check my implementation I discover that the application service interface and DTO folder are in the .Application project.

    My questions are:

    1. Could this be why my code does not pass Tests?
    2. Which is the correct project to implement the interface; .Application or .Application.Shared?
    3. Why does the github repository has version 5.0.0 code and the code generator emit version 5.3.0 code? There are 102 text files with differences between versions. This makes code checking difficult.
    4. Why are Dto folders for Configuration, Install, and MultiTenancy in the .Application project? This breaks the pattern of most Dto folders being located in the .Application.Shared project.

    I have double checked all my code, and as best as I can follow the instructions, I believe I have implemented the code correctly. I remain baffled why it will not pass all Tests.

    I've attached the related projects in a zip file if you care to investigate into which folders are the files I implemented the code in, and if the code is correct. Thank you for your assistance. PhoneBookDemo.src.zip

  • User Avatar
    0
    aaron created
    Support Team

    Try this:

    public ListResultDto<PersonListDto> GetPeople(GetPeopleInput input)
    {
        // ...
    
        // return new ListResultDto<PersonListDto>(persons.MapTo<List<PersonListDto>>());
        return new ListResultDto<PersonListDto>(ObjectMapper.Map<List<PersonListDto>>(persons));
    }
    
  • User Avatar
    0
    timmackey created

    Your posted solution works. Thank you for updating the instructions document.

    Until the aspnet-zero-samples/PhoneBook-Angular project on github is updated and tested, those files are basically useless as a reference when problems arise.

  • User Avatar
    0
    alper created
    Support Team

    Thanks @aaron and @TimMackey. Fixed the code on GitHub and updated the documentation.

  • User Avatar
    0
    duffyvector created

    Hello, I found this post while researching where to add the

    using Abp.Application.Services;
    using Abp.Application.Services.Dto;
    
    namespace Acme.PhoneBookDemo.PhoneBook
    {
        public interface IPersonAppService : IApplicationService
        {
            ListResultDto<PersonListDto> GetPeople(GetPeopleInput input);
        }
    }
    

    It had a reference to the samples on GIThub: aspnet-zero-samples/PhoneBook-Angular project on github

    @aaron is there a completed solution to track where I may go wrong on this demo?

  • User Avatar
    0
    aaron created
    Support Team
  • User Avatar
    0
    duffyvector created

    @aaron - yes I tried that but I get a 404 not found

    <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-samples/tree/master/PhoneBook-Angular">https://github.com/aspnetzero/aspnet-ze ... ok-Angular</a>

  • User Avatar
    0
    duffyvector created

    Sory for the confusion I needed to add myself to the private github area via the licensing screen on <a class="postlink" href="https://aspnetzero.com/LicenseManagement">https://aspnetzero.com/LicenseManagement</a>. Got it now!! Thanks

  • User Avatar
    0
    alirizaadiyahsi created

    Thanks for feedback.