public async Task ForCreateTentativeReservationCommand_ShouldAddNewReservation()
        {
            // Given
            var repository      = new FakeRepository <Reservation>();
            var numberGenerator = new FakeReservationNumberGenerator();

            var commandHandler = new ReservationCommandHandler(
                repository,
                numberGenerator
                );

            var command = CreateTentativeReservation.Create(Guid.NewGuid(), Guid.NewGuid());

            // When
            await commandHandler.Handle(command, CancellationToken.None);

            //Then
            repository.Aggregates.Should().HaveCount(1);

            var reservation = repository.Aggregates.Values.Single();

            reservation
            .IsTentativeReservationWith(
                command.ReservationId,
                numberGenerator.LastGeneratedNumber,
                command.SeatId
                )
            .HasTentativeReservationCreatedEventWith(
                command.ReservationId,
                numberGenerator.LastGeneratedNumber,
                command.SeatId
                );
        }
Beispiel #2
0
        public async void CreateReservation_ContactInvalid_False()
        {
            //arrange
            var contact     = ContactFaker.GetContactContactNameGreater();
            var contactType = ContactTypeFaker.GetContactTypeOk();

            var faker = new Faker();

            var message = faker.Lorem.Paragraph();

            var createReservationCommand = new CreateReservationCommand(
                contactId: contact.Id,
                contactName: contact.Name,
                contactPhone: contact.Name,
                contactBirthdate: contact.BirthDate,
                contactTypeId: contactType.Id,
                message: message
                );


            _dependencyResolverMock
            .Setup(x =>
                   x.Resolve <IReservationRepository>())
            .Returns(_reservationRepositoryMock.Object);


            _dependencyResolverMock
            .Setup(x =>
                   x.Resolve <IContactRepository>())
            .Returns(_contactRepositoryMock.Object);


            _dependencyResolverMock
            .Setup(x =>
                   x.Resolve <IContactTypeRepository>())
            .Returns(_contactTypeRepositoryMock.Object);


            _contactRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactId.Value))
            .Returns(Task.FromResult((Contact)null));


            _contactTypeRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactTypeId))
            .Returns(Task.FromResult(contactType));

            var handler = new ReservationCommandHandler(_dependencyResolverMock.Object);

            //Act

            var result = await handler.Handle(createReservationCommand, new CancellationToken());


            //Assert

            Assert.False(result.Success);
            _contactRepositoryMock.Verify(x => x.GetByIdAsync(createReservationCommand.ContactId.Value), Times.Once);
            _reservationRepositoryMock.Verify(x => x.AddAsync(It.IsAny <Reservation>()), Times.Never);
            _reservationRepositoryMock.Verify(x => x.CommitAsync(), Times.Never);
        }