-
Notifications
You must be signed in to change notification settings - Fork 34
(#205) AzureSQL query tests on the controller. #207
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
+4,428
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.