public async Task GivenVersion_WhenGettingCurrentVersion_ThenConvertToSchemaVersion(int version, SchemaVersion expected) { IReadOnlySchemaManagerDataStore schemaManager = Substitute.For <IReadOnlySchemaManagerDataStore>(); var resolver = new SqlSchemaVersionResolver(schemaManager); using CancellationTokenSource tokenSource = new CancellationTokenSource(); schemaManager.GetCurrentSchemaVersionAsync(tokenSource.Token).Returns(Task.FromResult(version)); Assert.Equal(expected, await resolver.GetCurrentVersionAsync(tokenSource.Token)); }
/// <summary> /// Asynchronously fetches the current version from the SQL database. /// </summary> /// <param name="cancellationToken"> /// The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>. /// </param> /// <returns> /// A task representing the asychronous operation. The value of its <see cref="Task{TResult}.Result"/> /// property contains the current version in the SQL database. /// </returns> /// <exception cref="OperationCanceledException">The <paramref name="cancellationToken"/> was canceled.</exception> public async Task <SchemaVersion> GetCurrentVersionAsync(CancellationToken cancellationToken = default) => (SchemaVersion)await _schemaManager.GetCurrentSchemaVersionAsync(cancellationToken);