添加VS项目

master
bicijinlian 4 years ago
parent d1a0e08207
commit 3613d4f3ce

@ -0,0 +1,13 @@
using System;
namespace XUnitDIStudy.Model
{
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using XUnitDIStudy.Model;
namespace XUnitDIStudy.Service
{
public interface IStudentService
{
List<Student> GetAll();
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using XUnitDIStudy.Model;
namespace XUnitDIStudy.Service
{
public class StudentService:IStudentService
{
public List<Student> GetAll()
{
return new List<Student>()
{
new Student(){Id=1,Name="乔峰",Age=18 },
new Student(){Id=1,Name="段誉",Age=16 },
new Student(){Id=1,Name="阿紫",Age=20 },
new Student(){Id=1,Name="阿娇",Age=15 },
};
}
}
}

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\XUnitDIStudy.Model\XUnitDIStudy.Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,73 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.TestHost;
using System;
using System.Collections.Generic;
using XUnitDIStudy.Service;
namespace XUnitDIStudy.Test
{
public class Startup
{
/// <summary>
/// 自定义 host 构建
/// </summary>
/// <param name="hostBuilder"></param>
public void ConfigureHost(IHostBuilder hostBuilder)
{
hostBuilder
.ConfigureWebHost(config =>
{
config
.UseTestServer()
.UseStartup<WebApp.Startup>();
})
.ConfigureAppConfiguration(builder =>
{
// 注册配置
builder
.AddInMemoryCollection(new Dictionary<string, string>()
{
{"UserName", "Alice"}
})
.AddJsonFile("appsettings.json");
})
.ConfigureServices((context, services) =>
{
// 注册自定义服务
services.AddSingleton<IStudentService,StudentService>();
if (context.Configuration.GetValue<bool>("EnableDemo"))
{
}
});
}
/// <summary>
/// 注册服务(支持以下三种)
/// ConfigureServices(IServiceCollection services)
/// ConfigureServices(IServiceCollection services, HostBuilderContext hostBuilderContext)
/// ConfigureServices(HostBuilderContext hostBuilderContext, IServiceCollection services)
/// </summary>
public void ConfigureServices(IServiceCollection services, HostBuilderContext hostBuilderContext)
{
}
/// <summary>
/// 配置服务:类似于 asp.net core 里 Configure 方法
/// 可以注册已经注册的自定义服务
/// </summary>
public void Configure(IServiceProvider applicationServices)
{
}
}
}

@ -0,0 +1,15 @@
using System;
using Xunit;
namespace XUnitDIStudy.Test
{
public class UseXUnit
{
[Fact]
public void UseXunit_Test()
{
Assert.True(true,"ʹÓÃXUnit");
}
}
}

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="7.1.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XUnitDIStudy.Service\XUnitDIStudy.Service.csproj" />
<ProjectReference Include="..\XUnitDIStudy.WebApp\XUnitDIStudy.WebApp.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,49 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XUnitDIStudy.Model;
using XUnitDIStudy.Service;
namespace XUnitDIStudy.WebApp.Controllers
{
/// <summary>
/// 默认控制器
/// </summary>
[ApiController]
[Route("[controller]/[action]")]
public class DefaultController : ControllerBase
{
private readonly ILogger<DefaultController> _logger;
private readonly StudentService _studentService;
public DefaultController(ILogger<DefaultController> logger, StudentService studentService)
{
_logger = logger;
_studentService = studentService;
}
/// <summary>
/// 获取所有学生
/// </summary>
[HttpGet]
public List<Student> GetAll()
{
var list = _studentService.GetAll();
return list;
}
/// <summary>
/// 获取学生
/// </summary>
[HttpGet]
public Student Get()
{
return new Student() { Id=10,Name="小三",Age =90};
}
}
}

@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace XUnitDIStudy.WebApp
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:29571",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"XUnitDIStudy.WebApp": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,65 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace XUnitDIStudy.WebApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "XUnitDIStudy.WebApp", Version = "v1" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger(setup=>
{
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "XUnitDIStudy.WebApp v1");
//expression²ÎÊýΪ³õʼ¹ýÂË×Ö·û´®
c.EnableFilter(expression:"");
});
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XUnitDIStudy.Service\XUnitDIStudy.Service.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

@ -0,0 +1,11 @@
{
"EnableDemo": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitDIStudy.Service", "XUnitDIStudy.Service\XUnitDIStudy.Service.csproj", "{12105FBE-85A9-4B2A-88F9-3EDF67C8CD5F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitDIStudy.WebApp", "XUnitDIStudy.WebApp\XUnitDIStudy.WebApp.csproj", "{4E18B97C-D40D-449E-AB78-F97B5D4913F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitDIStudy.Test", "XUnitDIStudy.Test\XUnitDIStudy.Test.csproj", "{4D1A2657-8B91-49CD-97C3-F34FD3D6DCB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitDIStudy.Model", "XUnitDIStudy.Model\XUnitDIStudy.Model.csproj", "{706B4560-0B72-4EE8-9AF5-1907BB2CCCDB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{12105FBE-85A9-4B2A-88F9-3EDF67C8CD5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12105FBE-85A9-4B2A-88F9-3EDF67C8CD5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12105FBE-85A9-4B2A-88F9-3EDF67C8CD5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12105FBE-85A9-4B2A-88F9-3EDF67C8CD5F}.Release|Any CPU.Build.0 = Release|Any CPU
{4E18B97C-D40D-449E-AB78-F97B5D4913F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E18B97C-D40D-449E-AB78-F97B5D4913F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E18B97C-D40D-449E-AB78-F97B5D4913F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E18B97C-D40D-449E-AB78-F97B5D4913F3}.Release|Any CPU.Build.0 = Release|Any CPU
{4D1A2657-8B91-49CD-97C3-F34FD3D6DCB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D1A2657-8B91-49CD-97C3-F34FD3D6DCB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D1A2657-8B91-49CD-97C3-F34FD3D6DCB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D1A2657-8B91-49CD-97C3-F34FD3D6DCB8}.Release|Any CPU.Build.0 = Release|Any CPU
{706B4560-0B72-4EE8-9AF5-1907BB2CCCDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{706B4560-0B72-4EE8-9AF5-1907BB2CCCDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{706B4560-0B72-4EE8-9AF5-1907BB2CCCDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{706B4560-0B72-4EE8-9AF5-1907BB2CCCDB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F7A69734-95DF-437A-92F2-D8805ED1A10D}
EndGlobalSection
EndGlobal
Loading…
Cancel
Save