Exemple #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>()));
        }
Exemple #2
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var command = new DeleteGameCommand {
                Id = id
            };
            var result = _deleteHandler.Handle(command);

            return(await Response(result, _handler.Notifications));
        }
        public async Task Handle_GameExists_GameDeleted()
        {
            var game = Context.Games.First();

            await _sut.Handle(new DeleteGameCommand(game.Id), CancellationToken.None);

            var actual = Context.Games.FirstOrDefault(g => g.Id == game.Id);

            actual.Should().BeNull();
        }
Exemple #4
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>()));
        }
Exemple #5
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>()));
        }
Exemple #6
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>()));
        }