public void GetNonGenericMessageCriteriaShouldReturnAUniversalMatchForAProviderTypeWhichHasNoMatchingCriteriaInterface(FailureMessageUsageCriteriaFactory sut,
                                                                                                                               TwoGenericCriteria criteria)
        {
            var providerInfo = new TestingMessageProviderInfo(criteria);

            Assert.That(() => sut.GetNonGenericMessageCriteria(providerInfo, typeof(IRule <string, bool>)), Is.InstanceOf <AllowAllUsageCriteriaProvider>());
        }
        public void GetNonGenericMessageCriteriaShouldReturnADoubleGenericAdapterIfTheProviderTypeIsAmbiguousButMatchesADoubleGenericRule(FailureMessageUsageCriteriaFactory sut,
                                                                                                                                          AmbiguousGenericCriteria criteria)
        {
            var providerInfo = new TestingMessageProviderInfo(criteria);

            Assert.That(() => sut.GetNonGenericMessageCriteria(providerInfo, typeof(IRule <string, int>)), Is.InstanceOf <FailureMessageCriteriaAdapter <string, int> >());
        }
        public void GetNonGenericMessageCriteriaShouldReturnTheSameInstanceIfItImplementsTheNonGenericCriteriaInterface(FailureMessageUsageCriteriaFactory sut,
                                                                                                                        NonGenericCriteria criteria)
        {
            var providerInfo = new TestingMessageProviderInfo(criteria);

            Assert.That(() => sut.GetNonGenericMessageCriteria(providerInfo, typeof(IRule <string, int>)), Is.SameAs(criteria));
        }
        public void GetNonGenericMessageCriteriaShouldReturnASingleGenericAdapterForAProviderTypeWhichMatchesTheFirstTypeOfADoubleGenericRule(FailureMessageUsageCriteriaFactory sut,
                                                                                                                                              OneGenericCriteria criteria)
        {
            var providerInfo = new TestingMessageProviderInfo(criteria);

            Assert.That(() => sut.GetNonGenericMessageCriteria(providerInfo, typeof(IRule <string, int>)), Is.InstanceOf <FailureMessageCriteriaAdapter <string> >());
        }
        public void GetProviderShouldReturnTheProviderWithTheHighestPriorityValue([Frozen] IGetsMessageProviderInfoFactory providerFactoryFactory,
                                                                                  FailureMessageProviderSelector sut,
                                                                                  IGetsMessageProviderInfo providerFactory,
                                                                                  SampleProvider provider1,
                                                                                  SampleProvider provider2,
                                                                                  SampleProvider provider3,
                                                                                  [RuleResult] ValidationRuleResult ruleResult)
        {
            var info1 = new TestingMessageProviderInfo(provider1, 4);
            var info2 = new TestingMessageProviderInfo(provider2, 10);
            var info3 = new TestingMessageProviderInfo(provider3, 3);

            Mock.Get(providerFactoryFactory).Setup(x => x.GetProviderInfoFactory()).Returns(providerFactory);
            Mock.Get(providerFactory).Setup(x => x.GetMessageProviderInfo(ruleResult)).Returns(new[] { info1, info2, info3 });

            Assert.That(() => sut.GetProvider(ruleResult), Is.SameAs(provider2));
        }
Exemplo n.º 6
0
        public void GetMessageProviderInfoShouldIncreasePriorityBy10ForMatchingProvider([Frozen] IGetsMessageProviderInfo wrapped,
                                                                                        [Frozen] IGetsNonGenericMessageCriteria criteriaFactory,
                                                                                        CriteriaApplyingMessageProviderInfoDecorator sut,
                                                                                        TestingMessageProviderInfo info,
                                                                                        [RuleResult] ValidationRuleResult ruleResult,
                                                                                        IHasFailureMessageUsageCriteria criteria)
        {
            Mock.Get(wrapped).Setup(x => x.GetMessageProviderInfo(ruleResult)).Returns(new[] { info });
            Mock.Get(criteriaFactory).Setup(x => x.GetNonGenericMessageCriteria(info, ruleResult.RuleInterface)).Returns(criteria);
            Mock.Get(criteria).Setup(x => x.CanGetFailureMessage(ruleResult)).Returns(true);

            Assert.That(() => sut.GetMessageProviderInfo(ruleResult).Single().Priority,
                        Is.EqualTo(info.Priority + 10));
        }
Exemplo n.º 7
0
        public void GetMessageProviderInfoShouldExcludeProvidersWhichDoNotMatchCriteria([Frozen] IGetsMessageProviderInfo wrapped,
                                                                                        [Frozen] IGetsNonGenericMessageCriteria criteriaFactory,
                                                                                        CriteriaApplyingMessageProviderInfoDecorator sut,
                                                                                        TestingMessageProviderInfo info1,
                                                                                        TestingMessageProviderInfo info2,
                                                                                        TestingMessageProviderInfo info3,
                                                                                        [RuleResult] ValidationRuleResult ruleResult,
                                                                                        IHasFailureMessageUsageCriteria criteria1,
                                                                                        IHasFailureMessageUsageCriteria criteria2,
                                                                                        IHasFailureMessageUsageCriteria criteria3)
        {
            Mock.Get(wrapped).Setup(x => x.GetMessageProviderInfo(ruleResult)).Returns(new[] { info1, info2, info3 });
            Mock.Get(criteriaFactory).Setup(x => x.GetNonGenericMessageCriteria(info1, ruleResult.RuleInterface)).Returns(criteria1);
            Mock.Get(criteriaFactory).Setup(x => x.GetNonGenericMessageCriteria(info2, ruleResult.RuleInterface)).Returns(criteria2);
            Mock.Get(criteriaFactory).Setup(x => x.GetNonGenericMessageCriteria(info3, ruleResult.RuleInterface)).Returns(criteria3);
            Mock.Get(criteria1).Setup(x => x.CanGetFailureMessage(ruleResult)).Returns(true);
            Mock.Get(criteria2).Setup(x => x.CanGetFailureMessage(ruleResult)).Returns(false);
            Mock.Get(criteria3).Setup(x => x.CanGetFailureMessage(ruleResult)).Returns(true);

            Assert.That(() => sut.GetMessageProviderInfo(ruleResult).Select(x => x.MessageProvider),
                        Is.EquivalentTo(new [] { info1.MessageProvider, info3.MessageProvider }));
        }