public static void Construct_Throws_ArgumentNullException_WhenGivenNullTemplateNameSource()
        {
            // Arrange
            var options   = new TemplateProviderOptions();
            var iOptions  = TestOptions.Create(options);
            var templates = Mock.Of <IEnumerable <ITemplateRegistration> >(MockBehavior.Strict);
            var paramName = "templateNameSource";

            var tests = new Action[]
            {
                () => new TemplateProvider(null, templates, options),
                () => new TemplateProvider(null, templates, iOptions.Object)
            };

            // Act

            // Assert
            using (new AssertionScope())
            {
                foreach (var test in tests)
                {
                    test.Should().Throw <ArgumentNullException>()
                    .Which.ParamName.Should().Be(paramName);
                }
            }
        }
        public TemplateProviderTests()
        {
            _nameSource           = new Mock <ITemplateNameSource>(MockBehavior.Strict);
            _templates            = new List <ITemplateRegistration>();
            _options              = new TemplateProviderOptions();
            _lazyTemplateProvider = new Lazy <TemplateProvider>(()
                                                                => new TemplateProvider(_nameSource.Object, _templates, TestOptions.Create(_options).Object));
            _viewEngine    = new Mock <IViewEngine>(MockBehavior.Strict);
            _context       = new TestViewContext <TestModel>();
            _purpose       = Guid.NewGuid().ToString();
            _viewDirectory = Guid.NewGuid().ToString();

            _options.TemplateViewPaths.Add(_purpose, _viewDirectory);
        }
        /// <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);
        }
Example #4
0
 public TemplateProviderOptionsTests()
 {
     _options = new TemplateProviderOptions();
 }