Exclude benchmark apps from builds (#7171)
This commit is contained in:
parent
35746adf68
commit
61bc18fee3
|
|
@ -60,6 +60,14 @@
|
|||
$(RepositoryRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.csproj;
|
||||
$(RepositoryRoot)src\ProjectTemplates\Web.Spa.ProjectTemplates\content\**\*.csproj;
|
||||
" />
|
||||
|
||||
<!-- Exclude the benchmarks because they use <PackageReference>. -->
|
||||
<ProjectToExclude Include="
|
||||
$(RepositoryRoot)src\Mvc\benchmarkapps\**\*.csproj;
|
||||
$(RepositoryRoot)src\Servers\Kestrel\perf\PlatformBenchmarks\**\*.csproj;
|
||||
$(RepositoryRoot)src\SignalR\perf\benchmarkapps\**\*.csproj;
|
||||
" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<Choose>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<Project>
|
||||
|
||||
<Import Project="$(MSBuildThisFileDirectory)..\..\..\build\sources.props" />
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<!-- This file prevents any other Directory.Build.targets from a parent folder to be loaded -->
|
||||
<Project>
|
||||
</Project>
|
||||
|
|
@ -1,223 +0,0 @@
|
|||
// 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.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class BasicApiTest : IClassFixture<BasicApiFixture>
|
||||
{
|
||||
private static readonly byte[] PetBytes = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)
|
||||
.GetBytes(@"{
|
||||
""category"" : {
|
||||
""name"" : ""Cats""
|
||||
},
|
||||
""images"": [
|
||||
{
|
||||
""url"": ""http://example.com/images/fluffy1.png""
|
||||
},
|
||||
{
|
||||
""url"": ""http://example.com/images/fluffy2.png""
|
||||
},
|
||||
],
|
||||
""tags"": [
|
||||
{
|
||||
""name"": ""orange""
|
||||
},
|
||||
{
|
||||
""name"": ""kitty""
|
||||
}
|
||||
],
|
||||
""age"": 2,
|
||||
""hasVaccinations"": ""true"",
|
||||
""name"" : ""fluffy"",
|
||||
""status"" : ""available""
|
||||
}");
|
||||
|
||||
public BasicApiTest(BasicApiFixture fixture)
|
||||
{
|
||||
Client = fixture.CreateClient();
|
||||
}
|
||||
|
||||
public HttpClient Client { get; }
|
||||
|
||||
[Fact]
|
||||
public async Task Token_WithUnknownUser_ReturnsForbidden()
|
||||
{
|
||||
// Arrange & Act
|
||||
var response = await Client.GetAsync("/token?username=fallguy@example.com");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Token_WithKnownUser_ReturnsOkAndToken()
|
||||
{
|
||||
// Arrange & Act
|
||||
var response = await Client.GetAsync("/token?username=reader@example.com");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType);
|
||||
|
||||
var token = await response.Content.ReadAsStringAsync();
|
||||
Assert.NotNull(token);
|
||||
Assert.NotEmpty(token);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FindByStatus_WithNoToken_ReturnsUnauthorized()
|
||||
{
|
||||
// Arrange & Act
|
||||
var response = await Client.GetAsync("/pet/findByStatus?status=available");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("reader@example.com")]
|
||||
[InlineData("writer@example.com")]
|
||||
public async Task FindByStatus_WithToken_ReturnsOkAndPet(string username)
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var token = await Client.GetStringAsync($"/token?username={username}");
|
||||
|
||||
// Assert 1 (guard)
|
||||
Assert.NotEmpty(token);
|
||||
|
||||
// Arrange 2
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "/pet/findByStatus?status=available");
|
||||
request.Headers.Add(HeaderNames.Authorization, $"Bearer {token}");
|
||||
|
||||
// Act 2
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert 2
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType);
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
Assert.NotNull(json);
|
||||
Assert.NotEmpty(json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FindById_WithInvalidPetId_ReturnsNotFound()
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var token = await Client.GetStringAsync("/token?username=reader@example.com");
|
||||
|
||||
// Assert 1 (guard)
|
||||
Assert.NotEmpty(token);
|
||||
|
||||
// Arrange 2
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "/pet/100");
|
||||
request.Headers.Add(HeaderNames.Authorization, $"Bearer {token}");
|
||||
|
||||
// Act 2
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert 2
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FindById_WithValidPetId_ReturnsOkAndPet()
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var token = await Client.GetStringAsync("/token?username=reader@example.com");
|
||||
|
||||
// Assert 1 (guard)
|
||||
Assert.NotEmpty(token);
|
||||
|
||||
// Arrange 2
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "/pet/-1");
|
||||
request.Headers.Add(HeaderNames.Authorization, $"Bearer {token}");
|
||||
|
||||
// Act 2
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert 2
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType);
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
Assert.NotNull(json);
|
||||
Assert.NotEmpty(json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddPet_WithInsufficientClaims_ReturnsForbidden()
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var token = await Client.GetStringAsync("/token?username=reader@example.com");
|
||||
|
||||
// Assert 1 (guard)
|
||||
Assert.NotEmpty(token);
|
||||
|
||||
// Arrange 2
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "/pet")
|
||||
{
|
||||
Content = new ByteArrayContent(PetBytes)
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
{ "Content-Type", "application/json" },
|
||||
},
|
||||
},
|
||||
Headers =
|
||||
{
|
||||
{ HeaderNames.Authorization, $"Bearer {token}" },
|
||||
},
|
||||
};
|
||||
|
||||
// Act 2
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert 2
|
||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddPet_WithValidClaims_ReturnsCreated()
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var token = await Client.GetStringAsync("/token?username=writer@example.com");
|
||||
|
||||
// Assert 1 (guard)
|
||||
Assert.NotEmpty(token);
|
||||
|
||||
// Arrange 2
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "/pet")
|
||||
{
|
||||
Content = new ByteArrayContent(PetBytes)
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
{ HeaderNames.ContentType, "application/json" },
|
||||
},
|
||||
},
|
||||
Headers =
|
||||
{
|
||||
{ HeaderNames.Authorization, $"Bearer {token}" },
|
||||
},
|
||||
};
|
||||
|
||||
// Act 2
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert 2
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
var location = response.Headers.Location.ToString();
|
||||
Assert.NotNull(location);
|
||||
Assert.EndsWith("/1", location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
// 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.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class BasicViewsTest : IClassFixture<BasicViewsFixture>
|
||||
{
|
||||
public BasicViewsTest(BasicViewsFixture fixture)
|
||||
{
|
||||
Client = fixture.CreateClient();
|
||||
}
|
||||
|
||||
public HttpClient Client { get; }
|
||||
|
||||
[Theory]
|
||||
[InlineData("/")]
|
||||
[InlineData("/Home/HtmlHelpers")]
|
||||
public async Task Get_ReturnsOkAndAntiforgeryToken(string path)
|
||||
{
|
||||
// Arrange & Act
|
||||
var response = await Client.GetAsync(path);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("text/html", response.Content.Headers.ContentType.MediaType);
|
||||
|
||||
var html = await response.Content.ReadAsStringAsync();
|
||||
Assert.NotNull(html);
|
||||
Assert.NotEmpty(html);
|
||||
|
||||
var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(html, "/");
|
||||
Assert.NotNull(token);
|
||||
Assert.NotEmpty(token);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/")]
|
||||
[InlineData("/Home/HtmlHelpers")]
|
||||
public async Task Post_ReturnsOkAndNewPerson(string path)
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var html = await Client.GetStringAsync(path);
|
||||
|
||||
// Assert 1 (guard)
|
||||
Assert.NotEmpty(html);
|
||||
|
||||
// Arrange 2
|
||||
var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(html, "/");
|
||||
var name = Guid.NewGuid().ToString();
|
||||
name = name.Substring(startIndex: 0, length: name.LastIndexOf('-'));
|
||||
var form = new Dictionary<string, string>
|
||||
{
|
||||
{ "__RequestVerificationToken", token },
|
||||
{ "Age", "12" },
|
||||
{ "BirthDate", "2006-03-01T09:51:43.041-07:00" },
|
||||
{ "Name", name },
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(form);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, path)
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
|
||||
// Act 2
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert 2
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.NotNull(body);
|
||||
Assert.Contains($@"value=""{name}""", body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// 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 BasicApi;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class BasicApiFixture : MvcTestFixture<Startup>
|
||||
{
|
||||
// Do not leave .db file behind. Also, ensure added pet gets expected id (1) in subsequent runs.
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Startup.DropDatabase(Server.Host.Services);
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// 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 BasicViews;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class BasicViewsFixture : MvcTestFixture<Startup>
|
||||
{
|
||||
// Do not leave .db file behind.
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Startup.DropDatabase(Server.Host.Services);
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,8 +26,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Mvc.Testing" />
|
||||
<ProjectReference Include="..\..\benchmarkapps\BasicApi\BasicApi.csproj" />
|
||||
<ProjectReference Include="..\..\benchmarkapps\BasicViews\BasicViews.csproj" />
|
||||
<ProjectReference Include="..\..\samples\MvcSandbox\MvcSandbox.csproj" />
|
||||
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Mvc.Core.TestCommon\Microsoft.AspNetCore.Mvc.Core.TestCommon.csproj" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<Project>
|
||||
|
||||
<Import Project="$(MSBuildThisFileDirectory)..\..\..\..\..\build\sources.props" />
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<!-- This file prevents any other Directory.Build.targets from a parent folder to be loaded -->
|
||||
<Project>
|
||||
</Project>
|
||||
|
|
@ -9,12 +9,9 @@
|
|||
<IsTestAssetProject>true</IsTestAssetProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Utf8Json" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- These references are used when running locally -->
|
||||
<ItemGroup Condition="'$(BenchmarksTargetFramework)' == ''">
|
||||
<Reference Include="Utf8Json" />
|
||||
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
|
||||
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" />
|
||||
|
||||
|
|
@ -23,7 +20,8 @@
|
|||
|
||||
<!-- These references are used when running on the Benchmarks Server -->
|
||||
<ItemGroup Condition="'$(BenchmarksTargetFramework)' != ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" version="2.2.0" />
|
||||
<PackageReference Include="Utf8Json" Version="1.3.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" Version="2.2.0" />
|
||||
<KnownFrameworkReference
|
||||
Update="Microsoft.AspNetCore.App"
|
||||
DefaultRuntimeFrameworkVersion="$(MicrosoftAspNetCoreAppPackageVersion)"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<Project>
|
||||
|
||||
<Import Project="$(MSBuildThisFileDirectory)..\..\..\..\build\sources.props" />
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<!-- This file prevents any other Directory.Build.targets from a parent folder to be loaded -->
|
||||
<Project>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue