public void PopulateFeature_ThrowsIfSingleAssemblyContainsMultipleAttributesWithTheSamePath() { // Arrange var path1 = "/Views/test/Index.cshtml"; var path2 = "/views/test/index.cshtml"; var expected = string.Join( Environment.NewLine, "The following precompiled view paths differ only in case, which is not supported:", path1, path2); var part = new AssemblyPart(typeof(object).GetTypeInfo().Assembly); var featureProvider = new TestableViewsFeatureProvider(new Dictionary <AssemblyPart, IEnumerable <RazorViewAttribute> > { { part, new[] { new RazorViewAttribute(path1, typeof(object)), new RazorViewAttribute(path2, typeof(object)), } }, }); var applicationPartManager = new ApplicationPartManager(); applicationPartManager.ApplicationParts.Add(part); applicationPartManager.FeatureProviders.Add(featureProvider); var feature = new ViewsFeature(); // Act & Assert var ex = Assert.Throws <InvalidOperationException>(() => applicationPartManager.PopulateFeature(feature)); Assert.Equal(expected, ex.Message); }
public void PopulateFeature_PrefersViewsFromPartsWithHigherPrecedence() { // Arrange var part1 = new AssemblyPart(typeof(ViewsFeatureProvider).Assembly); var item1 = new TestRazorCompiledItem(typeof(StringBuilder), "mvc.1.0.view", "/Areas/Admin/Views/Shared/_Layout.cshtml", new object[] { }); var part2 = new AssemblyPart(GetType().Assembly); var item2 = new TestRazorCompiledItem(typeof(string), "mvc.1.0.view", "/Areas/Admin/Views/Shared/_Layout.cshtml", new object[] { }); var item3 = new TestRazorCompiledItem(typeof(string), "mvc.1.0.view", "/Areas/Admin/Views/Shared/_Partial.cshtml", new object[] { }); var items = new Dictionary <AssemblyPart, IReadOnlyList <RazorCompiledItem> > { { part1, new[] { item1 } }, { part2, new[] { item2, item3, } }, }; var featureProvider = new TestableViewsFeatureProvider(items, attributes: new Dictionary <AssemblyPart, IEnumerable <RazorViewAttribute> >()); var partManager = new ApplicationPartManager(); partManager.ApplicationParts.Add(part1); partManager.ApplicationParts.Add(part2); partManager.FeatureProviders.Add(featureProvider); var feature = new ViewsFeature(); // Act partManager.PopulateFeature(feature); // Assert Assert.Collection(feature.ViewDescriptors.OrderBy(f => f.RelativePath, StringComparer.Ordinal), view => Assert.Same(item1, view.Item), view => Assert.Same(item3, view.Item)); }
public void PopulateFeature_ReturnsViewsFromAllAvailableApplicationParts() { // Arrange var part1 = new AssemblyPart(typeof(object).GetTypeInfo().Assembly); var part2 = new AssemblyPart(GetType().GetTypeInfo().Assembly); var featureProvider = new TestableViewsFeatureProvider(new Dictionary <AssemblyPart, IEnumerable <RazorViewAttribute> > { { part1, new[] { new RazorViewAttribute("/Views/test/Index.cshtml", typeof(object)), } }, { part2, new[] { new RazorViewAttribute("/Areas/Admin/Views/Index.cshtml", typeof(string)), new RazorViewAttribute("/Areas/Admin/Views/About.cshtml", typeof(int)), } }, }); var applicationPartManager = new ApplicationPartManager(); applicationPartManager.ApplicationParts.Add(part1); applicationPartManager.ApplicationParts.Add(part2); applicationPartManager.FeatureProviders.Add(featureProvider); var feature = new ViewsFeature(); // Act applicationPartManager.PopulateFeature(feature); // Assert Assert.Collection(feature.ViewDescriptors.OrderBy(f => f.RelativePath, StringComparer.Ordinal), view => { Assert.Equal("/Areas/Admin/Views/About.cshtml", view.RelativePath); Assert.Equal(typeof(int), view.ViewAttribute.ViewType); }, view => { Assert.Equal("/Areas/Admin/Views/Index.cshtml", view.RelativePath); Assert.Equal(typeof(string), view.ViewAttribute.ViewType); }, view => { Assert.Equal("/Views/test/Index.cshtml", view.RelativePath); Assert.Equal(typeof(object), view.ViewAttribute.ViewType); }); }
public void PopulateFeature_ReturnsViewsFromAllAvailableApplicationParts() { // Arrange var part1 = new AssemblyPart(typeof(object).GetTypeInfo().Assembly); var part2 = new AssemblyPart(GetType().GetTypeInfo().Assembly); var featureProvider = new TestableViewsFeatureProvider(new Dictionary <AssemblyPart, Type> { { part1, typeof(ViewInfoContainer1) }, { part2, typeof(ViewInfoContainer2) }, }); var applicationPartManager = new ApplicationPartManager(); applicationPartManager.ApplicationParts.Add(part1); applicationPartManager.ApplicationParts.Add(part2); applicationPartManager.FeatureProviders.Add(featureProvider); var feature = new ViewsFeature(); // Act applicationPartManager.PopulateFeature(feature); // Assert Assert.Collection(feature.Views.OrderBy(f => f.Key, StringComparer.Ordinal), view => { Assert.Equal("/Areas/Admin/Views/About.cshtml", view.Key); Assert.Equal(typeof(int), view.Value); }, view => { Assert.Equal("/Areas/Admin/Views/Index.cshtml", view.Key); Assert.Equal(typeof(string), view.Value); }, view => { Assert.Equal("/Views/test/Index.cshtml", view.Key); Assert.Equal(typeof(object), view.Value); }); }
public void PopulateFeature_ReturnsViewsFromAllAvailableApplicationParts() { // Arrange var part1 = new AssemblyPart(typeof(object).Assembly); var part2 = new AssemblyPart(GetType().Assembly); var items = new Dictionary <AssemblyPart, IReadOnlyList <RazorCompiledItem> > { { part1, new[] { new TestRazorCompiledItem(typeof(object), "mvc.1.0.view", "/Views/test/Index.cshtml", new object[] { }), // This one doesn't have a RazorViewAttribute new TestRazorCompiledItem(typeof(StringBuilder), "mvc.1.0.view", "/Views/test/About.cshtml", new object[] { }), } }, { part2, new[] { new TestRazorCompiledItem(typeof(string), "mvc.1.0.view", "/Areas/Admin/Views/Index.cshtml", new object[] { }), } }, }; var attributes = new Dictionary <AssemblyPart, IEnumerable <RazorViewAttribute> > { { part1, new[] { new RazorViewAttribute("/Views/test/Index.cshtml", typeof(object)), } }, { part2, new[] { new RazorViewAttribute("/Areas/Admin/Views/Index.cshtml", typeof(string)), // This one doesn't have a RazorCompiledItem new RazorViewAttribute("/Areas/Admin/Views/About.cshtml", typeof(int)), } }, }; var featureProvider = new TestableViewsFeatureProvider(items, attributes); var partManager = new ApplicationPartManager(); partManager.ApplicationParts.Add(part1); partManager.ApplicationParts.Add(part2); partManager.FeatureProviders.Add(featureProvider); var feature = new ViewsFeature(); // Act partManager.PopulateFeature(feature); // Assert Assert.Collection(feature.ViewDescriptors.OrderBy(f => f.RelativePath, StringComparer.Ordinal), view => { Assert.Empty(view.ExpirationTokens); Assert.True(view.IsPrecompiled); Assert.Null(view.Item); Assert.Equal("/Areas/Admin/Views/About.cshtml", view.RelativePath); Assert.Equal(typeof(int), view.Type); Assert.Equal("/Areas/Admin/Views/About.cshtml", view.ViewAttribute.Path); Assert.Equal(typeof(int), view.ViewAttribute.ViewType); }, view => { // This one doesn't have a RazorCompiledItem Assert.Empty(view.ExpirationTokens); Assert.True(view.IsPrecompiled); Assert.Equal("/Areas/Admin/Views/Index.cshtml", view.Item.Identifier); Assert.Equal("mvc.1.0.view", view.Item.Kind); Assert.Equal(typeof(string), view.Item.Type); Assert.Equal("/Areas/Admin/Views/Index.cshtml", view.RelativePath); Assert.Equal(typeof(string), view.Type); Assert.Equal("/Areas/Admin/Views/Index.cshtml", view.ViewAttribute.Path); Assert.Equal(typeof(string), view.ViewAttribute.ViewType); }, view => { // This one doesn't have a RazorViewAttribute Assert.Empty(view.ExpirationTokens); Assert.True(view.IsPrecompiled); Assert.Equal("/Views/test/About.cshtml", view.Item.Identifier); Assert.Equal("mvc.1.0.view", view.Item.Kind); Assert.Equal(typeof(StringBuilder), view.Item.Type); Assert.Equal("/Views/test/About.cshtml", view.RelativePath); Assert.Equal(typeof(StringBuilder), view.Type); Assert.Null(view.ViewAttribute); }, view => { Assert.Empty(view.ExpirationTokens); Assert.True(view.IsPrecompiled); Assert.Equal("/Views/test/Index.cshtml", view.Item.Identifier); Assert.Equal("mvc.1.0.view", view.Item.Kind); Assert.Equal(typeof(object), view.Item.Type); Assert.Equal("/Views/test/Index.cshtml", view.RelativePath); Assert.Equal(typeof(object), view.Type); Assert.Equal("/Views/test/Index.cshtml", view.ViewAttribute.Path); Assert.Equal(typeof(object), view.ViewAttribute.ViewType); }); }