Skip to content

Latest commit

 

History

History
52 lines (45 loc) · 2.67 KB

Boxed.DotnetNewTest.md

File metadata and controls

52 lines (45 loc) · 2.67 KB

.NET Boxed Banner

Boxed.DotnetNewTest

Boxed.DotnetNewTest Boxed.DotnetNewTest package in dotnet-boxed feed in Azure Artifacts Boxed.DotnetNewTest NuGet Package Downloads

A unit test framework for project templates built using dotnet new.

  1. Install dotnet new based project templates from a directory.
  2. Run dotnet restore, dotnet build and dotnet publish commands.
  3. For ASP.NET Core project templates you can run dotnet run which gives you a HttpClient that you can use to call the app and run further tests.
public class ApiTemplateTest
{
    public ApiTemplateTest() => DotnetNew.Install<ApiTemplateTest>("ApiTemplate.sln").Wait();

    [Theory]
    [InlineData("StatusEndpointOn", "status-endpoint=true")]
    [InlineData("StatusEndpointOff", "status-endpoint=false")]
    public async Task RestoreAndBuild_CustomArguments_IsSuccessful(string name, params string[] arguments)
    {
        using (var tempDirectory = TempDirectory.NewTempDirectory())
        {
            var dictionary = arguments
                .Select(x => x.Split('=', StringSplitOptions.RemoveEmptyEntries))
                .ToDictionary(x => x.First(), x => x.Last());
            var project = await tempDirectory.DotnetNew("api", name, dictionary);
            await project.DotnetRestore();
            await project.DotnetBuild();
        }
    }

    [Fact]
    public async Task Run_DefaultArguments_IsSuccessful()
    {
        using (var tempDirectory = TempDirectory.NewTempDirectory())
        {
            var project = await tempDirectory.DotnetNew("api", "DefaultArguments");
            await project.DotnetRestore();
            await project.DotnetBuild();
            await project.DotnetRun(
                @"Source\DefaultArguments",
                async (httpClient, httpsClient) =>
                {
                    var httpResponse = await httpsClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
                });
        }
    }
}