vendredi 10 avril 2015

Model-View-Presenter Conversion

I work on a .NET application that very loosely followed an n-tier kind of architecture (the business objects (not logic) and data access were split out). We are now looking to get into unit testing (probably using NUnit), and want to start to refactor the code into an MVP architecture. Based on some previous work done by someone else, I just refactored a screen into what I hope is MVP.


I moved almost all of the logic out of the form code (Form.vb) and into the presenter (FormPresenter.vb). Basically, the form looks like this:



Public Property SomeField As String Implements IForm.SomeField
Get
Return txtSomeField.Text
End Get
Set(value As String)
txtSomeField.Text = value
End Set

Public Event ClickBtnSomeButton(..) Implements IForm.ClickBtnSomeButton

Private Sub OnClick_BtnSomeButton(..)
RaiseEvent ClickBtnSomeButton(..)
End Sub


The presenter then contains all of the logic that used to be in the form. For instance, a button click event:



Public Sub OnClick_BtnEditOrder(ByVal sender As Object, ByVal e As System.EventArgs)
View.CursorType = Cursors.WaitCursor

Try
If Not _enabledActions.Contains("Edit Order") Then Return
If View.SelectedInquiryRow Is Nothing Then Return
ShowView_Act()
Catch ex As Exception
HandleException(ex, Me.ToString, "OnClick_btnEditOrder", True, True)
Finally
View.CursorType = Cursors.Default
End Try
End Sub


The form works, it seems to be a much better design, but I have no idea how to test this. The only public methods are the event methods. Anything I would want to test (like perhaps the phone number formatting) is just a private method, called only by the events.


So, ultimately, my question is: Did I refactor incorrectly, or is there simply nothing worth testing here?


Aucun commentaire:

Enregistrer un commentaire