コード例 #1
0
        /// <summary>
        /// Gets the template names for the <paramref name="metadata"/>. <paramref name="templateName"/>, if set,
        /// is used before any of the names from <see cref="TemplateNameSource"/>.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        /// <param name="templateName">Name of the template.</param>
        protected virtual IEnumerable <string> GetTemplateNames(ModelMetadata metadata, string templateName)
        {
            if (!string.IsNullOrEmpty(templateName))
            {
                yield return(templateName);
            }

            foreach (var name in TemplateNameSource.GetTemplateNames(metadata))
            {
                yield return(name);
            }
        }
コード例 #2
0
        public void GetTemplateNames_InTheCorrectOrder()
        {
            // Arrange
            var metadata       = _metadataProvider.GetMetadataForProperty(typeof(TestModel), "Birthday");
            var componentTypes = new[]
            {
                typeof(IDictionary <string, int>),
                typeof(IDictionary <,>),
                typeof(IEnumerable <KeyValuePair <string, int> >),
                typeof(object),
                typeof(int),
                typeof(TemplateNameSourceTests)
            };

            var expected = new[]
            {
                TestModel.BirthdayHint,
                TestModel.BirthdayDataType,
                "IDictionary(String,Int32)",
                "IDictionary(TKey,TValue)",
                "IEnumerable(KeyValuePair(String,Int32))",
                "Object",
                "Int32",
                "TemplateNameSourceTests"
            };

            _typeExplorer.Setup(m => m.Navigate(metadata.ModelType))
            .Returns(componentTypes)
            .Verifiable();

            // Act
            var result = _nameSource.GetTemplateNames(metadata);

            // Assert
            result.Should().BeEquivalentTo(expected, cfg => cfg.WithStrictOrdering());
            _typeExplorer.Verify();
        }