diff --git a/src/EntityFramework.Core/ChangeTracking/Internal/StateManager.cs b/src/EntityFramework.Core/ChangeTracking/Internal/StateManager.cs index b930cc44f96..f582d765b9f 100644 --- a/src/EntityFramework.Core/ChangeTracking/Internal/StateManager.cs +++ b/src/EntityFramework.Core/ChangeTracking/Internal/StateManager.cs @@ -307,9 +307,7 @@ public virtual async Task SaveChangesAsync(bool acceptAllChangesOnSuccess, try { - var result - = await SaveChangesAsync(entriesToSave, cancellationToken) - .WithCurrentCulture(); + var result = await SaveChangesAsync(entriesToSave, cancellationToken); if (acceptAllChangesOnSuccess) { @@ -334,7 +332,7 @@ var result protected virtual async Task SaveChangesAsync( [NotNull] IReadOnlyList entriesToSave, CancellationToken cancellationToken = default(CancellationToken)) - => await _dataStore.SaveChangesAsync(entriesToSave, cancellationToken).WithCurrentCulture(); + => await _dataStore.SaveChangesAsync(entriesToSave, cancellationToken); public virtual void AcceptAllChanges() { diff --git a/src/EntityFramework.Core/DbContext.cs b/src/EntityFramework.Core/DbContext.cs index 6c307d9fc9a..5c97cf3d183 100644 --- a/src/EntityFramework.Core/DbContext.cs +++ b/src/EntityFramework.Core/DbContext.cs @@ -397,7 +397,7 @@ public virtual Task SaveChangesAsync(CancellationToken cancellationToken = try { - return await stateManager.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken).WithCurrentCulture(); + return await stateManager.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); } catch (Exception ex) { diff --git a/src/EntityFramework.Core/EntityFramework.Core.csproj b/src/EntityFramework.Core/EntityFramework.Core.csproj index 189ae5038c9..709dedb1c8d 100644 --- a/src/EntityFramework.Core/EntityFramework.Core.csproj +++ b/src/EntityFramework.Core/EntityFramework.Core.csproj @@ -200,7 +200,6 @@ - diff --git a/src/EntityFramework.Core/Extensions/EntityFrameworkQueryableExtensions.cs b/src/EntityFramework.Core/Extensions/EntityFrameworkQueryableExtensions.cs index 60a49f306b3..7c0efe139b8 100644 --- a/src/EntityFramework.Core/Extensions/EntityFrameworkQueryableExtensions.cs +++ b/src/EntityFramework.Core/Extensions/EntityFrameworkQueryableExtensions.cs @@ -2358,7 +2358,7 @@ public static void Load([NotNull] this IQueryable source) using (var enumerator = asyncEnumerable.GetEnumerator()) { - while (await enumerator.MoveNext().WithCurrentCulture()) + while (await enumerator.MoveNext()) { } } diff --git a/src/EntityFramework.Core/Extensions/EntityFrameworkTaskExtensions.cs b/src/EntityFramework.Core/Extensions/EntityFrameworkTaskExtensions.cs deleted file mode 100644 index ff38a7af31e..00000000000 --- a/src/EntityFramework.Core/Extensions/EntityFrameworkTaskExtensions.cs +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -#if NET45 -using System.Threading; -#endif -using System.Runtime.CompilerServices; -using JetBrains.Annotations; -using Microsoft.Data.Entity.Utilities; - -// ReSharper disable once CheckNamespace - -namespace System.Threading.Tasks -{ - /// - /// Contains extension methods for the class. - /// - public static class EntityFrameworkTaskExtensions - { - /// - /// Configures an awaiter used to await this to avoid - /// marshalling the continuation back to the original context, but preserve the - /// current culture and UI culture. - /// - /// Calling this has no effect on platforms that don't use . - /// - /// The type of the result produced by the associated . - /// - /// The task to be awaited on. - /// An object used to await this task. - public static CultureAwaiter WithCurrentCulture([NotNull] this Task task) - { - Check.NotNull(task, nameof(task)); - - return new CultureAwaiter(task); - } - - /// - /// Configures an awaiter used to await this to avoid - /// marshalling the continuation back to the original context, but preserve the - /// current culture and UI culture. - /// - /// Calling this has no effect on platforms that don't use . - /// The task to be awaited on. - /// An object used to await this task. - public static CultureAwaiter WithCurrentCulture([NotNull] this Task task) - { - Check.NotNull(task, nameof(task)); - - return new CultureAwaiter(task); - } - - /// - /// Provides an awaitable object that allows for awaits on that - /// preserve the culture. - /// - /// - /// The type of the result produced by the associated . - /// - /// This type is intended for compiler use only. - public struct CultureAwaiter : ICriticalNotifyCompletion - { - private readonly Task _task; - - /// - /// Constructs a new instance of the class. - /// - /// The task to be awaited on. - public CultureAwaiter([NotNull] Task task) - { - _task = task; - } - - /// Gets an awaiter used to await this . - /// An awaiter instance. - /// This method is intended for compiler user rather than use directly in code. - public CultureAwaiter GetAwaiter() => this; - - /// - /// Gets whether this Task has completed. - /// - /// - /// will return true when the Task is in one of the three - /// final states: RanToCompletion, - /// Faulted, or - /// Canceled. - /// - public bool IsCompleted => _task.IsCompleted; - - /// Ends the await on the completed . - /// The result of the completed . - /// The awaiter was not properly initialized. - /// The task was canceled. - /// The task completed in a Faulted state. - public T GetResult() => _task.GetAwaiter().GetResult(); - - /// This method is not implemented and should not be called. - /// The action to invoke when the await operation completes. - public void OnCompleted(Action continuation) - { - throw new NotImplementedException(); - } - - /// - /// Schedules the continuation onto the associated with this - /// . - /// - /// The action to invoke when the await operation completes. - /// - /// The argument is null - /// (Nothing in Visual Basic). - /// - /// The awaiter was not properly initialized. - /// This method is intended for compiler user rather than use directly in code. - public void UnsafeOnCompleted(Action continuation) - { -#if NET45 - var currentCulture = Thread.CurrentThread.CurrentCulture; - var currentUICulture = Thread.CurrentThread.CurrentUICulture; - _task.ConfigureAwait(continueOnCapturedContext: false).GetAwaiter().UnsafeOnCompleted( - () => - { - var originalCulture = Thread.CurrentThread.CurrentCulture; - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - Thread.CurrentThread.CurrentCulture = currentCulture; - Thread.CurrentThread.CurrentUICulture = currentUICulture; - try - { - continuation(); - } - finally - { - Thread.CurrentThread.CurrentCulture = originalCulture; - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - }); -#else - _task.GetAwaiter().UnsafeOnCompleted(continuation); -#endif - } - } - - /// - /// Provides an awaitable object that allows for awaits on that - /// preserve the culture. - /// - /// This type is intended for compiler use only. - public struct CultureAwaiter : ICriticalNotifyCompletion - { - private readonly Task _task; - - /// - /// Constructs a new instance of the class. - /// - /// The task to be awaited on. - public CultureAwaiter([NotNull] Task task) - { - _task = task; - } - - /// Gets an awaiter used to await this . - /// An awaiter instance. - /// This method is intended for compiler user rather than use directly in code. - public CultureAwaiter GetAwaiter() => this; - - /// - /// Gets whether this Task has completed. - /// - /// - /// will return true when the Task is in one of the three - /// final states: RanToCompletion, - /// Faulted, or - /// Canceled. - /// - public bool IsCompleted => _task.IsCompleted; - - /// Ends the await on the completed . - /// The awaiter was not properly initialized. - /// The task was canceled. - /// The task completed in a Faulted state. - public void GetResult() => _task.GetAwaiter().GetResult(); - - /// This method is not implemented and should not be called. - /// The action to invoke when the await operation completes. - public void OnCompleted(Action continuation) - { - throw new NotImplementedException(); - } - - /// - /// Schedules the continuation onto the associated with this - /// . - /// - /// The action to invoke when the await operation completes. - /// - /// The argument is null - /// (Nothing in Visual Basic). - /// - /// The awaiter was not properly initialized. - /// This method is intended for compiler user rather than use directly in code. - public void UnsafeOnCompleted(Action continuation) - { -#if NET45 - var currentCulture = Thread.CurrentThread.CurrentCulture; - var currentUICulture = Thread.CurrentThread.CurrentUICulture; - _task.ConfigureAwait(continueOnCapturedContext: false).GetAwaiter().UnsafeOnCompleted( - () => - { - var originalCulture = Thread.CurrentThread.CurrentCulture; - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - Thread.CurrentThread.CurrentCulture = currentCulture; - Thread.CurrentThread.CurrentUICulture = currentUICulture; - try - { - continuation(); - } - finally - { - Thread.CurrentThread.CurrentCulture = originalCulture; - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - }); -#else - _task.GetAwaiter().UnsafeOnCompleted(continuation); -#endif - } - } - } -} diff --git a/src/EntityFramework.Core/Query/AsyncLinqOperatorProvider.cs b/src/EntityFramework.Core/Query/AsyncLinqOperatorProvider.cs index ded7969d73e..602fe7afe56 100644 --- a/src/EntityFramework.Core/Query/AsyncLinqOperatorProvider.cs +++ b/src/EntityFramework.Core/Query/AsyncLinqOperatorProvider.cs @@ -147,7 +147,7 @@ public async Task MoveNext(CancellationToken cancellationToken) _inner = _exceptionInterceptor._innerFactory().GetEnumerator(); } - return await _inner.MoveNext(cancellationToken).WithCurrentCulture(); + return await _inner.MoveNext(cancellationToken); } catch (Exception e) { diff --git a/src/EntityFramework.Core/Query/QueryBuffer.cs b/src/EntityFramework.Core/Query/QueryBuffer.cs index b573601d1f8..1b99ab159e7 100644 --- a/src/EntityFramework.Core/Query/QueryBuffer.cs +++ b/src/EntityFramework.Core/Query/QueryBuffer.cs @@ -324,14 +324,12 @@ var entityKey relatedEntitiesLoaders, ct, currentNavigationIndex + 1, - queryStateManager) - .WithCurrentCulture(); + queryStateManager); return targetEntity; }) .Where(e => e != null) - .ToList(cancellationToken) - .WithCurrentCulture()); + .ToList(cancellationToken)); } private IEntityType IncludeCore( diff --git a/src/EntityFramework.Core/Query/TaskResultAsyncEnumerable.cs b/src/EntityFramework.Core/Query/TaskResultAsyncEnumerable.cs index 877e755c082..c520b00df06 100644 --- a/src/EntityFramework.Core/Query/TaskResultAsyncEnumerable.cs +++ b/src/EntityFramework.Core/Query/TaskResultAsyncEnumerable.cs @@ -39,7 +39,7 @@ public async Task MoveNext(CancellationToken cancellationToken) if (!_moved) { - await _task.WithCurrentCulture(); + await _task; _moved = true; diff --git a/src/EntityFramework.Relational/Query/AsyncIncludeCollectionIterator.cs b/src/EntityFramework.Relational/Query/AsyncIncludeCollectionIterator.cs index 37483d93a30..7326da15a3b 100644 --- a/src/EntityFramework.Relational/Query/AsyncIncludeCollectionIterator.cs +++ b/src/EntityFramework.Relational/Query/AsyncIncludeCollectionIterator.cs @@ -73,8 +73,7 @@ public async Task MoveNext(CancellationToken cancellationToken) { _relatedValuesEnumerable._iterator._hasRemainingRows = await _relatedValuesEnumerable._iterator._relatedValuesEnumerator - .MoveNext(cancellationToken) - .WithCurrentCulture(); + .MoveNext(cancellationToken); _relatedValuesEnumerable._iterator._moveNextPending = false; } diff --git a/src/EntityFramework.Relational/Query/AsyncQueryMethodProvider.cs b/src/EntityFramework.Relational/Query/AsyncQueryMethodProvider.cs index 2960d656546..81776b19af3 100644 --- a/src/EntityFramework.Relational/Query/AsyncQueryMethodProvider.cs +++ b/src/EntityFramework.Relational/Query/AsyncQueryMethodProvider.cs @@ -35,10 +35,8 @@ public class AsyncQueryMethodProvider : IQueryMethodProvider { var result = await enumerator.Current.IsDBNullAsync(0, cancellationToken) - .WithCurrentCulture() ? default(TResult) - : await enumerator.Current.GetFieldValueAsync(0, cancellationToken) - .WithCurrentCulture(); + : await enumerator.Current.GetFieldValueAsync(0, cancellationToken); return result; } diff --git a/src/EntityFramework.Relational/Query/AsyncQueryingEnumerable.cs b/src/EntityFramework.Relational/Query/AsyncQueryingEnumerable.cs index 28d341cfb46..62342791479 100644 --- a/src/EntityFramework.Relational/Query/AsyncQueryingEnumerable.cs +++ b/src/EntityFramework.Relational/Query/AsyncQueryingEnumerable.cs @@ -61,8 +61,7 @@ public async Task MoveNext(CancellationToken cancellationToken) var hasNext = await (_reader == null ? InitializeAndReadAsync(cancellationToken) - : _reader.ReadAsync(cancellationToken)) - .WithCurrentCulture(); + : _reader.ReadAsync(cancellationToken)); Current = !hasNext ? default(T) : _enumerable._shaper(_reader); @@ -72,8 +71,7 @@ var hasNext private async Task InitializeAndReadAsync(CancellationToken cancellationToken) { await _enumerable._relationalQueryContext.Connection - .OpenAsync(cancellationToken) - .WithCurrentCulture(); + .OpenAsync(cancellationToken); using (var command = _enumerable._commandBuilder @@ -83,12 +81,12 @@ await _enumerable._relationalQueryContext.Connection { _enumerable._logger.LogCommand(command); - _reader = await command.ExecuteReaderAsync(cancellationToken).WithCurrentCulture(); + _reader = await command.ExecuteReaderAsync(cancellationToken); } _enumerable._relationalQueryContext.RegisterDataReader(_reader); - return await _reader.ReadAsync(cancellationToken).WithCurrentCulture(); + return await _reader.ReadAsync(cancellationToken); } public T Current { get; private set; } diff --git a/src/EntityFramework.Relational/RelationalConnection.cs b/src/EntityFramework.Relational/RelationalConnection.cs index 037b88783b9..25059dee7c4 100644 --- a/src/EntityFramework.Relational/RelationalConnection.cs +++ b/src/EntityFramework.Relational/RelationalConnection.cs @@ -118,7 +118,7 @@ public virtual RelationalTransaction BeginTransaction(IsolationLevel isolationLe throw new InvalidOperationException(Strings.TransactionAlreadyStarted); } - await OpenAsync(cancellationToken).WithCurrentCulture(); + await OpenAsync(cancellationToken); return BeginTransactionWithNoPreconditions(isolationLevel); } @@ -180,7 +180,7 @@ public virtual async Task OpenAsync(CancellationToken cancellationToken = defaul #endif if (_openedCount == 0) { - await _connection.Value.OpenAsync(cancellationToken).WithCurrentCulture(); + await _connection.Value.OpenAsync(cancellationToken); } _openedCount++; } diff --git a/src/EntityFramework.Relational/RelationalDataStoreCreator.cs b/src/EntityFramework.Relational/RelationalDataStoreCreator.cs index 64597f4de4e..26fa148e4a1 100644 --- a/src/EntityFramework.Relational/RelationalDataStoreCreator.cs +++ b/src/EntityFramework.Relational/RelationalDataStoreCreator.cs @@ -77,9 +77,9 @@ public virtual async Task EnsureDeletedAsync(IModel model, CancellationTok { Check.NotNull(model, nameof(model)); - if (await ExistsAsync(cancellationToken).WithCurrentCulture()) + if (await ExistsAsync(cancellationToken)) { - await DeleteAsync(cancellationToken).WithCurrentCulture(); + await DeleteAsync(cancellationToken); return true; } @@ -110,17 +110,17 @@ public virtual async Task EnsureCreatedAsync(IModel model, CancellationTok { Check.NotNull(model, nameof(model)); - if (!await ExistsAsync(cancellationToken).WithCurrentCulture()) + if (!await ExistsAsync(cancellationToken)) { - await CreateAsync(cancellationToken).WithCurrentCulture(); - await CreateTablesAsync(model, cancellationToken).WithCurrentCulture(); + await CreateAsync(cancellationToken); + await CreateTablesAsync(model, cancellationToken); return true; } - if (!await HasTablesAsync(cancellationToken).WithCurrentCulture()) + if (!await HasTablesAsync(cancellationToken)) { - await CreateTablesAsync(model, cancellationToken).WithCurrentCulture(); + await CreateTablesAsync(model, cancellationToken); return true; } diff --git a/src/EntityFramework.Relational/SqlStatementExecutor.cs b/src/EntityFramework.Relational/SqlStatementExecutor.cs index 8ec6d0e1231..0a077cd115b 100644 --- a/src/EntityFramework.Relational/SqlStatementExecutor.cs +++ b/src/EntityFramework.Relational/SqlStatementExecutor.cs @@ -78,8 +78,7 @@ public SqlStatementExecutor([NotNull] ILoggerFactory loggerFactory) var command = CreateCommand(connection, transaction, sqlBatch.Sql); Logger.LogCommand(command); - await command.ExecuteNonQueryAsync(cancellationToken) - .WithCurrentCulture(); + await command.ExecuteNonQueryAsync(cancellationToken); } return Task.FromResult(null); }, @@ -119,12 +118,12 @@ await command.ExecuteNonQueryAsync(cancellationToken) { Logger.OpeningConnection(connection.ConnectionString); - await connection.OpenAsync(cancellationToken).WithCurrentCulture(); + await connection.OpenAsync(cancellationToken); } try { - return await action().WithCurrentCulture(); + return await action(); } finally { diff --git a/src/EntityFramework.Relational/Update/BatchExecutor.cs b/src/EntityFramework.Relational/Update/BatchExecutor.cs index 14f9e598401..e4053f7f622 100644 --- a/src/EntityFramework.Relational/Update/BatchExecutor.cs +++ b/src/EntityFramework.Relational/Update/BatchExecutor.cs @@ -78,7 +78,7 @@ public class BatchExecutor : IBatchExecutor Check.NotNull(connection, nameof(connection)); var rowsAffected = 0; - await connection.OpenAsync(cancellationToken).WithCurrentCulture(); + await connection.OpenAsync(cancellationToken); RelationalTransaction startedTransaction = null; try { @@ -93,8 +93,7 @@ public class BatchExecutor : IBatchExecutor connection.Transaction, _typeMapper, _context, - Logger, cancellationToken) - .WithCurrentCulture(); + Logger, cancellationToken); } startedTransaction?.Commit(); diff --git a/src/EntityFramework.Relational/Update/ReaderModificationCommandBatch.cs b/src/EntityFramework.Relational/Update/ReaderModificationCommandBatch.cs index 214ac3057d2..e18bed542ac 100644 --- a/src/EntityFramework.Relational/Update/ReaderModificationCommandBatch.cs +++ b/src/EntityFramework.Relational/Update/ReaderModificationCommandBatch.cs @@ -222,20 +222,18 @@ protected virtual void UpdateCachedCommandText(int commandPosition) try { - using (var reader = await storeCommand.ExecuteReaderAsync(cancellationToken).WithCurrentCulture()) + using (var reader = await storeCommand.ExecuteReaderAsync(cancellationToken)) { var actualResultSetCount = 0; do { commandIndex = ModificationCommands[commandIndex].RequiresResultPropagation ? await ConsumeResultSetWithPropagationAsync(commandIndex, reader, context, cancellationToken) - .WithCurrentCulture() - : await ConsumeResultSetWithoutPropagationAsync(commandIndex, reader, context, cancellationToken) - .WithCurrentCulture(); + : await ConsumeResultSetWithoutPropagationAsync(commandIndex, reader, context, cancellationToken); actualResultSetCount++; } while (commandIndex < ResultSetEnds.Count - && await reader.NextResultAsync(cancellationToken).WithCurrentCulture()); + && await reader.NextResultAsync(cancellationToken)); Debug.Assert(commandIndex == ModificationCommands.Count, "Expected " + ModificationCommands.Count + " results, got " + commandIndex); #if DEBUG @@ -303,7 +301,7 @@ private async Task ConsumeResultSetWithPropagationAsync(int commandIndex, D var tableModification = ModificationCommands[commandIndex]; Debug.Assert(tableModification.RequiresResultPropagation); - if (!await reader.ReadAsync(cancellationToken).WithCurrentCulture()) + if (!await reader.ReadAsync(cancellationToken)) { var expectedRowsAffected = rowsAffected + 1; while (++commandIndex < ResultSetEnds.Count @@ -371,7 +369,7 @@ private async Task ConsumeResultSetWithoutPropagationAsync(int commandIndex expectedRowsAffected++; } - if (await reader.ReadAsync(cancellationToken).WithCurrentCulture()) + if (await reader.ReadAsync(cancellationToken)) { var rowsAffected = reader.GetInt32(0); if (rowsAffected != expectedRowsAffected) diff --git a/src/EntityFramework.SqlServer/SqlServerDataStoreCreator.cs b/src/EntityFramework.SqlServer/SqlServerDataStoreCreator.cs index a7d782e7a16..5f380356f62 100644 --- a/src/EntityFramework.SqlServer/SqlServerDataStoreCreator.cs +++ b/src/EntityFramework.SqlServer/SqlServerDataStoreCreator.cs @@ -54,12 +54,11 @@ public override async Task CreateAsync(CancellationToken cancellationToken = def using (var masterConnection = _connection.CreateMasterConnection()) { await _statementExecutor - .ExecuteNonQueryAsync(masterConnection, null, CreateCreateOperations(), cancellationToken) - .WithCurrentCulture(); + .ExecuteNonQueryAsync(masterConnection, null, CreateCreateOperations(), cancellationToken); ClearPool(); } - await ExistsAsync(retryOnNotExists: true, cancellationToken: cancellationToken).WithCurrentCulture(); + await ExistsAsync(retryOnNotExists: true, cancellationToken: cancellationToken); } public override void CreateTables(IModel model) @@ -74,16 +73,14 @@ public override async Task CreateTablesAsync(IModel model, CancellationToken can _connection, _connection.DbTransaction, CreateSchemaCommands(Check.NotNull(model, nameof(model))), - cancellationToken) - .WithCurrentCulture(); + cancellationToken); public override bool HasTables() => (int)_statementExecutor.ExecuteScalar(_connection, _connection.DbTransaction, CreateHasTablesCommand()) != 0; public override async Task HasTablesAsync(CancellationToken cancellationToken = default(CancellationToken)) => (int)(await _statementExecutor - .ExecuteScalarAsync(_connection, _connection.DbTransaction, CreateHasTablesCommand(), cancellationToken) - .WithCurrentCulture()) != 0; + .ExecuteScalarAsync(_connection, _connection.DbTransaction, CreateHasTablesCommand(), cancellationToken)) != 0; private IEnumerable CreateSchemaCommands(IModel model) => _sqlGenerator.Generate(_modelDiffer.GetDifferences(null, model), model); @@ -134,7 +131,7 @@ private async Task ExistsAsync(bool retryOnNotExists, CancellationToken ca { try { - await _connection.OpenAsync(cancellationToken).WithCurrentCulture(); + await _connection.OpenAsync(cancellationToken); _connection.Close(); return true; } @@ -201,8 +198,7 @@ public override async Task DeleteAsync(CancellationToken cancellationToken = def using (var masterConnection = _connection.CreateMasterConnection()) { await _statementExecutor - .ExecuteNonQueryAsync(masterConnection, null, CreateDropCommands(), cancellationToken) - .WithCurrentCulture(); + .ExecuteNonQueryAsync(masterConnection, null, CreateDropCommands(), cancellationToken); } } diff --git a/src/Shared/AsyncEnumerableExtensions.cs b/src/Shared/AsyncEnumerableExtensions.cs index f65e9762ef8..51234ae6880 100644 --- a/src/Shared/AsyncEnumerableExtensions.cs +++ b/src/Shared/AsyncEnumerableExtensions.cs @@ -44,12 +44,12 @@ public AsyncSelectEnumerator(AsyncSelectEnumerable enumerable) public async Task MoveNext(CancellationToken cancellationToken) { - if (!await _enumerator.MoveNext(cancellationToken).WithCurrentCulture()) + if (!await _enumerator.MoveNext(cancellationToken)) { return false; } - Current = await _selector(_enumerator.Current, cancellationToken).WithCurrentCulture(); + Current = await _selector(_enumerator.Current, cancellationToken); return true; } diff --git a/test/EntityFramework.Core.FunctionalTests/DeadlockTestBase.cs b/test/EntityFramework.Core.FunctionalTests/DeadlockTestBase.cs deleted file mode 100644 index d96c6f81ec7..00000000000 --- a/test/EntityFramework.Core.FunctionalTests/DeadlockTestBase.cs +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -#if NET45 - -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Threading; -using Microsoft.Data.Entity.FunctionalTests.TestModels.Northwind; -using Xunit; - -namespace Microsoft.Data.Entity.FunctionalTests -{ - public abstract class DeadlockTestBase - where TTestStore : TestStore - { - protected abstract TTestStore CreateTestDatabase(); - - protected abstract DbContext CreateContext(TTestStore testDatabase); - - protected abstract DbContext CreateContext(); - - [Fact] - public void ToListAsync_does_not_deadlock() - { - using (var context = CreateContext()) - { - RunDeadlockTest(context.Set().ToListAsync); - } - } - - [Fact] - public void DbSet_LoadAsync_does_not_deadlock() - { - using (var context = CreateContext()) - { - RunDeadlockTest(context.Set().LoadAsync); - } - } - - [Fact] - public void DbContext_SaveChangesAsync_does_not_deadlock() - { - using (var testDatabase = CreateTestDatabase()) - { - using (var context = CreateContext(testDatabase)) - { - context.Set().Add(new Product { ProductID = 78, SupplierID = 1 }); - RunDeadlockTest(() => context.SaveChangesAsync()); - } - } - } - - private void RunDeadlockTest(Func asyncOperation) - { - var dispatcherThread = new Thread(Dispatcher.Run) { Name = "Dispatcher" }; - dispatcherThread.Start(); - - Dispatcher dispatcher = null; - // Wait for dispatcher to start up - while ((dispatcher = Dispatcher.FromThread(dispatcherThread)) == null) - { - Thread.Sleep(TimeSpan.FromMilliseconds(15)); - } - - try - { - Assert.Equal( - DispatcherOperationStatus.Completed, - dispatcher.InvokeAsync( - () => Assert.True(asyncOperation().Wait(TimeSpan.FromMinutes(1)), "Async operation resulted in a deadlock")) - .Wait(TimeSpan.FromMinutes(1.5))); - } - catch (TaskCanceledException) - { - // Sometimes thrown by the dispatcher, doesn't indicate a deadlock - } - finally - { - // Do our best to cleanup, but don't fail the test if not possible to do so in the allocated time - dispatcher.BeginInvokeShutdown(DispatcherPriority.Send); - var startShutdownTime = DateTime.Now; - while (!dispatcher.HasShutdownFinished - && DateTime.Now - startShutdownTime < TimeSpan.FromSeconds(10)) - { - Thread.Sleep(TimeSpan.FromMilliseconds(100)); - } - - Task.Run(() => dispatcherThread.Abort()).Wait(TimeSpan.FromSeconds(10)); - } - } - } -} - -#endif diff --git a/test/EntityFramework.Core.FunctionalTests/EntityFramework.Core.FunctionalTests.csproj b/test/EntityFramework.Core.FunctionalTests/EntityFramework.Core.FunctionalTests.csproj index f326a8ac903..fe56c798c11 100644 --- a/test/EntityFramework.Core.FunctionalTests/EntityFramework.Core.FunctionalTests.csproj +++ b/test/EntityFramework.Core.FunctionalTests/EntityFramework.Core.FunctionalTests.csproj @@ -72,7 +72,6 @@ - diff --git a/test/EntityFramework.Core.FunctionalTests/TestStore.cs b/test/EntityFramework.Core.FunctionalTests/TestStore.cs index ef05e5a7e41..f8843b6e7df 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestStore.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestStore.cs @@ -22,11 +22,11 @@ protected virtual async Task CreateSharedAsync(string name, Func initializ { var asyncLock = _creationLocks.GetOrAdd(name, new AsyncLock()); - using (await asyncLock.LockAsync().WithCurrentCulture()) + using (await asyncLock.LockAsync()) { if (!_createdDatabases.Contains(name)) { - await initializeDatabase().WithCurrentCulture(); + await initializeDatabase(); _createdDatabases.Add(name); diff --git a/test/EntityFramework.Core.Tests/EntityFramework.Core.Tests.csproj b/test/EntityFramework.Core.Tests/EntityFramework.Core.Tests.csproj index dd45db0502b..0433de6cffd 100644 --- a/test/EntityFramework.Core.Tests/EntityFramework.Core.Tests.csproj +++ b/test/EntityFramework.Core.Tests/EntityFramework.Core.Tests.csproj @@ -103,7 +103,6 @@ - diff --git a/test/EntityFramework.Core.Tests/Extensions/TaskExtensionsTest.cs b/test/EntityFramework.Core.Tests/Extensions/TaskExtensionsTest.cs deleted file mode 100644 index 6842550e9d9..00000000000 --- a/test/EntityFramework.Core.Tests/Extensions/TaskExtensionsTest.cs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -#if NET45 -namespace System.Threading.Tasks.Tests -{ - using System.Globalization; - using System.Threading; - using System.Threading.Tasks; - using Xunit; - - public class TaskExtensionsTest - { - [Fact] - public void NonGeneric_WithCurrentCulture_preserves_culture() - { - var originalCulture = Thread.CurrentThread.CurrentCulture; - var expectedCulture = new CultureInfo("de-DE"); - Thread.CurrentThread.CurrentCulture = expectedCulture; - - try - { - var culture = GetCurrentCultureAsync().Result; - - Assert.Equal(expectedCulture, culture); - } - finally - { - Thread.CurrentThread.CurrentCulture = originalCulture; - } - } - - [Fact] - public void Generic_WithCurrentCulture_preserves_culture() - { - var originalCulture = Thread.CurrentThread.CurrentCulture; - var expectedCulture = new CultureInfo("de-DE"); - Thread.CurrentThread.CurrentCulture = expectedCulture; - - try - { - var culture = GetCurrentCultureAsync().Result; - - Assert.Equal(expectedCulture, culture); - } - finally - { - Thread.CurrentThread.CurrentCulture = originalCulture; - } - } - - [Fact] - public void NonGeneric_WithCurrentCulture_preserves_ui_culture() - { - var originalCulture = Thread.CurrentThread.CurrentUICulture; - var expectedCulture = new CultureInfo("de-DE"); - Thread.CurrentThread.CurrentUICulture = expectedCulture; - - try - { - var culture = GetCurrentUICultureAsync().Result; - - Assert.Equal(expectedCulture, culture); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalCulture; - } - } - - [Fact] - public void Generic_WithCurrentCulture_preserves_ui_culture() - { - var originalCulture = Thread.CurrentThread.CurrentUICulture; - var expectedCulture = new CultureInfo("de-DE"); - Thread.CurrentThread.CurrentUICulture = expectedCulture; - - try - { - var culture = GetCurrentUICultureAsync().Result; - - Assert.Equal(expectedCulture, culture); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalCulture; - } - } - - private async Task GetCurrentCultureAsync() - { - await ConfigurableYield().WithCurrentCulture(); - return Thread.CurrentThread.CurrentCulture; - } - - private async Task GetCurrentCultureAsync() - { - await ConfigurableYield().WithCurrentCulture(); - return Thread.CurrentThread.CurrentCulture; - } - - private async Task GetCurrentUICultureAsync() - { - await ConfigurableYield().WithCurrentCulture(); - return Thread.CurrentThread.CurrentUICulture; - } - - private async Task GetCurrentUICultureAsync() - { - await ConfigurableYield().WithCurrentCulture(); - return Thread.CurrentThread.CurrentUICulture; - } - - private async Task ConfigurableYield() - { - await Task.Yield(); - } - - private async Task ConfigurableYield() - { - await Task.Yield(); - return default(T); - } - } -} -#endif diff --git a/test/EntityFramework.InMemory.FunctionalTests/DeadlockInMemoryTest.cs b/test/EntityFramework.InMemory.FunctionalTests/DeadlockInMemoryTest.cs deleted file mode 100644 index fac54094e67..00000000000 --- a/test/EntityFramework.InMemory.FunctionalTests/DeadlockInMemoryTest.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -#if NET45 - -using Microsoft.Data.Entity.FunctionalTests; -using Xunit; - -namespace Microsoft.Data.Entity.InMemory.FunctionalTests -{ - public class DeadlockInMemoryTest : DeadlockTestBase, IClassFixture - { - private readonly NorthwindQueryInMemoryFixture _fixture; - - public DeadlockInMemoryTest(NorthwindQueryInMemoryFixture fixture) - { - _fixture = fixture; - } - - protected override InMemoryTestStore CreateTestDatabase() - { - return new InMemoryTestStore(); - } - - protected override DbContext CreateContext(InMemoryTestStore testDatabase) - { - return _fixture.CreateContext(); - } - - protected override DbContext CreateContext() - { - return _fixture.CreateContext(); - } - } -} - -#endif diff --git a/test/EntityFramework.InMemory.FunctionalTests/EntityFramework.InMemory.FunctionalTests.csproj b/test/EntityFramework.InMemory.FunctionalTests/EntityFramework.InMemory.FunctionalTests.csproj index 3f20ae6058d..31792699e0c 100644 --- a/test/EntityFramework.InMemory.FunctionalTests/EntityFramework.InMemory.FunctionalTests.csproj +++ b/test/EntityFramework.InMemory.FunctionalTests/EntityFramework.InMemory.FunctionalTests.csproj @@ -61,7 +61,6 @@ - diff --git a/test/EntityFramework.SqlServer.FunctionalTests/DeadlockSqlServerTest.cs b/test/EntityFramework.SqlServer.FunctionalTests/DeadlockSqlServerTest.cs deleted file mode 100644 index 7efefc83d27..00000000000 --- a/test/EntityFramework.SqlServer.FunctionalTests/DeadlockSqlServerTest.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -#if NET45 - -using Microsoft.Data.Entity.FunctionalTests; -using Xunit; - -namespace Microsoft.Data.Entity.SqlServer.FunctionalTests -{ - public class DeadlockSqlServerTest : DeadlockTestBase, IClassFixture - { - private readonly NorthwindQuerySqlServerFixture _fixture; - public DeadlockSqlServerTest(NorthwindQuerySqlServerFixture fixture) - { - _fixture = fixture; - } - - protected override SqlServerTestStore CreateTestDatabase() - { - return SqlServerTestStore.CreateScratch(createDatabase: false); - } - - protected override DbContext CreateContext(SqlServerTestStore testDatabase) - { - var context = _fixture.CreateContext(testDatabase); - context.Database.EnsureCreated(); - return context; - } - - protected override DbContext CreateContext() - { - return _fixture.CreateContext(); - } - } -} - -#endif diff --git a/test/EntityFramework.SqlServer.FunctionalTests/EntityFramework.SqlServer.FunctionalTests.csproj b/test/EntityFramework.SqlServer.FunctionalTests/EntityFramework.SqlServer.FunctionalTests.csproj index 7e796586c7a..c1be7f193c3 100644 --- a/test/EntityFramework.SqlServer.FunctionalTests/EntityFramework.SqlServer.FunctionalTests.csproj +++ b/test/EntityFramework.SqlServer.FunctionalTests/EntityFramework.SqlServer.FunctionalTests.csproj @@ -1,4 +1,4 @@ - + @@ -83,7 +83,6 @@ - diff --git a/test/EntityFramework.SqlServer.FunctionalTests/SqlServerTestStore.cs b/test/EntityFramework.SqlServer.FunctionalTests/SqlServerTestStore.cs index 255c438b892..91ad2b93538 100644 --- a/test/EntityFramework.SqlServer.FunctionalTests/SqlServerTestStore.cs +++ b/test/EntityFramework.SqlServer.FunctionalTests/SqlServerTestStore.cs @@ -313,7 +313,7 @@ private async Task DeleteDatabaseAsync(string name) { using (var master = new SqlConnection(CreateConnectionString("master"))) { - await master.OpenAsync().WithCurrentCulture(); + await master.OpenAsync(); using (var command = master.CreateCommand()) { @@ -327,7 +327,7 @@ private async Task DeleteDatabaseAsync(string name) DROP DATABASE [{0}]; END", name); - await command.ExecuteNonQueryAsync().WithCurrentCulture(); + await command.ExecuteNonQueryAsync(); var userFolder = Environment.GetEnvironmentVariable("USERPROFILE"); try