コード例 #1
0
        public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new DeleteGameCommandHandler(this.deletableEntityRepository, this.mediatorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
コード例 #2
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var sut     = new DeleteGameCommandHandler(this.deletableEntityRepository, this.mediatorMock.Object);
            var command = new DeleteGameCommand()
            {
                Id       = 90125,
                GameName = It.IsAny <string>()
            };

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
コード例 #3
0
 public GameController(RegisterGameCommandHandler handler,
                       AuthenticatedUser authenticatedUser,
                       UpdateGameCommandHandler updateHandler,
                       DeleteGameCommandHandler deleteHandler,
                       IGameRepository friendRepository,
                       IUnitOfWork unitOfWork) : base(unitOfWork)
 {
     _handler           = handler;
     _updateHandler     = updateHandler;
     _deleteHandler     = deleteHandler;
     _authenticatedUser = authenticatedUser;
     _friendRepository  = friendRepository;
 }
コード例 #4
0
        public async Task Handle_GivenValidRequest_ShouldThrowDeleteFailureException()
        {
            // Arrange
            var sut    = new DeleteGameCommandHandler(this.deletableEntityRepository, this.mediatorMock.Object);
            var gameId = 2;

            var desiredEntity = this.deletableEntityRepository
                                .AllAsNoTracking()
                                .SingleOrDefault(g => g.Id == gameId);

            this.deletableEntityRepository.Delete(desiredEntity);
            await this.deletableEntityRepository.SaveChangesAsync();

            var command = new DeleteGameCommand()
            {
                Id       = gameId,
                GameName = It.IsAny <string>()
            };

            // Act & Assert
            await Should.ThrowAsync <DeleteFailureException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
コード例 #5
0
        public async Task Handle_GivenValidRequest_ShouldMarkEntityAsDeleted()
        {
            // Arrange
            var gameId            = 2;
            var deleteGameCommand = new DeleteGameCommand()
            {
                Id       = gameId,
                GameName = It.IsAny <string>()
            };

            var sut = new DeleteGameCommandHandler(deletableEntityRepository, this.mediatorMock.Object);

            // Act
            var id = await sut.Handle(deleteGameCommand, It.IsAny <CancellationToken>());

            // Assert
            var deletedGameEntity = deletableEntityRepository
                                    .AllAsNoTrackingWithDeleted()
                                    .SingleOrDefault(x => x.Id == gameId);

            deletedGameEntity.IsDeleted.ShouldBe(true);
            id.ShouldBe(gameId);
            this.mediatorMock.Verify(x => x.Publish(It.IsAny <GameDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
コード例 #6
0
 public void SetUp()
 {
     _sut = new DeleteGameCommandHandler(Context, NullLogger <DeleteGameCommandHandler> .Instance);
 }