Skip to content

Issues/344 #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
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
12 changes: 12 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Datasync Community Toolkit

This is a set of instructions for the GitHub Copilot to support the Datasync Community Toolkit.

## Project Layout

* `/docs` - documentation, mostly Markdown supporting `mkdocs` document generation.
* `/infra` - infrastructure definition to support live testing.
* `/samples` - sample code for the library.
* `/src` - source code for the NuGet packages.
* `/templates` - the template source code.
* `/tests` - the test projects
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
<PackageVersion Include="System.Text.Json" Version="9.0.4" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="9.0.4" />
<PackageVersion Include="TestContainers.MySql" Version="4.4.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
89 changes: 0 additions & 89 deletions infra/modules/mysql.bicep

This file was deleted.

15 changes: 0 additions & 15 deletions infra/resources.bicep
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@ var appServiceName = 'web-${resourceToken}'
var azsqlServerName = 'sql-${resourceToken}'
var cosmosServerName = 'cosmos-${resourceToken}'
var pgsqlServerName = 'pgsql-${resourceToken}'
var mysqlServerName = 'mysql-${resourceToken}'
var mongoServerName = 'mongo-${resourceToken}'
var mongoaciServerName = 'mongoaci-${resourceToken}'

@@ -81,19 +80,6 @@ module pgsql './modules/postgresql.bicep' = {
}
}

module mysql './modules/mysql.bicep' = {
name: 'mysql-deployment-${resourceToken}'
params: {
location: location
tags: tags
databaseName: testDatabaseName
firewallRules: clientIpFirewallRules
sqlServerName: mysqlServerName
sqlAdminUsername: sqlAdminUsername
sqlAdminPassword: sqlAdminPassword
}
}

