-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8c81e9
commit 24ec586
Showing
3 changed files
with
92 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/CommunityToolkit.Datasync.Server.Test/Live/PgSQL_Controller_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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 CommunityToolkit.Datasync.Server.EntityFrameworkCore; | ||
using CommunityToolkit.Datasync.Server.Test.Helpers; | ||
using CommunityToolkit.Datasync.TestCommon.Databases; | ||
using Microsoft.EntityFrameworkCore; | ||
using Xunit.Abstractions; | ||
|
||
namespace CommunityToolkit.Datasync.Server.Test.Live; | ||
|
||
[ExcludeFromCodeCoverage] | ||
[Collection("LiveTestsCollection")] | ||
public class PgSQL_Controller_Tests : LiveControllerTests<PgEntityMovie> | ||
{ | ||
#region Setup | ||
private readonly DatabaseFixture _fixture; | ||
private readonly Random random = new(); | ||
private readonly string connectionString; | ||
private readonly List<PgEntityMovie> movies; | ||
private readonly Lazy<PgDbContext> _context; | ||
|
||
public PgSQL_Controller_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base() | ||
{ | ||
this._fixture = fixture; | ||
this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_PGSQL_CONNECTIONSTRING"); | ||
if (!string.IsNullOrEmpty(this.connectionString)) | ||
{ | ||
this._context = new Lazy<PgDbContext>(() => PgDbContext.CreateContext(this.connectionString, output)); | ||
this.movies = Context.Movies.AsNoTracking().ToList(); | ||
} | ||
} | ||
|
||
private PgDbContext Context { get => this._context.Value; } | ||
|
||
protected override bool CanRunLiveTests() => !string.IsNullOrEmpty(this.connectionString); | ||
|
||
protected override Task<PgEntityMovie> GetEntityAsync(string id) | ||
=> Task.FromResult(Context.Movies.AsNoTracking().SingleOrDefault(m => m.Id == id)); | ||
|
||
protected override Task<int> GetEntityCountAsync() | ||
=> Task.FromResult(Context.Movies.Count()); | ||
|
||
protected override Task<IRepository<PgEntityMovie>> GetPopulatedRepositoryAsync() | ||
=> Task.FromResult<IRepository<PgEntityMovie>>(new EntityTableRepository<PgEntityMovie>(Context)); | ||
|
||
protected override Task<string> GetRandomEntityIdAsync(bool exists) | ||
=> Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : Guid.NewGuid().ToString()); | ||
#endregion | ||
} |