Isolating your BLL from your DAL and unit testing it

This article will teach you how to set up a basic service and repository, to isolate your BLL (Business Logic Layer) from your DAL (Data Access Layer), so you can easily create unit tests for your BLL. This solution doesn’t use any ORM (Object Relational Mapping) like e.g. Entity Framework. This is only to explain how to isolate logic from data and how to test your logic in isolation.

Continue reading

How to mock and test WCF services using Moq

I really needed to mock and test WCF services for a new project I’m working on. I had heard great things about the Moq mocking framework so I decided to use that.

Continue reading

.NET Config Transforms and how they are useful

Config Transforms are a nifty method to have your configuration vary, depending on which build configuration you are running or what servers you are publishing to. This gets the most useful when you’re deploying to many kinds of different servers; Development, staging, production, etc.

Continue reading

Problem with SimpleMembership and Roles

I had a problem with SimpleMembership, Authorize attributes and roles. When I ran my program, I occasionally got the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

To fix it, I had to go to /Account/LogOff and log in again. Very weird problem. I tried Googling it without any luck, until I stumpled upon this blog post. That saved my day. I decided to write down the method here, in case if his blog went down. For users who stumble upon this problem. Continue reading

WebMatrix SimpleMembership upgrade path

Before Microsoft released MVC 4, I created my project with the good old ASP.NET Membership Provider. After release of MVC 4, Microsoft switched to SimpleMembership by WebMatrix. My project was pretty huge, so I searched for an upgrade path to switch without harming the project. I was in no luck finding a method to switch over, so I followed my own “upgrade path” and decided to share it with the world.

Continue reading

How to mock the DataContext (Entity Framework)

Earlier I wrote an article about how to mock the LINQ DataContext. I promised to write an article about how to do the same method with Entity Framework. It’s quite similar, but the only difference is creating an IDbContext interface and using DbSet<T>. Continue reading

How to mock the DataContext (LINQ)

When it comes to mocking the LINQ DataContext, it’s not an easy task to do, because DataContext (base class) doesn’t implement any interface, so you have to create a wrapper around the DataContext. I decided to follow the Unit Of Work pattern and created also a Generic Repository to access the model classes from the DataContext. Continue reading

© 2020

Theme by Anders NorenUp ↑