Exemplo n.º 1
0
        private static void SetRewardThreshold(RewardRatioAttributeModel conditionRewardRatio)
        {
            var threshold = 0m;

            foreach (var ratio in conditionRewardRatio.Ratios.OrderBy(r => r.Order))
            {
                threshold += ratio.PaymentRatio;

                ratio.Threshold += threshold;
            }
        }
        public void When_ConditionRewardRatioNewOneChangedToNull_Expect_NotValidResponse()
        {
            // Arrange
            var ratio = new RewardRatioAttributeModel()
            {
                Ratios = new List <RatioAttributeModel>()
                {
                    new RatioAttributeModel()
                    {
                        Order        = 1,
                        RewardRatio  = 20m,
                        PaymentRatio = 10m,
                        Threshold    = 10m
                    },
                    new RatioAttributeModel()
                    {
                        Order        = 2,
                        PaymentRatio = 10m,
                        RewardRatio  = 20m,
                        Threshold    = 20m
                    },
                    new RatioAttributeModel()
                    {
                        Order        = 3,
                        PaymentRatio = 70m,
                        RewardRatio  = 70m,
                        Threshold    = 100m
                    }
                }
            };

            var bonusTypeValidationServiceMock = new Mock <IBonusTypeValidationService>();
            var fixture = new ConditionValidationServiceTestFixture();

            fixture.DbConditions[0].RewardRatio = ratio;
            fixture.Conditions[0].RewardRatio   = null;

            var conditionValidationService = new ConditionValidationService(bonusTypeValidationServiceMock.Object);

            // Act
            var validationResult = conditionValidationService.ValidateConditionPropertiesAreNotChanged(fixture.Conditions[0], fixture.DbConditions[0]);

            // Assert
            Assert.False(validationResult.IsValid);
            Assert.NotEmpty(validationResult.ValidationMessages);
        }
Exemplo n.º 3
0
        private bool AreRatiosChanged(RewardRatioAttributeModel newRatio, RewardRatioAttributeModel oldRatio)
        {
            var oldRatios = oldRatio != null ? oldRatio.Ratios : new List <RatioAttributeModel>();
            var newRatios = newRatio != null ? newRatio.Ratios : new List <RatioAttributeModel>();

            if (oldRatios.Count != newRatios.Count)
            {
                return(true);
            }

            foreach (var ratio in newRatios)
            {
                if (!oldRatios.Any(c => c.AreEqual(ratio)))
                {
                    return(true);
                }
            }

            return(false);
        }