From 89f03ec620233f33b3eadec486b448cf035699bf Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Mon, 27 Apr 2020 04:38:53 -0700 Subject: [PATCH] Response type: Fix return type --- .../Resource/Conflict/ConflictsInlineCore.cs | 31 ++++---- .../src/Resource/Container/ContainerCore.cs | 4 +- .../src/Resource/Database/DatabaseCore.cs | 4 +- .../src/Resource/Permission/PermissionCore.cs | 46 +++++------- .../Permission/PermissionInlineCore.cs | 28 ++++---- .../src/Resource/Scripts/ScriptsCore.cs | 2 +- .../src/Resource/Scripts/ScriptsInlineCore.cs | 71 +++++++++---------- .../src/Resource/User/UserCore.cs | 11 +-- .../src/Resource/User/UserInlineCore.cs | 39 +++++----- 9 files changed, 100 insertions(+), 136 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/Conflict/ConflictsInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Conflict/ConflictsInlineCore.cs index 349ef3fb35..3c10e0aa8f 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Conflict/ConflictsInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Conflict/ConflictsInlineCore.cs @@ -9,18 +9,15 @@ namespace Microsoft.Azure.Cosmos using System.Threading.Tasks; // This class acts as a wrapper for environments that use SynchronizationContext. - internal sealed class ConflictsInlineCore : Conflicts + internal sealed class ConflictsInlineCore : ConflictsCore { - private readonly ConflictsCore conflicts; - - internal ConflictsInlineCore(ConflictsCore conflicts) + internal ConflictsInlineCore( + CosmosClientContext clientContext, + ContainerInternal container) + : base( + clientContext, + container) { - if (conflicts == null) - { - throw new ArgumentNullException(nameof(conflicts)); - } - - this.conflicts = conflicts; } public override Task DeleteAsync( @@ -28,7 +25,7 @@ public override Task DeleteAsync( PartitionKey partitionKey, CancellationToken cancellationToken = default(CancellationToken)) { - return TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.DeleteAsync(conflict, partitionKey, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteAsync(conflict, partitionKey, cancellationToken)); } public override FeedIterator GetConflictQueryStreamIterator( @@ -36,7 +33,7 @@ public override FeedIterator GetConflictQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.conflicts.GetConflictQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetConflictQueryStreamIterator( queryText, continuationToken, requestOptions)); @@ -47,7 +44,7 @@ public override FeedIterator GetConflictQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.conflicts.GetConflictQueryIterator( + return new FeedIteratorInlineCore(base.GetConflictQueryIterator( queryText, continuationToken, requestOptions)); @@ -58,7 +55,7 @@ public override FeedIterator GetConflictQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.conflicts.GetConflictQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetConflictQueryStreamIterator( queryDefinition, continuationToken, requestOptions)); @@ -69,7 +66,7 @@ public override FeedIterator GetConflictQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.conflicts.GetConflictQueryIterator( + return new FeedIteratorInlineCore(base.GetConflictQueryIterator( queryDefinition, continuationToken, requestOptions)); @@ -80,12 +77,12 @@ public override Task> ReadCurrentAsync( PartitionKey partitionKey, CancellationToken cancellationToken = default(CancellationToken)) { - return TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.ReadCurrentAsync(cosmosConflict, partitionKey, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReadCurrentAsync(cosmosConflict, partitionKey, cancellationToken)); } public override T ReadConflictContent(ConflictProperties cosmosConflict) { - return this.conflicts.ReadConflictContent(cosmosConflict); + return base.ReadConflictContent(cosmosConflict); } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs index a72d8db468..5072297636 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs @@ -39,8 +39,8 @@ protected ContainerCore( id: containerId); this.Database = database; - this.Conflicts = new ConflictsInlineCore(new ConflictsCore(this.ClientContext, this)); - this.Scripts = new ScriptsInlineCore(new ScriptsCore(this, this.ClientContext)); + this.Conflicts = new ConflictsInlineCore(this.ClientContext, this); + this.Scripts = new ScriptsInlineCore(this, this.ClientContext); this.cachedUriSegmentWithoutId = this.GetResourceSegmentUriWithoutId(); this.queryClient = cosmosQueryClient ?? new CosmosQueryClientCore(this.ClientContext, this); this.lazyBatchExecutor = new Lazy(() => this.ClientContext.GetExecutorForContainer(this)); diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs index 0986cbe0f7..234f2465cd 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs @@ -457,10 +457,10 @@ public override User GetUser(string id) throw new ArgumentNullException(nameof(id)); } - return new UserInlineCore(new UserCore( + return new UserInlineCore( this.ClientContext, this, - id)); + id); } public Task CreateUserStreamAsync( diff --git a/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionCore.cs index 0fe7415806..0f5cb81767 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionCore.cs @@ -17,12 +17,8 @@ namespace Microsoft.Azure.Cosmos /// internal class PermissionCore : Permission { - /// - /// Only used for unit testing - /// - internal PermissionCore() - { - } + private readonly Uri linkUri; + private readonly CosmosClientContext clientContext; internal PermissionCore( CosmosClientContext clientContext, @@ -30,27 +26,16 @@ internal PermissionCore( string userId) { this.Id = userId; - this.ClientContext = clientContext; - this.LinkUri = clientContext.CreateLink( + this.clientContext = clientContext; + this.linkUri = clientContext.CreateLink( parentLink: user.LinkUri.OriginalString, uriPathSegment: Paths.PermissionsPathSegment, id: userId); - - this.User = user; } /// public override string Id { get; } - /// - /// Returns a reference to a user object. - /// - public User User { get; } - - internal virtual Uri LinkUri { get; } - - internal virtual CosmosClientContext ClientContext { get; } - /// public override Task DeleteAsync(RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) @@ -59,11 +44,12 @@ public override Task DeleteAsync(RequestOptions requestOptio requestOptions: requestOptions, cancellationToken: cancellationToken); - return this.ClientContext.ResponseFactory.CreatePermissionResponseAsync(this, response); + return this.clientContext.ResponseFactory.CreatePermissionResponseAsync(this, response); } - public Task DeletePermissionStreamAsync(RequestOptions requestOptions = null, - CancellationToken cancellationToken = default(CancellationToken)) + public Task DeletePermissionStreamAsync( + RequestOptions requestOptions, + CancellationToken cancellationToken) { return this.ProcessStreamAsync( streamPayload: null, @@ -82,7 +68,7 @@ public override Task ReadAsync(int? tokenExpiryInSeconds = n requestOptions: requestOptions, cancellationToken: cancellationToken); - return this.ClientContext.ResponseFactory.CreatePermissionResponseAsync(this, response); + return this.clientContext.ResponseFactory.CreatePermissionResponseAsync(this, response); } public Task ReadPermissionStreamAsync(int? tokenExpiryInSeconds = null, @@ -108,14 +94,14 @@ public override Task ReplaceAsync(PermissionProperties permi throw new ArgumentNullException(nameof(permissionProperties)); } - this.ClientContext.ValidateResource(permissionProperties.Id); + this.clientContext.ValidateResource(permissionProperties.Id); Task response = this.ReplaceStreamInternalAsync( - streamPayload: this.ClientContext.SerializerCore.ToStream(permissionProperties), + streamPayload: this.clientContext.SerializerCore.ToStream(permissionProperties), tokenExpiryInSeconds: tokenExpiryInSeconds, requestOptions: requestOptions, cancellationToken: cancellationToken); - return this.ClientContext.ResponseFactory.CreatePermissionResponseAsync(this, response); + return this.clientContext.ResponseFactory.CreatePermissionResponseAsync(this, response); } public Task ReplacePermissionStreamAsync(PermissionProperties permissionProperties, @@ -127,9 +113,9 @@ public Task ReplacePermissionStreamAsync(PermissionProperties p throw new ArgumentNullException(nameof(permissionProperties)); } - this.ClientContext.ValidateResource(permissionProperties.Id); + this.clientContext.ValidateResource(permissionProperties.Id); return this.ReplaceStreamInternalAsync( - streamPayload: this.ClientContext.SerializerCore.ToStream(permissionProperties), + streamPayload: this.clientContext.SerializerCore.ToStream(permissionProperties), requestOptions: requestOptions, cancellationToken: cancellationToken); } @@ -158,7 +144,7 @@ private Task ProcessStreamAsync( return this.ProcessResourceOperationStreamAsync( streamPayload: streamPayload, operationType: operationType, - linkUri: this.LinkUri, + linkUri: this.linkUri, resourceType: ResourceType.Permission, tokenExpiryInSeconds: tokenExpiryInSeconds, requestOptions: requestOptions, @@ -174,7 +160,7 @@ private Task ProcessResourceOperationStreamAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.ClientContext.ProcessResourceOperationStreamAsync( + return this.clientContext.ProcessResourceOperationStreamAsync( resourceUri: linkUri, resourceType: resourceType, operationType: operationType, diff --git a/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionInlineCore.cs index 0cb8dcd531..be4feba2dc 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionInlineCore.cs @@ -4,25 +4,21 @@ namespace Microsoft.Azure.Cosmos { - using System; using System.Threading; using System.Threading.Tasks; // This class acts as a wrapper for environments that use SynchronizationContext. - internal sealed class PermissionInlineCore : Permission + internal sealed class PermissionInlineCore : PermissionCore { - private readonly PermissionCore permission; - - public override string Id => this.permission.Id; - - internal PermissionInlineCore(PermissionCore database) + internal PermissionInlineCore( + CosmosClientContext clientContext, + UserCore user, + string userId) + : base( + clientContext, + user, + userId) { - if (database == null) - { - throw new ArgumentNullException(nameof(database)); - } - - this.permission = database; } public override Task ReadAsync( @@ -30,7 +26,7 @@ public override Task ReadAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.permission.ReadAsync(tokenExpiryInSeconds, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReadAsync(tokenExpiryInSeconds, requestOptions, cancellationToken)); } public override Task ReplaceAsync( @@ -39,14 +35,14 @@ public override Task ReplaceAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.permission.ReplaceAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken)); } public override Task DeleteAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.permission.DeleteAsync(requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteAsync(requestOptions, cancellationToken)); } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsCore.cs index fc687ece8d..66af9e35dd 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsCore.cs @@ -10,7 +10,7 @@ namespace Microsoft.Azure.Cosmos.Scripts using System.Threading.Tasks; using Microsoft.Azure.Documents; - internal sealed class ScriptsCore : Scripts + internal class ScriptsCore : Scripts { private readonly ContainerInternal container; private readonly CosmosClientContext clientContext; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsInlineCore.cs index 31233f6aac..f8c7835c46 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Scripts/ScriptsInlineCore.cs @@ -10,18 +10,15 @@ namespace Microsoft.Azure.Cosmos.Scripts using System.Threading.Tasks; // This class acts as a wrapper for environments that use SynchronizationContext. - internal sealed class ScriptsInlineCore : Scripts + internal sealed class ScriptsInlineCore : ScriptsCore { - private readonly ScriptsCore scripts; - - internal ScriptsInlineCore(ScriptsCore scripts) + internal ScriptsInlineCore( + ContainerInternal container, + CosmosClientContext clientContext) + : base( + container, + clientContext) { - if (scripts == null) - { - throw new ArgumentNullException(nameof(scripts)); - } - - this.scripts = scripts; } public override Task CreateStoredProcedureAsync( @@ -29,7 +26,7 @@ public override Task CreateStoredProcedureAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.CreateStoredProcedureAsync(storedProcedureProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.CreateStoredProcedureAsync(storedProcedureProperties, requestOptions, cancellationToken)); } public override FeedIterator GetStoredProcedureQueryIterator( @@ -37,7 +34,7 @@ public override FeedIterator GetStoredProcedureQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetStoredProcedureQueryIterator( + return new FeedIteratorInlineCore(base.GetStoredProcedureQueryIterator( queryDefinition, continuationToken, requestOptions)); @@ -48,7 +45,7 @@ public override FeedIterator GetStoredProcedureQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetStoredProcedureQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetStoredProcedureQueryStreamIterator( queryDefinition, continuationToken, requestOptions)); @@ -59,7 +56,7 @@ public override FeedIterator GetStoredProcedureQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetStoredProcedureQueryIterator( + return new FeedIteratorInlineCore(base.GetStoredProcedureQueryIterator( queryText, continuationToken, requestOptions)); @@ -70,7 +67,7 @@ public override FeedIterator GetStoredProcedureQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetStoredProcedureQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetStoredProcedureQueryStreamIterator( queryText, continuationToken, requestOptions)); @@ -81,7 +78,7 @@ public override Task ReadStoredProcedureAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ReadStoredProcedureAsync(id, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReadStoredProcedureAsync(id, requestOptions, cancellationToken)); } public override Task ReplaceStoredProcedureAsync( @@ -89,7 +86,7 @@ public override Task ReplaceStoredProcedureAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ReplaceStoredProcedureAsync(storedProcedureProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceStoredProcedureAsync(storedProcedureProperties, requestOptions, cancellationToken)); } public override Task DeleteStoredProcedureAsync( @@ -97,7 +94,7 @@ public override Task DeleteStoredProcedureAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.DeleteStoredProcedureAsync(id, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteStoredProcedureAsync(id, requestOptions, cancellationToken)); } public override Task> ExecuteStoredProcedureAsync( @@ -107,7 +104,7 @@ public override Task> ExecuteStoredProce StoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ExecuteStoredProcedureAsync(storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ExecuteStoredProcedureAsync(storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)); } public override Task ExecuteStoredProcedureStreamAsync( @@ -117,7 +114,7 @@ public override Task ExecuteStoredProcedureStreamAsync( StoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ExecuteStoredProcedureStreamAsync(storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ExecuteStoredProcedureStreamAsync(storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)); } public override Task ExecuteStoredProcedureStreamAsync( @@ -127,7 +124,7 @@ public override Task ExecuteStoredProcedureStreamAsync( StoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ExecuteStoredProcedureStreamAsync(storedProcedureId, streamPayload, partitionKey, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ExecuteStoredProcedureStreamAsync(storedProcedureId, streamPayload, partitionKey, requestOptions, cancellationToken)); } public override Task CreateTriggerAsync( @@ -135,7 +132,7 @@ public override Task CreateTriggerAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.CreateTriggerAsync(triggerProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.CreateTriggerAsync(triggerProperties, requestOptions, cancellationToken)); } public override FeedIterator GetTriggerQueryIterator( @@ -143,7 +140,7 @@ public override FeedIterator GetTriggerQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetTriggerQueryIterator( + return new FeedIteratorInlineCore(base.GetTriggerQueryIterator( queryDefinition, continuationToken, requestOptions)); @@ -154,7 +151,7 @@ public override FeedIterator GetTriggerQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetTriggerQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetTriggerQueryStreamIterator( queryDefinition, continuationToken, requestOptions)); @@ -165,7 +162,7 @@ public override FeedIterator GetTriggerQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetTriggerQueryIterator( + return new FeedIteratorInlineCore(base.GetTriggerQueryIterator( queryText, continuationToken, requestOptions)); @@ -176,7 +173,7 @@ public override FeedIterator GetTriggerQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetTriggerQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetTriggerQueryStreamIterator( queryText, continuationToken, requestOptions)); @@ -187,7 +184,7 @@ public override Task ReadTriggerAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ReadTriggerAsync(id, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReadTriggerAsync(id, requestOptions, cancellationToken)); } public override Task ReplaceTriggerAsync( @@ -195,7 +192,7 @@ public override Task ReplaceTriggerAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ReplaceTriggerAsync(triggerProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceTriggerAsync(triggerProperties, requestOptions, cancellationToken)); } public override Task DeleteTriggerAsync( @@ -203,7 +200,7 @@ public override Task DeleteTriggerAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.DeleteTriggerAsync(id, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteTriggerAsync(id, requestOptions, cancellationToken)); } public override Task CreateUserDefinedFunctionAsync( @@ -211,7 +208,7 @@ public override Task CreateUserDefinedFunctionAsync RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.CreateUserDefinedFunctionAsync(userDefinedFunctionProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.CreateUserDefinedFunctionAsync(userDefinedFunctionProperties, requestOptions, cancellationToken)); } public override FeedIterator GetUserDefinedFunctionQueryIterator( @@ -219,7 +216,7 @@ public override FeedIterator GetUserDefinedFunctionQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetUserDefinedFunctionQueryIterator( + return new FeedIteratorInlineCore(base.GetUserDefinedFunctionQueryIterator( queryDefinition, continuationToken, requestOptions)); @@ -230,7 +227,7 @@ public override FeedIterator GetUserDefinedFunctionQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetUserDefinedFunctionQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetUserDefinedFunctionQueryStreamIterator( queryDefinition, continuationToken, requestOptions)); @@ -241,7 +238,7 @@ public override FeedIterator GetUserDefinedFunctionQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetUserDefinedFunctionQueryIterator( + return new FeedIteratorInlineCore(base.GetUserDefinedFunctionQueryIterator( queryText, continuationToken, requestOptions)); @@ -252,7 +249,7 @@ public override FeedIterator GetUserDefinedFunctionQueryStreamIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.scripts.GetUserDefinedFunctionQueryStreamIterator( + return new FeedIteratorInlineCore(base.GetUserDefinedFunctionQueryStreamIterator( queryText, continuationToken, requestOptions)); @@ -263,7 +260,7 @@ public override Task ReadUserDefinedFunctionAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ReadUserDefinedFunctionAsync(id, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReadUserDefinedFunctionAsync(id, requestOptions, cancellationToken)); } public override Task ReplaceUserDefinedFunctionAsync( @@ -271,7 +268,7 @@ public override Task ReplaceUserDefinedFunctionAsyn RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ReplaceUserDefinedFunctionAsync(userDefinedFunctionProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceUserDefinedFunctionAsync(userDefinedFunctionProperties, requestOptions, cancellationToken)); } public override Task DeleteUserDefinedFunctionAsync( @@ -279,7 +276,7 @@ public override Task DeleteUserDefinedFunctionAsync RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.scripts.DeleteUserDefinedFunctionAsync(id, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteUserDefinedFunctionAsync(id, requestOptions, cancellationToken)); } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/User/UserCore.cs b/Microsoft.Azure.Cosmos/src/Resource/User/UserCore.cs index edf258d707..60933fa863 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/User/UserCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/User/UserCore.cs @@ -17,13 +17,6 @@ namespace Microsoft.Azure.Cosmos /// internal class UserCore : User { - /// - /// Only used for unit testing - /// - internal UserCore() - { - } - internal UserCore( CosmosClientContext clientContext, DatabaseInternal database, @@ -136,10 +129,10 @@ public override Permission GetPermission(string id) throw new ArgumentNullException(nameof(id)); } - return new PermissionInlineCore(new PermissionCore( + return new PermissionInlineCore( this.ClientContext, this, - id)); + id); } /// diff --git a/Microsoft.Azure.Cosmos/src/Resource/User/UserInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/User/UserInlineCore.cs index 7114854dd5..c02bf20fce 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/User/UserInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/User/UserInlineCore.cs @@ -9,27 +9,24 @@ namespace Microsoft.Azure.Cosmos using System.Threading.Tasks; // This class acts as a wrapper for environments that use SynchronizationContext. - internal sealed class UserInlineCore : User + internal sealed class UserInlineCore : UserCore { - private readonly UserCore user; - - public override string Id => this.user.Id; - - internal UserInlineCore(UserCore database) + internal UserInlineCore( + CosmosClientContext clientContext, + DatabaseInternal database, + string userId) + : base( + clientContext, + database, + userId) { - if (database == null) - { - throw new ArgumentNullException(nameof(database)); - } - - this.user = database; } public override Task ReadAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.user.ReadAsync(requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReadAsync(requestOptions, cancellationToken)); } public override Task ReplaceAsync( @@ -37,19 +34,19 @@ public override Task ReplaceAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.user.ReplaceAsync(userProperties, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceAsync(userProperties, requestOptions, cancellationToken)); } public override Task DeleteAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.user.DeleteAsync(requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteAsync(requestOptions, cancellationToken)); } public override Permission GetPermission(string id) { - return this.user.GetPermission(id); + return base.GetPermission(id); } public override Task CreatePermissionAsync( @@ -58,7 +55,7 @@ public override Task CreatePermissionAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.user.CreatePermissionAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.CreatePermissionAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken)); } public override Task UpsertPermissionAsync( @@ -67,7 +64,7 @@ public override Task UpsertPermissionAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { - return TaskHelper.RunInlineIfNeededAsync(() => this.user.UpsertPermissionAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken)); + return TaskHelper.RunInlineIfNeededAsync(() => base.UpsertPermissionAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken)); } public override FeedIterator GetPermissionQueryIterator( @@ -75,7 +72,7 @@ public override FeedIterator GetPermissionQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.user.GetPermissionQueryIterator( + return new FeedIteratorInlineCore(base.GetPermissionQueryIterator( queryText, continuationToken, requestOptions)); @@ -86,12 +83,10 @@ public override FeedIterator GetPermissionQueryIterator( string continuationToken = null, QueryRequestOptions requestOptions = null) { - return new FeedIteratorInlineCore(this.user.GetPermissionQueryIterator( + return new FeedIteratorInlineCore(base.GetPermissionQueryIterator( queryDefinition, continuationToken, requestOptions)); } - - public static implicit operator UserCore(UserInlineCore userInlineCore) => userInlineCore.user; } }