Exemple #1
0
        public void ShouldNotVerifyIfNoRulesetsPass()
        {
            const int ruleset1Id = 789;
            const int ruleset2Id = 9008;

            var rulesets = new List <MPProductRuleSet>
            {
                FactoryGirl.NET.FactoryGirl.Build <MPProductRuleSet>(r => { r.ProductId = r.ProductId + 2; r.RulesetId = ruleset1Id; }),
                FactoryGirl.NET.FactoryGirl.Build <MPProductRuleSet>(r => { r.ProductId = r.ProductId + 3; r.RulesetId = ruleset2Id; })
            };

            var rules1    = new List <IRule>();
            var startDate = DateTime.Today.AddDays(-30);

            rules1.Add(new GenderRule(startDate, null, 1));
            rules1.Add(new RegistrationRule(startDate, null, 1000));

            var rules2 = new List <IRule>();

            rules2.Add(new GenderRule(startDate, null, 1));
            rules2.Add(new RegistrationRule(startDate, null, 1000));

            var result1 = new MPRuleSetResult
            {
                AllRulesPass = false,
                RuleResults  = new List <MPRuleResult>()
            };

            var result2 = new MPRuleSetResult
            {
                AllRulesPass = false,
                RuleResults  = new List <MPRuleResult>()
            };

            _rulesetRepository.Setup(m => m.GetRulesInRuleset(ruleset1Id)).Returns(rules1);
            _rulesetRepository.Setup(m => m.GetRulesInRuleset(ruleset2Id)).Returns(rules2);
            _rulesetRepository.Setup(m => m.AllRulesPass(rules1, It.IsAny <Dictionary <string, object> >())).Returns(result1);
            _rulesetRepository.Setup(m => m.AllRulesPass(rules2, It.IsAny <Dictionary <string, object> >())).Returns(result2);
            var res = _fixture.VerifyRulesets(rulesets, new Dictionary <string, object>());

            Assert.IsFalse(res);
        }
Exemple #2
0
        public bool VerifyCampRules(int eventId, int gender)
        {
            var currentCampers       = _eventParticipantRepository.GetEventParticipantCountByGender(eventId, gender);
            var currentCampersPlusMe = currentCampers + 1;
            var ruleData             = new Dictionary <string, object>
            {
                { "GenderId", gender },
                { "registrantCount", currentCampersPlusMe }
            };
            var mpEvent         = _eventRepository.GetEvent(eventId);
            var productRulesets = _productRulesetsRepository.GetProductRulesets(mpEvent.OnlineProductId ?? 0);

            productRulesets = productRulesets.Where(p => (p.StartDate <= DateTime.Now && (p.EndDate == null || p.EndDate >= DateTime.Now))).ToList();
            var rulesPass = _productRulesetsRepository.VerifyRulesets(productRulesets, ruleData);

            return(rulesPass);
        }