Unit Testing the Use of TransactionScope

后端 未结 5 1239
情书的邮戳
情书的邮戳 2021-01-31 09:35

The preamble: I have designed a strongly interfaced and fully mockable data layer class that expects the business layer to create a TransactionScope when multip

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-31 10:03

    I'm a Java developer, so I'm uncertain about the C# details, but it seems to me that you need two unit tests here.

    The first one should be a "blue sky" test that succeeds. Your unit test should ensure that all records that are ACID appear in the database after the transaction is committed.

    The second one should be "wonky" version that does the InsertFoo operation and then throws an exception before attempting the InsertBar. A successful test will show that the exception has been thrown and that neither the Foo nor Bar objects have been committed to the database.

    If both of these pass, I'd say that your TransactionScope is working as it should.

提交回复
热议问题