ASP.NET هو إطار عمل ويب مفتوح المصدر، تم إنشاؤه بواسطة Microsoft لإنشاء تطبيقات وخدمات الويب الحديثة باستخدام .NET. ASP.NET عبارة عن منصة مشتركة ويعمل على أنظمة التشغيل Windows وLinux وmacOS وDocker.
المزيد: https://dotnet.microsoft.com/en-us/learn/aspnet/what-is-aspnet
إنشاء مشروع الحل
dotnet new sln -n Tutorial-Apiإنشاء مشروع ASP.NET Web Api
dotnet new webapi -o Apiإنشاء مشروع XUnit
dotnet new xunit -o Xunit.Testsإضافة مشاريع إلى الحل
dotnet sln add .Tutorial.ApiTutorial.Api.csproj
dotnet sln add .XUnit.TestsXUnit.Tests.csprojإضافة مشروع مرجعي إلى مشروع xunit
dotnet add . /XUnit.Tests/XUnit.Tests.csproj reference .Tutorial.ApiTutorial.Api.csproj أضف تبعية MongoDB Driver إلى المشروع
dotnet add package MongoDB.Driver --version 2.18.0مونغوشيل
Install mongo-shell
https://www.mongodb.com/docs/mongodb-shell/install/
> mongod --dbpath < data_directory_path >
> show dbs
> use tutorialdb
> db.createCollection( ' tutorials ' )
> db.tutorials.insertMany([{ " title " : " Design Patterns " , " description " : " " , " published " : false}])
> db.tutorials.find().pretty ()
dotnet run --project . /Tutorial.Api/اختيال : https://localhost:7272/swagger

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run#examples
الحصول على /api/tutorials
إجابة
[
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
},
{
"id" : " 63732124796b18bc753e9157 " ,
"title" : " dotnet " ,
"description" : " microsoft " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
}
]الحصول على /api/tutorials/{id}
إجابة
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
}بوست /api/tutorials
هيئة الطلب
{
"title" : " string " ,
"description" : " string " ,
}هيئة الاستجابة
{
"code" : " 200 " ,
"message" : " Inserted a single document Success "
}احذف /api/tutorials
هيئة الاستجابة
{
"code" : " 200 " ,
"message" : " All deleted "
}حذف /api/tutorials/{id}
هيئة الاستجابة
{
"code" : " 200 " ,
"message" : " Deleted id 63730beabd3cb05f2331be45 "
}وضع /api/tutorials/{id}
هيئة الطلب
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : true
}هيئة الاستجابة
{
"code" : " 200 " ,
"message" : " Deleted id 63730beabd3cb05f2331be45 "
} dotnet buildاستعادة كطبقات مميزة
dotnet restoreإنشاء ونشر الإصدار
dotnet publish -c Release -o out تشغيل التغطية
dotnet test --collect:"XPlat Code Coverage"أضف ReportGenerator nuget
dotnet add package ReportGenerator --version 5.1.10أداة الإعداد ReportGenerator
dotnet tool install -g dotnet-reportgenerator-globaltoolالمزيد: https://www.nuget.org/packages/ReportGenerator
reportgenerator -reports:"XUnit.TestsTestResults*coverage.cobertura.xml" -targetdir:". /coveragereport" -reporttypes:Html متغيرات البيئة
| اسم البيئة | قيمة |
|---|---|
| البرنامج التعليميقاعدة البيانات__سلسلة_الاتصال | مونجودب: //xxxxxxxxx |
| البرنامج التعليمي قاعدة البيانات__DatabaseName | com.tutudb |
| قاعدة بيانات البرنامج التعليمي__ اسم مجموعة البرنامج التعليمي | دروس |
https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger#aspnet-core-applications
أضف حزمة ApplicationInsights
dotnet add package Microsoft.ApplicationInsights.AspNetCore --version 2.21.0...