1
0
Форкнуть 0

Added 2.0 version of WebApi Test app and associated changes.

This commit is contained in:
Cijo Thomas 2017-09-08 10:46:53 -07:00
Родитель f9e25a610c
Коммит e917993a18
30 изменённых файлов: 387 добавлений и 21 удалений

Просмотреть файл

@ -32,8 +32,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ApplicationInsigh
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTestUtils", "test\FunctionalTestUtils\FunctionalTestUtils.csproj", "{B7217A00-66FA-49A8-8EF3-39C07E1F7E33}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiShimFw46.FunctionalTests", "test\WebApiShimFw46.FunctionalTests\WebApiShimFw46.FunctionalTests.csproj", "{11FB2EE6-7199-4AFF-BC73-25F35675F233}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmptyApp.FunctionalTests", "test\EmptyApp.FunctionalTests\EmptyApp.FunctionalTests.csproj", "{71CE2DB2-C7AA-4454-B5F2-774BC575E321}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmptyApp20.FunctionalTests", "test\EmptyApp20.FunctionalTests\EmptyApp20.FunctionalTests.csproj", "{C47AFD8A-3326-4391-8115-69349C04C3DA}"
@ -44,6 +42,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVCFramework.FunctionalTest
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVCFramework20.FunctionalTests", "test\MVCFramework20.FunctionalTests\MVCFramework20.FunctionalTests.csproj", "{51198C41-CD4A-4006-84D4-DE20A0A44363}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi.FunctionalTests", "test\WebApi.FunctionalTests\WebApi.FunctionalTests.csproj", "{325C4ECE-BD4A-4CF2-BC80-FBD1024B5935}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi20.FunctionalTests", "test\WebApi20.FunctionalTests\WebApi20.FunctionalTests.csproj", "{C3B3F515-0305-4809-A9A8-37FD80428F74}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -62,10 +64,6 @@ Global
{B7217A00-66FA-49A8-8EF3-39C07E1F7E33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7217A00-66FA-49A8-8EF3-39C07E1F7E33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7217A00-66FA-49A8-8EF3-39C07E1F7E33}.Release|Any CPU.Build.0 = Release|Any CPU
{11FB2EE6-7199-4AFF-BC73-25F35675F233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11FB2EE6-7199-4AFF-BC73-25F35675F233}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11FB2EE6-7199-4AFF-BC73-25F35675F233}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11FB2EE6-7199-4AFF-BC73-25F35675F233}.Release|Any CPU.Build.0 = Release|Any CPU
{71CE2DB2-C7AA-4454-B5F2-774BC575E321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71CE2DB2-C7AA-4454-B5F2-774BC575E321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71CE2DB2-C7AA-4454-B5F2-774BC575E321}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -86,6 +84,14 @@ Global
{51198C41-CD4A-4006-84D4-DE20A0A44363}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51198C41-CD4A-4006-84D4-DE20A0A44363}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51198C41-CD4A-4006-84D4-DE20A0A44363}.Release|Any CPU.Build.0 = Release|Any CPU
{325C4ECE-BD4A-4CF2-BC80-FBD1024B5935}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{325C4ECE-BD4A-4CF2-BC80-FBD1024B5935}.Debug|Any CPU.Build.0 = Debug|Any CPU
{325C4ECE-BD4A-4CF2-BC80-FBD1024B5935}.Release|Any CPU.ActiveCfg = Release|Any CPU
{325C4ECE-BD4A-4CF2-BC80-FBD1024B5935}.Release|Any CPU.Build.0 = Release|Any CPU
{C3B3F515-0305-4809-A9A8-37FD80428F74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3B3F515-0305-4809-A9A8-37FD80428F74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3B3F515-0305-4809-A9A8-37FD80428F74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3B3F515-0305-4809-A9A8-37FD80428F74}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -95,12 +101,13 @@ Global
{95EC3635-22E4-4C3A-A066-F5823A0648DA} = {2E6DDE9E-8C75-4F9C-8906-08EBDD6E73EF}
{2766D8AF-C20B-4F3A-8260-6C2D39B7A8A0} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{B7217A00-66FA-49A8-8EF3-39C07E1F7E33} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{11FB2EE6-7199-4AFF-BC73-25F35675F233} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{71CE2DB2-C7AA-4454-B5F2-774BC575E321} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{C47AFD8A-3326-4391-8115-69349C04C3DA} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{937AF006-898E-43FD-80A6-B20D7E3A1944} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{1D5825CC-2EC9-43A1-BE32-778EFF5EAC80} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{51198C41-CD4A-4006-84D4-DE20A0A44363} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{325C4ECE-BD4A-4CF2-BC80-FBD1024B5935} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
{C3B3F515-0305-4809-A9A8-37FD80428F74} = {8B5230E5-8138-44D6-839F-DF9248F195EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {047855A4-470F-43B1-8B74-69651DD6B8A6}

Просмотреть файл

@ -13,7 +13,8 @@
<!--<Solution Include="src\Microsoft.ApplicationInsights.AspNetCore\Microsoft.ApplicationInsights.AspNetCore.xproj" />-->
<!-- Tests -->
<TestProject Include="test\Microsoft.ApplicationInsights.AspNetCore.Tests\ " />
<TestProject Include="test\WebApiShimFw46.FunctionalTests\ " />
<TestProject Include="test\WebApi.FunctionalTests\ " />
<TestProject Include="test\WebApi20.FunctionalTests\ " />
<TestProject Include="test\EmptyApp.FunctionalTests\ " />
<TestProject Include="test\EmptyApp20.FunctionalTests\ " />
<TestProject Include="test\MVCFramework.FunctionalTests\ " />

Просмотреть файл

@ -1,4 +1,4 @@
namespace MVCFramework45.FunctionalTests.FunctionalTest
namespace MVCFramework.FunctionalTests.FunctionalTest
{
using FunctionalTestUtils;
using Microsoft.ApplicationInsights.DataContracts;

Просмотреть файл

@ -1,6 +1,6 @@
using System.Diagnostics;
namespace MVCFramework45.FunctionalTests.FunctionalTest
namespace MVCFramework.FunctionalTests.FunctionalTest
{
using System;
using System.Collections.Generic;

Просмотреть файл

@ -1,7 +1,7 @@
using Xunit;
[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace MVCFramework45.FunctionalTests.FunctionalTest
namespace MVCFramework.FunctionalTests.FunctionalTest
{
using System;
using FunctionalTestUtils;

Просмотреть файл

@ -1,7 +1,7 @@
using System.Threading;
using System.Threading.Tasks;
namespace MVCFramework45.FunctionalTests.FunctionalTest
namespace MVCFramework.FunctionalTests.FunctionalTest
{
using System.Linq;
using System.Net.Http;

Просмотреть файл

@ -1,4 +1,4 @@
namespace MVCFramework45.FunctionalTests.FunctionalTest
namespace MVCFramework.FunctionalTests.FunctionalTest
{
using FunctionalTestUtils;
using Xunit;

Просмотреть файл

@ -1,4 +1,4 @@
namespace WebApiShimFw46.FunctionalTests.FunctionalTest
namespace WebApi.FunctionalTests.FunctionalTest
{
using System;
using FunctionalTestUtils;
@ -8,7 +8,7 @@
public class ExceptionTelemetryWebApiTests : TelemetryTestsBase
{
private const string assemblyName = "WebApiShimFw46.FunctionalTests";
private const string assemblyName = "WebApi.FunctionalTests";
[Fact]
public void TestBasicRequestPropertiesAfterRequestingControllerThatThrows()

Просмотреть файл

@ -1,4 +1,4 @@
namespace WebApiShimFw46.FunctionalTests.FunctionalTest
namespace WebApi.FunctionalTests.FunctionalTest
{
using FunctionalTestUtils;
using Microsoft.ApplicationInsights.DataContracts;
@ -6,7 +6,7 @@
public class RequestTelemetryWebApiTests : TelemetryTestsBase
{
private const string assemblyName = "WebApiShimFw46.FunctionalTests";
private const string assemblyName = "WebApi.FunctionalTests";
[Fact]
public void TestBasicRequestPropertiesAfterRequestingValuesController()

Просмотреть файл

@ -1,13 +1,13 @@
using Xunit;
[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace WebApiShimFw46.FunctionalTests.FunctionalTest
namespace WebApi.FunctionalTests.FunctionalTest
{
using FunctionalTestUtils;
public class TelemetryModuleWorkingWebApiTests : TelemetryTestsBase
{
private const string assemblyName = "WebApiShimFw46.FunctionalTests";
private const string assemblyName = "WebApi.FunctionalTests";
// The NET451 conditional check is wrapped inside the test to make the tests visible in the test explorer. We can move them to the class level once if the issue is resolved.

Просмотреть файл

@ -6,11 +6,11 @@
<RuntimeIdentifier Condition=" '$(TargetFramework)' == 'net46' ">win7-x86</RuntimeIdentifier>
<DelaySign>true</DelaySign>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>WebApiShimFw46.FunctionalTests</AssemblyName>
<AssemblyName>WebApi.FunctionalTests</AssemblyName>
<AssemblyOriginatorKeyFile>../../keys/35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>WebApiShimFw46.FunctionalTests</PackageId>
<PackageId>WebApi.FunctionalTests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);portable-net45+win8</PackageTargetFallback>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.1.1</RuntimeFrameworkVersion>

Просмотреть файл

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
namespace WebApi20.FunctionalTests.Controllers
{
[Route("api/[controller]")]
public class ExceptionController : Controller
{
// GET: api/exception
[HttpGet]
public IEnumerable<string> Get()
{
throw new InvalidOperationException();
}
}
}

Просмотреть файл

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace WebApi20.FunctionalTests.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

Просмотреть файл

@ -0,0 +1,42 @@
namespace WebApi20.FunctionalTests.FunctionalTest
{
using System;
using FunctionalTestUtils;
using Microsoft.ApplicationInsights.DataContracts;
using Xunit;
using Microsoft.ApplicationInsights.Extensibility;
public class ExceptionTelemetryWebApiTests : TelemetryTestsBase
{
private const string assemblyName = "WebApi20.FunctionalTests";
[Fact]
public void TestBasicRequestPropertiesAfterRequestingControllerThatThrows()
{
using (var server = new InProcessServer(assemblyName))
{
const string RequestPath = "/api/exception";
var expectedRequestTelemetry = new RequestTelemetry();
expectedRequestTelemetry.Name = "GET Exception/Get";
expectedRequestTelemetry.ResponseCode = "500";
expectedRequestTelemetry.Success = false;
expectedRequestTelemetry.Url = new System.Uri(server.BaseHost + RequestPath);
this.ValidateBasicRequest(server, RequestPath, expectedRequestTelemetry);
}
}
[Fact]
public void TestBasicExceptionPropertiesAfterRequestingControllerThatThrows()
{
using (var server = new InProcessServer(assemblyName))
{
var expectedExceptionTelemetry = new ExceptionTelemetry();
expectedExceptionTelemetry.Exception = new InvalidOperationException();
this.ValidateBasicException(server, "/api/exception", expectedExceptionTelemetry);
}
}
}
}

Просмотреть файл

@ -0,0 +1,63 @@
namespace WebApi20.FunctionalTests.FunctionalTest
{
using FunctionalTestUtils;
using Microsoft.ApplicationInsights.DataContracts;
using Xunit;
public class RequestTelemetryWebApiTests : TelemetryTestsBase
{
private const string assemblyName = "WebApi20.FunctionalTests";
[Fact]
public void TestBasicRequestPropertiesAfterRequestingValuesController()
{
using (var server = new InProcessServer(assemblyName))
{
const string RequestPath = "/api/values";
var expectedRequestTelemetry = new RequestTelemetry();
expectedRequestTelemetry.Name = "GET Values/Get";
expectedRequestTelemetry.ResponseCode = "200";
expectedRequestTelemetry.Success = true;
expectedRequestTelemetry.Url = new System.Uri(server.BaseHost + RequestPath);
this.ValidateBasicRequest(server, RequestPath, expectedRequestTelemetry);
}
}
[Fact]
public void TestBasicRequestPropertiesAfterRequestingNotExistingController()
{
using (var server = new InProcessServer(assemblyName))
{
const string RequestPath = "/api/notexistingcontroller";
var expectedRequestTelemetry = new RequestTelemetry();
expectedRequestTelemetry.Name = "GET /api/notexistingcontroller";
expectedRequestTelemetry.ResponseCode = "404";
expectedRequestTelemetry.Success = false;
expectedRequestTelemetry.Url = new System.Uri(server.BaseHost + RequestPath);
this.ValidateBasicRequest(server, RequestPath, expectedRequestTelemetry);
}
}
[Fact]
public void TestBasicRequestPropertiesAfterRequestingWebApiShimRoute()
{
using (var server = new InProcessServer(assemblyName))
{
const string RequestPath = "/api/values/1";
var expectedRequestTelemetry = new RequestTelemetry();
expectedRequestTelemetry.Name = "GET Values/Get [id]";
expectedRequestTelemetry.ResponseCode = "200";
expectedRequestTelemetry.Success = true;
expectedRequestTelemetry.Url = new System.Uri(server.BaseHost + RequestPath);
this.ValidateBasicRequest(server, RequestPath, expectedRequestTelemetry);
}
}
}
}

Просмотреть файл

@ -0,0 +1,28 @@
using Xunit;
[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace WebApi20.FunctionalTests.FunctionalTest
{
using FunctionalTestUtils;
public class TelemetryModuleWorkingWebApiTests : TelemetryTestsBase
{
private const string assemblyName = "WebApi20.FunctionalTests";
// The NET451 conditional check is wrapped inside the test to make the tests visible in the test explorer. We can move them to the class level once if the issue is resolved.
[Fact]
public void TestBasicDependencyPropertiesAfterRequestingBasicPage()
{
this.ValidateBasicDependency(assemblyName, "/api/values");
}
[Fact]
public void TestIfPerformanceCountersAreCollected()
{
#if NET451 || NET461
ValidatePerformanceCountersAreCollected(assemblyName);
#endif
}
}
}

Просмотреть файл

@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:11955/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApi20.FunctionalTests": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:11956/"
}
}
}

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.ApplicationInsights.Channel;
using FunctionalTestUtils;
namespace WebApi20.FunctionalTests
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ITelemetryChannel>(new BackTelemetryChannel());
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc(routes =>
{
// Add the following route for porting Web API 2 controllers.
routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
});
}
}
}

Просмотреть файл

@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<RuntimeIdentifier Condition=" '$(TargetFramework)' == 'net461' ">win7-x86</RuntimeIdentifier>
<DelaySign>true</DelaySign>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>WebApi20.FunctionalTests</AssemblyName>
<AssemblyOriginatorKeyFile>../../keys/35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>WebApi20.FunctionalTests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(PackageTargetFallback);portable-net45+win8</PackageTargetFallback>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">2.0.0</RuntimeFrameworkVersion>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\test\$(MSBuildProjectName)</OutputPath>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<None Update="App.config">
<Generator>SettingsSingleFileGenerator</Generator>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="config.json;xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FunctionalTestUtils\FunctionalTestUtils.csproj" />
<ProjectReference Include="..\..\src\Microsoft.ApplicationInsights.AspNetCore\Microsoft.ApplicationInsights.AspNetCore.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.WebApiCompatShim" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}

Просмотреть файл

@ -0,0 +1,5 @@
{
"parallelizeAssembly": false,
"parallelizeTestCollections": false,
"shadowCopy": false
}