-
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.
(#205) AzureSQL query tests on the controller.
- Loading branch information
1 parent
7ee4c9b
commit 63210cf
Showing
3 changed files
with
4,428 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
tests/CommunityToolkit.Datasync.Server.Test/Helpers/LiveTestsCollection.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,22 @@ | ||
// 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.Test.Helpers; | ||
|
||
/// <summary> | ||
/// This can be used to share state between the various live tests. It isn't used right now. | ||
/// </summary> | ||
public class DatabaseFixture | ||
{ | ||
|
||
} | ||
|
||
[CollectionDefinition("LiveTestsCollection", DisableParallelization = true)] | ||
public class LiveTestsCollection : ICollectionFixture<DatabaseFixture> | ||
{ | ||
// 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. | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
tests/CommunityToolkit.Datasync.Server.Test/Live/AzureSQL/Controller_Query_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.AzureSQL; | ||
|
||
[ExcludeFromCodeCoverage] | ||
[Collection("LiveTestsCollection")] | ||
public class AzureSql_Controller_Query_Tests : LiveControllerTests<AzureSqlEntityMovie> | ||
{ | ||
#region Setup | ||
private readonly DatabaseFixture _fixture; | ||
private readonly Random random = new(); | ||
private readonly string connectionString; | ||
private readonly List<AzureSqlEntityMovie> movies; | ||
private readonly Lazy<AzureSqlDbContext> _context; | ||
|
||
public AzureSql_Controller_Query_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base() | ||
{ | ||
this._fixture = fixture; | ||
this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_AZSQL_CONNECTIONSTRING"); | ||
if (!string.IsNullOrEmpty(this.connectionString)) | ||
{ | ||
this._context = new Lazy<AzureSqlDbContext>(() => AzureSqlDbContext.CreateContext(this.connectionString, output)); | ||
this.movies = [.. Context.Movies.AsNoTracking()]; | ||
} | ||
} | ||
|
||
private AzureSqlDbContext Context { get => this._context.Value; } | ||
|
||
protected override bool CanRunLiveTests() => !string.IsNullOrEmpty(this.connectionString); | ||
|
||
protected override Task<AzureSqlEntityMovie> 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<AzureSqlEntityMovie>> GetPopulatedRepositoryAsync() | ||
=> Task.FromResult<IRepository<AzureSqlEntityMovie>>(new EntityTableRepository<AzureSqlEntityMovie>(Context)); | ||
|
||
protected override Task<string> GetRandomEntityIdAsync(bool exists) | ||
=> Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : Guid.NewGuid().ToString()); | ||
#endregion | ||
} |
Oops, something went wrong.