Exemplo n.º 1
0
        public void CanGetCalculationLogicExceptionForInvalidParam_OutOfRange()
        {
            // Arrange
            int inputLogic = 3;

            // Act
            IProbabilityLogic result = AppCoreFactory.CreateCalculationLogic(inputLogic);

            // Assert
        }
Exemplo n.º 2
0
        public void CanGetEitherCalculationLogic()
        {
            // Arrange
            int calculationLogic = 2;

            // Act
            IProbabilityLogic result = AppCoreFactory.CreateCalculationLogic(calculationLogic);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(EitherProbabilityLogic));
        }
        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);
        }