diff --git a/sdk/storage/Azure.Storage.Common/src/StorageTransferOptions.cs b/sdk/storage/Azure.Storage.Common/src/StorageTransferOptions.cs index 6ccb2dcf6a0a..f7e526ea5f2f 100644 --- a/sdk/storage/Azure.Storage.Common/src/StorageTransferOptions.cs +++ b/sdk/storage/Azure.Storage.Common/src/StorageTransferOptions.cs @@ -19,7 +19,7 @@ public struct StorageTransferOptions : IEquatable [EditorBrowsable(EditorBrowsableState.Never)] public int? MaximumTransferLength { - get => (int?)MaximumTransferSize; + get => checked((int?)MaximumTransferSize); set => MaximumTransferSize = value; } @@ -43,7 +43,7 @@ public int? MaximumTransferLength [EditorBrowsable(EditorBrowsableState.Never)] public int? InitialTransferLength { - get => (int?)InitialTransferSize; + get => checked((int?)InitialTransferSize); set => InitialTransferSize = value; } diff --git a/sdk/storage/Azure.Storage.Common/tests/StorageTransferOptionsTests.cs b/sdk/storage/Azure.Storage.Common/tests/StorageTransferOptionsTests.cs new file mode 100644 index 000000000000..77c209e4b5b0 --- /dev/null +++ b/sdk/storage/Azure.Storage.Common/tests/StorageTransferOptionsTests.cs @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace Azure.Storage.Tests +{ + public class StorageTransferOptionsTests + { + /// + /// Tests non-throwing cases for backwards compatibility of int? facade + /// . + /// + /// + [TestCase(default)] + [TestCase(1)] + [TestCase(int.MaxValue)] + public void MaxTransferLengthBackCompatTest(long? realSize) + { + var options = new StorageTransferOptions + { + MaximumTransferSize = realSize + }; + + Assert.AreEqual(options.MaximumTransferSize, realSize); + Assert.AreEqual(options.MaximumTransferLength, realSize); + } + + /// + /// Tests throwing cases for backwards compatibility of int? facade + /// . + /// + /// + [TestCase(int.MaxValue + 1L)] + [TestCase(long.MaxValue)] + public void MaxTransferLengthBackCompatOverflowTest(long? realSize) + { + var options = new StorageTransferOptions + { + MaximumTransferSize = realSize + }; + + Assert.AreEqual(options.MaximumTransferSize, realSize); + Assert.Throws(() => _ = options.MaximumTransferLength); + } + + /// + /// Tests non-throwing cases for backwards compatibility of int? facade + /// . + /// + /// + [TestCase(default)] + [TestCase(1)] + [TestCase(int.MaxValue)] + public void InitialTransferLengthBackCompatTest(long? realSize) + { + var options = new StorageTransferOptions + { + InitialTransferSize = realSize + }; + + Assert.AreEqual(options.InitialTransferSize, realSize); + Assert.AreEqual(options.InitialTransferLength, realSize); + } + + /// + /// Tests throwing cases for backwards compatibility of int? facade + /// . + /// + /// + [TestCase(int.MaxValue + 1L)] + [TestCase(long.MaxValue)] + public void InitialTransferLengthBackCompatOverflowTest(long? realSize) + { + var options = new StorageTransferOptions + { + InitialTransferSize = realSize + }; + + Assert.AreEqual(options.InitialTransferSize, realSize); + Assert.Throws(() => _ = options.InitialTransferLength); + } + } +}