?????????????VS????????????????????????????????????xunit??????????????????VS???????????????

/// <summary>
/// ??????????
/// </summary>
[TestClass]
public class BaseUnitTest
{
    IsolationLevel _isolationLevel = IsolationLevel.Unspecified;
    TransactionScopeOption _scopeOption = TransactionScopeOption.Required;
    TransactionScope _transactionScope;
    bool _openAutoRollback = true;

     /// <summary>
    /// ??????
    /// </summary>
    /// <param name="autoRollback">???????????????????</param>
    public BaseUnitTest(bool autoRollback = true)
    {
        _openAutoRollback = autoRollback;
    }

     /// <summary>
    /// ??????????????
    /// </summary>
    [TestInitialize]
    public void AutoRollbackBefore()
    {
        if (_openAutoRollback)
        {
            var options = new TransactionOptions();
            options.IsolationLevel = _isolationLevel;
            options.Timeout = new TimeSpan(0?? 1?? 0);
            _transactionScope = new TransactionScope(_scopeOption?? options);
        }
    }

     /// <summary>
    /// ????????????????????
    /// </summary>
    [TestCleanup]
    public void AutoRollbackAfter()
    {
        if (_openAutoRollback)
        {
            if (_transactionScope == null)
                throw new InvalidOperationException("δ?????TransactionScope");
            //???????
            _transactionScope.Dispose();
            //??????????
            _transactionScope = null;
            //??????е????
            RemoveHttpRuntimeCache();
        }
    }

     /// <summary>
    /// ??????е?HttpRuntime????
    /// </summary>
    [DebuggerStepThrough]
    private void RemoveHttpRuntimeCache()
   {
        var cache = HttpRuntime.Cache.GetEnumerator();
        var keys = new List<string>();
        while (cache.MoveNext())
        {
            keys.Add(cache.Key.ToString());
        }
        foreach (var key in keys)
        {
            HttpRuntime.Cache.Remove(key);
        }
    }

     /// <summary>
    /// ???ò???????????
    /// </summary>
    protected void SetAutoRollbackIsUnavailabled()
    {
        _openAutoRollback = false;
    }
}

?????????RemoveHttpRuntimeCache?????????????????????HttpRuntime???棬?????????е???????????????????????£?????????п????????????????????????????滺?檔

???????????????????????£???TransactionScope????????????????????????MSDN????“TransactionScope”???????