private decimal ApplyRule(decimal value, DistributionFlowRule flowRule)
        {
            var rule   = flowRule.Rule;
            var amount = flowRule.Amount;

            switch (rule)
            {
            case FlowRule.None:
                return(0);

            case FlowRule.FixedFromBase:
                return(amount);

            case FlowRule.PercentFromBase:
                return(Math.Round(value * amount / 100, 2, MidpointRounding.AwayFromZero));

            case FlowRule.AllRest:
                if (_allRestValue != null)
                {
                    return(_allRestValue.Value > value ? value : _allRestValue.Value);
                }
                _allRestValue = value / _recipients.Count(x => x.FlowRule.Rule == FlowRule.AllRest);
                _allRestValue = Math.Round(_allRestValue.Value, 2, MidpointRounding.AwayFromZero);
                return(_allRestValue.Value);

            default:
                throw new ArgumentOutOfRangeException(nameof(rule), rule, null);
            }
        }
Beispiel #2
0
        public EndPointRulesSchema()
        {
            RecipientRule_FixedFromBase1000 = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.FixedFromBase,
                Amount      = 1000
            };

            RecipientRule_FixedFromBase500 = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.FixedFromBase,
                Amount      = 500
            };

            NotParticipantSourceRule = new DistributionFlowRule
            {
                CanFlow     = false,
                Destination = FlowDestination.Source,
                Rule        = FlowRule.None,
                Amount      = 0
            };

            NotParticipantRecipientRule = new DistributionFlowRule
            {
                CanFlow     = false,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.None,
                Amount      = 0
            };

            SourceRule_SourceDestination = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Source,
                Rule        = FlowRule.None,
                Amount      = 0
            };

            RecipientRule_PercentFromBase25 = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.PercentFromBase,
                Amount      = 25
            };

            RecipientRule_FixedFromBase3000 = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.FixedFromBase,
                Amount      = 3000
            };

            RecipientRule_FixedFromBase2500 = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.FixedFromBase,
                Amount      = 2500
            };

            RecipientRule_AllRest = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.AllRest,
                Amount      = 0
            };

            RecipientRule_PercentFromBase30 = new DistributionFlowRule
            {
                CanFlow     = true,
                Destination = FlowDestination.Recipient,
                Rule        = FlowRule.PercentFromBase,
                Amount      = 30
            };
        }
Beispiel #3
0
 public FlowEndPointMock(int id, string name, decimal balance,
                         DistributionFlowRule rule) : this(id, name, balance)
 {
     FlowRule = rule ?? throw new ArgumentNullException(nameof(rule));
 }