Example #1
0
        public IActionResult GetByRangeDate([FromQuery] ByDateRangeRequest request)
        {
            try
            {
                HolidaysResponse response = _holidaysClient.GetByDateRange(request);
                LogData          logData  = new()
                {
                    CallSide         = nameof(HolidaysController),
                    CallerMethodName = nameof(GetByRangeDate),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = response
                };

                _logger.AddLog(logData);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(HolidaysController),
                    CallerMethodName = nameof(GetByRangeDate),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = ex
                };

                _logger.AddErrorLog(logData);
                return(InternalServerError());
            }
        }
    }
Example #2
0
        public void GetByPersonIdAndDateRange_should_return_response_from_grpc_client()
        {
            // Arrange
            ByPersonIdAndDateRangeRequest request = new()
            {
                Person = new ByPersonIdRequest
                {
                    PersonId = 1
                },
                Range = new ByDateRangeRequest
                {
                    From = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()),
                    To   = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime().AddDays(15))
                }
            };

            OtherPaymentsResponse response = new OtherPaymentsResponse
            {
                Status = new BaseResponse
                {
                    Code         = Code.Success,
                    ErrorMessage = string.Empty
                }
            };

            response.Data.Add(new OtherPaymentData
            {
                Id        = 1,
                PersonId  = 1,
                CreatedOn = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()),
                Comment   = "test",
                Value     = 10
            });

            BaseMock.Response = response;

            LogData expectedLog = new()
            {
                CallSide         = nameof(OtherPaymentsController),
                CallerMethodName = nameof(_otherPaymentsController.GetByPersonIdAndDateRange),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = response
            };

            // Act
            ObjectResult          actual     = _otherPaymentsController.GetByPersonIdAndDateRange(request) as ObjectResult;
            OtherPaymentsResponse actualData = actual.Value as OtherPaymentsResponse;

            // Assert
            Assert.AreEqual(200, actual.StatusCode, "StatusCode as expected");
            Assert.AreEqual(response, actualData, "Response data as expected");
            _loggerMock.Verify(m => m.AddLog(expectedLog), Times.Once);
            _otherPaymentsClientMock.Verify(m => m.GetByPersonIdAndDateRange(request, null, null, new CancellationToken()), Times.Once);
        }

        [Test]
Example #3
0
        public void GetByPersionIdAndDateRange_should_return_all_day_offs_by_specified_person()
        {
            // Arrange
            ByPersonIdAndDateRangeRequest request = new()
            {
                Person = new ByPersonIdRequest {
                    PersonId = 1
                },
                Range = new ByDateRangeRequest {
                    From = Timestamp.FromDateTime(new DateTime(2020, 12, 15, 0, 0, 0, DateTimeKind.Utc)), To = Timestamp.FromDateTime(new DateTime(2021, 1, 15, 0, 0, 0, DateTimeKind.Utc))
                }
            };

            DayOffsResponse expectedResponse = new()
            {
                Status = new BaseResponse {
                    Code = Code.Success, ErrorMessage = string.Empty
                }
            };

            expectedResponse.Data.Add(new DayOffData
            {
                Id         = _dayOff1.Id,
                CreatedOn  = Timestamp.FromDateTime(_dayOff1.CreatedOn),
                DayOffType = (int)_dayOff1.DayOffType,
                Hours      = _dayOff1.Hours,
                IsPaid     = _dayOff1.IsPaid,
                PersonId   = _dayOff1.PersonId
            });

            LogData expectedLog = new()
            {
                CallSide         = nameof(DayOffsService),
                CallerMethodName = nameof(_dayOffsService.GetByPersonIdAndDateRange),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = expectedResponse
            };

            // Act
            DayOffsResponse actual = _dayOffsService.GetByPersonIdAndDateRange(request, null).Result;

            // Assert
            Assert.AreEqual(expectedResponse, actual, "Response as expected");
            _loggerMock.Verify(mocks => mocks.AddLog(expectedLog), Times.Once);
        }

        [Test]
Example #4
0
        public void GetByPersonIdAndDateRange_should_return_all_other_payments_by_specified_person_and_date_range()
        {
            // Arrange
            ByPersonIdAndDateRangeRequest request = new()
            {
                Person = new ByPersonIdRequest {
                    PersonId = 1
                },
                Range = new ByDateRangeRequest {
                    From = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()), To = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime().AddDays(5))
                }
            };

            OtherPaymentsResponse expectedResponse = new()
            {
                Status = new BaseResponse {
                    Code = Code.Success, ErrorMessage = string.Empty
                }
            };

            expectedResponse.Data.Add(new OtherPaymentData
            {
                Id        = _otherPayment1.Id,
                Comment   = _otherPayment1.Comment,
                CreatedOn = Timestamp.FromDateTime(_otherPayment1.CreatedOn),
                PersonId  = _otherPayment1.PersonId,
                Value     = _otherPayment1.Value
            });

            LogData expectedLog = new()
            {
                CallSide         = nameof(OtherPaymentsService),
                CallerMethodName = nameof(_otherPaymentsService.GetByPersonIdAndDateRange),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = expectedResponse
            };

            // Act
            OtherPaymentsResponse actual = _otherPaymentsService.GetByPersonIdAndDateRange(request, null).Result;

            // Assert
            Assert.AreEqual(expectedResponse, actual, "Response as expected");
            _loggerMock.Verify(mocks => mocks.AddLog(expectedLog), Times.Once);
        }

        [Test]
Example #5
0
        public override Task <HolidaysResponse> GetByDateRange(ByDateRangeRequest request, ServerCallContext context)
        {
            HolidaysResponse response = new()
            {
                Status = new BaseResponse {
                    Code = Code.Success, ErrorMessage = string.Empty
                }
            };

            try
            {
                IQueryable <Holiday> holidays = _holidaysRepository.GetByDateRange(request.From.ToDateTime().Date, request.To.ToDateTime().Date);

                foreach (Holiday holiday in holidays)
                {
                    response.Data.Add(ToRpcModel(holiday));
                }

                LogData logData = new()
                {
                    CallSide         = nameof(HolidaysService),
                    CallerMethodName = nameof(GetByDateRange),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = response
                };
                _logger.AddLog(logData);
            }
            catch (Exception ex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(HolidaysService),
                    CallerMethodName = nameof(GetByDateRange),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = ex
                };
                _logger.AddErrorLog(logData);
                response.Status.Code         = Code.UnknownError;
                response.Status.ErrorMessage = "An error occured while loading holidays data";
            }

            return(Task.FromResult(response));
        }
Example #6
0
        public void GetByPersonIdAndDateRange_should_handle_exception()
        {
            // Arrange
            BaseMock.ShouldThrowException = true;
            ByPersonIdAndDateRangeRequest request = new()
            {
                Person = new ByPersonIdRequest {
                    PersonId = 1
                },
                Range = new ByDateRangeRequest {
                    From = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()), To = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime().AddDays(5))
                }
            };

            OtherPaymentsResponse expectedResponse = new()
            {
                Status = new BaseResponse {
                    Code = Code.UnknownError, ErrorMessage = "An error ocured while loading other payments"
                }
            };

            LogData expectedLog = new()
            {
                CallSide         = nameof(OtherPaymentsService),
                CallerMethodName = nameof(_otherPaymentsService.GetByPersonIdAndDateRange),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = new Exception("Test exception")
            };

            // Act
            OtherPaymentsResponse actual = _otherPaymentsService.GetByPersonIdAndDateRange(request, null).Result;

            // Assert
            Assert.AreEqual(expectedResponse, actual, "Response as expected");
            _loggerMock.Verify(mocks => mocks.AddErrorLog(expectedLog), Times.Once);
        }

        [Test]
Example #7
0
        public void GetByPersonIdAndDateRange_should_handle_exception()
        {
            // Arrange
            ByPersonIdAndDateRangeRequest request = new()
            {
                Person = new ByPersonIdRequest
                {
                    PersonId = 1
                },
                Range = new ByDateRangeRequest
                {
                    From = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()),
                    To   = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime().AddDays(15))
                }
            };

            BaseMock.ShouldThrowException = true;

            LogData expectedLog = new()
            {
                CallSide         = nameof(OtherPaymentsController),
                CallerMethodName = nameof(_otherPaymentsController.GetByPersonIdAndDateRange),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = new Exception(BaseMock.ExceptionMessage)
            };

            // Act
            ObjectResult actual = _otherPaymentsController.GetByPersonIdAndDateRange(request) as ObjectResult;

            // Assert
            Assert.AreEqual(500, actual.StatusCode, "StatusCode as expected");
            Assert.AreEqual(BaseMock.ErrorResponseMessage, actual.Value, "Response data as expected");
            _loggerMock.Verify(m => m.AddErrorLog(expectedLog), Times.Once);
            _otherPaymentsClientMock.Verify(m => m.GetByPersonIdAndDateRange(request, null, null, new CancellationToken()), Times.Once);
        }
    }
}