vb.net - NUnit test how to prepare/modify function -


probably simple question beginner in area. have nunit project , test similar functions example below. see pass id , looping through, when data found delete records.

now regards test instead of delete collect of id's (those going deleted) , compare them in test project.

what got on mind extend function additional variables store id's add additional paraemeter function istest boolean , in places deletes put statment like: if test not delete add ids variables, think bad idea.

how should accomplished right way?

 public sub deleverythingassociatedwithsection(secid integer)         using con new sqlconnection(strcon)             con.open()             using transaction = con.begintransaction                 try                     dim dthtmlsection_katsubkatdal new datatable                     dthtmlsection_katsubkatdal = ctype(new htmlsection_katsubkatdal().getallbysecid(secid), datatable)                     if dthtmlsection_katsubkatdal isnot nothing                         each sec_katsubkat datarow in dthtmlsection_katsubkatdal.rows                             dim dtsubsec_seckatsubkat_subsubkat new datatable                             dtsubsec_seckatsubkat_subsubkat = ctype(new dalsubsec_seckatsubkat_subsubkat().getallbysec_katsub(cint(sec_katsubkat(0))), datatable)                             if dtsubsec_seckatsubkat_subsubkat isnot nothing                                 each subsec datarow in dtsubsec_seckatsubkat_subsubkat.rows                                     dim dthtmlsentence_subsec_seckatsubkat_subsubkat 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                                         each sent datarow in dthtmlsentence_subsec_seckatsubkat_subsubkat.rows                                             dim dtartikel_beschreibung new datatable                                             dtartikel_beschreibung = ctype(new artikel_beschreibungdal().getallbysentence(cint(sent(0))), datatable)                                             if dtartikel_beschreibung isnot nothing                                                 each artbesch 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 made far without exception, commit.                     transaction.commit()                 catch ex exception                     transaction.rollback()                     throw 'rethrow exception.                 end try             end using         end using     end sub 

i think making complicated. write test this... (pseudo-code)

// arrange set section data. assume.that(section exists data) // optional, in case setup fails  // act delete section  // assert try data in section assert.that(no data found) 

Comments