Exemplo n.º 1
0
        public async Task Should_UpdateLeaveType_When_PassParameters()
        {
            // Arrange
            var entity = new LeaveType()
            {
                ColorCode              = "ffffff",
                CompanyId              = 1,
                CreatedAt              = DateTime.Now,
                CreatedBy              = -1,
                DefaultDaysPerYear     = 10,
                IsActive               = true,
                IsAllowNegativeBalance = true,
                IsApproverRequired     = false,
                IsDefault              = true,
                IsDeleted              = true,
                IsHalfDaysActivated    = true,
                IsHideLeaveTypeName    = false,
                IsReasonRequired       = true,
                IsUnlimited            = false,
                LeaveTypeName          = "Test Name"
            };

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

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

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

            var request = new UpdateLeaveTypeCommand(companyId: 1,
                                                     userId: 1,
                                                     leaveTypeId: 1,
                                                     isHalfDaysActivated: false,
                                                     isHideLeaveTypeName: false,
                                                     typeName: "Test Name - 1",
                                                     isApprovalRequired: false,
                                                     defaultDaysPerYear: 5,
                                                     isUnlimited: false,
                                                     isReasonRequired: false,
                                                     allowNegativeBalance: false,
                                                     color: "aaaaaa",
                                                     isActive: true);

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

            // Assert
            Assert.Equal("Test Name - 1", result.LeaveTypeName);
            Assert.Equal("aaaaaa", result.ColorCode);
            Assert.False(result.IsHalfDaysActivated);
            Assert.False(result.IsHideLeaveTypeName);
            Assert.False(result.IsApproverRequired);
            Assert.Equal(5, result.DefaultDaysPerYear);
            Assert.False(result.IsUnlimited);
            Assert.False(result.IsReasonRequired);
            Assert.False(result.IsAllowNegativeBalance);
            Assert.Equal(1, result.ModifiedBy);
        }
Exemplo n.º 2
0
        public async Task Should_ThrowException_When_PassInvalidLeaveTypeId()
        {
            // Arrange
            var entity = new LeaveType()
            {
                ColorCode              = "ffffff",
                CompanyId              = 2,
                CreatedAt              = DateTime.Now,
                CreatedBy              = -1,
                DefaultDaysPerYear     = 10,
                IsActive               = true,
                IsAllowNegativeBalance = true,
                IsApproverRequired     = false,
                IsDefault              = true,
                IsDeleted              = true,
                IsHalfDaysActivated    = true,
                IsHideLeaveTypeName    = false,
                IsReasonRequired       = true,
                IsUnlimited            = false,
                LeaveTypeName          = "Test Name"
            };

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

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

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

            var request = new UpdateLeaveTypeCommand(companyId: 1,
                                                     userId: 1,
                                                     leaveTypeId: 1,
                                                     isHalfDaysActivated: false,
                                                     isHideLeaveTypeName: false,
                                                     typeName: "Test Name - 2",
                                                     isApprovalRequired: false,
                                                     defaultDaysPerYear: 5,
                                                     isUnlimited: false,
                                                     isReasonRequired: false,
                                                     allowNegativeBalance: false,
                                                     color: "aaaaaa",
                                                     isActive: true);

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

            // Assert
            Assert.Equal(ExceptionMessages.ItemNotFound, exception.Message);
            Assert.Equal(404, exception.Code);
        }