說明從ASP.NET MVC 5遷移至ASP.NET Core 2.x會遭遇哪技術上的變更,要如何將既有專案項目移轉到新的ASP.NET Core環境,並做出哪些調整。同時運用ASP.NET Core內建的Dependency Injection相依性注入來註冊你的服務,以達成IoC控制反轉的目的。最後用ASP.NET Core內建的單元測試,包括MStest, NUnit, xUnit來測試專案Function,達到提升品質的目的。在測試的同時,一併介紹如何使用Test Explorer, Live Testing, Code Coverage工具來輔助測試。
碼魔法網站:https://www.codemagic.com.tw/
碼魔法FB : https://www.facebook.com/CodeMagicTw/
ASP.NET Core MVC 2.2 - Development & Unit Testing. How to Choose between NET Core and .NET Framework. Choose between ASP.NET Core 2.1 and ASP.NET Core 2.2.
9. 跨平台 Windows平台
.NET Core .NET Framework
ASP.NET Core ASP.NET
ASP.NET Core MVC ASP.NET MVC
.NET Core與.NET名詞對比
10. 兩兩種.NET Core開發途徑
Visual Studio 2017 & 2019
CLI + ⽂文字編輯器 ( Visual Studio Code, vim, Atom…)
Visual Studio
2017/2019
Visual Studio
for Mac
Visual Studio
Code
.NET Core
CLI tools
19. Choosing .NET Framework
Your app uses third-party .NET libraries or NuGet
packages not available for .NET Core.
Your app uses .NET technologies that aren't available
for .NET Core.
Your app uses a platform that doesn’t support .NET
Core.
21. 三種ASP.NET Core選擇
ASP.NET Core MVC 2.0 / 2.1 / 2.2 ?
ASP.NET Core 2.0不考慮
jQuery Validation v1.14.0
ASP.NET Core 2.1
Bootstrap 3.3.7 + jQuery
ASP.NET Core 2.2
Bootstrap 4.1.3 + jQuery 3.3.1
22. ASP.NET Core 2.0, 2.1, 2.2
三者看似相同的⼩小改版,怎麼選?
ASP.NET Core 2.0:Execution Performance
Microsoft.AspNetCore.All ( metapackage )
ASP.NET Core 2.1:Build & Execution Performance
ASP.NET Core 2.2:Functional ,APIs Performance
ASP.NET Core 2.1 & 2.2
Shared Framework — Microsoft.AspNetCore.App, *.All
23. Runtime Package Store
ASP.NET Core 2.0
/usr/local/share/dotnet/store/x64/netcoreapp2.0
ASP.NET Core 2.1 & 2.2
/usr/local/share/dotnet/shared/Microsoft.AspNetCore.app/
41. .NET Core內建單元測試框架
dotnet new
dotnet new mstest
Templates Short Name Language Tags
-----------------------------------------------------------------------
Unit Test Project mstest [C#], F#, VB Test/MSTest
NUnit 3 Test Project nunit [C#], F#, VB Test/NUnit
xUnit Test Project xunit [C#], F#, VB Test/xUnit
47. Unit Test — Bad Naming
Public void Test_SqrtValue()
{
//Arrange
Var Calc = new Calc();
//Act
Var sqrtValue = Calc.GetSqrt(4);
//Assert
Assert.Equal(2, sqrtValue);
}
初始化
動作(執⾏行行)
斷⾔言(評估執⾏行行結果預
48. Unit Test — Good Naming
Public void GetSqrt_SingleNumber_ReturnrSqrtValue()
{
//Arrange
Var Calc = new Calc();
//Act
Var sqrtValue = Calc.GetSqrt(4);
//Assert
Assert.Equal(2, sqrtValue);
}
MethodName_TestScenario_ExpectedBehavior
53. 但~相依特定實作是不好的
FubonBankServices service = new FubonBankServices()
EsunBankServices service = new EsunBankServices()
相依特定實作,⼀一旦替換實作,所有類別程式必須修改
在專案中⼀一堆類別程式初始FubonBankServices,若若
FubonBankSevices需要組態,會在專案的各⾓角設定組態
未實作interface介⾯面,導致單元測試難以Mocking或Stubing
60. 註冊服務的三種Lifetime指令
AddScoped⽅方法—Scoped lifetime service
are created once per request
AddTransient⽅方法 — Transient lifetime service
are created each time they're requested
AddSingleton⽅方法 — Singleton lifetime service
are only created at the first request time
64. Better integration with popular Open API (Swagger) libraries including design-time
checks with code analyzers
Introduction of Endpoint Routing with up to 20% improved routing performance in
MVC
Improved URL generation with the LinkGenerator class & support for route
Parameter Transformers (and a post from Scott Hanselman)
New Health Checks API for application health monitoring
Up to 400% improved throughput on IIS due to in-process hosting support
Up to 15% improved MVC model validation performance
Problem Details (RFC 7807) support in MVC for detailed API error results
Preview of HTTP/2 server support in ASP.NET Core
Template updates for Bootstrap 4 and Angular 6
Java client for ASP.NET Core SignalR
Up to 60% improved HTTP Client performance on Linux and 20% on Windows
http://bit.ly/2sn6oWT