Exemplo n.º 1
0
        public void CanGetCalculationLoggingObj()
        {
            // Arrange
            string   message    = "This is a test message for logging obj";
            double   leftInput  = 0.5;
            double   rightInput = 0.5;
            int      logicCode  = 1;
            double   result     = 0.25;
            DateTime timeStamp  = DateTime.Now;

            // Act
            ICalculationLogging actualCalcresult = AppCoreFactory.GetCalculationLoggingObj(
                message,
                leftInput,
                rightInput,
                logicCode,
                result,
                timeStamp
                );

            // Assert
            Assert.IsNotNull(actualCalcresult);
            Assert.AreEqual(message, actualCalcresult.Message);
            Assert.AreEqual(leftInput, actualCalcresult.LeftInput);
            Assert.AreEqual(rightInput, actualCalcresult.RightInput);
            Assert.AreEqual(logicCode, actualCalcresult.LogicId);
            Assert.AreEqual(result, actualCalcresult.Result);
            Assert.AreEqual(timeStamp, actualCalcresult.TimeStamp);
        }
        public ICalculationResult GetCalculationResult(
            double leftInput,
            double rightInput,
            int logicCode
            )
        {
            if (!IsInputsValidForProbabilityCalculation(leftInput, rightInput))
            {
                throw new InvalidOperationException(c_InvalidInputErrMsg);
            }

            if (logicCode == default(int))
            {
                throw new InvalidOperationException(nameof(logicCode));
            }

            ICalculationResult result           = null;
            IProbabilityLogic  probabilityLogic =
                AppCoreFactory.CreateCalculationLogic(logicCode);

            if (probabilityLogic != null)
            {
                result = AppCoreFactory.CreateCalculatinoResult(
                    // using Decorator Pattern
                    probabilityLogic.GetCalculationResult(leftInput, rightInput)
                    );

                result.CalculationLogging = AppCoreFactory.GetCalculationLoggingObj(
                    c_ResultLogginMessage,
                    leftInput,
                    rightInput,
                    (int)logicCode,
                    result.Result,
                    // TODO : fix testability technical debt
                    DateTime.Now
                    );

                _logger.LogInformation(
                    $"{result.CalculationLogging.Message} " +
                    $"timeStamp = {result.CalculationLogging.TimeStamp}, " +
                    $"leftInput = {result.CalculationLogging.LeftInput}, " +
                    $"rightInput = {result.CalculationLogging.RightInput}, " +
                    $"calculationLogic = {result.CalculationLogging.LogicId}, " +
                    $"result = {result.CalculationLogging.Result}"
                    );
            }

            return(result);
        }