Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit aa43965

Browse files
committed
Feedback addressed
1 parent 019be2c commit aa43965

File tree

11 files changed

+49
-118
lines changed

11 files changed

+49
-118
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manage View

samples/Mvc.ControllerForMultipleAreasSample/Areas/Products/Controllers/HomeController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Mvc;
25

36
namespace ControllerForMultipleAreasSample.Areas.Products.Controllers
47
{
5-
[MultipleAreas(new string[] { "Products", "Services" })]
8+
[MultipleAreas("Products", "Services", "Manage")]
69
public class HomeController : Controller
710
{
811
public IActionResult Index()
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
using System;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Linq;
26

37
namespace ControllerForMultipleAreasSample
48
{
5-
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
9+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
610
public class MultipleAreasAttribute : Attribute
711
{
8-
public MultipleAreasAttribute(string[] areaNames)
12+
public MultipleAreasAttribute(string area1, string area2, params string[] areaNames)
913
{
10-
AreaNames = areaNames;
14+
AreaNames = new string[] { area1, area2 };
15+
AreaNames = AreaNames.Concat(areaNames).ToArray();
1116
}
1217

13-
public string[] AreaNames { get; private set; }
18+
public string[] AreaNames { get; }
1419
}
1520
}

samples/Mvc.ControllerForMultipleAreasSample/MultipleAreasControllerConvention.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,22 @@ namespace ControllerForMultipleAreasSample
77
{
88
public class MultipleAreasControllerConvention : IApplicationModelConvention
99
{
10-
public MultipleAreasControllerConvention()
11-
{
12-
ControllerModels = new List<ControllerModel>();
13-
}
14-
15-
public IList<ControllerModel> ControllerModels { get; set; }
16-
1710
public void Apply(ApplicationModel application)
1811
{
12+
var controllerModels = new List<ControllerModel>();
1913
foreach (var controller in application.Controllers)
2014
{
21-
var areas = controller.ControllerType.GetCustomAttributes<MultipleAreasAttribute>().FirstOrDefault();
22-
var areaNames = areas?.AreaNames;
23-
24-
for (var i = 0; i < areaNames?.Length; i++)
15+
var areaNames = controller.ControllerType.GetCustomAttributes<MultipleAreasAttribute>().FirstOrDefault()?.AreaNames;
16+
controller.RouteValues.Add("area", areaNames[0]);
17+
for (var i = 1; i < areaNames?.Length; i++)
2518
{
26-
if (i == 0)
27-
{
28-
controller.RouteValues.Add("area", areaNames[i]);
29-
}
30-
31-
else
32-
{
33-
var controllerCopy = new ControllerModel(controller);
34-
controllerCopy.RouteValues["area"] = areaNames[i];
35-
ControllerModels.Add(controllerCopy);
36-
}
19+
var controllerCopy = new ControllerModel(controller);
20+
controllerCopy.RouteValues["area"] = areaNames[i];
21+
controllerModels.Add(controllerCopy);
3722
}
3823
}
3924

40-
foreach (var model in ControllerModels)
25+
foreach (var model in controllerModels)
4126
{
4227
application.Controllers.Add(model);
4328
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

3+
<Import Project="..\..\build\dependencies.props" />
4+
35
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
<IsPackable>false</IsPackable>
7+
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
58
</PropertyGroup>
69

710
<ItemGroup>
8-
<Folder Include="wwwroot\" />
9-
</ItemGroup>
10-
11-
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
11+
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
12+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreVersion)" />
13+
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="$(AspNetCoreVersion)" />
14+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(AspNetCoreVersion)" />
1315
</ItemGroup>
1416

1517
</Project>

samples/Mvc.ControllerForMultipleAreasSample/Program.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
64
using Microsoft.AspNetCore;
75
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
106

117
namespace ControllerForMultipleAreasSample
128
{

samples/Mvc/Mvc.ControllerForMultipleAreasSample/Mvc.ControllerForMultipleAreasSample.csproj

Lines changed: 0 additions & 15 deletions
This file was deleted.

samples/Mvc/Mvc.ControllerForMultipleAreasSample/Program.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

samples/Mvc/Mvc.ControllerForMultipleAreasSample/Startup.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

test/Entropy.FunctionalTests/Entropy.FunctionalTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
</ItemGroup>
5151

5252
<ItemGroup>
53+
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
5354
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(AspNetCoreVersion)" />
5455
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(AspNetIntegrationTestingVersion)" />
5556
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />

test/Entropy.FunctionalTests/MvcTests/ControllerForMultipleAreasTest.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task ProductsArea()
3131
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
3232
Assert.Contains("Products View", content);
3333
}
34-
34+
3535
[Fact]
3636
public async Task ServicesArea()
3737
{
@@ -43,5 +43,17 @@ public async Task ServicesArea()
4343
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
4444
Assert.Contains("Services View", content);
4545
}
46+
47+
[Fact]
48+
public async Task ManageArea()
49+
{
50+
// Arrange & Act
51+
var response = await Client.GetAsync("/Manage/Home/Index");
52+
var content = await response.Content.ReadAsStringAsync();
53+
54+
// Assert
55+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
56+
Assert.Contains("Manage View", content);
57+
}
4658
}
4759
}

0 commit comments

Comments
 (0)