public async Task Should_ReturnEmptyList_When_PassInvalidCompanyId()
        {
            // Arrange
            var leaveType = new LeaveTypeDb()
            {
                LeaveTypeId = 1,
                CompanyId   = 1,
                CreatedAt   = DateTime.Now,
                CreatedBy   = -1,
                IsDeleted   = false,
                IsActive    = true
            };

            _fixture.Context.LeaveTypes.Add(leaveType);
            _fixture.Context.SaveChanges();

            IRepository <LeaveTypeDb> repository = new Repository <LeaveTypeDb>(_fixture.Context);

            var handler = new GetLeaveTypeListHandler(repository, _mapper, _logger);

            var queryRequest = new GetLeaveTypeListQuery(companyId: -1);

            // Act
            var tcs = new CancellationToken();

            var result = await handler.Handle(queryRequest, tcs);

            // Assert
            Assert.Empty(result);
        }
Example #2
0
        public async Task <LeaveTypeDto> Handle(CreateLeaveTypeCommand request, CancellationToken cancellationToken)
        {
            bool isNameUnique = await _repository.IsLeaveTypeNameExistAsync(request.CompanyId, request.LeaveTypeName);

            if (isNameUnique)
            {
                throw new VacationTrackingException(ExceptionMessages.LeaveTypeNameAlreadyExist, $"Leave type name: {request.LeaveTypeName} already exist", 400);
            }

            var entity = new LeaveTypeDb()
            {
                ColorCode              = request.ColorCode,
                CompanyId              = request.CompanyId,
                CreatedAt              = DateTime.Now,
                CreatedBy              = request.UserId,
                DefaultDaysPerYear     = request.DefaultDaysPerYear,
                IsActive               = true,
                IsAllowNegativeBalance = request.IsAllowNegativeBalance,
                IsApproverRequired     = request.IsApproverRequired,
                IsDefault              = false,
                IsDeleted              = false,
                IsHalfDaysActivated    = request.IsHalfDaysActivated,
                IsHideLeaveTypeName    = request.IsHideLeaveTypeName,
                IsReasonRequired       = request.IsReasonRequired,
                IsUnlimited            = request.IsUnlimited,
                LeaveTypeName          = request.LeaveTypeName
            };

            _repository.Insert(entity);
            int affectedRows = await _unitOfWork.SaveChangesAsync();

            //TODO: Fire "leaveTypeCreated" event
            return(_mapper.Map <LeaveTypeDto>(entity));
        }