1

I have a system.resx resources file that is used in a SubmitClick method

Protected Sub SubmitClick(ByVal sender As Object, ByVal e As EventArgs)

  (...)

  If (... AndAlso ...) Then
      SetError(Resources.system.groupNoAdminTran)
  End If

End Sub

My problem is that no matter how I try to unit test this, the test will fail when the SetError is hit with a:

"Could not load file or assembly 'App_GlobalResources' or one of its
 dependencies. The system cannot find the file specified."

Is there any way I can mock the Resources.system?

Thanks

kooshka
  • 871
  • 1
  • 9
  • 19
  • What breaks? Are you getting an error? Your unit test doesn't pass? How does your unit test look? – Darin Dimitrov Dec 05 '11 at 09:08
  • When the SetError is hit the Unit Test fails with "Could not load file or assembly 'App_GlobalResources' or one of its dependencies. The system cannot find the file specified." – kooshka Dec 05 '11 at 09:17
  • Your question seems to be a duplicate of: http://stackoverflow.com/questions/4153748/app-globalresources-not-loading-in-a-unit-test-case – Gilles Dec 05 '11 at 20:30

1 Answers1

0

This solution may not be elegant but is the one that I used in the end, feel free to criticise.

Manually created a property for each needed string in the Resources:

Public Property GroupNoAdminTran() As String
    Get
        If String.IsNullOrEmpty(_groupNoAdminTran) Then
            _groupNoAdminTran = Resources.system.groupNoAdminTran
        End If
        Return _groupNoAdminTran
    End Get
    Set(ByVal value As String)
        _groupNoAdminTran = value
    End Set
End Property

Which can then be used like:

Protected Sub SubmitClick(ByVal sender As Object, ByVal e As EventArgs)

  (...)

  If (... AndAlso ...) Then
      SetError(GroupNoAdminTran)
  End If

End Sub 

As for the test, a simple mock will do:

_moqView.Setup(x => x.GroupNoAdminTran).Returns("GroupNoAdminTranTest");

and that's all. I hope this helps.

kooshka
  • 871
  • 1
  • 9
  • 19