コード例 #1
0
        public IControlMatch GetFor(Type type, IEnumerable <UIHint> uiHints)
        {
            foreach (var uiHint in uiHints)
            {
                var match = UIHintControlMatcher.GetFor(uiHint);

                if (Logger.IsEnabled(LogLevel.Information))
                {
                    Logger.LogInformation($"Match for {JsonConvert.SerializeObject(uiHint, Formatting.None)}: {JsonConvert.SerializeObject(match, Formatting.None)}");
                }

                if (match != null)
                {
                    return(match);
                }
            }

            {
                var match = TypeControlMatcher.GetFor(type);

                if (match != null)
                {
                    return(match);
                }
            }

            foreach (var uiHint in uiHints)
            {
                if (uiHint.Parameters.Any())
                {
                    continue;
                }

                if (Controls.ContainsKey(uiHint.Id))
                {
                    return(new UIHintControlMatch(uiHint.Id, uiHint.Id, new Dictionary <string, object>()));
                }
            }

            if (type.IsInterface)
            {
                return(new PolymorphicControlMatch("polymorphic-form", PolymorphicFormFinder.FindFor(type).ToList().AsReadOnly()));
            }

            return(null);
        }
コード例 #2
0
        public void FindsForms()
        {
            var contentTypeProvider = Mock.Of <IContentTypeProvider>();

            Mock.Get(contentTypeProvider).Setup(p => p.GetAll()).Returns(new List <ContentTypeDescriptor> {
            });

            var formA        = new FormDescriptor("lorem", typeof(FormA));
            var formB        = new FormDescriptor("ipsum", typeof(FormB));
            var formProvider = Mock.Of <IFormProvider>();

            Mock.Get(formProvider).Setup(p => p.GetAll()).Returns(new List <FormDescriptor> {
                formA, formB
            });

            var result = new PolymorphicFormFinder(contentTypeProvider, formProvider).FindFor(typeof(FormInterface));

            Assert.Equal(new List <string> {
                "lorem"
            }, result);
        }