Exemplo n.º 1
0
        public void CanGetCalculationResultObj()
        {
            // Arrange
            double inputResult = 1;

            // Act
            ICalculationResult result = AppCoreFactory.CreateCalculatinoResult(inputResult);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Result, inputResult);
        }
        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);
        }