From 46fd82ea1ca508e8fe9ed61e5292dbe80c22eaf8 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 17 Oct 2019 08:43:25 -0700 Subject: [PATCH 1/6] Turn large mutable structs into classes --- .../src/AppendBlobClient.cs | 12 ++-- .../Azure.Storage.Blobs/src/BlobBaseClient.cs | 6 +- .../Azure.Storage.Blobs/src/BlobClient.cs | 20 +++--- .../src/BlockBlobClient.cs | 12 ++-- .../src/Models/BlobHttpHeaders.cs | 55 +++++----------- .../src/Models/ReleasedObjectInfo.cs | 36 +---------- .../Azure.Storage.Blobs/src/PageBlobClient.cs | 12 ++-- .../src/Sas/BlobSasBuilder.cs | 59 +---------------- .../src/Sas/AccountSasBuilder.cs | 53 ++-------------- .../src/Sas/FileSasBuilder.cs | 63 ++----------------- .../src/Sas/QueueSasBuilder.cs | 52 ++------------- 11 files changed, 63 insertions(+), 317 deletions(-) diff --git a/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs index 07d378d985d5..c18b358d8a73 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs @@ -271,7 +271,7 @@ protected sealed override BlobBaseClient WithCustomerProvidedKeyCore(CustomerPro /// a failure occurs. /// public virtual Response Create( - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, AppendBlobAccessConditions? accessConditions = default, CancellationToken cancellationToken = default) => @@ -315,7 +315,7 @@ public virtual Response Create( /// a failure occurs. /// public virtual async Task> CreateAsync( - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, AppendBlobAccessConditions? accessConditions = default, CancellationToken cancellationToken = default) => @@ -355,7 +355,7 @@ await CreateInternal( /// a failure occurs. /// public virtual Response CreateIfNotExists( - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, CancellationToken cancellationToken = default) => CreateIfNotExistsInternal( @@ -393,7 +393,7 @@ public virtual Response CreateIfNotExists( /// a failure occurs. /// public virtual async Task> CreateIfNotExistsAsync( - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, CancellationToken cancellationToken = default) => await CreateIfNotExistsInternal( @@ -434,7 +434,7 @@ await CreateIfNotExistsInternal( /// a failure occurs. /// private async Task> CreateIfNotExistsInternal( - BlobHttpHeaders? httpHeaders, + BlobHttpHeaders httpHeaders, Metadata metadata, bool async, CancellationToken cancellationToken) @@ -502,7 +502,7 @@ private async Task> CreateIfNotExistsInternal( /// a failure occurs. /// private async Task> CreateInternal( - BlobHttpHeaders? httpHeaders, + BlobHttpHeaders httpHeaders, Metadata metadata, AppendBlobAccessConditions? accessConditions, bool async, diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs index 97657f85037f..c160fbf8c995 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs @@ -2411,7 +2411,7 @@ private async Task> GetPropertiesInternal( /// a failure occurs. /// public virtual Response SetHttpHeaders( - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, BlobAccessConditions? accessConditions = default, CancellationToken cancellationToken = default) => SetHttpHeadersInternal( @@ -2447,7 +2447,7 @@ public virtual Response SetHttpHeaders( /// a failure occurs. /// public virtual async Task> SetHttpHeadersAsync( - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, BlobAccessConditions? accessConditions = default, CancellationToken cancellationToken = default) => await SetHttpHeadersInternal( @@ -2486,7 +2486,7 @@ await SetHttpHeadersInternal( /// a failure occurs. /// private async Task> SetHttpHeadersInternal( - BlobHttpHeaders? httpHeaders, + BlobHttpHeaders httpHeaders, BlobAccessConditions? accessConditions, bool async, CancellationToken cancellationToken) diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs index 872ff3528787..1818277dfc26 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs @@ -437,7 +437,7 @@ public virtual Task> UploadAsync( #pragma warning restore AZC0002 // Client method should have cancellationToken as the last optional parameter /// - /// The + /// The /// operation creates a new block blob or updates the content of an /// existing block blob. Updating an existing block blob overwrites /// any existing metadata on the blob. @@ -490,7 +490,7 @@ public virtual Task> UploadAsync( [ForwardsClientCalls] public virtual Response Upload( Stream content, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, IProgress progressHandler = default, @@ -510,7 +510,7 @@ public virtual Response Upload( .EnsureCompleted(); /// - /// The + /// The /// operation creates a new block blob or updates the content of an /// existing block blob. Updating an existing block blob overwrites /// any existing metadata on the blob. @@ -563,7 +563,7 @@ public virtual Response Upload( [ForwardsClientCalls] public virtual Response Upload( FileInfo content, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, IProgress progressHandler = default, @@ -583,7 +583,7 @@ public virtual Response Upload( .EnsureCompleted(); /// - /// The + /// The /// operation creates a new block blob or updates the content of an /// existing block blob. Updating an existing block blob overwrites /// any existing metadata on the blob. @@ -636,7 +636,7 @@ public virtual Response Upload( [ForwardsClientCalls] public virtual Task> UploadAsync( Stream content, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, IProgress progressHandler = default, @@ -655,7 +655,7 @@ public virtual Task> UploadAsync( cancellationToken: cancellationToken); /// - /// The + /// The /// operation creates a new block blob or updates the content of an /// existing block blob. Updating an existing block blob overwrites /// any existing metadata on the blob. @@ -708,7 +708,7 @@ public virtual Task> UploadAsync( [ForwardsClientCalls] public virtual Task> UploadAsync( FileInfo content, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, IProgress progressHandler = default, @@ -778,7 +778,7 @@ public virtual Task> UploadAsync( /// internal async Task> StagedUploadAsync( Stream content, - BlobHttpHeaders? blobHttpHeaders, + BlobHttpHeaders blobHttpHeaders, Metadata metadata, BlobAccessConditions? blobAccessConditions, IProgress progressHandler, @@ -952,7 +952,7 @@ Task> CommitBlockListAsync( /// internal async Task> StagedUploadAsync( FileInfo file, - BlobHttpHeaders? blobHttpHeaders, + BlobHttpHeaders blobHttpHeaders, Metadata metadata, BlobAccessConditions? blobAccessConditions, IProgress progressHandler, diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs index 9cb594481867..3f50c4b732cb 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs @@ -367,7 +367,7 @@ protected sealed override BlobBaseClient WithCustomerProvidedKeyCore(CustomerPro /// public virtual Response Upload( Stream content, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, AccessTier? accessTier = default, @@ -433,7 +433,7 @@ public virtual Response Upload( /// public virtual async Task> UploadAsync( Stream content, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, AccessTier? accessTier = default, @@ -502,7 +502,7 @@ await UploadInternal( /// internal async Task> UploadInternal( Stream content, - BlobHttpHeaders? blobHttpHeaders, + BlobHttpHeaders blobHttpHeaders, Metadata metadata, BlobAccessConditions? blobAccessConditions, AccessTier? accessTier, @@ -1145,7 +1145,7 @@ private async Task> StageBlockFromUriInternal( /// public virtual Response CommitBlockList( IEnumerable base64BlockIds, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, AccessTier? accessTier = default, @@ -1212,7 +1212,7 @@ public virtual Response CommitBlockList( /// public virtual async Task> CommitBlockListAsync( IEnumerable base64BlockIds, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, BlobAccessConditions? accessConditions = default, AccessTier? accessTier = default, @@ -1282,7 +1282,7 @@ await CommitBlockListInternal( /// internal async Task> CommitBlockListInternal( IEnumerable base64BlockIds, - BlobHttpHeaders? blobHttpHeaders, + BlobHttpHeaders blobHttpHeaders, Metadata metadata, BlobAccessConditions? blobAccessConditions, AccessTier? accessTier, diff --git a/sdk/storage/Azure.Storage.Blobs/src/Models/BlobHttpHeaders.cs b/sdk/storage/Azure.Storage.Blobs/src/Models/BlobHttpHeaders.cs index 353f44bebc48..3b130807ca42 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Models/BlobHttpHeaders.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Models/BlobHttpHeaders.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.ComponentModel; namespace Azure.Storage.Blobs.Models { @@ -13,7 +14,7 @@ namespace Azure.Storage.Blobs.Models /// /// For more information, see . /// - public struct BlobHttpHeaders : IEquatable + public class BlobHttpHeaders { /// /// The MIME content type of the blob. @@ -59,53 +60,25 @@ public struct BlobHttpHeaders : IEquatable public string CacheControl { get; set; } /// - /// Check if two BlobHttpHeaders instances are equal. + /// Creates a string representation of a + /// . /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - public override bool Equals(object obj) - => obj is BlobHttpHeaders other && Equals(other); - - /// - /// Get a hash code for the BlobHttpHeaders. - /// - /// Hash code for the BlobHttpHeaders. - public override int GetHashCode() - => CacheControl.GetHashCode() - ^ ContentDisposition.GetHashCode() - ^ ContentEncoding.GetHashCode() - ^ ContentLanguage.GetHashCode() - ^ ContentHash.GetHashCode() - ^ ContentType.GetHashCode() - ; + [EditorBrowsable(EditorBrowsableState.Never)] + public override string ToString() => base.ToString(); /// - /// Check if two BlobHttpHeaders instances are equal. + /// Check if two instances are equal. /// - /// The first instance to compare. - /// The second instance to compare. + /// The instance to compare to. /// True if they're equal, false otherwise. - public static bool operator ==(BlobHttpHeaders left, BlobHttpHeaders right) => left.Equals(right); - - /// - /// Check if two BlobHttpHeaders instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(BlobHttpHeaders left, BlobHttpHeaders right) => !(left == right); + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => base.Equals(obj); /// - /// Check if two BlobHttpHeaders instances are equal. + /// Get a hash code for the . /// - /// The instance to compare to. - public bool Equals(BlobHttpHeaders other) - => CacheControl == other.CacheControl - && ContentDisposition == other.ContentDisposition - && ContentEncoding == other.ContentEncoding - && ContentLanguage == other.ContentLanguage - && ContentHash == other.ContentHash - && ContentType == other.ContentType - ; + /// Hash code for the . + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => base.GetHashCode(); } } diff --git a/sdk/storage/Azure.Storage.Blobs/src/Models/ReleasedObjectInfo.cs b/sdk/storage/Azure.Storage.Blobs/src/Models/ReleasedObjectInfo.cs index a163c5ba8cbf..f3c910fd5bee 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Models/ReleasedObjectInfo.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Models/ReleasedObjectInfo.cs @@ -10,7 +10,7 @@ namespace Azure.Storage.Blobs.Models /// Provides the version state of a succesfully released blob or container /// object. /// - public readonly struct ReleasedObjectInfo : IEquatable + public class ReleasedObjectInfo { /// /// The ETag contains a value that you can use to perform operations @@ -74,43 +74,13 @@ internal ReleasedObjectInfo(BlobContainerInfo info) /// The instance to compare to. /// True if they're equal, false otherwise. [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => - obj is ReleasedObjectInfo other && Equals(other); - - /// - /// Check if two instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - public bool Equals(ReleasedObjectInfo other) => - ETag == other.ETag && - LastModified == other.LastModified; + public override bool Equals(object obj) => base.Equals(obj); /// /// Get a hash code for the . /// /// Hash code for the . [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => - ETag.GetHashCode() ^ - LastModified.GetHashCode(); - - /// - /// Check if two instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(ReleasedObjectInfo left, ReleasedObjectInfo right) => - left.Equals(right); - - /// - /// Check if two instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(ReleasedObjectInfo left, ReleasedObjectInfo right) => - !(left == right); + public override int GetHashCode() => base.GetHashCode(); } } diff --git a/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs index 31fdc5fa3580..fa3247505fb3 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs @@ -304,7 +304,7 @@ protected sealed override BlobBaseClient WithCustomerProvidedKeyCore(CustomerPro public virtual Response Create( long size, long? sequenceNumber = default, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, PageBlobAccessConditions? accessConditions = default, CancellationToken cancellationToken = default) => @@ -362,7 +362,7 @@ public virtual Response Create( public virtual async Task> CreateAsync( long size, long? sequenceNumber = default, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, PageBlobAccessConditions? accessConditions = default, CancellationToken cancellationToken = default) => @@ -416,7 +416,7 @@ await CreateInternal( public virtual Response CreateIfNotExists( long size, long? sequenceNumber = default, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, CancellationToken cancellationToken = default) => CreateIfNotExistsInternal( @@ -468,7 +468,7 @@ public virtual Response CreateIfNotExists( public virtual async Task> CreateIfNotExistsAsync( long size, long? sequenceNumber = default, - BlobHttpHeaders? httpHeaders = default, + BlobHttpHeaders httpHeaders = default, Metadata metadata = default, CancellationToken cancellationToken = default) => await CreateIfNotExistsInternal( @@ -524,7 +524,7 @@ await CreateIfNotExistsInternal( private async Task> CreateIfNotExistsInternal( long size, long? sequenceNumber, - BlobHttpHeaders? httpHeaders, + BlobHttpHeaders httpHeaders, Metadata metadata, bool async, CancellationToken cancellationToken) @@ -606,7 +606,7 @@ private async Task> CreateIfNotExistsInternal( private async Task> CreateInternal( long size, long? sequenceNumber, - BlobHttpHeaders? httpHeaders, + BlobHttpHeaders httpHeaders, Metadata metadata, PageBlobAccessConditions? accessConditions, bool async, diff --git a/sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs b/sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs index ce00703d5062..8ec4c080bb94 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs @@ -14,7 +14,7 @@ namespace Azure.Storage.Sas /// Signature (SAS) for an Azure Storage container or blob. /// For more information, see . /// - public struct BlobSasBuilder : IEquatable + public class BlobSasBuilder { /// /// The storage service version to use to authenticate requests made @@ -355,66 +355,13 @@ public override string ToString() => /// True if they're equal, false otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) - => obj is BlobSasBuilder other && Equals(other); + => base.Equals(obj); /// /// Get a hash code for the BlobSasBuilder. /// /// Hash code for the BlobSasBuilder. [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => - BlobName.GetHashCode() ^ - CacheControl.GetHashCode() ^ - BlobContainerName.GetHashCode() ^ - ContentDisposition.GetHashCode() ^ - ContentEncoding.GetHashCode() ^ - ContentLanguage.GetHashCode() ^ - ContentType.GetHashCode() ^ - ExpiresOn.GetHashCode() ^ - Identifier.GetHashCode() ^ - IPRange.GetHashCode() ^ - Permissions.GetHashCode() ^ - Protocol.GetHashCode() ^ - StartsOn.GetHashCode() ^ - Version.GetHashCode(); - - /// - /// Check if two BlobSasBuilder instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(BlobSasBuilder left, BlobSasBuilder right) => - left.Equals(right); - - /// - /// Check if two BlobSasBuilder instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(BlobSasBuilder left, BlobSasBuilder right) => - !(left == right); - - /// - /// Check if two BlobSasBuilder instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - public bool Equals(BlobSasBuilder other) => - BlobName == other.BlobName && - CacheControl == other.CacheControl && - BlobContainerName == other.BlobContainerName && - ContentDisposition == other.ContentDisposition && - ContentEncoding == other.ContentEncoding && - ContentLanguage == other.ContentEncoding && - ContentType == other.ContentType && - ExpiresOn == other.ExpiresOn && - Identifier == other.Identifier && - IPRange == other.IPRange && - Permissions == other.Permissions && - Protocol == other.Protocol && - StartsOn == other.StartsOn && - Version == other.Version; + public override int GetHashCode() => base.GetHashCode(); } } diff --git a/sdk/storage/Azure.Storage.Common/src/Sas/AccountSasBuilder.cs b/sdk/storage/Azure.Storage.Common/src/Sas/AccountSasBuilder.cs index 7816e898de5d..8984621026fe 100644 --- a/sdk/storage/Azure.Storage.Common/src/Sas/AccountSasBuilder.cs +++ b/sdk/storage/Azure.Storage.Common/src/Sas/AccountSasBuilder.cs @@ -12,7 +12,7 @@ namespace Azure.Storage.Sas /// For more information, see /// . /// - public struct AccountSasBuilder : IEquatable + public class AccountSasBuilder { /// /// The storage service version to use to authenticate requests made @@ -139,8 +139,7 @@ public SasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential shared /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => - base.ToString(); + public override string ToString() => base.ToString(); /// /// Check if two instances are equal. @@ -148,57 +147,13 @@ public override string ToString() => /// The instance to compare to. /// True if they're equal, false otherwise. [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => - obj is AccountSasBuilder other && - Equals(other); + public override bool Equals(object obj) => base.Equals(obj); /// /// Get a hash code for the . /// /// Hash code for the . [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => - ExpiresOn.GetHashCode() ^ - IPRange.GetHashCode() ^ - (Permissions?.GetHashCode() ?? 0) ^ - Protocol.GetHashCode() ^ - ResourceTypes.GetHashCode() ^ - (Services.GetHashCode()) ^ - StartsOn.GetHashCode() ^ - (Version?.GetHashCode() ?? 0); - - /// - /// Check if two instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(AccountSasBuilder left, AccountSasBuilder right) => - left.Equals(right); - - /// - /// Check if two instances are not - /// equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(AccountSasBuilder left, AccountSasBuilder right) => - !(left == right); - - /// - /// Check if two instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - public bool Equals(AccountSasBuilder other) => - ExpiresOn == other.ExpiresOn && - IPRange == other.IPRange && - Permissions == other.Permissions && - Protocol == other.Protocol && - ResourceTypes == other.ResourceTypes && - Services == other.Services && - StartsOn == other.StartsOn && - Version == other.Version; + public override int GetHashCode() => base.GetHashCode(); } } diff --git a/sdk/storage/Azure.Storage.Files/src/Sas/FileSasBuilder.cs b/sdk/storage/Azure.Storage.Files/src/Sas/FileSasBuilder.cs index b06827bdd0fd..8fa9ecfe22f9 100644 --- a/sdk/storage/Azure.Storage.Files/src/Sas/FileSasBuilder.cs +++ b/sdk/storage/Azure.Storage.Files/src/Sas/FileSasBuilder.cs @@ -11,7 +11,7 @@ namespace Azure.Storage.Sas /// Signature (SAS) for an Azure Storage share, directory, or file. /// For more information, see . /// - public struct FileSasBuilder : IEquatable + public class FileSasBuilder { /// /// The storage service version to use to authenticate requests made @@ -202,8 +202,7 @@ private static string GetCanonicalName(string account, string shareName, string /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => - base.ToString(); + public override string ToString() => base.ToString(); /// /// Check if two FileSasBuilder instances are equal. @@ -211,67 +210,13 @@ public override string ToString() => /// The instance to compare to. /// True if they're equal, false otherwise. [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) - => obj is FileSasBuilder other && Equals(other); + public override bool Equals(object obj) => base.Equals(obj); /// /// Get a hash code for the FileSasBuilder. /// /// Hash code for the FileSasBuilder. [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() - => CacheControl.GetHashCode() - ^ ContentDisposition.GetHashCode() - ^ ContentEncoding.GetHashCode() - ^ ContentLanguage.GetHashCode() - ^ ContentType.GetHashCode() - ^ ExpiresOn.GetHashCode() - ^ FilePath.GetHashCode() - ^ Identifier.GetHashCode() - ^ IPRange.GetHashCode() - ^ Permissions.GetHashCode() - ^ Protocol.GetHashCode() - ^ ShareName.GetHashCode() - ^ StartsOn.GetHashCode() - ^ Version.GetHashCode() - ; - - /// - /// Check if two FileSasBuilder instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(FileSasBuilder left, FileSasBuilder right) => left.Equals(right); - - /// - /// Check if two FileSasBuilder instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(FileSasBuilder left, FileSasBuilder right) => !(left == right); - - /// - /// Check if two FileSasBuilder instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - public bool Equals(FileSasBuilder other) - => CacheControl == other.CacheControl - && ContentDisposition == other.ContentDisposition - && ContentEncoding == other.ContentEncoding - && ContentLanguage == other.ContentEncoding - && ContentType == other.ContentType - && ExpiresOn == other.ExpiresOn - && FilePath == other.FilePath - && Identifier == other.Identifier - && IPRange == other.IPRange - && Permissions == other.Permissions - && Protocol == other.Protocol - && ShareName == other.ShareName - && StartsOn == other.StartsOn - && Version == other.Version - ; + public override int GetHashCode() => base.GetHashCode(); } } diff --git a/sdk/storage/Azure.Storage.Queues/src/Sas/QueueSasBuilder.cs b/sdk/storage/Azure.Storage.Queues/src/Sas/QueueSasBuilder.cs index 65fb4c16dfe4..fd139f5a92ad 100644 --- a/sdk/storage/Azure.Storage.Queues/src/Sas/QueueSasBuilder.cs +++ b/sdk/storage/Azure.Storage.Queues/src/Sas/QueueSasBuilder.cs @@ -11,7 +11,7 @@ namespace Azure.Storage.Sas /// Signature (SAS) for an Azure Storage queue. /// For more information, see . /// - public struct QueueSasBuilder : IEquatable + public class QueueSasBuilder { /// /// The storage service version to use to authenticate requests made @@ -147,8 +147,7 @@ private static string GetCanonicalName(string account, string queueName) => /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => - base.ToString(); + public override string ToString() => base.ToString(); /// /// Check if two QueueSasBuilder instances are equal. @@ -156,56 +155,13 @@ public override string ToString() => /// The instance to compare to. /// True if they're equal, false otherwise. [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => - obj is QueueSasBuilder other && Equals(other); + public override bool Equals(object obj) => base.Equals(obj); /// /// Get a hash code for the QueueSasBuilder. /// /// Hash code for the QueueSasBuilder. [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => - ExpiresOn.GetHashCode() ^ - Identifier.GetHashCode() ^ - IPRange.GetHashCode() ^ - Permissions.GetHashCode() ^ - Protocol.GetHashCode() ^ - QueueName.GetHashCode() ^ - StartsOn.GetHashCode() ^ - Version.GetHashCode(); - - /// - /// Check if two QueueSasBuilder instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(QueueSasBuilder left, QueueSasBuilder right) => - left.Equals(right); - - /// - /// Check if two QueueSasBuilder instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - - public static bool operator !=(QueueSasBuilder left, QueueSasBuilder right) => - !(left == right); - - /// - /// Check if two QueueSasBuilder instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - public bool Equals(QueueSasBuilder other) => - ExpiresOn == other.ExpiresOn && - Identifier == other.Identifier && - IPRange == other.IPRange && - Permissions == other.Permissions && - Protocol == other.Protocol && - QueueName == other.QueueName && - StartsOn == other.StartsOn && - Version == other.Version; + public override int GetHashCode() => base.GetHashCode(); } } From 0e9f1c51fb0d321ef8deef9246eaac22200c6b48 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 17 Oct 2019 10:24:23 -0700 Subject: [PATCH 2/6] PageInfo --- .../src/Generated/BlobRestClient.cs | 174 +++++------------- .../Azure.Storage.Blobs/swagger/readme.md | 5 +- 2 files changed, 44 insertions(+), 135 deletions(-) diff --git a/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs b/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs index e652b731f623..d825086f8c52 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs @@ -7723,42 +7723,36 @@ internal static Azure.Core.HttpMessage UploadPagesAsync_CreateMessage( { case 201: { + // Create the result + Azure.Storage.Blobs.Models.PageInfo _value = new Azure.Storage.Blobs.Models.PageInfo(); // Get response headers string _header; - Azure.ETag eTag = default; - System.DateTimeOffset lastModified = default; - byte[] contentHash = default; - byte[] contentCrc64 = default; - long blobSequenceNumber = default; - string encryptionKeySha256 = default; if (response.Headers.TryGetValue("ETag", out _header)) { - eTag = new Azure.ETag(_header); + _value.ETag = new Azure.ETag(_header); } if (response.Headers.TryGetValue("Last-Modified", out _header)) { - lastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + _value.LastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); } if (response.Headers.TryGetValue("Content-MD5", out _header)) { - contentHash = System.Convert.FromBase64String(_header); + _value.ContentHash = System.Convert.FromBase64String(_header); } if (response.Headers.TryGetValue("x-ms-content-crc64", out _header)) { - contentCrc64 = System.Convert.FromBase64String(_header); + _value.ContentCrc64 = System.Convert.FromBase64String(_header); } if (response.Headers.TryGetValue("x-ms-blob-sequence-number", out _header)) { - blobSequenceNumber = long.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + _value.BlobSequenceNumber = long.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); } if (response.Headers.TryGetValue("x-ms-encryption-key-sha256", out _header)) { - encryptionKeySha256 = _header; + _value.EncryptionKeySha256 = _header; } - Azure.Storage.Blobs.Models.PageInfo _value = new Azure.Storage.Blobs.Models.PageInfo(eTag, lastModified, contentHash, contentCrc64, blobSequenceNumber, encryptionKeySha256); - // Create the response return Response.FromValue(_value, response); } @@ -7964,42 +7958,36 @@ internal static Azure.Core.HttpMessage ClearPagesAsync_CreateMessage( { case 201: { + // Create the result + Azure.Storage.Blobs.Models.PageInfo _value = new Azure.Storage.Blobs.Models.PageInfo(); // Get response headers string _header; - Azure.ETag eTag = default; - System.DateTimeOffset lastModified = default; - byte[] contentHash = default; - byte[] contentCrc64 = default; - long blobSequenceNumber = default; - string encryptionKeySha256 = default; if (response.Headers.TryGetValue("ETag", out _header)) { - eTag = new Azure.ETag(_header); + _value.ETag = new Azure.ETag(_header); } if (response.Headers.TryGetValue("Last-Modified", out _header)) { - lastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + _value.LastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); } if (response.Headers.TryGetValue("Content-MD5", out _header)) { - contentHash = System.Convert.FromBase64String(_header); + _value.ContentHash = System.Convert.FromBase64String(_header); } if (response.Headers.TryGetValue("x-ms-content-crc64", out _header)) { - contentCrc64 = System.Convert.FromBase64String(_header); + _value.ContentCrc64 = System.Convert.FromBase64String(_header); } if (response.Headers.TryGetValue("x-ms-blob-sequence-number", out _header)) { - blobSequenceNumber = long.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + _value.BlobSequenceNumber = long.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); } if (response.Headers.TryGetValue("x-ms-encryption-key-sha256", out _header)) { - encryptionKeySha256 = _header; + _value.EncryptionKeySha256 = _header; } - Azure.Storage.Blobs.Models.PageInfo _value = new Azure.Storage.Blobs.Models.PageInfo(eTag, lastModified, contentHash, contentCrc64, blobSequenceNumber, encryptionKeySha256); - // Create the response return Response.FromValue(_value, response); } @@ -8265,42 +8253,36 @@ internal static Azure.Core.HttpMessage UploadPagesFromUriAsync_CreateMessage( { case 201: { + // Create the result + Azure.Storage.Blobs.Models.PageInfo _value = new Azure.Storage.Blobs.Models.PageInfo(); // Get response headers string _header; - Azure.ETag eTag = default; - System.DateTimeOffset lastModified = default; - byte[] contentHash = default; - byte[] contentCrc64 = default; - long blobSequenceNumber = default; - string encryptionKeySha256 = default; if (response.Headers.TryGetValue("ETag", out _header)) { - eTag = new Azure.ETag(_header); + _value.ETag = new Azure.ETag(_header); } if (response.Headers.TryGetValue("Last-Modified", out _header)) { - lastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + _value.LastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); } if (response.Headers.TryGetValue("Content-MD5", out _header)) { - contentHash = System.Convert.FromBase64String(_header); + _value.ContentHash = System.Convert.FromBase64String(_header); } if (response.Headers.TryGetValue("x-ms-content-crc64", out _header)) { - contentCrc64 = System.Convert.FromBase64String(_header); + _value.ContentCrc64 = System.Convert.FromBase64String(_header); } if (response.Headers.TryGetValue("x-ms-blob-sequence-number", out _header)) { - blobSequenceNumber = long.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + _value.BlobSequenceNumber = long.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); } if (response.Headers.TryGetValue("x-ms-encryption-key-sha256", out _header)) { - encryptionKeySha256 = _header; + _value.EncryptionKeySha256 = _header; } - Azure.Storage.Blobs.Models.PageInfo _value = new Azure.Storage.Blobs.Models.PageInfo(eTag, lastModified, contentHash, contentCrc64, blobSequenceNumber, encryptionKeySha256); - // Create the response return Response.FromValue(_value, response); } @@ -18068,131 +18050,53 @@ public static PageBlobInfo PageBlobInfo( } #endregion class PageBlobInfo -#region struct PageInfo +#region class PageInfo namespace Azure.Storage.Blobs.Models { /// /// PageInfo /// - public readonly partial struct PageInfo: System.IEquatable + public partial class PageInfo { /// /// The ETag contains a value that you can use to perform operations conditionally. If the request version is 2011-08-18 or newer, the ETag value will be in quotes. /// - public Azure.ETag ETag { get; } + public Azure.ETag ETag { get; internal set; } /// /// Returns the date and time the container was last modified. Any operation that modifies the blob, including an update of the blob's metadata or properties, changes the last-modified time of the blob. /// - public System.DateTimeOffset LastModified { get; } + public System.DateTimeOffset LastModified { get; internal set; } /// /// If the blob has an MD5 hash and this operation is to read the full blob, this response header is returned so that the client can check for message content integrity. /// #pragma warning disable CA1819 // Properties should not return arrays - public byte[] ContentHash { get; } + public byte[] ContentHash { get; internal set; } #pragma warning restore CA1819 // Properties should not return arrays /// /// This header is returned so that the client can check for message content integrity. The value of this header is computed by the Blob service; it is not necessarily the same value specified in the request headers. /// #pragma warning disable CA1819 // Properties should not return arrays - public byte[] ContentCrc64 { get; } + public byte[] ContentCrc64 { get; internal set; } #pragma warning restore CA1819 // Properties should not return arrays /// /// The current sequence number for the page blob. This is only returned for page blobs. /// - public long BlobSequenceNumber { get; } + public long BlobSequenceNumber { get; internal set; } /// /// The SHA-256 hash of the encryption key used to encrypt the pages. This header is only returned when the pages were encrypted with a customer-provided key. /// - public string EncryptionKeySha256 { get; } + public string EncryptionKeySha256 { get; internal set; } /// /// Prevent direct instantiation of PageInfo instances. /// You can use BlobsModelFactory.PageInfo instead. /// - internal PageInfo( - Azure.ETag eTag, - System.DateTimeOffset lastModified, - byte[] contentHash, - byte[] contentCrc64, - long blobSequenceNumber, - string encryptionKeySha256) - { - ETag = eTag; - LastModified = lastModified; - ContentHash = contentHash; - ContentCrc64 = contentCrc64; - BlobSequenceNumber = blobSequenceNumber; - EncryptionKeySha256 = encryptionKeySha256; - } - - /// - /// Check if two PageInfo instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - [System.ComponentModel.EditorBrowsable((System.ComponentModel.EditorBrowsableState.Never))] - public bool Equals(PageInfo other) - { - if (!ETag.Equals(other.ETag)) - { - return false; - } - if (!LastModified.Equals(other.LastModified)) - { - return false; - } - if (!System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(ContentHash, other.ContentHash)) - { - return false; - } - if (!System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(ContentCrc64, other.ContentCrc64)) - { - return false; - } - if (!BlobSequenceNumber.Equals(other.BlobSequenceNumber)) - { - return false; - } - if (!System.StringComparer.Ordinal.Equals(EncryptionKeySha256, other.EncryptionKeySha256)) - { - return false; - } - - return true; - } - - /// - /// Check if two PageInfo instances are equal. - /// - /// The instance to compare to. - /// True if they're equal, false otherwise. - [System.ComponentModel.EditorBrowsable((System.ComponentModel.EditorBrowsableState.Never))] - public override bool Equals(object obj) => obj is PageInfo && Equals((PageInfo)obj); - - /// - /// Get a hash code for the PageInfo. - /// - [System.ComponentModel.EditorBrowsable((System.ComponentModel.EditorBrowsableState.Never))] - public override int GetHashCode() - { - var hashCode = new Azure.Core.HashCodeBuilder(); - hashCode.Add(ETag); - hashCode.Add(LastModified); - hashCode.Add(System.Collections.StructuralComparisons.StructuralEqualityComparer.GetHashCode(ContentHash)); - hashCode.Add(System.Collections.StructuralComparisons.StructuralEqualityComparer.GetHashCode(ContentCrc64)); - hashCode.Add(BlobSequenceNumber); - if (EncryptionKeySha256 != null) - { - hashCode.Add(EncryptionKeySha256, System.StringComparer.Ordinal); - } - - return hashCode.ToHashCode(); - } + internal PageInfo() { } } /// @@ -18211,11 +18115,19 @@ public static PageInfo PageInfo( long blobSequenceNumber, string encryptionKeySha256) { - return new PageInfo(eTag, lastModified, contentHash, contentCrc64, blobSequenceNumber, encryptionKeySha256); + return new PageInfo() + { + ETag = eTag, + LastModified = lastModified, + ContentHash = contentHash, + ContentCrc64 = contentCrc64, + BlobSequenceNumber = blobSequenceNumber, + EncryptionKeySha256 = encryptionKeySha256, + }; } } } -#endregion struct PageInfo +#endregion class PageInfo #region class PageList namespace Azure.Storage.Blobs.Models diff --git a/sdk/storage/Azure.Storage.Blobs/swagger/readme.md b/sdk/storage/Azure.Storage.Blobs/swagger/readme.md index 129d0a0962ba..7a302e3f0f48 100644 --- a/sdk/storage/Azure.Storage.Blobs/swagger/readme.md +++ b/sdk/storage/Azure.Storage.Blobs/swagger/readme.md @@ -248,7 +248,6 @@ directive: transform: > $.get.description = "Returns the sku name and account kind"; $.get.responses["200"]["x-az-response-name"] = "AccountInfo"; - $.get.responses["200"]["x-az-struct"] = true; - from: swagger-document where: $["x-ms-paths"] transform: > @@ -729,7 +728,6 @@ directive: transform: > $.put.responses["201"]["x-az-response-name"] = "PageInfo"; $.put.responses["201"].description = "The operation completed successfully."; - $.put.responses["201"]["x-az-struct"] = true; $.put.responses["201"].headers["x-ms-blob-sequence-number"].description = "The current sequence number for the page blob. This is only returned for page blobs."; $.put.responses["201"].headers["x-ms-request-server-encrypted"]["x-az-demote-header"] = true; ``` @@ -742,7 +740,6 @@ directive: transform: > $.put.responses["201"]["x-az-response-name"] = "PageInfo"; $.put.responses["201"].description = "The operation completed successfully."; - $.put.responses["201"]["x-az-struct"] = true; $.put.responses["201"].headers["x-ms-blob-sequence-number"].description = "The current sequence number for the page blob. This is only returned for page blobs."; $.put.responses["201"].headers["x-ms-request-server-encrypted"] = { "x-ms-client-name": "IsServerEncrypted", @@ -766,7 +763,6 @@ directive: $.put.operationId = "PageBlob_UploadPagesFromUri"; $.put.responses["201"]["x-az-response-name"] = "PageInfo"; $.put.responses["201"].description = "The operation completed successfully."; - $.put.responses["201"]["x-az-struct"] = true; $.put.responses["201"].headers["x-ms-blob-sequence-number"].description = "The current sequence number for the page blob. This is only returned for page blobs."; $.put.responses["201"].headers["x-ms-request-server-encrypted"]["x-az-demote-header"] = true; $.put.responses["304"] = { @@ -1338,6 +1334,7 @@ directive: $.PageList["x-az-public"] = false; $.PageRange["x-az-public"] = false; $.ClearRange["x-az-public"] = false; +``` ### Access Policy properties renaming ``` yaml From 863d4bc2472ca474037be33e64084ba7a25c9bc2 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 17 Oct 2019 10:53:42 -0700 Subject: [PATCH 3/6] Rem tests --- .../Azure.Storage.Blobs/tests/PageInfoTest.cs | 208 ------------------ 1 file changed, 208 deletions(-) delete mode 100644 sdk/storage/Azure.Storage.Blobs/tests/PageInfoTest.cs diff --git a/sdk/storage/Azure.Storage.Blobs/tests/PageInfoTest.cs b/sdk/storage/Azure.Storage.Blobs/tests/PageInfoTest.cs deleted file mode 100644 index 758fe212b886..000000000000 --- a/sdk/storage/Azure.Storage.Blobs/tests/PageInfoTest.cs +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Azure.Storage.Blobs.Models; -using NUnit.Framework; - -namespace Azure.Storage.Blobs.Tests -{ - /// - /// These tests are related to our generated struct behavior. - /// - public class PageInfoTest - { - [Test] - public void EqualsReturnsTrueForEqualValues() - { - var hash = new byte[] { 1, 2, 3 }; - - var info1 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash, - hash, - 1, - "key1"); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash, - hash, - 1, - "key1"); - - Assert.True(info1.Equals(info2)); - Assert.True(info2.Equals(info1)); - - Assert.AreEqual(info1.GetHashCode(), info2.GetHashCode()); - } - - [Test] - public void EqualsReturnsTrueForNullValues() - { - var info1 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - null, - null, - 1, - null); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - null, - null, - 1, - null); - - Assert.True(info1.Equals(info2)); - Assert.True(info2.Equals(info1)); - - Assert.AreEqual(info1.GetHashCode(), info2.GetHashCode()); - - } - - [Test] - public void EqualsReturnsTrueIfCompareContentHashByValues() - { - var hash1 = new byte[] { 1, 2, 3 }; - var hash2 = new byte[] { 1, 2, 3 }; - - var info1 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash1, - hash1, - 1, - "key1"); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash2, - hash1, - 1, - "key1"); - - Assert.True(info1.Equals(info2)); - Assert.True(info2.Equals(info1)); - - Assert.AreEqual(info1.GetHashCode(), info2.GetHashCode()); - } - - [Test] - public void EqualsReturnsTrueIfCompareContentCrc64ByValues() - { - var hash1 = new byte[] { 1, 2, 3 }; - var hash2 = new byte[] { 1, 2, 3 }; - - var info1 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash1, - hash1, - 1, - "key1"); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash1, - hash2, - 1, - "key1"); - - Assert.True(info1.Equals(info2)); - Assert.True(info2.Equals(info1)); - - Assert.AreEqual(info1.GetHashCode(), info2.GetHashCode()); - } - - [Test] - public void EqualsReturnsFalseIfCompareContentHashWithNull() - { - var hash = new byte[] { 1, 2, 3 }; - - var info1 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - null, - hash, - 1, - "key1"); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash, - hash, - 1, - "key1"); - - Assert.True(!info1.Equals(info2)); - Assert.True(!info2.Equals(info1)); - - Assert.AreNotEqual(info1.GetHashCode(), info2.GetHashCode()); - - } - - [Test] - public void EqualsReturnsFalseIfCompareContentCrc64WithNull() - { - var hash = new byte[] { 1, 2, 3 }; - - var info1 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash, - null, - 1, - "key1"); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash, - hash, - 1, - "key1"); - - Assert.True(!info1.Equals(info2)); - Assert.True(!info2.Equals(info1)); - - Assert.AreNotEqual(info1.GetHashCode(), info2.GetHashCode()); - - } - - - [Test] - public void EqualsReturnFalseIfCompareDifferentValues() - { - var hash = new byte[] { 1, 2, 3 }; - - var info1 = new PageInfo( - new ETag("B"), - new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), - hash, - hash, - 1, - "key1"); - - var info2 = new PageInfo( - new ETag("A"), - new DateTimeOffset(2019, 11, 25, 1, 1, 1, TimeSpan.Zero), - hash, - hash, - 2, - "key2"); - - Assert.True(!info1.Equals(info2)); - Assert.True(!info2.Equals(info1)); - - Assert.AreNotEqual(info1.GetHashCode(), info2.GetHashCode()); - } - } -} From e0477629d27087be68943959622bdbb4aed7549b Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 17 Oct 2019 11:17:53 -0700 Subject: [PATCH 4/6] More --- .../src/DirectoryClient.cs | 24 ++++----- .../Azure.Storage.Files/src/FileClient.cs | 24 ++++----- .../src/Models/FileHttpHeaders.cs | 46 +++------------- .../src/Models/FileSmbProperties.cs | 53 +++++-------------- .../src/Models/NtfsFileAttributes.cs | 35 ++---------- .../src/Models/StorageDirectoryInfo.cs | 2 +- .../src/Models/StorageFileInfo.cs | 2 +- .../Azure.Storage.Files/src/ShareClient.cs | 4 +- .../tests/DirectoryClientTests.cs | 10 ++-- .../tests/FileClientTests.cs | 12 ++--- .../Azure.Storage.Files/tests/FileTestBase.cs | 4 +- 11 files changed, 63 insertions(+), 153 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs b/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs index c0c3876b5604..9fbcb95427ab 100644 --- a/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs @@ -339,7 +339,7 @@ private void SetNameFieldsIfNull() /// public virtual Response Create( Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => CreateInternal( @@ -379,7 +379,7 @@ public virtual Response Create( /// public virtual async Task> CreateAsync( Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => await CreateInternal( @@ -422,7 +422,7 @@ await CreateInternal( /// private async Task> CreateInternal( Metadata metadata, - FileSmbProperties? smbProperties, + FileSmbProperties smbProperties, string filePermission, bool async, CancellationToken cancellationToken) @@ -731,7 +731,7 @@ private async Task> GetPropertiesInternal( /// a failure occurs. /// public virtual Response SetHttpHeaders( - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => SetHttpHeadersInternal( @@ -766,7 +766,7 @@ public virtual Response SetHttpHeaders( /// a failure occurs. /// public virtual async Task> SetHttpHeadersAsync( - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => await SetHttpHeadersInternal( @@ -804,7 +804,7 @@ await SetHttpHeadersInternal( /// a failure occurs. /// private async Task> SetHttpHeadersInternal( - FileSmbProperties? smbProperties, + FileSmbProperties smbProperties, string filePermission, bool async, CancellationToken cancellationToken) @@ -1481,7 +1481,7 @@ private async Task> ForceCloseHandlesInter public virtual Response CreateSubdirectory( string subdirectoryName, Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) { @@ -1526,7 +1526,7 @@ public virtual Response CreateSubdirectory( public virtual async Task> CreateSubdirectoryAsync( string subdirectoryName, Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) { @@ -1632,9 +1632,9 @@ await GetSubdirectoryClient(subdirectoryName) public virtual Response CreateFile( string fileName, long maxSize, - FileHttpHeaders? httpHeaders = default, + FileHttpHeaders httpHeaders = default, Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) { @@ -1689,9 +1689,9 @@ public virtual Response CreateFile( public virtual async Task> CreateFileAsync( string fileName, long maxSize, - FileHttpHeaders? httpHeaders = default, + FileHttpHeaders httpHeaders = default, Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) { diff --git a/sdk/storage/Azure.Storage.Files/src/FileClient.cs b/sdk/storage/Azure.Storage.Files/src/FileClient.cs index 58a0ce5118f1..eca9f941b777 100644 --- a/sdk/storage/Azure.Storage.Files/src/FileClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/FileClient.cs @@ -357,9 +357,9 @@ private void SetNameFieldsIfNull() /// public virtual Response Create( long maxSize, - FileHttpHeaders? httpHeaders = default, + FileHttpHeaders httpHeaders = default, Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => CreateInternal( @@ -410,9 +410,9 @@ public virtual Response Create( /// public virtual async Task> CreateAsync( long maxSize, - FileHttpHeaders? httpHeaders = default, + FileHttpHeaders httpHeaders = default, Metadata metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => await CreateInternal( @@ -466,9 +466,9 @@ await CreateInternal( /// private async Task> CreateInternal( long maxSize, - FileHttpHeaders? httpHeaders, + FileHttpHeaders httpHeaders, Metadata metadata, - FileSmbProperties? smbProperties, + FileSmbProperties smbProperties, string filePermission, bool async, CancellationToken cancellationToken) @@ -1282,8 +1282,8 @@ private async Task> GetPropertiesInternal( /// public virtual Response SetHttpHeaders( long? newSize = default, - FileHttpHeaders? httpHeaders = default, - FileSmbProperties? smbProperties = default, + FileHttpHeaders httpHeaders = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => SetHttpHeadersInternal( @@ -1330,8 +1330,8 @@ public virtual Response SetHttpHeaders( /// public virtual async Task> SetHttpHeadersAsync( long? newSize = default, - FileHttpHeaders? httpHeaders = default, - FileSmbProperties? smbProperties = default, + FileHttpHeaders httpHeaders = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) => await SetHttpHeadersInternal( @@ -1381,8 +1381,8 @@ await SetHttpHeadersInternal( /// private async Task> SetHttpHeadersInternal( long? newSize, - FileHttpHeaders? httpHeaders, - FileSmbProperties? smbProperties, + FileHttpHeaders httpHeaders, + FileSmbProperties smbProperties, string filePermission, bool async, CancellationToken cancellationToken) diff --git a/sdk/storage/Azure.Storage.Files/src/Models/FileHttpHeaders.cs b/sdk/storage/Azure.Storage.Files/src/Models/FileHttpHeaders.cs index afe2790907df..2d7be69fa402 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/FileHttpHeaders.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/FileHttpHeaders.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.ComponentModel; namespace Azure.Storage.Files.Models { @@ -15,7 +16,7 @@ namespace Azure.Storage.Files.Models /// /// For more information, see . /// - public struct FileHttpHeaders : IEquatable + public class FileHttpHeaders { /// /// The MIME content type of the file. @@ -65,49 +66,14 @@ public struct FileHttpHeaders : IEquatable /// /// The instance to compare to. /// True if they're equal, false otherwise. - public override bool Equals(object obj) - => obj is FileHttpHeaders other && Equals(other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => base.Equals(obj); /// /// Get a hash code for the FileHttpHeaders. /// /// Hash code for the FileHttpHeaders. - public override int GetHashCode() - => ContentType.GetHashCode() - ^ ContentHash.GetHashCode() - ^ ContentEncoding.GetHashCode() - ^ ContentLanguage.GetHashCode() - ^ ContentDisposition.GetHashCode() - ^ CacheControl.GetHashCode() - ; - - /// - /// Check if two FileHttpHeaders instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(FileHttpHeaders left, FileHttpHeaders right) => left.Equals(right); - - /// - /// Check if two FileHttpHeaders instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(FileHttpHeaders left, FileHttpHeaders right) => !(left == right); - - /// - /// Check if two FileHttpHeaders instances are equal. - /// - /// The instance to compare to. - public bool Equals(FileHttpHeaders other) - => CacheControl == other.CacheControl - && ContentDisposition == other.ContentDisposition - && ContentEncoding == other.ContentEncoding - && ContentLanguage == other.ContentLanguage - && ContentHash == other.ContentHash - && ContentType == other.ContentType - ; + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => base.GetHashCode(); } } diff --git a/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs b/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs index bc6bbb9872e3..9f75aac86566 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs @@ -3,21 +3,24 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; +#pragma warning disable SA1402 // File may only contain a single type + namespace Azure.Storage.Files.Models { /// /// The SMB properties for a file. /// - public struct FileSmbProperties : IEquatable + public class FileSmbProperties { /// /// The file system attributes for this file. /// - public NtfsFileAttributes? FileAttributes { get; set; } + public NtfsFileAttributes FileAttributes { get; set; } /// /// The key of the file permission. @@ -49,6 +52,10 @@ public struct FileSmbProperties : IEquatable /// public string ParentId { get; internal set; } + internal FileSmbProperties() + { + } + internal FileSmbProperties(RawStorageFileInfo rawStorageFileInfo) { FileAttributes = NtfsFileAttributes.Parse(rawStorageFileInfo.FileAttributes); @@ -110,50 +117,16 @@ internal FileSmbProperties(RawStorageDirectoryProperties rawStorageDirectoryProp /// /// The other instance to compare to. /// + [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object other) - => other is FileSmbProperties props && Equals(props); + => base.Equals(other); /// /// Gets the hash code for the FileSmbProperties. /// /// - public override int GetHashCode() - => FileAttributes.GetHashCode() - ^ FilePermissionKey.GetHashCode() - ^ FileCreationTime.GetHashCode() - ^ FileLastWriteTime.GetHashCode() - ^ FileChangeTime.GetHashCode() - ^ FileId.GetHashCode() - ^ ParentId.GetHashCode(); - - /// - /// Check if two FileSmbProperties instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're equal, false otherwise. - public static bool operator ==(FileSmbProperties left, FileSmbProperties right) => left.Equals(right); - - /// - /// Check if two FileSmbProperties instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// True if they're not equal, false otherwise. - public static bool operator !=(FileSmbProperties left, FileSmbProperties right) => !(left == right); - - /// - /// Check if two FileSmbProperties instances are equal. - /// - /// The other instance to compare to. - public bool Equals(FileSmbProperties other) - => FileAttributes == other.FileAttributes - && FilePermissionKey == other.FilePermissionKey - && FileCreationTime == other.FileCreationTime - && FileLastWriteTime == other.FileLastWriteTime - && FileChangeTime == other.FileChangeTime - && FileId == other.FileId - && ParentId == other.ParentId; + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => base.GetHashCode(); internal string FileCreationTimeToString() => NullableDateTimeOffsetToString(FileCreationTime); diff --git a/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs b/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs index bb6a9b70645b..0d1eb35a6fa7 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs @@ -14,7 +14,7 @@ namespace Azure.Storage.Files.Models /// /// NTFS file attributes for Files and Directories. /// - public struct NtfsFileAttributes : IEquatable + public class NtfsFileAttributes { /// /// The File or Directory has no NTFS attributes. @@ -87,41 +87,12 @@ public struct NtfsFileAttributes : IEquatable public override bool Equals(object other) => other is NtfsFileAttributes attributes && Equals(attributes); - /// - /// Checks if two FileNtfsAttributes are equal to each other. - /// - /// TThe other instance to compare to. - /// - public bool Equals(NtfsFileAttributes other) - => None == other.None - && ReadOnly == other.ReadOnly - && Hidden == other.Hidden - && System == other.System - && Normal == other.Normal - && Directory == other.Directory - && Archive == other.Archive - && Temporary == other.Temporary - && Offline == other.Offline - && NotContentIndexed == other.NotContentIndexed - && NoScrubData == other.NoScrubData; - /// /// Get a hash code for the FileNtfsAttributes. /// /// Hash code for the FileNtfsAttributes. [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => - (None ? 0b00000000001 : 0) + - (ReadOnly ? 0b00000000010 : 0) + - (Hidden ? 0b00000000100 : 0) + - (System ? 0b00000001000 : 0) + - (Normal ? 0b00000010000 : 0) + - (Directory ? 0b00000100000 : 0) + - (Archive ? 0b00001000000 : 0) + - (Temporary ? 0b00010000000 : 0) + - (Offline ? 0b00100000000 : 0) + - (NotContentIndexed ? 0b01000000000 : 0) + - (NoScrubData ? 0b10000000000 : 0); + public override int GetHashCode() => base.GetHashCode(); /// /// ToString @@ -199,7 +170,7 @@ public override string ToString() /// /// string to parse /// - public static NtfsFileAttributes? Parse(string attributesString) + public static NtfsFileAttributes Parse(string attributesString) { if (attributesString == null) { diff --git a/sdk/storage/Azure.Storage.Files/src/Models/StorageDirectoryInfo.cs b/sdk/storage/Azure.Storage.Files/src/Models/StorageDirectoryInfo.cs index 50e2a14d38da..5df2828a8517 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/StorageDirectoryInfo.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/StorageDirectoryInfo.cs @@ -30,7 +30,7 @@ public class StorageDirectoryInfo /// /// The directory's SMB properties. /// - public FileSmbProperties? SmbProperties { get; set; } + public FileSmbProperties SmbProperties { get; set; } internal StorageDirectoryInfo(RawStorageDirectoryInfo rawStorageDirectoryInfo) { diff --git a/sdk/storage/Azure.Storage.Files/src/Models/StorageFileInfo.cs b/sdk/storage/Azure.Storage.Files/src/Models/StorageFileInfo.cs index 4c61a1be67a4..9149f68fe816 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/StorageFileInfo.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/StorageFileInfo.cs @@ -37,7 +37,7 @@ public class StorageFileInfo /// /// The file's SMB properties. /// - public FileSmbProperties? SmbProperties { get; set; } + public FileSmbProperties SmbProperties { get; set; } internal StorageFileInfo(RawStorageFileInfo rawStorageFileInfo) { diff --git a/sdk/storage/Azure.Storage.Files/src/ShareClient.cs b/sdk/storage/Azure.Storage.Files/src/ShareClient.cs index df40292a22ff..7ba69e293908 100644 --- a/sdk/storage/Azure.Storage.Files/src/ShareClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/ShareClient.cs @@ -1593,7 +1593,7 @@ private async Task> CreatePermissionInternal( public virtual Response CreateDirectory( string directoryName, IDictionary metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) { @@ -1640,7 +1640,7 @@ public virtual Response CreateDirectory( public virtual async Task> CreateDirectoryAsync( string directoryName, IDictionary metadata = default, - FileSmbProperties? smbProperties = default, + FileSmbProperties smbProperties = default, string filePermission = default, CancellationToken cancellationToken = default) { diff --git a/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs index f5ba85f9b182..fd1e2c7134e4 100644 --- a/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs @@ -185,8 +185,8 @@ public async Task CreateAsync_SmbProperties() // Assert AssertValidStorageDirectoryInfo(response); //Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.Value.FileAttributes); - Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.Value.FileCreationTime); - Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.Value.FileLastWriteTime); + Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.FileCreationTime); + Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.FileLastWriteTime); } } @@ -331,9 +331,9 @@ public async Task SetPropertiesAsync_SmbProperties() // Assert AssertValidStorageDirectoryInfo(response); - Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.Value.FileAttributes); - Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.Value.FileCreationTime); - Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.Value.FileLastWriteTime); + Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.FileAttributes); + Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.FileCreationTime); + Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.FileLastWriteTime); } } diff --git a/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs index 66bf8aa2f5a1..5e138257f6db 100644 --- a/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs @@ -205,9 +205,9 @@ public async Task CreateAsync_SmbProperties() // Assert AssertValidStorageFileInfo(response); - Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.Value.FileAttributes); - Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.Value.FileCreationTime); - Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.Value.FileLastWriteTime); + Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.FileAttributes); + Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.FileCreationTime); + Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.FileLastWriteTime); } } @@ -483,9 +483,9 @@ public async Task SetPropertiesAsync_SmbProperties() // Assert AssertValidStorageFileInfo(response); - Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.Value.FileAttributes); - Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.Value.FileCreationTime); - Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.Value.FileLastWriteTime); + Assert.AreEqual(smbProperties.FileAttributes, response.Value.SmbProperties.FileAttributes); + Assert.AreEqual(smbProperties.FileCreationTime, response.Value.SmbProperties.FileCreationTime); + Assert.AreEqual(smbProperties.FileLastWriteTime, response.Value.SmbProperties.FileLastWriteTime); } } diff --git a/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs b/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs index a7c98cbae322..4b5779b01da9 100644 --- a/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs +++ b/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs @@ -179,7 +179,7 @@ public static void AssertValidStorageFileInfo(StorageFileInfo storageFileInfo) Assert.IsNotNull(storageFileInfo.LastModified); Assert.IsNotNull(storageFileInfo.IsServerEncrypted); Assert.IsNotNull(storageFileInfo.SmbProperties); - AssertValidFileSmbProperties(storageFileInfo.SmbProperties.Value); + AssertValidFileSmbProperties(storageFileInfo.SmbProperties); } public static void AssertValidStorageDirectoryInfo(StorageDirectoryInfo storageDirectoryInfo) @@ -187,7 +187,7 @@ public static void AssertValidStorageDirectoryInfo(StorageDirectoryInfo storageD Assert.IsNotNull(storageDirectoryInfo.ETag); Assert.IsNotNull(storageDirectoryInfo.LastModified); Assert.IsNotNull(storageDirectoryInfo.SmbProperties); - AssertValidFileSmbProperties(storageDirectoryInfo.SmbProperties.Value); + AssertValidFileSmbProperties(storageDirectoryInfo.SmbProperties); } public static void AssertValidFileSmbProperties(FileSmbProperties fileSmbProperties) From 04a1c9dbb33b19ec5b8f54e9fe4397d0bd8a98b3 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 17 Oct 2019 12:14:49 -0700 Subject: [PATCH 5/6] Bring back some --- .../src/Models/NtfsFileAttributes.cs | 31 ++++++++++++++++++- .../tests/DirectoryClientTests.cs | 13 +++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs b/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs index 0d1eb35a6fa7..b1c9b794a712 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/NtfsFileAttributes.cs @@ -87,12 +87,41 @@ public class NtfsFileAttributes public override bool Equals(object other) => other is NtfsFileAttributes attributes && Equals(attributes); + /// + /// Checks if two FileNtfsAttributes are equal to each other. + /// + /// TThe other instance to compare to. + /// + public bool Equals(NtfsFileAttributes other) + => None == other.None + && ReadOnly == other.ReadOnly + && Hidden == other.Hidden + && System == other.System + && Normal == other.Normal + && Directory == other.Directory + && Archive == other.Archive + && Temporary == other.Temporary + && Offline == other.Offline + && NotContentIndexed == other.NotContentIndexed + && NoScrubData == other.NoScrubData; + /// /// Get a hash code for the FileNtfsAttributes. /// /// Hash code for the FileNtfsAttributes. [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => base.GetHashCode(); + public override int GetHashCode() => + (None ? 0b00000000001 : 0) + + (ReadOnly ? 0b00000000010 : 0) + + (Hidden ? 0b00000000100 : 0) + + (System ? 0b00000001000 : 0) + + (Normal ? 0b00000010000 : 0) + + (Directory ? 0b00000100000 : 0) + + (Archive ? 0b00001000000 : 0) + + (Temporary ? 0b00010000000 : 0) + + (Offline ? 0b00100000000 : 0) + + (NotContentIndexed ? 0b01000000000 : 0) + + (NoScrubData ? 0b10000000000 : 0); /// /// ToString diff --git a/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs index fd1e2c7134e4..e774aff698d5 100644 --- a/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs @@ -268,7 +268,7 @@ public async Task GetPropertiesAsync() // Assert Assert.AreEqual(createResponse.Value.ETag, getPropertiesResponse.Value.ETag); Assert.AreEqual(createResponse.Value.LastModified, getPropertiesResponse.Value.LastModified); - Assert.AreEqual(createResponse.Value.SmbProperties, getPropertiesResponse.Value.SmbProperties); + AssertPropertiesEqual(createResponse.Value.SmbProperties, getPropertiesResponse.Value.SmbProperties); } } @@ -625,5 +625,16 @@ public async Task DeleteFileAsync() async () => await file.GetPropertiesAsync()); } } + + private void AssertPropertiesEqual(FileSmbProperties left, FileSmbProperties right) + { + Assert.AreEqual(left.FileAttributes, right.FileAttributes); + Assert.AreEqual(left.FileCreationTime, right.FileCreationTime); + Assert.AreEqual(left.FileChangeTime, right.FileChangeTime); + Assert.AreEqual(left.FileId, right.FileId); + Assert.AreEqual(left.FileLastWriteTime, right.FileLastWriteTime); + Assert.AreEqual(left.FilePermissionKey, right.FilePermissionKey); + Assert.AreEqual(left.ParentId, right.ParentId); + } } } From 260351eac22f45d960a5b0fc96c45d097614d66e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 17 Oct 2019 12:32:47 -0700 Subject: [PATCH 6/6] Reuse method --- .../src/Models/FileSmbProperties.cs | 7 +++---- .../Azure.Storage.Files/tests/DirectoryClientTests.cs | 10 ---------- .../Azure.Storage.Files/tests/FileClientTests.cs | 4 ++-- sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs | 11 +++++++++++ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs b/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs index 9f75aac86566..f5d8d08e8a19 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/FileSmbProperties.cs @@ -140,10 +140,9 @@ private static string NullableDateTimeOffsetToString(DateTimeOffset? dateTimeOff private static string DateTimeOffSetToString(DateTimeOffset dateTimeOffset) => dateTimeOffset.UtcDateTime.ToString(Constants.File.FileTimeFormat, CultureInfo.InvariantCulture); } - - /// - /// FilesModelFactory provides utilities for mocking. - /// + /// + /// FilesModelFactory provides utilities for mocking. + /// public static partial class FilesModelFactory { /// diff --git a/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs index e774aff698d5..454df6680a9a 100644 --- a/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/DirectoryClientTests.cs @@ -626,15 +626,5 @@ public async Task DeleteFileAsync() } } - private void AssertPropertiesEqual(FileSmbProperties left, FileSmbProperties right) - { - Assert.AreEqual(left.FileAttributes, right.FileAttributes); - Assert.AreEqual(left.FileCreationTime, right.FileCreationTime); - Assert.AreEqual(left.FileChangeTime, right.FileChangeTime); - Assert.AreEqual(left.FileId, right.FileId); - Assert.AreEqual(left.FileLastWriteTime, right.FileLastWriteTime); - Assert.AreEqual(left.FilePermissionKey, right.FilePermissionKey); - Assert.AreEqual(left.ParentId, right.ParentId); - } } } diff --git a/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs index 5e138257f6db..ab17a3f6be0a 100644 --- a/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/FileClientTests.cs @@ -331,7 +331,7 @@ public async Task GetPropertiesAsync() Assert.AreEqual(createResponse.Value.ETag, getPropertiesResponse.Value.ETag); Assert.AreEqual(createResponse.Value.LastModified, getPropertiesResponse.Value.LastModified); Assert.AreEqual(createResponse.Value.IsServerEncrypted, getPropertiesResponse.Value.IsServerEncrypted); - Assert.AreEqual(createResponse.Value.SmbProperties, getPropertiesResponse.Value.SmbProperties); + AssertPropertiesEqual(createResponse.Value.SmbProperties, getPropertiesResponse.Value.SmbProperties); } } @@ -784,7 +784,7 @@ await file.UploadRangeAsync( Assert.AreEqual(getPropertiesResponse.Value.CopySource, downloadResponse.Value.Details.CopySource); Assert.AreEqual(getPropertiesResponse.Value.CopyStatus, downloadResponse.Value.Details.CopyStatus); Assert.AreEqual(getPropertiesResponse.Value.IsServerEncrypted, downloadResponse.Value.Details.IsServerEncrypted); - Assert.AreEqual(getPropertiesResponse.Value.SmbProperties, downloadResponse.Value.Details.SmbProperties); + AssertPropertiesEqual(getPropertiesResponse.Value.SmbProperties, downloadResponse.Value.Details.SmbProperties); } } diff --git a/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs b/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs index 4b5779b01da9..6d7516cbf6d2 100644 --- a/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs +++ b/sdk/storage/Azure.Storage.Files/tests/FileTestBase.cs @@ -201,6 +201,17 @@ public static void AssertValidFileSmbProperties(FileSmbProperties fileSmbPropert Assert.IsNotNull(fileSmbProperties.ParentId); } + internal static void AssertPropertiesEqual(FileSmbProperties left, FileSmbProperties right) + { + Assert.AreEqual(left.FileAttributes, right.FileAttributes); + Assert.AreEqual(left.FileCreationTime, right.FileCreationTime); + Assert.AreEqual(left.FileChangeTime, right.FileChangeTime); + Assert.AreEqual(left.FileId, right.FileId); + Assert.AreEqual(left.FileLastWriteTime, right.FileLastWriteTime); + Assert.AreEqual(left.FilePermissionKey, right.FilePermissionKey); + Assert.AreEqual(left.ParentId, right.ParentId); + } + private class DisposingShare : IDisposable { public ShareClient ShareClient { get; }