可能是一个简单的问题,但我是这个领域的初学者。有NUnit项目,并希望测试类似的功能,如下面这个例子。如你所见,我传递一些id然后循环,当数据发现我删除记录。
现在关于测试我想要而不是删除我想收集所有这些id(将被删除的那些)并在我的测试项目中进行比较。
我想到的是扩展我的功能,使用额外的变量来存储id'然后添加额外的paraemeter以像isTest一样运行为布尔值,并在删除地方的地方添加如下:如果测试然后不删除但是添加ids变量,但我认为这是个坏主意。
如何以正确的方式实现这一目标?
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)
我认为你太复杂了。只需写一个这样的测试......(伪代码)
start /D a_path .