Пример #1
0
        public async Task Should_get_all_coffee_places()
        {
            var coffeePlace1 = new CoffeePlaceBuilder()
                               .Build();
            var coffeePlace2 = new CoffeePlaceBuilder()
                               .Build();
            var coffeePlaces = new List <CoffeePlace> {
                coffeePlace1, coffeePlace2
            };

            _coffeePlaceRepository
            .GetAllAsync()
            .Returns(coffeePlaces);

            var coffeePlacesResponse = await _coffeePlaceService
                                       .GetAll();

            coffeePlacesResponse
            .Should()
            .SatisfyRespectively(
                item1 =>
            {
                item1
                .Should()
                .BeEquivalentTo(coffeePlace1, opt => opt.ExcludingMissingMembers());
            },
                item2 =>
            {
                item2
                .Should()
                .BeEquivalentTo(coffeePlace2, opt => opt.ExcludingMissingMembers());
            });
        }
Пример #2
0
        public async Task Should_update_a_coffee_place()
        {
            var command = new UpdateCoffeePlaceCommandBuilder()
                          .Build();

            var coffeePlace = new CoffeePlaceBuilder()
                              .WithId(command.CoffeePlaceId)
                              .Build();

            _coffeePlaceRepository
            .GetByIdAsync(command.CoffeePlaceId)
            .Returns(coffeePlace);

            var response = await _coffeePlaceService
                           .Update(command);

            response
            .Id
            .Should()
            .Be(command.CoffeePlaceId);
            response
            .Name
            .Should()
            .Be(command.Name);
            response
            .PersonCoffeePlaceAssociations
            .Should()
            .BeEmpty();
        }
Пример #3
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);
        }
Пример #4
0
        public async Task Should_get_a_coffee_place_by_id()
        {
            const long coffeePlaceId = 1;

            var coffeePlace = new CoffeePlaceBuilder()
                              .WithId(coffeePlaceId)
                              .Build();

            _coffeePlaceRepository
            .GetByIdAsync(coffeePlaceId)
            .Returns(coffeePlace);

            var coffeePlaceResponse = await _coffeePlaceService
                                      .GetByIdWithDetails(coffeePlaceId);

            coffeePlaceResponse
            .Should()
            .BeEquivalentTo(coffeePlace, opt => opt.ExcludingMissingMembers());
        }
Пример #5
0
        public async Task Should_create_a_person()
        {
            var coffeePlace = new CoffeePlaceBuilder()
                              .Build();
            var eventRoom = new EventRoomBuilder()
                            .Build();

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

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

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

            var person = await _personService
                         .Create(command);

            await _personRepository
            .Received(1)
            .AddAsync(Arg.Is <Person>(a =>
                                      Equals(a.FirstName, command.FirstName) &&
                                      Equals(a.LastName, command.LastName) &&
                                      a.PersonCoffeePlaceAssociations.Count == 1 &&
                                      a.PersonEventRoomAssociations.Count == 1));

            person
            .Should()
            .NotBeNull();
        }