Skip to content
Open
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AspirePreviewSuffix>-preview.1.26170.3</AspirePreviewSuffix>
<AspNetCoreVersion>9.0.0</AspNetCoreVersion>
<DotNetExtensionsVersion>10.0.5</DotNetExtensionsVersion>
<OpenTelemetryVersion>1.12.0</OpenTelemetryVersion>
<OpenTelemetryVersion>1.15.3</OpenTelemetryVersion>
<TestContainersVersion>4.8.1</TestContainersVersion>
<MEAIVersion>10.0.0</MEAIVersion>
<ServiceDiscoveryVersion>10.0.0</ServiceDiscoveryVersion>
Expand Down
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
<!-- OpenTelemetry packages -->
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="$(OpenTelemetryVersion)-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
<PackageVersion Include="OpenTelemetry.Exporter.InMemory" Version="$(OpenTelemetryVersion)" />
</ItemGroup>
<ItemGroup Label="Build Dependencies">
Expand Down Expand Up @@ -87,8 +87,8 @@
<PackageVersion Include="RavenDB.Client" Version="6.2.1" />
<PackageVersion Include="RavenDB.TestDriver" Version="6.2.1" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
<PackageVersion Include="SurrealDb.MinimalApis.Extensions" Version="0.9.0" />
<PackageVersion Include="SurrealDb.Net" Version="0.9.0" />
<PackageVersion Include="SurrealDb.MinimalApis.Extensions" Version="0.10.2" />
<PackageVersion Include="SurrealDb.Net" Version="0.10.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.3.1" />
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.10" />
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using SurrealDb.Net.Models;
using System.ComponentModel.DataAnnotations.Schema;

namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models;

[Table(Table)]
public class Todo : Record
{
internal const string Table = "todo";

[Column("title")]
public string? Title { get; set; }

[Column("due_by")]
public DateOnly? DueBy { get; set; } = null;

[Column("is_complete")]
public bool IsComplete { get; set; } = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Bogus;

namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models;

/// <summary>
/// Faker test class to generate fake <see cref="Todo"/> objects.
/// </summary>
public class TodoFaker : Faker<Todo>
{
public TodoFaker()
{
RuleFor(o => o.Title, f => f.Lorem.Sentence());
RuleFor(o => o.DueBy, f => f.Date.FutureDateOnly());
RuleFor(o => o.IsComplete, f => f.Random.Bool());
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
using SurrealDb.Net.Models;
using System.ComponentModel.DataAnnotations.Schema;

namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models;

/// <summary>
/// Weather forecast model.
/// </summary>
[Table(Table)]
public class WeatherForecast : Record
{
internal const string Table = "weatherForecast";

/// <summary>
/// Date of the weather forecast.
/// </summary>
[Column("date")]
public DateTime Date { get; set; }

/// <summary>
/// Country of the weather forecast.
/// </summary>
[Column("country")]
public string? Country { get; set; }

/// <summary>
/// Temperature in Celsius.
/// </summary>
[Column("temperature_c")]
public int TemperatureC { get; set; }

/// <summary>
/// Temperature in Fahrenheit.
/// </summary>
[Column("temperature_f")]
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

/// <summary>
/// Summary of the weather forecast.
/// </summary>
[Column("summary")]
public string? Summary { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models;

/// <summary>
/// Faker test class to generate fake WeatherForecast objects.
/// Faker test class to generate fake <see cref="WeatherForecast"/> objects.
/// </summary>
public class WeatherForecastFaker : Faker<WeatherForecast>
{
Expand All @@ -21,9 +21,6 @@ public class WeatherForecastFaker : Faker<WeatherForecast>
"Scorching"
};

/// <summary>
/// Constructor
/// </summary>
public WeatherForecastFaker()
{
RuleFor(o => o.Date, f => f.Date.Recent());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
using CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models;
using Microsoft.AspNetCore.Mvc;
using SurrealDb.Net;

var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;

builder.AddServiceDefaults();

builder.AddSurrealClient("db", settings =>
{
settings.Options!.NamingPolicy = "CamelCase";
});
builder.AddSurrealClient("db");

var app = builder.Build();

app.MapDefaultEndpoints();

app.MapGroup("/api")
.MapSurrealEndpoints<WeatherForecast>(
.MapSurrealEndpoints<WeatherForecast, SurrealDbSession>(
"/weatherForecast",
new() { EnableMutations = false }
)
.MapSurrealEndpoints<Todo>("/todo");
.MapSurrealEndpoints<Todo, SurrealDbSession>("/todo");

app.MapPost("/init", InitializeDbAsync);

app.Run();

Task InitializeDbAsync(ISurrealDbClient surrealDbClient)
Task InitializeDbAsync()
{
const int initialCount = 5;
var weatherForecasts = new WeatherForecastFaker().Generate(initialCount);

var tasks = weatherForecasts.Select(weatherForecast =>
surrealDbClient.Create(WeatherForecast.Table, weatherForecast)
var todos = new TodoFaker().Generate(initialCount);

var surrealDbClient = new SurrealDbClient(
SurrealDbOptions
.Create()
.FromConnectionString(configuration.GetConnectionString("db")!)
.Build()
);

return Task.WhenAll(tasks);
var weatherForecastTasks = weatherForecasts.Select(async weatherForecast => {
await surrealDbClient.Create(WeatherForecast.Table, weatherForecast);
return Task.CompletedTask;
});

var todoTasks = todos.Select(async todo => {
await surrealDbClient.Create(Todo.Table, todo);
return Task.CompletedTask;
});

return Task.WhenAll(weatherForecastTasks.Concat(todoTasks));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ internal sealed class SurrealDbContainerImageTags
public const string Registry = "docker.io";
/// <summary>surrealdb/surrealdb</summary>
public const string Image = "surrealdb/surrealdb";
/// <summary>v2.4</summary>
public const string Tag = "v2.4";
/// <summary>v3.0</summary>
public const string Tag = "v3.0";

/// <summary>docker.io</summary>
public const string SurrealistRegistry = "docker.io";
/// <summary>surrealdb/surrealist</summary>
public const string SurrealistImage = "surrealdb/surrealist";
/// <summary>3.6.9</summary>
public const string SurrealistTag = "3.6.9";
/// <summary>3.8.3</summary>
public const string SurrealistTag = "3.8.3";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public sealed class SurrealDbClientSettings
/// Gets or sets the Service lifetime to register services under.
/// </summary>
/// <value>
/// The default value is <see langword="ServiceLifetime.Singleton"/>.
/// The default value is <see langword="ServiceLifetime.Scoped"/>.
/// </value>
public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Singleton;
public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Scoped;

/// <summary>
/// Gets or sets a boolean value that indicates whether the SurrealDB health check is disabled or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public async Task ApiServiceStartsAndRespondsOk()
await fixture.ResourceNotificationService.WaitForResourceHealthyAsync(resourceName).WaitAsync(TimeSpan.FromMinutes(1));
var httpClient = fixture.CreateHttpClient(resourceName);

var todoResponse = await httpClient.GetAsync("/api/todo");
Assert.Equal(HttpStatusCode.OK, todoResponse.StatusCode);

var initResponse = await httpClient.PostAsync("/init", null);
Assert.Equal(HttpStatusCode.OK, initResponse.StatusCode);

var todoResponse = await httpClient.GetAsync("/api/todo");
Assert.Equal(HttpStatusCode.OK, todoResponse.StatusCode);

var weatherForecastResponse = await httpClient.GetAsync("/api/weatherForecast");
Assert.Equal(HttpStatusCode.OK, weatherForecastResponse.StatusCode);
Expand Down
Loading