Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di ASP.NET Core
ASP.NET Core
Getting Started with ASP.NET CoreProject Structure and ConfigurationCore ConceptsData, Validation and AuthenticationTestingDeployment
Discussioni

Guida a ASP.NET Core · 5/6

Testing

Per ora questo capitolo è disponibile solo in inglese.

ASP.NET Core apps are usually tested at two levels: unit tests for services and logic, and integration tests that host the whole app in memory with WebApplicationFactory. xUnit is the most widely used test framework in .NET; NUnit and MSTest work in the same way.

Create a test project

dotnet new xunit -o tests/TodoApi.Tests
dotnet add tests/TodoApi.Tests/TodoApi.Tests.csproj reference src/TodoApi/TodoApi.csproj
dotnet add tests/TodoApi.Tests/TodoApi.Tests.csproj package Microsoft.AspNetCore.Mvc.Testing
dotnet sln add tests/TodoApi.Tests/TodoApi.Tests.csproj
dotnet test

dotnet test builds and runs every test project in the solution; editors show the same tests in a test explorer.

Unit tests

Plain classes need no web host at all:

public static class Slug
{
    public static string Create(string title) =>
        string.Join('-', title.ToLowerInvariant().Split(' ', StringSplitOptions.RemoveEmptyEntries));
}
public class SlugTests
{
    [Fact]
    public void Joins_words_with_hyphens()
    {
        Assert.Equal("hello-asp-net", Slug.Create("Hello ASP NET"));
    }

    [Theory]
    [InlineData("  spaced   out ", "spaced-out")]
    [InlineData("One", "one")]
    public void Normalizes_input(string input, string expected)
    {
        Assert.Equal(expected, Slug.Create(input));
    }
}

[Fact] marks a single test and [Theory] runs the same test for each [InlineData] row. When a service has dependencies, depend on interfaces or abstractions such as TimeProvider so tests can pass fakes, written by hand or with a library like NSubstitute or Moq.

Integration tests with WebApplicationFactory

WebApplicationFactory<TEntryPoint> from Microsoft.AspNetCore.Mvc.Testing starts the app on an in-memory test server and hands you an HttpClient. It runs the real Program.cs, configuration and DI, so routing, middleware and serialization are all exercised.

With top-level statements, the compiler-generated Program class is not public. Newer SDKs can generate the declaration below for you; adding it at the end of Program.cs works with every version:

public partial class Program { }
using System.Net;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Mvc.Testing;

public class TodoApiTests(WebApplicationFactory<Program> factory)
    : IClassFixture<WebApplicationFactory<Program>>
{
    [Fact]
    public async Task Get_unknown_todo_returns_404()
    {
        var client = factory.CreateClient();

        var response = await client.GetAsync("/todos/999");

        Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
    }

    [Fact]
    public async Task Post_then_get_returns_the_todo()
    {
        var client = factory.CreateClient();

        var created = await client.PostAsJsonAsync("/todos", new { title = "Write tests" });
        created.EnsureSuccessStatusCode();
        var todo = await created.Content.ReadFromJsonAsync<Todo>();

        var fetched = await client.GetFromJsonAsync<Todo>($"/todos/{todo!.Id}");
        Assert.Equal("Write tests", fetched!.Title);
    }
}
Domande su questo capitolo?
Capitolo precedenteData, Validation and AuthenticationCapitolo successivoDeployment

IClassFixture creates one app per test class and shares it between that class's tests, so tests should not depend on each other's data.

Customizing the test host

Derive from WebApplicationFactory to choose the environment or replace services. ConfigureTestServices runs after the app's own registrations:

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Time.Testing;

public class TodoApiFactory : WebApplicationFactory<Program>
{
    public FakeTimeProvider Time { get; } = new();

    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        builder.UseEnvironment("Testing");
        builder.ConfigureTestServices(services =>
        {
            services.RemoveAll<TimeProvider>();
            services.AddSingleton<TimeProvider>(Time);
        });
    }
}

FakeTimeProvider comes from the Microsoft.Extensions.TimeProvider.Testing package; tests call Time.Advance(...) to move the clock. For the database, point the Testing environment at a throwaway database, or start a real one in Docker with Testcontainers.

dotnet test --filter "FullyQualifiedName~TodoApiTests"
dotnet test --collect:"XPlat Code Coverage"

Summary

  • Create an xUnit project with dotnet new xunit and run it with dotnet test.
  • Unit-test services directly; keep dependencies replaceable.
  • WebApplicationFactory<Program> hosts the real app in memory for integration tests.
  • Override the environment and services in a custom factory with ConfigureTestServices.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.