Visual Studio 2010 seems to be mixing up the above mentioned libraries.
This code sample is from the book "Pro ASP.NET MVC2 Framework" by Steven Sanderson.
[TestMethod]
public void HomePage_Recognizes_New_Visitor_And_Sets_Cookie()
{
// Arrange: First prepare some mock context objects
var mockContext = new Mock<HttpContextBase>();
var mockRequest = new Mock<HttpRequestBase>();
var mockResponse = new Mock<HttpResponseBase>();
// The following lines define associations between the different mock objects
// (i.e. tells Moq what alue to use for tMockContext.Request)
mockContext.Setup(x=> x.Request).Returns(mockRequest.Object);
mockContext.Setup(x=> x.Response).Returns(mockResponse.Object);
mockRequest.Setup(x=> x.Cookies).Returns(new HttpCookieCollection());
mockResponse.Setup(x=> x.Cookies).Returns(new HttpCookieCollection());
var homeController = new HomeController();
var requestContext = new RequestContext(mockContext.Object, new RouteData());
homeController.ControllerContext = new ControllerContext(requestContext, homeController);
// Act
ViewResult viewResult = homeController.HomePage();
// Assert
Assert.AreEqual(String.Empty, viewResult.ViewName);
Assert.IsTrue((bool)viewResult.ViewData["IsFirstVisit"]);
Assert.AreEqual(1, homeController.Response.Cookies.Count);
Assert.AreEqual(bool.TrueString, homeController.Response.Cookies["HasVisitedBefore"].Value);
}
My project references the System.Web and System.Web.Abstractions libraries.
When the code file is only "using System.Web" I get two errors:
If I add "using System.Web.Abstractions" to the code file and build the project, the above errors go away but then then I get the following error:
Interestingly, in both cases when I place a dot after Response, Intellisense prompts me with the correct choices (i.e. Response.Cookies). It seems like Intellisense has information about HttpResponseBase that the build engine does not.
Any idea what may be causing this?
Can you double check that under your Project References you have both System.Web
and System.Web.Abstractions
?
Using the source code for the book downloaded from the Apress site, I can build your code without errors, but when I remove the reference to System.Web.Abstractions
, I get the same behavior, including the intellisense information prompts you noted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With