Ejemplo n.º 1
0
        public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new CreateMatchCommandHandler(
                It.IsAny <IDeletableEntityRepository <Match> >(),
                It.IsAny <IDeletableEntityRepository <Team> >(),
                It.IsAny <IDeletableEntityRepository <PlayWeek> >());

            // Act & Assert
            await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 2
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowForbiddenException()
        {
            // Arrange
            var teamsRepository     = new EfDeletableEntityRepository <Team>(this.dbContext);
            var playWeeksRepository = new EfDeletableEntityRepository <PlayWeek>(this.dbContext);

            var command = new CreateMatchCommand {
                HomeTeamId = 1, AwayTeamId = 4, PlayWeekId = 1, PlayDate = new DateTime(2019, 08, 15), TournamentTableId = 1
            };
            var sut = new CreateMatchCommandHandler(this.deletableEntityRepository, teamsRepository, playWeeksRepository);

            // Act & Assert
            await Should.ThrowAsync <ForbiddenException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 3
0
        public async System.Threading.Tasks.Task CreateMatchWithValidInputReturnSuccessTestAsync()
        {
            //Arrange
            Mock <IRepository <Domain.MainBoundleContext.Match> > matchMoqRepository = new Mock <IRepository <Domain.MainBoundleContext.Match> >();

            matchMoqRepository.Setup(m => m.InsertAtomic(It.IsAny <Domain.MainBoundleContext.Match>()))
            .Verifiable();
            Mock <IRepository <Manager> > managerMoqRepository = new Mock <IRepository <Manager> >();

            managerMoqRepository.Setup(m => m.GetByID(It.IsAny <int>()))
            .Returns(new Manager
            {
                Id   = 3,
                Name = "Test",
            });
            Mock <IRepository <Referee> > refereeMoqRepository = new Mock <IRepository <Referee> >();

            refereeMoqRepository.Setup(m => m.GetByID(It.IsAny <int>()))
            .Verifiable();
            Mock <IRepository <Player> > playerMoqRepository = new Mock <IRepository <Player> >();

            playerMoqRepository.Setup(m => m.Get(It.IsAny <bool>()))
            .Verifiable();
            Mock <IRepository <PlayerMatch> > playerMatchMoqRepository = new Mock <IRepository <PlayerMatch> >();

            playerMatchMoqRepository.Setup(m => m.Insert(It.IsAny <PlayerMatch>()))
            .Verifiable();

            var moqUnitOfWork = new Mock <IUnitOfWork>();

            moqUnitOfWork.Setup(uow => uow.MatchRepository).Returns(matchMoqRepository.Object);
            moqUnitOfWork.Setup(uow => uow.ManagerRepository).Returns(managerMoqRepository.Object);
            moqUnitOfWork.Setup(uow => uow.RefereeRepository).Returns(refereeMoqRepository.Object);
            moqUnitOfWork.Setup(uow => uow.PlayerRepository).Returns(playerMoqRepository.Object);
            moqUnitOfWork.Setup(uow => uow.PlayerMatchRepository).Returns(playerMatchMoqRepository.Object);

            var createMatchCommand = new CreateMatchCommand();

            var createMatchCommandHandler = new CreateMatchCommandHandler(moqUnitOfWork.Object);

            // Act
            await createMatchCommandHandler.Handle(createMatchCommand, CancellationToken.None);

            //Assert
            matchMoqRepository.Verify(m => m.InsertAtomic(It.IsAny <Domain.MainBoundleContext.Match>()), Times.Once,
                                      "CreateAsync must be called only once");

            moqUnitOfWork.Verify(m => m.Commit(), Times.Once, "Commit must be called only once");
        }
Ejemplo n.º 4
0
        public async Task Handle_GivenValidRequest_ShouldCreateMatch()
        {
            // Arrange
            var teamsRepository     = new EfDeletableEntityRepository <Team>(this.dbContext);
            var playWeeksRepository = new EfDeletableEntityRepository <PlayWeek>(this.dbContext);

            var command = new CreateMatchCommand {
                HomeTeamId = 1, AwayTeamId = 5, PlayWeekId = 1, PlayDate = new DateTime(2019, 08, 15), TournamentTableId = 1
            };
            var sut = new CreateMatchCommandHandler(this.deletableEntityRepository, teamsRepository, playWeeksRepository);

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

            // Assert
            matchId.ShouldBeGreaterThan(0);

            var createdMatch = this.dbContext.Matches.SingleOrDefault(x => x.ScheduledDate == new DateTime(2019, 08, 15));

            createdMatch.HomeTeamId.ShouldBe(1);
        }