コード例 #1
0
        public async Task Should_update_a_person()
        {
            var coffeePlace = new CoffeePlaceBuilder()
                              .Build();
            var eventRoom = new EventRoomBuilder()
                            .Build();

            var command = new UpdatePersonCommandBuilder()
                          .WithCoffeePlaceIds(new List <long> {
                coffeePlace.Id
            })
                          .WithEventRoomIds(new List <long> {
                eventRoom.Id
            })
                          .Build();

            var person = new PersonBuilder()
                         .WithId(command.PersonId)
                         .Build();

            _coffeePlaceRepository
            .GetByIds(command.CoffeePlaceIds)
            .Returns(new List <CoffeePlace> {
                coffeePlace
            });

            _eventRoomRepository
            .GetByIds(command.EventRoomIds)
            .Returns(new List <EventRoom> {
                eventRoom
            });

            _personRepository
            .GetByIdAsync(command.PersonId)
            .Returns(person);

            var personResponse = await _personService
                                 .Update(command);

            personResponse
            .Should()
            .BeEquivalentTo(command, opt => opt.ExcludingMissingMembers());

            await _personRepository
            .Received(1)
            .DeleteAssociationsByIdAsync(command.PersonId);
        }
コード例 #2
0
        public async Task Should_not_update_a_person_if_they_are_not_found()
        {
            var command = new UpdatePersonCommandBuilder()
                          .Build();

            _personRepository
            .GetByIdAsync(command.PersonId)
            .ReturnsNull();

            Action act = () => _personService
                         .Update(command)
                         .GetAwaiter()
                         .GetResult();

            act
            .Should()
            .Throw <NotFoundException>()
            .Where(w => w.Message == "Pessoa não encontrada.");

            await _coffeePlaceRepository
            .DidNotReceiveWithAnyArgs()
            .GetByIds(default);