module cosmos './modules/cosmos.bicep' = {
name: 'cosmos-deployment-${resourceToken}'
params: {
@@ -150,6 +136,5 @@ output AZSQL_CONNECTIONSTRING string = azuresql.outputs.AZSQL_CONNECTIONSTRING
output COSMOS_CONNECTIONSTRING string = cosmos.outputs.COSMOS_CONNECTIONSTRING
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGO_CONNECTIONSTRING
output MONGOACI_CONNECTIONSTRING string = mongoaci.outputs.MONGO_CONNECTIONSTRING
output MYSQL_CONNECTIONSTRING string = mysql.outputs.MYSQL_CONNECTIONSTRING
output PGSQL_CONNECTIONSTRING string = pgsql.outputs.PGSQL_CONNECTIONSTRING
output SERVICE_ENDPOINT string = app_service.outputs.SERVICE_ENDPOINT
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

using CommunityToolkit.Datasync.TestCommon;
using CommunityToolkit.Datasync.TestCommon.Databases;
using CommunityToolkit.Datasync.TestCommon.Fixtures;
using Microsoft.EntityFrameworkCore;
using Xunit.Abstractions;

@@ -13,19 +14,16 @@ namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test;

[ExcludeFromCodeCoverage]
[Collection("LiveTestsCollection")]
public class MysqlEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : RepositoryTests<MysqlEntityMovie>, IAsyncLifetime
public class MysqlEntityTableRepository_Tests(MySqlDatabaseFixture fixture, ITestOutputHelper output) : RepositoryTests<MysqlEntityMovie>, IClassFixture<MySqlDatabaseFixture>, IAsyncLifetime
{
#region Setup
private readonly Random random = new();
private List<MysqlEntityMovie> movies = [];

public async Task InitializeAsync()
{
if (!string.IsNullOrEmpty(ConnectionStrings.MySql))
{
Context = await MysqlDbContext.CreateContextAsync(ConnectionStrings.MySql, output);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
}
Context = await MysqlDbContext.CreateContextAsync(fixture.ConnectionString, output);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
}

public async Task DisposeAsync()
@@ -38,7 +36,7 @@ public async Task DisposeAsync()

private MysqlDbContext Context { get; set; }

protected override bool CanRunLiveTests() => !string.IsNullOrEmpty(ConnectionStrings.MySql);
protected override bool CanRunLiveTests() => true;

protected override async Task<MysqlEntityMovie> GetEntityAsync(string id)
=> await Context.Movies.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id);
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using CommunityToolkit.Datasync.Server.EntityFrameworkCore;
using CommunityToolkit.Datasync.Server.Test.Helpers;
using CommunityToolkit.Datasync.TestCommon.Databases;
using CommunityToolkit.Datasync.TestCommon.Fixtures;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Xunit.Abstractions;
@@ -13,24 +14,16 @@ namespace CommunityToolkit.Datasync.Server.Test.Live;

[ExcludeFromCodeCoverage]
[Collection("LiveTestsCollection")]
public class MySQL_Controller_Tests(DatabaseFixture fixture, ITestOutputHelper output) : LiveControllerTests<MysqlEntityMovie>, IAsyncLifetime
public class MySQL_Controller_Tests(MySqlDatabaseFixture fixture, ITestOutputHelper output) : LiveControllerTests<MysqlEntityMovie>, IClassFixture<MySqlDatabaseFixture>, IAsyncLifetime
{
#region Setup
private readonly Random random = new();
private List<MysqlEntityMovie> movies = [];

public async Task InitializeAsync()
{
if (!string.IsNullOrEmpty(ConnectionStrings.MySql))
{
// Note: we don't clear entities on every run to speed up the test runs. This can only be done because
// the tests are read-only (associated with the query and get capabilities). If the test being run writes
// to the database then change clearEntities to true.
output.WriteLine($"MysqlIsInitialized = {fixture.MysqlIsInitialized}");
Context = await MysqlDbContext.CreateContextAsync(ConnectionStrings.MySql, output, clearEntities: !fixture.MysqlIsInitialized);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
fixture.MysqlIsInitialized = true;
}
Context = await MysqlDbContext.CreateContextAsync(fixture.ConnectionString, output);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
}

public async Task DisposeAsync()
@@ -45,7 +38,7 @@ public async Task DisposeAsync()

protected override string DriverName { get; } = "MySQL";

protected override bool CanRunLiveTests() => !string.IsNullOrEmpty(ConnectionStrings.MySql);
protected override bool CanRunLiveTests() => true;

protected override async Task<MysqlEntityMovie> GetEntityAsync(string id)
=> await Context.Movies.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
@@ -20,6 +20,7 @@
<PackageReference Include="Microsoft.Spatial" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" />
<PackageReference Include="TestContainers.MySql" />
</ItemGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@ public static class ConnectionStrings
public static readonly string CosmosDb = Environment.GetEnvironmentVariable("COSMOS_CONNECTION_STRING");
public static readonly string MongoCommunity = Environment.GetEnvironmentVariable("MONGOACI_CONNECTION_STRING");
public static readonly string CosmosMongo = Environment.GetEnvironmentVariable("MONGO_CONNECTION_STRING");
public static readonly string MySql = Environment.GetEnvironmentVariable("MYSQL_CONNECTION_STRING");
public static readonly string PgSql = Environment.GetEnvironmentVariable("PGSQL_CONNECTION_STRING");

public static readonly string Service = Environment.GetEnvironmentVariable("SERVICE_ENDPOINT");
public static readonly bool EnableLogging = (Environment.GetEnvironmentVariable("ENABLE_SQL_LOGGING") ?? "false") == "true";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Testcontainers.MySql;
using Xunit;

namespace CommunityToolkit.Datasync.TestCommon.Fixtures;

/// <summary>
/// A test fixture for impementing a MySQL database using Testcontainers.
/// </summary>
[ExcludeFromCodeCoverage]
public class MySqlDatabaseFixture : IAsyncLifetime
{
private readonly MySqlContainer _container;

public MySqlDatabaseFixture()
{
this._container = new MySqlBuilder()
.WithImage("mysql:lts-oracle")
.WithCleanUp(true)
.WithUsername("testuser")
.WithPassword("testpassword")
.WithDatabase("testdb")
.Build();
}

/// <inheritdoc />
public async Task DisposeAsync()
{
if (this._container is not null)
{
await this._container.DisposeAsync();
}
}

/// <inheritdoc />
public async Task InitializeAsync()
{
await this._container.StartAsync();
ConnectionString = this._container.GetConnectionString();
}

/// <summary>
/// The connection string for the MySQL database.
/// </summary>
public string ConnectionString { get; private set; } = string.Empty;
}
Empty file.