forked from aspnet/Mvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRazorViewEngineOptionsTest.cs
More file actions
97 lines (85 loc) · 3.37 KB
/
Copy pathRazorViewEngineOptionsTest.cs
File metadata and controls
97 lines (85 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.Razor
{
public class RazorViewEngineOptionsTest
{
[Fact]
public void AreaViewLocationFormats_ContainsExpectedLocations()
{
// Arrange
var services = new ServiceCollection().AddOptions();
var areaViewLocations = new[]
{
"/Areas/{2}/MvcViews/{1}/{0}.cshtml",
"/Areas/{2}/MvcViews/Shared/{0}.cshtml",
"/MvcViews/Shared/{0}.cshtml"
};
var builder = new MvcBuilder(services, new ApplicationPartManager());
builder.AddRazorOptions(options =>
{
options.AreaViewLocationFormats.Clear();
foreach (var location in areaViewLocations)
{
options.AreaViewLocationFormats.Add(location);
}
});
var serviceProvider = services.BuildServiceProvider();
var accessor = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>();
// Act
var formats = accessor.Value.AreaViewLocationFormats;
// Assert
Assert.Equal(areaViewLocations, formats, StringComparer.Ordinal);
}
[Fact]
public void ViewLocationFormats_ContainsExpectedLocations()
{
// Arrange
var services = new ServiceCollection().AddOptions();
var viewLocations = new[]
{
"/MvcViews/{1}/{0}.cshtml",
"/MvcViews/Shared/{0}.cshtml"
};
var builder = new MvcBuilder(services, new ApplicationPartManager());
builder.AddRazorOptions(options =>
{
options.ViewLocationFormats.Clear();
foreach (var location in viewLocations)
{
options.ViewLocationFormats.Add(location);
}
});
var serviceProvider = services.BuildServiceProvider();
var accessor = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>();
// Act
var formats = accessor.Value.ViewLocationFormats;
// Assert
Assert.Equal(viewLocations, formats, StringComparer.Ordinal);
}
[Fact]
public void AddRazorOptions_ConfiguresOptionsAsExpected()
{
// Arrange
var services = new ServiceCollection().AddOptions();
var fileProvider = new TestFileProvider();
// Act
var builder = new MvcBuilder(services, new ApplicationPartManager());
builder.AddRazorOptions(options =>
{
options.FileProviders.Add(fileProvider);
});
var serviceProvider = services.BuildServiceProvider();
// Assert
var accessor = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>();
Assert.Same(fileProvider, accessor.Value.FileProviders[0]);
}
}
}