2016-08-08 4 views
0

おそらく簡単な質問ですが、私はこの分野の初心者です。 NUnitプロジェクトをお持ちで、以下の例のような同様の関数をテストしたいと思います。あなたが見ているように、私はそれにいくつかのIDを渡し、その後、データが見つかったときにレコードを削除します。NUnitテスト機能の準備/修正方法

ここで、テストに関して、私は削除の代わりに、これらのID(削除される予定のもの)をすべて集めてテストプロジェクトで比較したいと思います。

私が気づいたのは、idを格納するための変数を追加して関数を拡張し、isTestのような機能をブールとして追加し、削除する場所にstatmentのような場所を追加することです。しかし、私は非常に悪い考えだと思う。

これはどのように正しい方法で達成する必要がありますか?

Public Sub DelEverythingAssociatedWithSection(secId As Integer) 
     Using con As New SqlConnection(strcon) 
      con.Open() 
      Using transaction = con.BeginTransaction 
       Try 
        Dim dtHtmlSection_KatSubkatDAL As New DataTable 
        dtHtmlSection_KatSubkatDAL = CType(New HtmlSection_KatSubkatDAL().GetAllBySecId(secId), DataTable) 
        If dtHtmlSection_KatSubkatDAL IsNot Nothing Then 
         For Each sec_katsubkat As DataRow In dtHtmlSection_KatSubkatDAL.Rows 
          Dim dtSubSec_SecKatSubKat_SubSubKat As New DataTable 
          dtSubSec_SecKatSubKat_SubSubKat = CType(New DALSubSec_SecKatSubKat_SubSubKat().GetAllBySec_KatSub(CInt(sec_katsubkat(0))), DataTable) 
          If dtSubSec_SecKatSubKat_SubSubKat IsNot Nothing Then 
           For Each subsec As DataRow In dtSubSec_SecKatSubKat_SubSubKat.Rows 
            Dim dtHtmlSentence_SubSec_SecKatSubKat_SubSubKat As New DataTable 
            dtHtmlSentence_SubSec_SecKatSubKat_SubSubKat = CType(New HtmlSentence_SubSec_SecKatSubKat_SubSubKatDAL().GetAllBySubSec_SecKatSubKat_SubSubKat(CInt(subsec(0))), DataTable) 
            If dtHtmlSentence_SubSec_SecKatSubKat_SubSubKat IsNot Nothing Then 
             For Each sent As DataRow In dtHtmlSentence_SubSec_SecKatSubKat_SubSubKat.Rows 
              Dim dtArtikel_Beschreibung As New DataTable 
              dtArtikel_Beschreibung = CType(New Artikel_BeschreibungDAL().GetAllBySentence(CInt(sent(0))), DataTable) 
              If dtArtikel_Beschreibung IsNot Nothing Then 
               For Each artBesch As DataRow In dtArtikel_Beschreibung.Rows 
                Call New Artikel_BeschreibungDAL().Delete(CInt(artBesch(0)), transaction) 
               Next 
              End If 
              Call New HtmlSentence_SubSec_SecKatSubKat_SubSubKatDAL().Delete(CInt(sent(0)), transaction) 
             Next 
            End If 
            Call New DALSubSec_SecKatSubKat_SubSubKat().Delete(CInt(subsec(0)), transaction) 
           Next 
          End If 
          Call New HtmlSection_KatSubkatDAL().Delete(CInt(sec_katsubkat(0)), transaction) 
         Next 
        End If 
        Call New DALSection().Delete(secId, transaction) 
        'If we made it this far without an exception, then commit. 
        transaction.Commit() 
       Catch ex As Exception 
        transaction.Rollback() 
        Throw 'Rethrow exception. 
       End Try 
      End Using 
     End Using 
    End Sub 
+0

誰にでも答えますか? –

答えて

0

あなたは複雑すぎると思います。このようなテストを書くだけ...(擬似コード)

// Arrange 
Set up a section with some data. 
Assume.That(section exists with data) // optional, in case setup fails 

// Act 
Delete the section 

// Assert 
Try to get the data in the section 
Assert.That(no data is found) 
+0

こんにちは、正直ではない。削除の代わりにデータを返すものはありません。もっと説明できますか? –

+0

セクションを削除できることをテストしている場合、そのセクションに返されるデータはないと思いますか? – Charlie

+0

擬似コードです!たくさん残っている。 :-) データを取得しようとする場所を示すために編集しました。 – Charlie

関連する問題