Skip to content

Commit

Permalink
merge from customers controller branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gpeipman committed Jan 18, 2020
2 parents 6cebac4 + 01ede87 commit 3246328
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Expand Up @@ -5,7 +5,7 @@

namespace AspNetCoreTests.IntegrationTests
{
[Collection("Serialize")]
[Collection("Sequential")]
public class CustomerControllerTests : TestBase
{
public CustomerControllerTests(TestApplicationFactory<FakeStartup> factory) : base(factory)
Expand All @@ -16,6 +16,8 @@ public CustomerControllerTests(TestApplicationFactory<FakeStartup> factory) : ba
[InlineData("/Customers")]
[InlineData("/Customers/Details")]
[InlineData("/Customers/Details/1")]
[InlineData("/Customers/Edit")]
[InlineData("/Customers/Edit/1")]
public async Task Get_EndpointsReturnFailToAnonymousUserForRestrictedUrls(string url)
{
// Arrange
Expand Down Expand Up @@ -43,15 +45,31 @@ public async Task Get_EndPointsReturnsSuccessForRegularUser(string url)
}

[Theory]
[InlineData("/Customers/Details")]
public async Task Get_DetailsWithNoIdReturnsBadSuccessForRegularUser(string url)
[InlineData("/Customers/Edit/")]
[InlineData("/Customers/Edit/1")]
public async Task Get_EditReturnsFailToRegularUser(string url)
{
var provider = TestClaimsProvider.WithUserClaims();
var client = Factory.CreateClientWithTestAuth(provider);

var response = await client.GetAsync(url);

Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
}

[Theory]
[InlineData("/Customers")]
[InlineData("/Customers/Details/1")]
[InlineData("/Customers/Edit/1")]
public async Task Get_EndPointsReturnsSuccessForAdmin(string url)
{
var provider = TestClaimsProvider.WithAdminClaims();
var client = Factory.CreateClientWithTestAuth(provider);

var response = await client.GetAsync(url);

response.EnsureSuccessStatusCode();
Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString());
}
}
}
Expand Up @@ -3,7 +3,7 @@

namespace AspNetCoreTests.IntegrationTests
{
[Collection("Serialize")]
[Collection("Sequential")]
public class HomeControllerTests : TestBase
{
public HomeControllerTests(TestApplicationFactory<FakeStartup> factory) : base(factory)
Expand Down
Expand Up @@ -37,5 +37,22 @@ public async Task<IActionResult> Details(int? id)

return View(model);
}

[Authorize(Roles = "Admin")]
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return BadRequest();
}

var model = await _customerService.GetCustomer(id.Value);
if (model == null)
{
return NotFound();
}

return View(model);
}
}
}
@@ -0,0 +1,5 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

0 comments on commit 3246328

Please sign in to comment.