I have a class that wraps the GetGlobalResourceObject and GetLocalResourceObjet so they can be used easily in MVC. The model validation classes then load the error messages dynamically from resource files. The problem is unit testing. The code uses "~/", and while everything functions correctly when the solution is run, I cannot see how to make the unit tests because I always receive the following error "System.Web.HttpException: The application relative virtual path '~/' cannot be made absolute, because the path to the application is not known."
The code that throws the exception is the following, used to evaluate an expression and return a global resource object.
Private Function GetExpressionFields(ByVal expression As String) As ResourceExpressionFields
Return GetExpressionFields(expression, "~/")
End Function
Private Function GetExpressionFields(ByVal expression As String, ByVal path As String) As ResourceExpressionFields
Dim context As New ExpressionBuilderContext(path)
Dim resource_builder As New ResourceExpressionBuilder()
Dim fields As ResourceExpressionFields
fields = DirectCast(resource_builder.ParseExpression(expression, GetType(String), context), ResourceExpressionFields)
Return fields
End Function
Any ideas on how to test this and other code that uses resource files?