public async void Handle_Should_Persist(
            [Frozen] Mock <IRepository <Guid, Venue> > repository
            , [Frozen] Venue venue
            , [Frozen] VenueCloseCommand command
            , VenueCloseCommandHandler handler)
        {
            // ARRANGE
            venue.Open();

            repository.Setup(r => r.FindByIdAsync(It.IsAny <Guid>(), It.IsAny <bool>()))
            .ReturnsAsync(venue);
            repository.Setup(r => r.UpdateAsync(It.IsAny <Venue>()));
            repository.Setup(r => r.UnitOfWork.SaveAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(true);

            // ACT
            var result = await handler.Handle(command);

            // Arrange
            Assert.True(result);
            // Repository.FindById is called
            repository.Verify(p => p.FindByIdAsync(command.Id, true), Times.Once);
            // Repository.Update is called
            repository.Verify(p => p.UpdateAsync(venue), Times.Once);
            // SaveEntitiesAsync is called
            repository.Verify(p => p.UnitOfWork.SaveAsync(It.IsAny <CancellationToken>()), Times.Once);

            repository.VerifyNoOtherCalls();
        }
Ejemplo n.º 2
0
        public void VenueCloseCommand_ShouldThrowException_WhenVenueIdIsEmpty()
        {
            // ARRANGE
            var cmd = new VenueCloseCommand {
                Id = Guid.Empty
            };
            var validator = new VenueCloseCommandValidator();

            // ACT
            var result = validator.Validate(cmd);

            Assert.Contains(result.Errors, o => o.PropertyName == "Id");
        }
        public async void CloseNotExisted_Should_ThrowException(
            [Frozen] Mock <IRepository <Guid, Venue> > repository
            , VenueCloseCommand command
            , VenueCloseCommandHandler handler
            )
        {
            // ARRANGE
            repository.Setup(r => r.FindByIdAsync(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Throws <NotFoundException>();

            // ACT
            await Assert.ThrowsAnyAsync <NotFoundException>(() => handler.Handle(command));

            // ASSERT
            repository.Verify(p => p.FindByIdAsync(It.IsAny <Guid>(), It.IsAny <bool>()));
            repository.VerifyNoOtherCalls();
        }