Skip to content
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

Made Storage Client CanGenerateSasUri properties mockable #18277

Merged
merged 3 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release History

## 12.9.0-beta.1 (Unreleased)

- Fixed bug where BlobBaseClient.CanGenerateSasUri, BlobContainerClient.CanGenerateSasUri, BlobServiceClient.CanGenerateSasUri was not mockable

## 12.8.0 (2021-01-12)
- Includes all features from 12.8.0-beta.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public BlobContainerClient(System.Uri blobContainerUri, Azure.Core.TokenCredenti
public BlobContainerClient(System.Uri blobContainerUri, Azure.Storage.Blobs.BlobClientOptions options = null) { }
public BlobContainerClient(System.Uri blobContainerUri, Azure.Storage.StorageSharedKeyCredential credential, Azure.Storage.Blobs.BlobClientOptions options = null) { }
public virtual string AccountName { get { throw null; } }
public bool CanGenerateSasUri { get { throw null; } }
public virtual bool CanGenerateSasUri { get { throw null; } }
public virtual string Name { get { throw null; } }
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Blobs.Models.BlobContainerInfo> Create(Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, Azure.Storage.Blobs.Models.BlobContainerEncryptionScopeOptions encryptionScopeOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -127,7 +127,7 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Core.TokenCredential crede
public BlobServiceClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options = null) { }
public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCredential credential, Azure.Storage.Blobs.BlobClientOptions options = null) { }
public string AccountName { get { throw null; } }
public bool CanGenerateAccountSasUri { get { throw null; } }
public virtual bool CanGenerateAccountSasUri { get { throw null; } }
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Blobs.BlobContainerClient> CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.BlobContainerClient>> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -1268,7 +1268,7 @@ public BlobBaseClient(System.Uri blobUri, Azure.Storage.Blobs.BlobClientOptions
public BlobBaseClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredential credential, Azure.Storage.Blobs.BlobClientOptions options = null) { }
public virtual string AccountName { get { throw null; } }
public virtual string BlobContainerName { get { throw null; } }
public bool CanGenerateSasUri { get { throw null; } }
public virtual bool CanGenerateSasUri { get { throw null; } }
public virtual string Name { get { throw null; } }
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response AbortCopyFromUri(string copyId, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctor
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public string AccountName
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateAccountSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateAccountSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Azure.Storage.Blobs.Models
{
/// <summary>
/// Propeties of a Blob
/// Properties of a Blob
/// </summary>
public partial class BlobProperties
{
Expand Down
17 changes: 17 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6051,6 +6051,23 @@ public void CanGenerateSas_WithVersion_False()
Assert.IsFalse(versionBlob.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Act
var blob = new Mock<BlobBaseClient>();
blob.Setup(x => x.CanGenerateSasUri).Returns(false);

// Assert
Assert.IsFalse(blob.Object.CanGenerateSasUri);

// Act
blob.Setup(x => x.CanGenerateSasUri).Returns(true);

// Assert
Assert.IsTrue(blob.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
17 changes: 17 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,23 @@ public void CanGenerateSas_ClientConstructors()
Assert.IsFalse(container5.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Act
var container = new Mock<BlobContainerClient>();
container.Setup(x => x.CanGenerateSasUri).Returns(false);

// Assert
Assert.IsFalse(container.Object.CanGenerateSasUri);

// Act
container.Setup(x => x.CanGenerateSasUri).Returns(true);

// Assert
Assert.IsTrue(container.Object.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_GetBlobClient()
{
Expand Down
17 changes: 17 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,23 @@ public void CanGenerateSas_GetContainerClient()
Assert.IsFalse(containerClient5.CanGenerateSasUri);
}

[Test]
public void CanGenerateAccountSas_Mockable()
{
// Act
var serviceClient = new Mock<BlobServiceClient>();
serviceClient.Setup(x => x.CanGenerateAccountSasUri).Returns(false);

// Assert
Assert.IsFalse(serviceClient.Object.CanGenerateAccountSasUri);

// Act
serviceClient.Setup(x => x.CanGenerateAccountSasUri).Returns(true);

// Assert
Assert.IsTrue(serviceClient.Object.CanGenerateAccountSasUri);
}

[Test]
public void GenerateAccountSas_RequiredParameters()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release History

## 12.7.0-beta.1 (Unreleased)

- Fixed bug where DataLakeFileSystemClient.CanGenerateSasUri, DataLakeDirectoryClient.CanGenerateSasUri, DataLakeFileClient.CanGenerateSasUri, DataLakePathClient.CanGenerateSasUri, DataLakeServiceClient.CanGenerateSasUri was not mockable

## 12.6.0 (2021-01-12)
- Includes all features from 12.6.0-beta.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public DataLakeFileSystemClient(System.Uri fileSystemUri, Azure.Storage.Files.Da
public DataLakeFileSystemClient(System.Uri fileSystemUri, Azure.Storage.StorageSharedKeyCredential credential) { }
public DataLakeFileSystemClient(System.Uri fileSystemUri, Azure.Storage.StorageSharedKeyCredential credential, Azure.Storage.Files.DataLake.DataLakeClientOptions options) { }
public virtual string AccountName { get { throw null; } }
public bool CanGenerateSasUri { get { throw null; } }
public virtual bool CanGenerateSasUri { get { throw null; } }
public virtual string Name { get { throw null; } }
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Files.DataLake.Models.FileSystemInfo> Create(Azure.Storage.Files.DataLake.Models.PublicAccessType publicAccessType = Azure.Storage.Files.DataLake.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -243,7 +243,7 @@ public DataLakePathClient(System.Uri pathUri, Azure.Storage.Files.DataLake.DataL
public DataLakePathClient(System.Uri pathUri, Azure.Storage.StorageSharedKeyCredential credential) { }
public DataLakePathClient(System.Uri pathUri, Azure.Storage.StorageSharedKeyCredential credential, Azure.Storage.Files.DataLake.DataLakeClientOptions options) { }
public virtual string AccountName { get { throw null; } }
public bool CanGenerateSasUri { get { throw null; } }
public virtual bool CanGenerateSasUri { get { throw null; } }
public virtual string FileSystemName { get { throw null; } }
public virtual string Name { get { throw null; } }
public virtual string Path { get { throw null; } }
Expand Down Expand Up @@ -295,7 +295,7 @@ public DataLakeServiceClient(System.Uri serviceUri, Azure.Storage.Files.DataLake
public DataLakeServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCredential credential) { }
public DataLakeServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCredential credential, Azure.Storage.Files.DataLake.DataLakeClientOptions options) { }
public virtual string AccountName { get { throw null; } }
public bool CanGenerateAccountSasUri { get { throw null; } }
public virtual bool CanGenerateAccountSasUri { get { throw null; } }
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Files.DataLake.DataLakeFileSystemClient> CreateFileSystem(string fileSystemName, Azure.Storage.Files.DataLake.Models.PublicAccessType publicAccessType = Azure.Storage.Files.DataLake.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.DataLake.DataLakeFileSystemClient>> CreateFileSystemAsync(string fileSystemName, Azure.Storage.Files.DataLake.Models.PublicAccessType publicAccessType = Azure.Storage.Files.DataLake.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Azure.Storage.Files.DataLake
public class DataLakeFileClient : DataLakePathClient
{
/// <summary>
/// Gets the maximum number of bytes that can be sent in a call
/// Gets the maximum number of bytes that can be sent in each append call in
/// to <see cref="UploadAsync(Stream, PathHttpHeaders, DataLakeRequestConditions, IProgress{long}, StorageTransferOptions, CancellationToken)"/>.
/// Supported value is now larger than <see cref="int.MaxValue"/>; please use
/// <see cref="MaxUploadLongBytes"/>.
Expand All @@ -37,8 +37,8 @@ public class DataLakeFileClient : DataLakePathClient
: int.MaxValue; // value is larger than can be represented by an int

/// <summary>
/// Gets the maximum number of bytes that can be sent in a call
/// to <see cref="UploadAsync(Stream, PathHttpHeaders, DataLakeRequestConditions, IProgress{long}, StorageTransferOptions, CancellationToken)"/>.
/// Gets the maximum number of bytes that can be sent in each append call in
/// <see cref="UploadAsync(Stream, PathHttpHeaders, DataLakeRequestConditions, IProgress{long}, StorageTransferOptions, CancellationToken)"/>.
/// </summary>
public virtual long MaxUploadLongBytes => Version < DataLakeClientOptions.ServiceVersion.V2019_12_12
? Constants.DataLake.Pre_2019_12_12_MaxAppendBytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public virtual string AccountName
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateAccountSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateAccountSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5087,6 +5087,23 @@ public void CanGenerateSas_GetSubDirectoryClient()
Assert.IsFalse(subdirectory3.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Act
var directory = new Mock<DataLakeDirectoryClient>();
directory.Setup(x => x.CanGenerateSasUri).Returns(false);

// Assert
Assert.IsFalse(directory.Object.CanGenerateSasUri);

// Act
directory.Setup(x => x.CanGenerateSasUri).Returns(true);

// Assert
Assert.IsTrue(directory.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
17 changes: 17 additions & 0 deletions sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,23 @@ public void CanGenerateSas_ClientConstructors()
Assert.IsFalse(file3.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Act
var file = new Mock<DataLakeFileClient>();
file.Setup(x => x.CanGenerateSasUri).Returns(false);

// Assert
Assert.IsFalse(file.Object.CanGenerateSasUri);

// Act
file.Setup(x => x.CanGenerateSasUri).Returns(true);

// Assert
Assert.IsTrue(file.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,23 @@ public void CanGenerateSas_GetDirectoryClient()
Assert.IsFalse(directory3.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Act
var filesystem = new Mock<DataLakeFileSystemClient>();
filesystem.Setup(x => x.CanGenerateSasUri).Returns(false);

// Assert
Assert.IsFalse(filesystem.Object.CanGenerateSasUri);

// Act
filesystem.Setup(x => x.CanGenerateSasUri).Returns(true);

// Assert
Assert.IsTrue(filesystem.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
17 changes: 17 additions & 0 deletions sdk/storage/Azure.Storage.Files.DataLake/tests/PathClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ public void CanGenerateSas_ClientConstructors()
Assert.IsFalse(blob5.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Act
var pathClient = new Mock<DataLakePathClient>();
pathClient.Setup(x => x.CanGenerateSasUri).Returns(false);

// Assert
Assert.IsFalse(pathClient.Object.CanGenerateSasUri);

// Act
pathClient.Setup(x => x.CanGenerateSasUri).Returns(true);

// Assert
Assert.IsTrue(pathClient.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,23 @@ public void CanGenerateSas_GetFileSystemClient()
Assert.IsFalse(fileSystemClient3.CanGenerateSasUri);
}

[Test]
public void CanGenerateAccountSas_Mockable()
{
// Act
var serviceClient = new Mock<DataLakeServiceClient>();
serviceClient.Setup(x => x.CanGenerateAccountSasUri).Returns(false);

// Assert
Assert.IsFalse(serviceClient.Object.CanGenerateAccountSasUri);

// Act
serviceClient.Setup(x => x.CanGenerateAccountSasUri).Returns(true);

// Assert
Assert.IsTrue(serviceClient.Object.CanGenerateAccountSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading