public ActionResult <CalculatorValue> ResolveMultiCondition([FromBody] MultiConditionPayload payload)
        {
            if (payload == null)
            {
                return(BadRequest($"{nameof(MultiConditionPayload)} cannot be null."));
            }

            if (_nullValidator.Validate(payload.ComparingValue))
            {
                return(BadRequest($"{nameof(payload.ComparingValue)} cannot be null."));
            }

            var conditions = GenerateConditions(payload.ReferenceData).ToArray();

            if (!conditions.Any())
            {
                return(BadRequest($"{nameof(payload.ReferenceData)} cannot be null or empty."));
            }

            ICondition <CalculatorValue> resolver = new MultiCondition(conditions, payload.Operator);
            var result = resolver.Evaluate(payload.ComparingValue);

            return(Ok(new Result <bool>()
            {
                Value = result,
                CorrelationId = payload.CorrelationId
            }
                      ));
        }
        public void Has_to_return_correct_value_for_and_operator()
        {
            ICondition <CalculatorValue> systemUnderTests = new MultiCondition(new[] { _condition1, _condition2 }, BooleanOperator.And);

            var valueToCompareTrue  = new CalculatorValue(15M);
            var valueToCompareFalse = new CalculatorValue(16M);

            Assert.IsTrue(systemUnderTests.Evaluate(valueToCompareTrue));
            Assert.IsFalse(systemUnderTests.Evaluate(valueToCompareFalse));
        }
Beispiel #3
0
        public void MultiConditionConstructor()
        {
            tlog.Debug(tag, $"MultiConditionConstructor START");

            var testingTarget = new MultiCondition();

            Assert.IsNotNull(testingTarget, "Can't create success object MultiCondition.");
            Assert.IsInstanceOf <MultiCondition>(testingTarget, "Should return MultiCondition instance.");

            Assert.False(testingTarget.GetState(new View()), "Should be false");

            tlog.Debug(tag, $"MultiConditionConstructor END");
        }
        public SwitchTests()
        {
            var condition1 = new Condition(new CalculatorValue(10M), LogicalOperator.Greater);
            var condition2 = new Condition(new CalculatorValue(20M), LogicalOperator.LessOrEqual);
            var condition3 = new Condition(new CalculatorValue(12M), LogicalOperator.Less);
            var condition4 = new Condition(new CalculatorValue(2M), LogicalOperator.GreaterOrEqual);

            var multiCondition1 = new MultiCondition(new[] { condition1, condition2 }, BooleanOperator.And);
            var multiCondition2 = new MultiCondition(new[] { condition3, condition4 }, BooleanOperator.And);

            _switchData = new Dictionary <IOrderedCondition <int, CalculatorValue>, decimal>
            {
                { new OrderedCondition(multiCondition2, 1), 1 },
                { new OrderedCondition(multiCondition1, 0), 0 }
            };
        }
Beispiel #5
0
 public void OnSealed()
 {
     tlog.Debug(tag, $"OnSealed START");
     try
     {
         var testingTarget = new MultiCondition();
         Assert.IsNotNull(testingTarget, "Can't create success object MultiCondition.");
         testingTarget.Conditions.Add(new BindingCondition());
         testingTarget.OnSealed();
         var v = new View();
         testingTarget.SetUp(v);
         testingTarget.TearDown(v);
     }
     catch (Exception e)
     {
         Assert.Fail("Catch exception: " + e.Message.ToString());
     }
     tlog.Debug(tag, $"OnSealed END");
 }
Beispiel #6
0
        private Dictionary <IOrderedCondition <int, CalculatorValue>, decimal> GetSwitchData(SwitchPayload payload)
        {
            var result = new Dictionary <IOrderedCondition <int, CalculatorValue>, decimal>();

            foreach (var item in payload.ReferenceData)
            {
                if (item.Conditions == null || !item.Conditions.Any())
                {
                    continue;
                }

                var conditions = item.Conditions
                                 .Where(condition => condition?.ReferenceValue != null)
                                 .Select(mConditionItem => new Condition(mConditionItem.ReferenceValue, mConditionItem.Operator))
                                 .Cast <ICondition <CalculatorValue> >();

                var multiCondition   = new MultiCondition(conditions, BooleanOperator.And);
                var orderedCondition = new OrderedCondition(multiCondition, item.Order);
                result.Add(orderedCondition, item.Value);
            }

            return(result);
        }