Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Leibowitz <mattleibow@live.com>2014-08-23 02:38:15 +0400
committerMatthew Leibowitz <mattleibow@live.com>2014-08-23 02:38:15 +0400
commit5b4172c8ccd0f196f24a4ade721896723ec17511 (patch)
tree811d0fe66ea9d2c317fc634437823a5242fb74f0 /mcs/class/System.Transactions
parent96b66b38673015fce249025b21af99cc0779009b (diff)
[system.transactions] Throw exception when an invalid TimeSpan is provided:
- MS.NET throws - prevent construction when an invalid (negative) timeout is provided
Diffstat (limited to 'mcs/class/System.Transactions')
-rw-r--r--mcs/class/System.Transactions/System.Transactions/TransactionScope.cs5
-rw-r--r--mcs/class/System.Transactions/Test/TransactionScopeTest.cs18
2 files changed, 22 insertions, 1 deletions
diff --git a/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs b/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs
index 9c9648c0f74..d996b785700 100644
--- a/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs
+++ b/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs
@@ -62,7 +62,6 @@ namespace System.Transactions
{
}
- [MonoTODO ("No TimeoutException is thrown")]
public TransactionScope (TransactionScopeOption option,
TimeSpan timeout)
{
@@ -92,6 +91,10 @@ namespace System.Transactions
completed = false;
isRoot = false;
nested = 0;
+
+ if (timeout < TimeSpan.Zero)
+ throw new ArgumentOutOfRangeException ("timeout");
+
this.timeout = timeout;
oldTransaction = Transaction.CurrentInternal;
diff --git a/mcs/class/System.Transactions/Test/TransactionScopeTest.cs b/mcs/class/System.Transactions/Test/TransactionScopeTest.cs
index 80925e27f52..1dbda6e1d22 100644
--- a/mcs/class/System.Transactions/Test/TransactionScopeTest.cs
+++ b/mcs/class/System.Transactions/Test/TransactionScopeTest.cs
@@ -19,6 +19,24 @@ namespace MonoTests.System.Transactions
{
[Test]
+ public void TransactionScopeWithInvalidTimeSpanThrows ()
+ {
+ try {
+ TransactionScope scope = new TransactionScope (TransactionScopeOption.Required, TimeSpan.FromSeconds (-1));
+ Assert.Fail ("Expected exception when passing TransactionScopeOption and an invalid TimeSpan.");
+ } catch (ArgumentOutOfRangeException ex) {
+ Assert.AreEqual (ex.ParamName, "timeout");
+ }
+
+ try {
+ TransactionScope scope = new TransactionScope (null, TimeSpan.FromSeconds (-1));
+ Assert.Fail ("Expected exception when passing TransactionScopeOption and an invalid TimeSpan.");
+ } catch (ArgumentOutOfRangeException ex) {
+ Assert.AreEqual (ex.ParamName, "timeout");
+ }
+ }
+
+ [Test]
public void TransactionScopeCommit ()
{
Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");