I am new to MOQ, but use it with NUnit for unit testing.
I have all the parts of my controller, but only the next line that gives the error message "Object not installed in the object instance."
Response.Cookies.Clear();
I have the following extension method to make fun of the controller context, which works for everything else that I have come up with so far (very thanks to the nice people on this forum).
public static int SetUpForTest(this System.Web.Mvc.Controller ctl, string username, TestingUtility.Roles role) { var routes = new RouteCollection(); MvcApplication.RegisterRoutes(routes); var request = new Mock<HttpRequestBase>(MockBehavior.Strict); request.SetupGet(x => x.ApplicationPath).Returns("/"); request.SetupGet(x => x.Url).Returns(new Uri("http://localhost/a", UriKind.Absolute)); request.SetupGet(x => x.ServerVariables).Returns(new System.Collections.Specialized.NameValueCollection()); var response = new Mock<HttpResponseBase>(MockBehavior.Strict); response.Setup(x => x.ApplyAppPathModifier(Moq.It.IsAny<String>())).Returns((String url) => url);
As you can see above, I tried to make fun of โgettingโ a collection of cookies, which doesn't help.
In addition, the actual Clear () method cannot be ridiculed because it is not a virtual method.
Obviously, I donโt want to check that cookies are being cleared, I just want to be able to ignore it when testing.
Thanks,
Greg
c # asp.net-mvc nunit moq
Greg
source share