diff --git a/Directory.Build.props b/Directory.Build.props index 3712834b7..f7335a490 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -16,7 +16,7 @@ -preview.1.26170.3 9.0.0 10.0.5 - 1.12.0 + 1.15.3 4.8.1 10.0.0 10.0.0 diff --git a/Directory.Packages.props b/Directory.Packages.props index 668a4938a..32ac1a301 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -55,10 +55,10 @@ - + - - + + @@ -87,8 +87,8 @@ - - + + diff --git a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/Todo.cs b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/Todo.cs index c4981aa71..ac82b7946 100644 --- a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/Todo.cs +++ b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/Todo.cs @@ -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; } \ No newline at end of file diff --git a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/TodoFaker.cs b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/TodoFaker.cs new file mode 100644 index 000000000..fda23c38a --- /dev/null +++ b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/TodoFaker.cs @@ -0,0 +1,16 @@ +using Bogus; + +namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; + +/// +/// Faker test class to generate fake objects. +/// +public class TodoFaker : Faker +{ + 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()); + } +} \ No newline at end of file diff --git a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecast.cs b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecast.cs index a90521be4..20d238b90 100644 --- a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecast.cs +++ b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecast.cs @@ -1,10 +1,12 @@ using SurrealDb.Net.Models; +using System.ComponentModel.DataAnnotations.Schema; namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; /// /// Weather forecast model. /// +[Table(Table)] public class WeatherForecast : Record { internal const string Table = "weatherForecast"; @@ -12,25 +14,30 @@ public class WeatherForecast : Record /// /// Date of the weather forecast. /// + [Column("date")] public DateTime Date { get; set; } /// /// Country of the weather forecast. /// + [Column("country")] public string? Country { get; set; } /// /// Temperature in Celsius. /// + [Column("temperature_c")] public int TemperatureC { get; set; } /// /// Temperature in Fahrenheit. /// + [Column("temperature_f")] public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); /// /// Summary of the weather forecast. /// + [Column("summary")] public string? Summary { get; set; } } \ No newline at end of file diff --git a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecastFaker.cs b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecastFaker.cs index 027fbe81e..3aa6fb8f3 100644 --- a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecastFaker.cs +++ b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecastFaker.cs @@ -3,7 +3,7 @@ namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; /// -/// Faker test class to generate fake WeatherForecast objects. +/// Faker test class to generate fake objects. /// public class WeatherForecastFaker : Faker { @@ -21,9 +21,6 @@ public class WeatherForecastFaker : Faker "Scorching" }; - /// - /// Constructor - /// public WeatherForecastFaker() { RuleFor(o => o.Date, f => f.Date.Recent()); diff --git a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Program.cs b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Program.cs index 0f13ace2e..f4ea51949 100644 --- a/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Program.cs +++ b/examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Program.cs @@ -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( + .MapSurrealEndpoints( "/weatherForecast", new() { EnableMutations = false } ) - .MapSurrealEndpoints("/todo"); + .MapSurrealEndpoints("/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)); } \ No newline at end of file diff --git a/src/CommunityToolkit.Aspire.Hosting.SurrealDb/SurrealDbContainerImageTags.cs b/src/CommunityToolkit.Aspire.Hosting.SurrealDb/SurrealDbContainerImageTags.cs index b2ec7e980..2ddb01068 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SurrealDb/SurrealDbContainerImageTags.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SurrealDb/SurrealDbContainerImageTags.cs @@ -9,13 +9,13 @@ internal sealed class SurrealDbContainerImageTags public const string Registry = "docker.io"; /// surrealdb/surrealdb public const string Image = "surrealdb/surrealdb"; - /// v2.4 - public const string Tag = "v2.4"; + /// v3.0 + public const string Tag = "v3.0"; /// docker.io public const string SurrealistRegistry = "docker.io"; /// surrealdb/surrealist public const string SurrealistImage = "surrealdb/surrealist"; - /// 3.6.9 - public const string SurrealistTag = "3.6.9"; + /// 3.8.3 + public const string SurrealistTag = "3.8.3"; } \ No newline at end of file diff --git a/src/CommunityToolkit.Aspire.SurrealDb/SurrealDbClientSettings.cs b/src/CommunityToolkit.Aspire.SurrealDb/SurrealDbClientSettings.cs index 02c077197..b03214397 100644 --- a/src/CommunityToolkit.Aspire.SurrealDb/SurrealDbClientSettings.cs +++ b/src/CommunityToolkit.Aspire.SurrealDb/SurrealDbClientSettings.cs @@ -20,9 +20,9 @@ public sealed class SurrealDbClientSettings /// Gets or sets the Service lifetime to register services under. /// /// - /// The default value is . + /// The default value is . /// - public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Singleton; + public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Scoped; /// /// Gets or sets a boolean value that indicates whether the SurrealDB health check is disabled or not. diff --git a/tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/AppHostTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/AppHostTests.cs index 29d1dc54d..e8c4308cc 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/AppHostTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/AppHostTests.cs @@ -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);