0
public class RollBack : OnMethodBoundaryAspect // or another AOP for meth interception
{
    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {
        try
        {
            ServiceConfig cfg = new ServiceConfig();
            cfg.Transaction = TransactionOption.RequiresNew;
            cfg.TrackingAppName = "Application Unit Tests";
            cfg.TransactionDescription = "Application Unit Tests Transaction";
            cfg.TransactionTimeout = 0x2710;
            ServiceDomain.Enter(cfg);
        }
        catch (Exception exception)
        {
            Console.WriteLine("Could not enter into a new transaction:\n" + exception);
        }
    }

    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        try
        {
            if (ContextUtil.IsInTransaction)
            {
                ContextUtil.SetAbort();
            }
            ServiceDomain.Leave();
        }
        catch (Exception exception)
        {
            Console.WriteLine("Could not leave an existing transaction:\n" + exception);
        }
    }
}
4

1 に答える 1

0

テスト後にロールバックするために、トランザクション内で戦術的にテストしていることがわかります。

私は個人的にゼロから始めて、テスト用のテーブルを作成し、後で削除します。別の一般的な手法は、データベースを既知の状態に復元することです。ただし、データベース内の多くの状態に依存している場合、テストが広すぎることを示していることをお勧めします。

これについては PHP について書きましたが、.NET でより頻繁に作業しています。

http://www.stevefenton.co.uk/Content/Blog/Date/201110/Blog/Database-Integration-Testing-With-Enhance-PHP/

于 2013-02-04T21:55:03.933 に答える