I have been reviewing hanselman article and I would like to really learn deeply how the following code works. It looks like generics and Extension methods? What other subjects I should get familiar with to really understand the following code. What type of subjects (like generics, extension methods???) I need to know to understand the whole code base mentioned in the article. Thanks
public static HttpContextBase FakeHttpContext()
{
var context = new Mock<HttpContextBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
context.Setup(ctx => ctx.Request).Returns(request.Object);
context.Setup(ctx => ctx.Response).Returns(response.Object);
context.Setup(ctx => ctx.Session).Returns(session.Object);
context.Setup(ctx => ctx.Server).Returns(server.Object);
return context.Object;
}
There’s lots of good stuff in that article but it is kind of hard to know how to answer your question. As you say there is use of generics, extension methods, lambda expressions, behind the scenes there will surely be some reflection going on in that mocking library (moq) and you will surely come across the linq extensions at some point when you get to writing tests. So all of that is probably worth reading up on.
The article is all about unit testing, ultimately, so an understanding of what a unit test is, why it is good etc would be useful – Pragmatic Unit Testing is a great book as an introduction to that topic. Then there is the whole test driven development approach, where you write tests first and fix them as you go along so you could read up on that too (though I would say just try it out and see how you get on).
So, try it, use it, have some fun and you will pick up what you need to know as you go.