Esempio n. 1
0
        public async Task Handle_GivenValidRequest_ShouldAddPlayerToTeam()
        {
            // Arrange
            var command = new RemovePlayerCommand {
                TeamId = 1, PlayerId = "Foo5"
            };

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");
            var sut = new RemovePlayerCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            this.dbContext.Add(new PlayerTeam {
                TeamId = 1, PlayerId = "Foo5"
            });
            this.dbContext.SaveChanges();

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

            // Assert
            affectedRows.ShouldBeGreaterThan(0);

            var isPlayerRemoved = this.dbContext.PlayerTeams.Any(x => x.PlayerId == "Foo5" && x.TeamId == 1 && !x.IsDeleted);

            isPlayerRemoved.ShouldBe(false);
        }
Esempio n. 2
0
        public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new RemovePlayerCommandHandler(It.IsAny <IDeletableEntityRepository <PlayerTeam> >(), It.IsAny <IUserAccessor>());

            // Act & Assert
            await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
Esempio n. 3
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new RemovePlayerCommand {
                TeamId = 1, PlayerId = "InvalidId"
            };

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");
            var sut = new RemovePlayerCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Esempio n. 4
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowOwnerOfAMustTransferOwnerShipBeforeLeavingTeamException()
        {
            // Arrange
            var command = new RemovePlayerCommand {
                TeamId = 1, PlayerId = "Foo1"
            };

            this.dbContext.PlayerTeams.Add(new PlayerTeam {
                PlayerId = "Foo5", TeamId = 1
            });
            this.dbContext.SaveChanges();

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");
            var sut = new RemovePlayerCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <OwnerOfAMustTransferOwnerShipBeforeLeavingTeamException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }