Exemplo n.º 1
0
        public void GetByManagerId_should_handle_exception()
        {
            // Arrange
            ByPersonIdRequest request = new ByPersonIdRequest
            {
                PersonId = 1
            };

            BaseMock.ShouldThrowException = true;

            LogData expectedLog = new()
            {
                CallSide         = nameof(StaffController),
                CallerMethodName = nameof(_staffController.GetByManagerId),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = new Exception(BaseMock.ExceptionMessage)
            };

            // Act
            ObjectResult actual = _staffController.GetByManagerId(request) as ObjectResult;

            // Assert
            Assert.AreEqual(500, actual.StatusCode, "StatusCode as expected");
            Assert.AreEqual(BaseMock.ErrorResponseMessage, actual.Value, "Response data as expected");
            _staffsClientMock.Verify(m => m.GetByManagerId(request, null, null, new CancellationToken()), Times.Once);
            _loggerMock.Verify(m => m.AddErrorLog(expectedLog), Times.Once);
        }
    }
Exemplo n.º 2
0
 public IActionResult GetByPersonId([FromQuery] ByPersonIdRequest request)
 {
     try
     {
         DayOffsResponse response = _dayOffsClient.GetByPersonId(request);
         LogData         logData  = new()
         {
             CallSide         = nameof(DayOffsController),
             CallerMethodName = nameof(GetByPersonId),
             CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
             Request          = request,
             Response         = response
         };
         _logger.AddLog(logData);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         LogData logData = new()
         {
             CallSide         = nameof(DayOffsController),
             CallerMethodName = nameof(GetByPersonId),
             CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
             Request          = request,
             Response         = ex
         };
         _logger.AddErrorLog(logData);
         return(InternalServerError());
     }
 }
Exemplo n.º 3
0
        public override Task <PersonResponse> GetById(ByPersonIdRequest request, ServerCallContext context)
        {
            PersonResponse response = new()
            {
                Status = new BaseResponse {
                    Code = Code.UnknownError, ErrorMessage = string.Empty
                },
                Data = null
            };

            try
            {
                Person     person = _peopleRepository.GetById(request.PersonId);
                PersonData data   = ToRpcModel(person);
                response.Data        = data;
                response.Status.Code = Code.Success;
                LogData logData = new()
                {
                    CallSide         = nameof(PeopleService),
                    CallerMethodName = nameof(GetById),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = response
                };
                _logger.AddLog(logData);
                return(Task.FromResult(response));
            }
            catch (NullReferenceException nrex)
            {
                response.Status.ErrorMessage = "An error occured while loading person data";
                response.Status.Code         = Code.DataError;
                LogData logData = new()
                {
                    CallSide         = nameof(PeopleService),
                    CallerMethodName = nameof(GetById),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = nrex
                };
                _logger.AddErrorLog(logData);
                return(Task.FromResult(response));
            }
            catch (Exception ex)
            {
                response.Status.ErrorMessage = "An error occured while loading person data";
                response.Status.Code         = Code.UnknownError;
                LogData logData = new()
                {
                    CallSide         = nameof(PeopleService),
                    CallerMethodName = nameof(GetById),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = ex
                };
                _logger.AddErrorLog(logData);
                return(Task.FromResult(response));
            }
        }
Exemplo n.º 4
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]
Exemplo n.º 5
0
        public void GetByManagerId_should_return_response_from_grpc_client()
        {
            // Arrange
            ByPersonIdRequest request = new ByPersonIdRequest
            {
                PersonId = 1
            };

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

            response.Data.Add(new StaffData
            {
                Id        = 1,
                ManagerId = 1,
                PersonId  = 2,
                CreatedOn = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()),
                MotivationModificatorId = 0,
                PositionId = 1
            });
            BaseMock.Response = response;

            LogData expectedLog = new()
            {
                CallSide         = nameof(StaffController),
                CallerMethodName = nameof(_staffController.GetByManagerId),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = response
            };

            // Act
            ObjectResult  actual     = _staffController.GetByManagerId(request) as ObjectResult;
            StaffResponse actualData = actual.Value as StaffResponse;

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

        [Test]
Exemplo n.º 6
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]
Exemplo n.º 7
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]
Exemplo n.º 8
0
        public override Task <OtherPaymentsResponse> GetByPersonId(ByPersonIdRequest request, ServerCallContext context)
        {
            OtherPaymentsResponse response = new OtherPaymentsResponse
            {
                Status = new BaseResponse
                {
                    Code         = Code.Success,
                    ErrorMessage = string.Empty
                }
            };

            try
            {
                IQueryable <OtherPayment> otherPayments = _otherPaymentsRepository.GetByPersonId(request.PersonId);

                foreach (OtherPayment otherPayment in otherPayments)
                {
                    response.Data.Add(ToRpcModel(otherPayment));
                }

                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(GetByPersonId),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = response
                };
                _logger.AddLog(logData);
            }
            catch (Exception ex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(GetByPersonId),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = ex
                };
                _logger.AddErrorLog(logData);
                response.Status.Code         = Code.UnknownError;
                response.Status.ErrorMessage = "An error ocured while loading other payments";
            }
            return(Task.FromResult(response));
        }
Exemplo n.º 9
0
        public override Task <StaffResponse> GetByPersonId(ByPersonIdRequest request, ServerCallContext context)
        {
            StaffResponse response = new()
            {
                Status = new BaseResponse {
                    Code = Code.Success, ErrorMessage = string.Empty
                }
            };

            try
            {
                IQueryable <Staff> staff = _staffRepository.GetByPersonId(request.PersonId);

                foreach (Staff s in staff)
                {
                    response.Data.Add(ToRpcModel(s));
                }

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

            return(Task.FromResult(response));
        }
Exemplo n.º 10
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]
Exemplo n.º 11
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(10))
                }
            };

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

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

            // Assert
            Assert.AreEqual(500, actual.StatusCode, "StatusCode as expected");
            Assert.AreEqual("An error occured while sending request", actual.Value, "Response data as expected");
            _loggerMock.Verify(m => m.AddErrorLog(expectedLog), Times.Once);
            _dayOffsClientMock.Verify(m => m.GetByPersonIdAndDateRange(request, null, null, new CancellationToken()), Times.Once);
        }
    }
}