I've got a base controller that I inherit all of my Controllers from. It's job is to basically set caching and error handling as well as check for mobile browsers.
My UI works fine, but my Unit Tests are failing.
Imports System.Web.Mvc
<HandleError()> _
<CompressFilter()> _
<OutputCache(Duration:=30, VaryByParam:="id")> _
Public Class BaseController : Inherits System.Web.Mvc.Controller
Protected Overrides Function View(ByVal viewName As String, ByVal masterName As String, ByVal model As Object) As System.Web.Mvc.ViewResult
Dim ismobile As Nullable(Of Boolean) = Request.Browser.IsMobileDevice
If ismobile Then
Return MyBase.View(viewName, "Mobile", model)
Else
Return MyBase.View(viewName, "Site", model)
End If
End Function
End Class
The error I'm getting in my Unit test is on Dim ismobile As Nullable(Of Boolean) = Request.Browser.IsMobileDevice
saying
Object Reference Not Set To An Instance Of An Object.
Edit:
Here is what my test class looks like
Imports System.Web.Mvc
Imports UrbanNow.Core
Imports Microsoft.VisualStudio.TestTools.UnitTesting
<TestClass()> Public Class EventsControllerTest
<TestMethod()> Public Sub Index()
''# Arrange
Dim controller As EventsController = New EventsController()
''# Act
Dim result As ViewResult = CType(controller.Index(), ViewResult)
''# Assert
Dim viewData As ViewDataDictionary = result.ViewData
End Sub
End Class
It's pretty much just a rip off of the test that gets setup when you create a new MVC Web Application.