/// <summary>
 /// Initializes a new instance of the <see cref="TemplateProvider"/> class.
 /// </summary>
 /// <param name="templateNameSource">The template name source.</param>
 /// <param name="templates">The templates.</param>
 /// <param name="options">The options.</param>
 public TemplateProvider(
     ITemplateNameSource templateNameSource,
     IEnumerable <ITemplateRegistration> templates,
     IOptions <TemplateProviderOptions> options)
     : this(templateNameSource, templates, options?.Value)
 {
 }
        public void AsITemplateNameSource_GetTypeName(Type type, string expected)
        {
            // Arrange
            ITemplateNameSource nameSource = _nameSource;

            // Act
            var actual = nameSource.GetTypeName(type);

            // Assert
            actual.Should().Be(expected);
        }
        public void AsITemplateNameSource_GetTypeName_ThrowsArgumentNullException_WhenGivenNullType()
        {
            // Arrange
            var paramName = "type";
            ITemplateNameSource nameSource = _nameSource;

            Action test = () => nameSource.GetTypeName(null);

            // Act

            // Assert
            test.Should().Throw <ArgumentNullException>()
            .And.ParamName.Should().Be(paramName);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateProvider"/> class.
        /// </summary>
        /// <param name="templateNameSource">The template name source.</param>
        /// <param name="templates">The templates.</param>
        /// <param name="options">The options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="templateNameSource"/>,
        /// <paramref name="templates"/>
        /// or
        /// <paramref name="options"/>
        /// </exception>
        public TemplateProvider(
            ITemplateNameSource templateNameSource,
            IEnumerable <ITemplateRegistration> templates,
            TemplateProviderOptions options)
        {
            Guard.NotNull(templateNameSource, nameof(templateNameSource));
            Guard.NotNull(templates, nameof(templates));
            Guard.NotNull(options, nameof(options));

            TemplateNameSource = templateNameSource;
            TemplateViewPaths  = options.TemplateViewPaths;

            var comparer = StringComparer.OrdinalIgnoreCase;

            TemplatesByPurpose = templates
                                 .GroupBy(t => t.Purpose, comparer)
                                 .ToDictionary(
                g => g.Key,
                g => g.ToDictionary(t => t.Name, comparer),
                comparer);
        }