WIP
This commit is contained in:
2
tests/Solar.Api.Tests/.gitignore
vendored
Normal file
2
tests/Solar.Api.Tests/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
bin/
|
||||
obj/
|
||||
20
tests/Solar.Api.Tests/Controllers/SolarLogController.cs
Normal file
20
tests/Solar.Api.Tests/Controllers/SolarLogController.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Solar.Api.Models;
|
||||
|
||||
namespace Solar.Api.Tests.Controllers;
|
||||
|
||||
[Collection("Default")]
|
||||
public class SolarLogController
|
||||
{
|
||||
private readonly DefaultWebApplicationFactory applicationFactory;
|
||||
|
||||
public SolarLogController(DefaultWebApplicationFactory applicationFactory)
|
||||
{
|
||||
this.applicationFactory = applicationFactory;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDayDetails_returns_for_existing_data()
|
||||
{
|
||||
var client = applicationFactory.CreateClient();
|
||||
}
|
||||
}
|
||||
6
tests/Solar.Api.Tests/DefaultCollectionDefinition.cs
Normal file
6
tests/Solar.Api.Tests/DefaultCollectionDefinition.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Solar.Api.Tests;
|
||||
|
||||
[CollectionDefinition("Default")]
|
||||
public class DefaultCollectionDefinition : ICollectionFixture<DefaultWebApplicationFactory>
|
||||
{
|
||||
}
|
||||
30
tests/Solar.Api.Tests/DefaultWebApplicationFactory.cs
Normal file
30
tests/Solar.Api.Tests/DefaultWebApplicationFactory.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Solar.Api.Tests;
|
||||
|
||||
public class DefaultWebApplicationFactory : WebApplicationFactory<Program>
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
services.AddDbContext<DatabaseContext>(options =>
|
||||
{
|
||||
options.UseSqlite("Data Source=test.db");
|
||||
});
|
||||
});
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
using var provider = services.BuildServiceProvider();
|
||||
using var scope = provider.CreateScope();
|
||||
using var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
||||
|
||||
databaseContext.Database.EnsureCreated();
|
||||
});
|
||||
}
|
||||
}
|
||||
18
tests/Solar.Api.Tests/Extensions/HttpClientExtensions.cs
Normal file
18
tests/Solar.Api.Tests/Extensions/HttpClientExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
using Shouldly;
|
||||
|
||||
namespace Solar.Api.Tests.Extensions;
|
||||
|
||||
public static class HttpClientExtensions
|
||||
{
|
||||
public static async Task<T> FetchJson<T>(this HttpClient client, string path) where T : class
|
||||
{
|
||||
var response = await client.GetAsync(path);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var result = JsonSerializer.Deserialize<T>(await response.Content.ReadAsStringAsync());
|
||||
result.ShouldNotBeNull();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
30
tests/Solar.Api.Tests/Solar.Api.Tests.csproj
Normal file
30
tests/Solar.Api.Tests/Solar.Api.Tests.csproj
Normal file
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="Shouldly" Version="4.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Solar.Api\Solar.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
2
tests/Solar.Api.Tests/Usings.cs
Normal file
2
tests/Solar.Api.Tests/Usings.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
global using Xunit;
|
||||
global using Solar.Api.Tests.Extensions;
|
||||
BIN
tests/Solar.Api.Tests/test.db
Normal file
BIN
tests/Solar.Api.Tests/test.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user