Monday, June 22, 2015

How to add a password to Web.config and encrypt it

I recently had the need to store a password in the web.config file in an ASP.NET web app and I wanted to encrypt it.  I did not want to encrypt the entire appSettings section of the Web.config, so here's a solution I came up with, answering my own question on Stack Overflow, community wiki style!

Need to Mock a DbSet for testing Entity Framework?

I wanted to create fast unit tests that did not rely on the database, nor data in the DB.  I used the Moq framework to create mock objects, but the Entity Framework DbSet was not easy to mock, so I created my own class.  The gist is on github.  View the readme in the gist for more details.  (One of the hardest things is to workaround the DbFunctions which only work for LINQ to Entities).