Example #1
0
        public void GetCandidateMessageProviderTypesShouldReturnCorrectInfoForARule([Frozen] IGetsRuleMatchingInfoForMessageProviderType matchingInfoProvider,
                                                                                    IGetsMessageProviderTypeMatchingInfoForRule info1,
                                                                                    IGetsMessageProviderTypeMatchingInfoForRule info2,
                                                                                    IGetsMessageProviderTypeMatchingInfoForRule info3,
                                                                                    IGetsMessageProviderTypeMatchingInfoForRule info4,
                                                                                    IGetsMessageProviderTypeMatchingInfoForRule info5,
                                                                                    [RuleResult] ValidationRuleResult ruleResult)
        {
            // These have to be three different types, to avoid a no-dupes exception
            var providerType1 = typeof(object);
            var providerType2 = typeof(string);
            var providerType3 = typeof(int);

            Mock.Get(matchingInfoProvider).Setup(x => x.GetMatchingInfo(providerType1)).Returns(new[] { info1 });
            Mock.Get(matchingInfoProvider).Setup(x => x.GetMatchingInfo(providerType2)).Returns(new[] { info2, info3 });
            Mock.Get(matchingInfoProvider).Setup(x => x.GetMatchingInfo(providerType3)).Returns(new[] { info4, info5 });
            Mock.Get(info1).Setup(x => x.IsMatch(ruleResult)).Returns(true);
            Mock.Get(info1).Setup(x => x.GetPriority()).Returns(1);
            Mock.Get(info2).Setup(x => x.IsMatch(ruleResult)).Returns(false);
            Mock.Get(info2).Setup(x => x.GetPriority()).Returns(2);
            Mock.Get(info3).Setup(x => x.IsMatch(ruleResult)).Returns(false);
            Mock.Get(info3).Setup(x => x.GetPriority()).Returns(3);
            Mock.Get(info4).Setup(x => x.IsMatch(ruleResult)).Returns(true);
            Mock.Get(info4).Setup(x => x.GetPriority()).Returns(4);
            Mock.Get(info5).Setup(x => x.IsMatch(ruleResult)).Returns(true);
            Mock.Get(info5).Setup(x => x.GetPriority()).Returns(5);
            var options = Mock.Of <IOptions <MessageProviderTypeOptions> >(x => x.Value == new MessageProviderTypeOptions {
                MessageProviderTypes = new[] { providerType1, providerType2, providerType3 }
            });

            var sut = new MessageProviderRegistry(matchingInfoProvider, options);

            var expected = new[] {
Example #2
0
        public void RegisterMessageProviderTypesShouldThrowIfDuplicateTypesAreAdded(IGetsRuleMatchingInfoForMessageProviderType matchingInfoProvider,
                                                                                    Type type)
        {
            Mock.Get(matchingInfoProvider).Setup(x => x.GetMatchingInfo(type)).Returns(Enumerable.Empty <IGetsMessageProviderTypeMatchingInfoForRule>());
            var options = Mock.Of <IOptions <MessageProviderTypeOptions> >(x => x.Value == new MessageProviderTypeOptions {
                MessageProviderTypes = new[] { type, type }
            });

            Assert.That(() => new MessageProviderRegistry(matchingInfoProvider, options), Throws.InvalidOperationException);
        }
        /// <summary>
        /// Initialises a new instance of <see cref="MessageProviderRegistry"/>.
        /// </summary>
        /// <param name="matchingInfoProvider">A service that gets message provider matching info.</param>
        /// <param name="typeOptions">An options object which indicates the available message provider types.</param>
        /// <exception cref="ArgumentNullException">If any parameter is <see langword="null" />.</exception>
        public MessageProviderRegistry(IGetsRuleMatchingInfoForMessageProviderType matchingInfoProvider,
                                       IOptions <MessageProviderTypeOptions> typeOptions)
        {
            if (typeOptions is null)
            {
                throw new ArgumentNullException(nameof(typeOptions));
            }

            this.matchingInfoProvider = matchingInfoProvider ?? throw new ArgumentNullException(nameof(matchingInfoProvider));
            RegisterMessageProviderTypes(typeOptions.Value.MessageProviderTypes);
        }
Example #4
0
 public void ConstructorShouldThrowIfTypesAreNull(IGetsRuleMatchingInfoForMessageProviderType matchingInfoProvider)
 {
     Assert.That(() => new MessageProviderRegistry(matchingInfoProvider, null), Throws.ArgumentNullException);
 }