From 9c225598adc614b77e9df1909f0ede0763e9d6b1 Mon Sep 17 00:00:00 2001 From: Adrian Hall Date: Fri, 10 Jan 2025 12:49:29 -0800 Subject: [PATCH] (#187) Serialize tests for better reliability --- .../AzureSqlEntityTableRepository_Tests.cs | 5 ++++- .../CosmosEntityTableRepository_Tests.cs | 5 ++++- .../LiveTestsCollection.cs | 21 +++++++++++++++++++ .../PgEntityTableRepository_Tests.cs | 5 ++++- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/LiveTestsCollection.cs diff --git a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/AzureSqlEntityTableRepository_Tests.cs b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/AzureSqlEntityTableRepository_Tests.cs index 0291eeab..0511b1b7 100644 --- a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/AzureSqlEntityTableRepository_Tests.cs +++ b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/AzureSqlEntityTableRepository_Tests.cs @@ -10,16 +10,19 @@ namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test; [ExcludeFromCodeCoverage] +[Collection("LiveTestsCollection")] public class AzureSqlEntityTableRepository_Tests : RepositoryTests { #region Setup + private readonly DatabaseFixture _fixture; private readonly Random random = new(); private readonly string connectionString; private readonly List movies; private readonly Lazy _context; - public AzureSqlEntityTableRepository_Tests(ITestOutputHelper output) : base() + public AzureSqlEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base() { + this._fixture = fixture; this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_AZSQL_CONNECTIONSTRING"); if (!string.IsNullOrEmpty(this.connectionString)) { diff --git a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/CosmosEntityTableRepository_Tests.cs b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/CosmosEntityTableRepository_Tests.cs index 4a842578..b9d9f59e 100644 --- a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/CosmosEntityTableRepository_Tests.cs +++ b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/CosmosEntityTableRepository_Tests.cs @@ -10,16 +10,19 @@ namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test; [ExcludeFromCodeCoverage] +[Collection("LiveTestsCollection")] public class CosmosEntityTableRepository_Tests : RepositoryTests { #region Setup + private readonly DatabaseFixture _fixture; private readonly Random random = new(); private readonly string connectionString; private readonly List movies; private readonly Lazy _context; - public CosmosEntityTableRepository_Tests(ITestOutputHelper output) : base() + public CosmosEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base() { + this._fixture = fixture; this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_COSMOS_CONNECTIONSTRING"); if (!string.IsNullOrEmpty(this.connectionString)) { diff --git a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/LiveTestsCollection.cs b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/LiveTestsCollection.cs new file mode 100644 index 00000000..0f8378a4 --- /dev/null +++ b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/LiveTestsCollection.cs @@ -0,0 +1,21 @@ +// 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. + +namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test; + +/// +/// This can be used to share state between the various live tests. It isn't used right now. +/// +public class DatabaseFixture +{ + +} + +[CollectionDefinition("LiveTestsCollection", DisableParallelization = true)] +public class LiveTestsCollection : ICollectionFixture +{ + // This class has no code, and is never created. Its purpose is simply + // to be the place to apply [CollectionDefinition] and all the + // ICollectionFixture<> interfaces. +} diff --git a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/PgEntityTableRepository_Tests.cs b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/PgEntityTableRepository_Tests.cs index 6be12b2c..0f061471 100644 --- a/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/PgEntityTableRepository_Tests.cs +++ b/tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/PgEntityTableRepository_Tests.cs @@ -10,16 +10,19 @@ namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test; [ExcludeFromCodeCoverage] +[Collection("LiveTestsCollection")] public class PgEntityTableRepository_Tests : RepositoryTests { #region Setup + private readonly DatabaseFixture _fixture; private readonly Random random = new(); private readonly string connectionString; private readonly List movies; private readonly Lazy _context; - public PgEntityTableRepository_Tests(ITestOutputHelper output) : base() + public PgEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base() { + this._fixture = fixture; this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_PGSQL_CONNECTIONSTRING"); if (!string.IsNullOrEmpty(this.connectionString)) {