Ejemplo n.º 1
0
        public async Task Should_ValidatorReturnFalse_When_PassTwoDaysWithIsHalfDaysTrue()
        {
            // Arrange
            _fixture.Context.LeaveTypes.Add(new LeaveType()
            {
                CompanyId              = 1,
                CreatedAt              = DateTime.Now,
                CreatedBy              = -1,
                IsActive               = true,
                DefaultDaysPerYear     = 2,
                IsDefault              = true,
                IsAllowNegativeBalance = false,
                IsApproverRequired     = true,
                IsDeleted              = false,
                IsHalfDaysActivated    = false,
                IsHideLeaveTypeName    = false,
                IsReasonRequired       = true,
                IsUnlimited            = false,
                LeaveTypeName          = "Test Leave Type",
                LeaveTypeId            = 1
            });
            _fixture.Context.Vacations.Add(new Vacation()
            {
                CreatedAt      = DateTime.Now,
                CreatedBy      = -1,
                EndDate        = new DateTime(year: 2020, month: 6, day: 8),
                IsHalfDay      = true,
                LeaveTypeId    = 1,
                StartDate      = new DateTime(year: 2020, month: 6, day: 8),
                UserId         = 1,
                VacationStatus = VacationStatus.Approved
            });
            _fixture.Context.SaveChanges();

            DateTime startDate = new DateTime(year: 2020, month: 6, day: 8);
            DateTime endDate   = new DateTime(year: 2020, month: 6, day: 10);

            var request = new CreateVacationCommand(companyId: 1,
                                                    userId: 1,
                                                    leaveTypeId: 1,
                                                    startDate,
                                                    endDate,
                                                    reason: string.Empty,
                                                    isHalfDay: true);

            var validator = new VacationCommandValidator();
            // Act
            var validationResult = await validator.ValidateAsync(request);

            // Assert
            Assert.False(validationResult.IsValid);
        }
Ejemplo n.º 2
0
        public async Task Should_CreateVacation_When_PassValidParameters()
        {
            // Arrange
            _fixture.Context.LeaveTypes.Add(new LeaveType()
            {
                CompanyId              = 1,
                CreatedAt              = DateTime.Now,
                CreatedBy              = -1,
                IsActive               = true,
                DefaultDaysPerYear     = 20,
                IsDefault              = true,
                IsAllowNegativeBalance = false,
                IsApproverRequired     = true,
                IsDeleted              = false,
                IsHalfDaysActivated    = false,
                IsHideLeaveTypeName    = false,
                IsReasonRequired       = false,
                IsUnlimited            = false,
                LeaveTypeName          = "Test Leave Type",
            });
            _fixture.Context.SaveChanges();


            DateTime startDate = new DateTime(year: 2020, month: 6, day: 8);
            DateTime endDate   = new DateTime(year: 2020, month: 6, day: 10);

            var request = new CreateVacationCommand(companyId: 1,
                                                    userId: 1,
                                                    leaveTypeId: 1,
                                                    startDate,
                                                    endDate,
                                                    reason: "test reason",
                                                    isHalfDay: false);

            var cancellationToken = new CancellationToken();
            var validator         = new VacationCommandValidator();

            // Act
            var result = await _handler.Handle(request, cancellationToken);

            var validationResult = await validator.ValidateAsync(request);

            // Assert
            Assert.Equal(1, result.VacationId);
            Assert.Equal(VacationStatus.Pending, result.VacationStatus);
            Assert.Equal(DateTime.Now.Date, result.CreatedAt.Date);
            Assert.Equal(1, result.CreatedBy);
            Assert.False(result.IsHalfDay);
            Assert.Equal("test reason", result.Reason);
            Assert.True(validationResult.IsValid);
        }
Ejemplo n.º 3
0
        public async Task Should_ValidatorReturnFalse_When_EndDateGreaterThanStartDate()
        {
            // Arrange
            DateTime startDate = new DateTime(year: 2020, month: 6, day: 8);
            DateTime endDate   = new DateTime(year: 2020, month: 6, day: 3);

            var request = new CreateVacationCommand(companyId: 1,
                                                    userId: 1,
                                                    leaveTypeId: 1,
                                                    startDate,
                                                    endDate,
                                                    reason: string.Empty,
                                                    isHalfDay: false);

            var validator = new VacationCommandValidator();

            // Act
            var result = await validator.ValidateAsync(request);

            //Assert
            Assert.False(result.IsValid);
        }