Skip to content

Commit 5d5a994

Browse files
Throw on transfer options facade overflow (Azure#19119)
Co-authored-by: jschrepp-MSFT <[email protected]>
1 parent f98032c commit 5d5a994

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

sdk/storage/Azure.Storage.Common/src/StorageTransferOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public struct StorageTransferOptions : IEquatable<StorageTransferOptions>
1919
[EditorBrowsable(EditorBrowsableState.Never)]
2020
public int? MaximumTransferLength
2121
{
22-
get => (int?)MaximumTransferSize;
22+
get => checked((int?)MaximumTransferSize);
2323
set => MaximumTransferSize = value;
2424
}
2525

@@ -43,7 +43,7 @@ public int? MaximumTransferLength
4343
[EditorBrowsable(EditorBrowsableState.Never)]
4444
public int? InitialTransferLength
4545
{
46-
get => (int?)InitialTransferSize;
46+
get => checked((int?)InitialTransferSize);
4747
set => InitialTransferSize = value;
4848
}
4949

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using NUnit.Framework;
10+
11+
namespace Azure.Storage.Tests
12+
{
13+
public class StorageTransferOptionsTests
14+
{
15+
/// <summary>
16+
/// Tests non-throwing cases for backwards compatibility of int? facade
17+
/// <see cref="StorageTransferOptions.MaximumTransferLength"/>.
18+
/// </summary>
19+
/// <param name="realSize"></param>
20+
[TestCase(default)]
21+
[TestCase(1)]
22+
[TestCase(int.MaxValue)]
23+
public void MaxTransferLengthBackCompatTest(long? realSize)
24+
{
25+
var options = new StorageTransferOptions
26+
{
27+
MaximumTransferSize = realSize
28+
};
29+
30+
Assert.AreEqual(options.MaximumTransferSize, realSize);
31+
Assert.AreEqual(options.MaximumTransferLength, realSize);
32+
}
33+
34+
/// <summary>
35+
/// Tests throwing cases for backwards compatibility of int? facade
36+
/// <see cref="StorageTransferOptions.MaximumTransferLength"/>.
37+
/// </summary>
38+
/// <param name="realSize"></param>
39+
[TestCase(int.MaxValue + 1L)]
40+
[TestCase(long.MaxValue)]
41+
public void MaxTransferLengthBackCompatOverflowTest(long? realSize)
42+
{
43+
var options = new StorageTransferOptions
44+
{
45+
MaximumTransferSize = realSize
46+
};
47+
48+
Assert.AreEqual(options.MaximumTransferSize, realSize);
49+
Assert.Throws<OverflowException>(() => _ = options.MaximumTransferLength);
50+
}
51+
52+
/// <summary>
53+
/// Tests non-throwing cases for backwards compatibility of int? facade
54+
/// <see cref="StorageTransferOptions.MaximumTransferLength"/>.
55+
/// </summary>
56+
/// <param name="realSize"></param>
57+
[TestCase(default)]
58+
[TestCase(1)]
59+
[TestCase(int.MaxValue)]
60+
public void InitialTransferLengthBackCompatTest(long? realSize)
61+
{
62+
var options = new StorageTransferOptions
63+
{
64+
InitialTransferSize = realSize
65+
};
66+
67+
Assert.AreEqual(options.InitialTransferSize, realSize);
68+
Assert.AreEqual(options.InitialTransferLength, realSize);
69+
}
70+
71+
/// <summary>
72+
/// Tests throwing cases for backwards compatibility of int? facade
73+
/// <see cref="StorageTransferOptions.MaximumTransferLength"/>.
74+
/// </summary>
75+
/// <param name="realSize"></param>
76+
[TestCase(int.MaxValue + 1L)]
77+
[TestCase(long.MaxValue)]
78+
public void InitialTransferLengthBackCompatOverflowTest(long? realSize)
79+
{
80+
var options = new StorageTransferOptions
81+
{
82+
InitialTransferSize = realSize
83+
};
84+
85+
Assert.AreEqual(options.InitialTransferSize, realSize);
86+
Assert.Throws<OverflowException>(() => _ = options.InitialTransferLength);
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)