Skip to content

Instantly share code, notes, and snippets.

@jongalloway
Last active June 4, 2019 03:41
Show Gist options
  • Select an option

  • Save jongalloway/7ca5fb724cb4ed887506249e2812d9c9 to your computer and use it in GitHub Desktop.

Select an option

Save jongalloway/7ca5fb724cb4ed887506249e2812d9c9 to your computer and use it in GitHub Desktop.

Revisions

  1. jongalloway revised this gist Sep 20, 2018. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions health-check-ping.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    [Fact]
    public async Task Get_HealthCheckReturnsHealthy()
    {
    // Arrange
    var client = _factory.CreateClient();

    // Act
    var response = await client.GetAsync("/health");

    // Assert
    response.EnsureSuccessStatusCode(); // Status Code 200-299
    Assert.Equal("Healthy",
    response.Content.ReadAsStringAsync().Result);

    }
  2. jongalloway created this gist Sep 20, 2018.
    38 changes: 38 additions & 0 deletions FunctionalTests.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    using Microsoft.AspNetCore.Mvc.Testing;
    using System;
    using System.Threading.Tasks;
    using Xunit;

    namespace WebApp.Tests
    {
    public class BasicTests
    : IClassFixture<WebApplicationFactory<Startup>>
    {
    private readonly WebApplicationFactory<Startup> _factory;

    public BasicTests(WebApplicationFactory<Startup> factory)
    {
    _factory = factory;
    }

    [Theory]
    [InlineData("/")]
    [InlineData("/Index")]
    [InlineData("/About")]
    [InlineData("/Privacy")]
    [InlineData("/Contact")]
    public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)
    {
    // Arrange
    var client = _factory.CreateClient();

    // Act
    var response = await client.GetAsync(url);

    // Assert
    response.EnsureSuccessStatusCode(); // Status Code 200-299
    Assert.Equal("text/html; charset=utf-8",
    response.Content.Headers.ContentType.ToString());
    }
    }
    }
    21 changes: 21 additions & 0 deletions WebApp.Test.csproj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>

    <IsPackable>false</IsPackable>
    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.2" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
    </ItemGroup>

    <ItemGroup>
    <ProjectReference Include="..\WebApp\WebApp.csproj" />
    </ItemGroup>

    </Project>