Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public async Task GivenThatPlanetDoesNotExist_WhenAddPlanetEndpointIsInvoked_The
{
Name = "Mars",
Mass = 6.4171,
Radius = 3389.5
Radius = 3389.5,
OrbitalPeriod = 686.98
};

// Act
Expand All @@ -30,8 +31,9 @@ public async Task GivenThatPlanetExist_WhenAddPlanetEndpointIsInvoked_Then400IsR
var planet = new Planet
{
Name = "Venus",
Mass = 6.4171,
Radius = 3389.5
Mass = 4.8675,
Radius = 6051.8,
OrbitalPeriod = 224.7
};

// Act
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace UniqueConstraintsInEFCore.Tests;
namespace UniqueConstraintsInEFCore.Tests;

public class SolarSystemApiApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build();
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder("mcr.microsoft.com/mssql/server:2022-latest").Build();

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Testcontainers.MsSql" Version="3.7.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="coverlet.collector" Version="10.0.1" />
<PackageReference Include="FluentAssertions" Version="7.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageReference Include="Testcontainers.MsSql" Version="4.15.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class Planet
public required string Name { get; set; }
public required double Mass { get; set; }
public required double Radius { get; set; }
public required double OrbitalPeriod { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using UniqueConstraintsInEFCore.Data;
using UniqueConstraintsInEFCore.Data.Models;
using UniqueConstraintsInEFCore.Services;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddOpenApi();

builder.Services.AddHostedService<InitializationService>();

Expand All @@ -17,8 +16,7 @@

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
}

app.UseHttpsRedirection();
Expand All @@ -27,18 +25,17 @@
{
try
{
await context.Planets.AddAsync(planet);
context.Planets.Add(planet);
await context.SaveChangesAsync();

return Results.Created($"/planets/{planet.Id}", planet);
}
catch
catch (DbUpdateException)
{
return Results.BadRequest();
}
})
.WithName("AddPlanet")
.WithOpenApi();
.WithName("AddPlanet");

app.Run();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.12" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Logging": {
"LogLevel": {
"Default": "Information",
Expand All @@ -7,6 +7,6 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"SolarSystemDatabase": "Server=127.0.0.1,1433; Database=Master ;User Id=SA; Password=yourStrong(!)Password; TrustServerCertificate=True"
"SolarSystemDatabase": "Server=127.0.0.1,1433; Database=SolarSystem;User Id=SA; Password=yourStrong(!)Password; TrustServerCertificate=True"
}
}
Loading