????????????????????????
???????????? ???????[ 2013/6/17 10:31:56 ] ????????
??????????????TDD?????????????鷳????????????????????????????????????????????????????????????????????????????鷳??
?????????xunit?????????AutoRollbackAttribute??????????????? ^_^?????????????????????????
?????????AutorollbackAttribute?????????
public class AutoRollbackAttribute : BeforeAfterTestAttribute
{
IsolationLevel isolationLevel = IsolationLevel.Unspecified;
TransactionScope scope;
TransactionScopeOption scopeOption = TransactionScopeOption.Required;
long timeoutInMS = -1;
/// <summary>
/// Gets or sets the isolation level of the transaction.
/// Default value is <see cref="IsolationLevel"/>.Unspecified.
/// </summary>
public IsolationLevel IsolationLevel
{
get { return isolationLevel; }
set { isolationLevel = value; }
}
/// <summary>
/// Gets or sets the scope option for the transaction.
/// Default value is <see cref="TransactionScopeOption"/>.Required.
/// </summary>
public TransactionScopeOption ScopeOption
{
get { return scopeOption; }
set { scopeOption = value; }
}
/// <summary>
/// Gets or sets the timeout of the transaction?? in milliseconds.
/// By default?? the transaction will not timeout.
/// </summary>
public long TimeoutInMS
{
get { return timeoutInMS; }
set { timeoutInMS = value; }
}
/// <summary>
/// Rolls back the transaction.
/// </summary>
public override void After(MethodInfo methodUnderTest)
{
scope.Dispose();
}
/// <summary>
/// Creates the transaction.
/// </summary>
public override void Before(MethodInfo methodUnderTest)
{
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = isolationLevel;
if (timeoutInMS > 0)
options.Timeout = new TimeSpan(timeoutInMS * 10);
scope = new TransactionScope(scopeOption?? options);
}
}
?????????????.Net Framework?????TransactionScope??TransactionScope??.NET 2.0???????????????????????????????????????????????????Щ????
????1???????????????
????2????????????????????????????????
???????????????????????????????????2?????????mongodb????????????????????????????????????????????????mongodb??????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11