February 2009 Entries

Unit Testing: Moq doesn't support property indexers

I hit a road block today writing some tests which were dependent upon another class's property indexer. When trying to do the following using Moq: 1: [TestMethod] 2: public void Test1() 3: { 4: Mock<HttpContextBase> context = new Mock<HttpContextBase>(); 5:  6: Object actual = null; 7:  ...

Entity Framework: Abstracting ObjectContext

Wither you are a TDD purest or not, if you are developing with Entity Framework and testability is important to you, then you have tried some workaround or applied some pattern to make testing possible in your project. When you have a class or method which depends on any external resource it is important to create some sort of abstraction in order to remove a dependency upon that resource so you can effectively test your code. The client I am currently working for has chosen to create a repository class which takes an ObjectContext argument in the constructor. The repository...

Entity Framework: How to Prevent Eager Loading

As we have been using Entity Framework on my current project I have found that it can be easy to kill eager loading on your queries. This can be a real problem if you are counting on it. I have been working on cross-cutting concerns up to this point, but because of my experience with Linq 2 SQL I was asked about some issues our team was having with eager loading. Namely, the Include() method, which is a method of the ObjectQuery type. If you've read any documentation on eager loading I'm sure you've read that using projections precludes the...

Entity Framework: Connection Strings

<add name="AdventureWorksEntities" connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl; provider=System.Data.SqlClient;provider connection string='Data Source=localhost; Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'" providerName="System.Data.EntityClient" /> According to MSDN, the above EntityClient connection string will search in the following locations for the specified csdl, ssdl and msl resource files: The calling assembly The referenced assemblies The assemblies in the bin directory of an applicationHowever, I have not found this to be...

Customizing Blogger: Placing Ads In Your Template

I've been struggling lately to place ads in my blogger template. The only thing that's really worked well is using the AdSense widget. But I've been wanting to place a banner ad in my template and blogger doesn't have a widget for that. When I have tried in the past, the size of my header has increased, but the ad won't display.Well, I tried again today and finally got a helpful error message from blogger:Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.XML error message: The reference to entity...

Mono Project: I had no idea

I usually prefer to blog about my own ideas and the learning process with new technologies. But when I read this article on InfoWorld I had to write about it. What's Mono? Mono is an open source implementation of Microsoft's .NET Framework. The big difference between Mono and .NET is that Mono runs on Linux, Max AND Windows. The Mono Project also has an implementation of Silverlight, named Moonlight, which allows Silverlight projects to run on Linux operating systems. So what? Well I always thought Mono was kinda cool, but I'm strictly an ASP.NET developer...

ASP.NET: Removing System.Web Dependencies

As a general rule I prefer to avoid referencing System.Web in my library classes. But if it can't be avoided it's still a good idea to avoid the use of HttpContext.Current. It must be nice to live in a perfect world you say? Yes, there are times that even this cannot be avoided. Or can it? Yes, it is possible by wrapping HttpContext.Current with a helper library which exposes only the methods required by your library. But there are times when even this is an arduous task at best. So what's a guy to do?System.Web.AbstractionsWell, it just got easier. If...

Lost In Translation – Episode 3: Users and Schemas

In my last post I mentioned I would be addressing tables next, but as I read through the documentation I realized something. Because Oracle doesn't have the same concept of databases as SQL Server I need to use schemas to segregate my data. In order to create a schema you must create a user. When you create a user in Oracle, a schema is implicitly created. Which means I need to create a user so I can place my tables and other database objects into a schema. I'll be using scripts in this episode instead of screenshots because...

 

 

Copyright © Mark J. Miller