Exemple #1
0
        public async Task Should_ThrowException_When_PassInvalidUserId()
        {
            // Arrange
            var team = new Team()
            {
                TeamName  = "Test Team",
                CompanyId = 1,
                CreatedAt = DateTime.UtcNow,
                CreatedBy = -1
            };

            team.TeamMembers.Add(new TeamMember()
            {
                IsApprover = true,
                IsMember   = true,
                UserId     = 1
            });
            _fixture.Context.Teams.Attach(team);
            await _fixture.Context.SaveChangesAsync();

            IUnitOfWork        unitOfWork     = new UnitOfWork(_fixture.Context);
            IRepository <Team> repository     = new Repository <Team>(_fixture.Context);
            IRepository <User> userRepository = new Repository <User>(_fixture.Context);

            var handler = new UpdateTeamHandler(unitOfWork, repository, userRepository, _logger, _mapper);

            var request = new UpdateTeamCommand(companyId: 1,
                                                userId: 1,
                                                teamId: 1,
                                                "Test Team - 1",
                                                members: new List <int>()
            {
                1, -22
            },
                                                approvers: new List <int>()
            {
                1
            });

            // Act
            var tcs = new CancellationToken();

            // Assert
            var exception = await Assert.ThrowsAsync <VacationTrackingException>(async() =>
            {
                var result = await handler.Handle(request, tcs);
            });

            Assert.Equal(ExceptionMessages.InvalidUserId, exception.Message);
            Assert.Equal(400, exception.Code);
        }
Exemple #2
0
        public async Task Should_UpdateTeam_When_PassValidParameters()
        {
            // Arrange
            var team = new Team()
            {
                TeamName  = "Test Team",
                CompanyId = 1,
                CreatedAt = DateTime.UtcNow,
                CreatedBy = -1
            };

            team.TeamMembers.Add(new TeamMember()
            {
                IsApprover = true,
                IsMember   = true,
                UserId     = 1
            });
            _fixture.Context.Teams.Attach(team);
            await _fixture.Context.SaveChangesAsync();

            IUnitOfWork        unitOfWork     = new UnitOfWork(_fixture.Context);
            IRepository <Team> repository     = new Repository <Team>(_fixture.Context);
            IRepository <User> userRepository = new Repository <User>(_fixture.Context);

            var handler = new UpdateTeamHandler(unitOfWork, repository, userRepository, _logger, _mapper);

            var request = new UpdateTeamCommand(companyId: 1,
                                                userId: 1,
                                                teamId: 1,
                                                "Test Team - 1",
                                                members: new List <int>()
            {
                1, 2
            },
                                                approvers: new List <int>()
            {
                1
            });

            // Act
            var tcs    = new CancellationToken();
            var result = await handler.Handle(request, tcs);

            // Assert
            Assert.Equal("Test Team - 1", result.TeamName);
            Assert.Equal(2, result.TeamMembers.Count(x => x.IsMember));
            Assert.Equal(1, result.TeamMembers.Count(x => x.IsApprover));
            Assert.Equal(1, result.ModifiedBy);
        }