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));
        }
 /// <summary>
 /// Initialises a new instance of <see cref="CriteriaApplyingMessageProviderInfoDecorator"/>.
 /// </summary>
 /// <param name="wrapped">A wrapped implementation</param>
 /// <param name="criteriaFactory">A criteria factory.</param>
 /// <exception cref="System.ArgumentNullException">If any parameter is <see langword="null" />.</exception>
 public CriteriaApplyingMessageProviderInfoDecorator(IGetsMessageProviderInfo wrapped, IGetsNonGenericMessageCriteria criteriaFactory)
 {
     this.wrapped         = wrapped ?? throw new System.ArgumentNullException(nameof(wrapped));
     this.criteriaFactory = criteriaFactory ?? throw new System.ArgumentNullException(nameof(criteriaFactory));
 }
 /// <summary>
 /// Initialises a new instance of <see cref="NullExcludingMessageProviderInfoDecorator"/>.
 /// </summary>
 /// <param name="wrapped">The wrapped service.</param>
 /// <exception cref="System.ArgumentNullException">If <paramref name="wrapped"/> is <see langword="null" />.</exception>
 public NullExcludingMessageProviderInfoDecorator(IGetsMessageProviderInfo wrapped)
 {
     this.wrapped = wrapped ?? throw new System.ArgumentNullException(nameof(wrapped));
 }
Beispiel #4
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));
        }
Beispiel #5
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 }));
        }
 public void GetMessageProviderInfoShouldExcludeProviderInfosWhereTheProviderIsNull([Frozen] IGetsMessageProviderInfo wrapped,
                                                                                    NullExcludingMessageProviderInfoDecorator sut,
                                                                                    MessageProviderInfo provider1,
                                                                                    MessageProviderInfo provider2,
                                                                                    MessageProviderInfo provider3,
                                                                                    IGetsFailureMessage providerService,
                                                                                    [RuleResult] ValidationRuleResult ruleResult)
 {
     Mock.Get(provider1).SetupGet(x => x.MessageProvider).Returns(providerService);
     Mock.Get(provider2).SetupGet(x => x.MessageProvider).Returns(() => null);
     Mock.Get(provider3).SetupGet(x => x.MessageProvider).Returns(providerService);
     Mock.Get(wrapped).Setup(x => x.GetMessageProviderInfo(ruleResult)).Returns(() => new[] { provider1, provider2, provider3 });
     Assert.That(() => sut.GetMessageProviderInfo(ruleResult), Is.EquivalentTo(new[] { provider1, provider3 }));
 }
 IGetsMessageProviderInfo WrapWithCriteriaApplyingDecorator(IGetsMessageProviderInfo wrapped)
 => new CriteriaApplyingMessageProviderInfoDecorator(wrapped, serviceProvider.GetRequiredService <IGetsNonGenericMessageCriteria>());
 static IGetsMessageProviderInfo WrapWithNullExcludingDecorator(IGetsMessageProviderInfo wrapped)
 => new NullExcludingMessageProviderInfoDecorator(wrapped);