public async Task Should_CreateVacation_When_PassHolidayDaysForOtherCompany() { // 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.Holidays.Add(new Holiday() { CompanyId = 2, CreatedAt = DateTime.Now.Date, CreatedBy = -1, EndDate = new DateTime(year: 2020, month: 6, day: 10), StartDate = new DateTime(year: 2020, month: 6, day: 8), IsFullDay = true, Name = "Company_2_Holiday" }); _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(); // Act var result = await _handler.Handle(request, cancellationToken); // 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); }
public async Task Should_ThrowException_When_VacationIsFullAndUserHasHalfDays() { // 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: 8); var request = new CreateVacationCommand(companyId: 1, userId: 1, leaveTypeId: 1, startDate, endDate, reason: "test reason", isHalfDay: false); var cancellationToken = new CancellationToken(); // Act & Assert var exception = await Assert.ThrowsAsync <VacationTrackingException>(async() => { var result = await _handler.Handle(request, cancellationToken); }); Assert.Equal(ExceptionMessages.VacationDateIsNotValid, exception.Message); Assert.Equal(400, exception.Code); }
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); }
public async Task Should_CreateVacation_When_FillReasonIfRequired() { // Arrange _fixture.Context.LeaveTypes.Add(new LeaveType() { CompanyId = 1, CreatedAt = DateTime.Now, CreatedBy = -1, IsActive = true, DefaultDaysPerYear = 1, IsDefault = true, IsAllowNegativeBalance = true, IsApproverRequired = true, IsDeleted = false, IsHalfDaysActivated = true, IsHideLeaveTypeName = false, IsReasonRequired = true, IsUnlimited = true, LeaveTypeName = "Test Leave Type", LeaveTypeId = 1 }); _fixture.Context.SaveChanges(); DateTime startDate = new DateTime(year: 2020, month: 6, day: 8); DateTime endDate = new DateTime(year: 2020, month: 6, day: 20); 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 validation = 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(validation.IsValid); }
public async Task <ActionResult <VacationDto> > CreateVacationAsync([FromBody] VacationModel model) { //Guid companyId = new Guid(_companyId); //Guid userId = new Guid(_userId); int companyId = 1; int userId = 1; var request = new CreateVacationCommand(companyId, userId, 12,//model.LeaveTypeId, model.StartDate, model.EndDate, model.Reason, model.IsHalfDays); return(Single(await CommandAsync(request))); }
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); }