コード例 #1
0
 public void LogInfo(string message)
 {
     if (_logToDatabase)
     {
         _loggerRepository.Log(LogLevelEnum.Info, message);
     }
     _logger.LogInformation(message);
 }
コード例 #2
0
        public void Add_Inputs_Returns_AppropriateValue(int a, int b, int expectedResult)
        {
            // arrange
            var math = new MathWebClient(_apiClient, _databaseLogger);

            // arrange mocking
            _apiClient.Get(Arg.Any <string>()).Returns((a + b).ToString());
            _databaseLogger.Log(Arg.Any <RequestLogDBModel>()).Returns(1);

            // act
            var actualResult = math.Add(a, b);

            // assert
            Assert.AreEqual(expectedResult, actualResult);
        }
コード例 #3
0
        public async Task <int> Create(DependentModel dependent)
        {
            try
            {
                if (dependent != null)
                {
                    decimal discount = dependent.DependentName?.StartsWith("a", StringComparison.OrdinalIgnoreCase) == true ? .10m : 0;
                    return(await dependentsRepository.Create(new DependentDataModel(dependent, discount)));
                }

                return(0);
            }
            catch (Exception ex)
            {
                await loggerRepository.Log(ex).ConfigureAwait(false);

                throw;
            }
        }
コード例 #4
0
        public async Task <int> Create(EmployeeModel employee)
        {
            try
            {
                if (employee != null)
                {
                    decimal discount = employee.EmployeeName?.StartsWith("a", StringComparison.OrdinalIgnoreCase) == true ? .10m : 0;
                    return(await employeeRepository.Create(new EmployeeDataModel(employee, discount)));
                }

                return(0);
            }
            catch (Exception ex)
            {
                await loggerRepository.Log(ex).ConfigureAwait(false);

                throw;
            }
        }
コード例 #5
0
        private void LogRequest(string apiRoute, bool isSuccess)
        {
            RequestLogDBModel requestLog = new RequestLogDBModel
            {
                LogMethod = apiRoute,
                IsSuccess = isSuccess,
                Timestamp = DateTime.Now
            };

            try
            {
                int rowsAffected = _logger.Log(requestLog);

                PrintLogInsertResultInConsole(rowsAffected, null);
            }
            catch (Exception ex)
            {
                PrintLogInsertResultInConsole(-1, ex.Message);
                throw;
            }
        }
コード例 #6
0
        public async Task <BenefitsBreakdownModel> GetBenefitsCostBreakdownByEmployeeId(int employeeId)
        {
            try
            {
                if (employeeId > 0)
                {
                    IEnumerable <BenefitCostDataModel> benefitCostDataModels = await benefitsRepository.GetBenefitsCostsByEmployeeId(employeeId);

                    EmployeeSalaryDataModel employeeSalaryDataModel = await employeeRepository.GetEmployeeSalaryData(employeeId);

                    return(benefitsBreakdown.GetBenefitsBreaksown(employeeSalaryDataModel, benefitCostDataModels));
                }

                return(null);
            }
            catch (Exception ex)
            {
                await loggerRepository.Log(ex).ConfigureAwait(false);

                throw;
            }
        }