Init repo
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MissionControl.Domain.Entities;
|
||||
using MissionControl.Server.Endpoints.Missions;
|
||||
using Shouldly;
|
||||
|
||||
namespace MissionControl.Server.Tests.Endpoints.Missions;
|
||||
|
||||
public class CreateMissionTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Creates_a_planned_mission_and_saves_it()
|
||||
{
|
||||
using var database = new TestDatabase();
|
||||
var endpoint = Factory.Create<CreateMission>(database.Context);
|
||||
var request = new CreateMissionRequest
|
||||
{
|
||||
Name = "Orbital Bloom",
|
||||
Description = "Grow the first orchard in orbit.",
|
||||
};
|
||||
|
||||
await endpoint.HandleAsync(request, CancellationToken.None);
|
||||
|
||||
var saved = await database.Context.Missions.SingleAsync();
|
||||
saved.Name.ShouldBe("Orbital Bloom");
|
||||
saved.Status.ShouldBe(MissionStatus.Planned);
|
||||
endpoint.Response.Id.ShouldBe(saved.Id);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Rejects_a_blank_mission_name(string name)
|
||||
{
|
||||
var validator = new CreateMissionRequestValidator();
|
||||
|
||||
var result = validator.Validate(new CreateMissionRequest { Name = name });
|
||||
|
||||
result.IsValid.ShouldBeFalse();
|
||||
result.Errors.ShouldContain(e => e.PropertyName == nameof(CreateMissionRequest.Name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="6.0.0" />
|
||||
<PackageReference Include="Shouldly" Version="4.3.0" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.4" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\MissionControl.Server\MissionControl.Server.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MissionControl.Data;
|
||||
|
||||
namespace MissionControl.Server.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// An in-memory SQLite database that speaks real EF Core, for fast endpoint tests
|
||||
/// without a SQL Server instance.
|
||||
/// </summary>
|
||||
public sealed class TestDatabase : IDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection = new("DataSource=:memory:");
|
||||
|
||||
public TestDatabase()
|
||||
{
|
||||
_connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<MissionControlContext>()
|
||||
.UseSqlite(_connection)
|
||||
.Options;
|
||||
|
||||
Context = new MissionControlContext(options);
|
||||
Context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public MissionControlContext Context { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Context.Dispose();
|
||||
_connection.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user