-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Storage] Use structs for model types where appropriate #7807
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d41bb32
[Storage] Change AccountInfo class to struct
ShivangiReja e284aa4
serialization and deserialization
ShivangiReja 669d849
Add equals and hashcode methods
ShivangiReja 583648c
Chnage PageInfo class to model
ShivangiReja eb47276
Change PageRange class to struct
ShivangiReja 59447e2
Remove unnecessary checks
ShivangiReja 803712e
Merge into master
ShivangiReja 24512d3
Address comments
ShivangiReja 5c3e125
Remove extra space
ShivangiReja a99fe02
"{" on a new line.
ShivangiReja ad47f2b
Merge into master
ShivangiReja 770986e
Generate code after merging into master
ShivangiReja 5a67504
Compare byte arrays by value and update related tests
ShivangiReja 2846eca
GetHashCode() returns false so revert - compare byte array by reference
ShivangiReja 9ca9e5b
Using StructuralComparisons.StructuralEqualityComparer for array comp…
ShivangiReja c593e6c
Nit fixes
ShivangiReja bd85865
Merge into master
ShivangiReja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
322 changes: 251 additions & 71 deletions
322
sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
// 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 | ||
{ | ||
/// <summary> | ||
/// These tests are related to our generated struct behavior. | ||
/// </summary> | ||
public class PageInfoTest | ||
{ | ||
[Test] | ||
public void EqualsReturnsTrueForEqualValues() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these tests are code-generated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, these are hand written tests. |
||
{ | ||
var hash = new byte[] { 1, 2, 3 }; | ||
|
||
var info1 = new PageInfo( | ||
new Core.Http.ETag("A"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
hash, | ||
hash, | ||
1, | ||
"key1"); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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 Core.Http.ETag("A"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
null, | ||
null, | ||
1, | ||
null); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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 Core.Http.ETag("A"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
hash1, | ||
hash1, | ||
1, | ||
"key1"); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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 Core.Http.ETag("A"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
hash1, | ||
hash1, | ||
1, | ||
"key1"); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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 Core.Http.ETag("A"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
null, | ||
hash, | ||
1, | ||
"key1"); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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 Core.Http.ETag("A"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
hash, | ||
null, | ||
1, | ||
"key1"); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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 Core.Http.ETag("B"), | ||
new DateTimeOffset(2019, 9, 25, 1, 1, 1, TimeSpan.Zero), | ||
hash, | ||
hash, | ||
1, | ||
"key1"); | ||
|
||
var info2 = new PageInfo( | ||
new Core.Http.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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment that these are related to our generated struct behavior so they make a little more sense to anyone else finding them in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I wasn't sure what this test was for at first.