ASP.NET es un marco web de código abierto, creado por Microsoft, para crear aplicaciones y servicios web modernos con .NET. ASP.NET es multiplataforma y se ejecuta en Windows, Linux, macOS y Docker.
más: https://dotnet.microsoft.com/en-us/learn/aspnet/what-is-aspnet
Crear proyecto de solución
dotnet new sln -n Tutorial-ApiCrear un proyecto ASP.NET Web Api
dotnet new webapi -o ApiCrear proyecto XUnit
dotnet new xunit -o Xunit.TestsAgregar proyectos a la solución
dotnet sln add .Tutorial.ApiTutorial.Api.csproj
dotnet sln add .XUnit.TestsXUnit.Tests.csprojAgregar proyecto de referencia al proyecto xunit
dotnet add . /XUnit.Tests/XUnit.Tests.csproj reference .Tutorial.ApiTutorial.Api.csproj Agregue el controlador MongoDB de dependencia al proyecto
dotnet add package MongoDB.Driver --version 2.18.0mangosta
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/Arrogancia: https://localhost:7272/arrogancia

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run#examples
OBTENER /api/tutoriales
Respuesta
[
{
"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 "
}
]OBTENER /api/tutoriales/{id}
Respuesta
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
}ENVIAR /api/tutoriales
Cuerpo de solicitud
{
"title" : " string " ,
"description" : " string " ,
}Cuerpo de respuesta
{
"code" : " 200 " ,
"message" : " Inserted a single document Success "
}BORRAR /api/tutoriales
Cuerpo de respuesta
{
"code" : " 200 " ,
"message" : " All deleted "
}BORRAR /api/tutoriales/{id}
Cuerpo de respuesta
{
"code" : " 200 " ,
"message" : " Deleted id 63730beabd3cb05f2331be45 "
}PUT /api/tutoriales/{id}
Cuerpo de solicitud
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : true
}Cuerpo de respuesta
{
"code" : " 200 " ,
"message" : " Deleted id 63730beabd3cb05f2331be45 "
} dotnet buildRestaurar como capas distintas
dotnet restoreCrear y publicar una versión
dotnet publish -c Release -o out Ejecutar cobertura
dotnet test --collect:"XPlat Code Coverage"Agregar nuget ReportGenerator
dotnet add package ReportGenerator --version 5.1.10Herramienta de configuración ReportGenerator
dotnet tool install -g dotnet-reportgenerator-globaltoolmás: https://www.nuget.org/packages/ReportGenerator
reportgenerator -reports:"XUnit.TestsTestResults*coverage.cobertura.xml" -targetdir:". /coveragereport" -reporttypes:Html Variables ambientales
| Nombre del entorno | Valor |
|---|---|
| TutorialBase de datos__ConnectionString | mongodb://xxxxxxxx |
| TutorialBase de datos__Nombre de la base de datos | tutorialdb |
| TutorialDatabase__TutorialCollectionName | tutoriales |
https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger#aspnet-core-applications
Agregar paquete ApplicationInsights
dotnet add package Microsoft.ApplicationInsights.AspNetCore --version 2.21.0...