Base solution for your next web application
Open Closed

Test Should_Create_Person_With_Valid_Arguments() fails #4928


User avatar
0
timmackey created

In the Acme.PhoneBookDemo project Should_Create_Person_With_Valid_Arguments() test fails, and CreateNewPerson dialog also fails.

In file PhoneBookDemo\aspnet-core\src\PhoneBookDemo.Application\Persons\PersonAppService.cs I made the following change to get the test to pass and the dialog to work.

    public async Task CreatePerson(CreatePersonInput input)
    {
        //Person person = ObjectMapper.Map<Person>(input);        // remove

        // add
        Person person = new Person
        {
            Name = input.Name,
            Surname = input.Surname,
            EmailAddress = input.EmailAddress
        };
        // end add

        await _personRepository.InsertAsync(person);
    }

If the above change is not the preferred solution, please advise.


4 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    I suppose you are referring to the PhoneBook-Angular solution. Anyway, I tested all 4 versions and they pass without any change:

    [attachment=0:2cuh4r7q]Acme.PhoneBookDemo.png[/attachment:2cuh4r7q]

  • User Avatar
    0
    timmackey created

    Yes, PhoneBook-Angular solution, version 5.3.0.

    When I execute the Test the following error occurs:

    Test Name: PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Create_Person_With_Valid_Arguments Test FullName: PhoneBookDemo.Tests.People.PersonAppService_Tests.Should_Create_Person_With_Valid_Arguments Test Source: C:\PhoneBookDemo\PhoneBookDemo\aspnet-core\test\PhoneBookDemo.Tests\People\PersonAppService_Tests.cs : line 50 Test Outcome: Failed Test Duration: 0:00:07.944

    Result StackTrace: at lambda_method(Closure , CreatePersonInput , Person , ResolutionContext ) at lambda_method(Closure , Object , Object , ResolutionContext ) at Abp.AutoMapper.AutoMapperObjectMapper.Map[TDestination](Object source) at PhoneBookDemo.Persons.PersonAppService.<CreatePerson>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinally>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithFinally>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at PhoneBookDemo.Tests.People.PersonAppService_Tests.<Should_Create_Person_With_Valid_Arguments>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Result Message: AutoMapper.AutoMapperConfigurationException : Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters

    CreatePersonInput -> Person (Destination member list) PhoneBookDemo.PhoneBook.CreatePersonInput -> PhoneBookDemo.PhoneBook.Person (Destination member list)

    Unmapped properties: IsDeleted DeleterUserId DeletionTime LastModificationTime LastModifierUserId CreationTime CreatorUserId Id

  • User Avatar
    0
    alper created
    Support Team

    Have you forgotten to do the mapping for CreatePersonInput?

    CustomDtoMapper.cs should have these mapping lines.

    configuration.CreateMap<Person, PersonListDto>();
    configuration.CreateMap<AddPhoneInput, Phone>();
    configuration.CreateMap<CreatePersonInput, Person>();
    configuration.CreateMap<Person, GetPersonForEditOutput>();
    configuration.CreateMap<Phone, PhoneInPersonListDto>();
    
  • User Avatar
    0
    timmackey created

    That is the solution! Thank you!