Articles : Page 1 of 1
-
Abstracting away issues of HttpContext from your ASP.NET MVC controllers
Feb 1203I've noticed that I write software in one of three modes: For myself: Shortcuts, less testing, not well-factored. For myself but in public: Mostly POP Forums, which I try to avoid letting it suck since others will use it and see the code. For sharing: Any day job or gig where others will use or maintain your code. You don't want to unleash crapsauce on others. I have to admit that second case isn't the most clean of endeavors. While I'm generally happy with the forum app and the feedba...
-
Using EntityFramework with ASP.NET MVC 3
Mar 1121A few people have asked about a comment I made on my last post: I might suggest (in this case) creating an ActionFilter and wrapping the Action in a transaction. It’s transparent, it’s fun… and all the kids are doing it. … and it got me thinking. All of the MSDN samples that I’ve seen which talk about using EF or LinqToSql with ASP.NET MVC almost always show the context being created inside an action or being passed in via a repository. This doesn’t have to be the case - in fact it probably...
-
Using EntityFramework with ASP.NET MVC 3
Mar 1121A few people have asked about a comment I made on my last post: I might suggest (in this case) creating an ActionFilter and wrapping the Action in a transaction. It’s transparent, it’s fun… and all the kids are doing it. … and it got me thinking. All of the MSDN samples that I’ve seen which talk about using EF or LinqToSql with ASP.NET MVC almost always show the context being created inside an action or being passed in via a repository. This doesn’t have to be the case - in fact it probabl...
-
ASP.NET MVC Unit Testing with UpdateModel and TryUpdateModel
Jan 1125Last week I was in the middle of re-writing an old MVC application. The app was written during the early days of MVC, and as a consequence it was a playground for learning and experimentation. As a developer, I am continuously learning new tricks so its’ no surprise that when I look at the code I wrote a few years ago, I generally will feel the urge to refactor it. For example, when I started out with ASP.NET MVC I did not fully understand how the model binders worked. Unfortunately, this mean...
-
Unit Testing Secure Controller Actions with Moq
Aug 1015One of the hardest things to unit test in MVC is security. Security is tough to test because there is a lot of setup involved in mocking the HttpContext, the Principal and the Identity. For example, in WeBlog I am using the following code in the Edit Post action. Post post = Repository.FirstOrDefault<Post>(x => x.ID == id); if (post == null) return View(NotFound if (!HttpContext.User.CanEditPost(post)) return View(PermissionDenied In order to make sure this code works properly I need to t...
- 1

