Unit testing multi-tenant database provider

My saga on supporting multiple tenants in ASP.NET Core web applications has come to point where tenants can use separate databases. It’s time now to write some tests for data context to make sure it behaves correct in unexpected situations. This post covers unit tests for data context and multi-tenancy.

Faking Azure ID identity in ASP.NET Core unit tests

When testing ASP.NET Core controllers in application that uses Azure AD we need usually current user at least for some tests. As there is no authenticated user when unit testing, we need to create one by our own. This blog post shows how to create claims identity for ASP.NET Core unit tests.

Using Entity Framework Core in-memory database for unit testing

ASP.NET Core applications can be tested with different testing frameworks and Entity Framework Core makes testing specially easy by removing different technical problems from our way by using in-memory data provider. This blog posts shows how to unit test controllers that use data from Entity Framework Core.

Using xUnit with ASP.NET Core

Writing tests for ASP.NET Core applications can be done using xUnit. xUnit works on both.NET Framework and .NET Core. This post shows how to set up and use xUnit with ASP.NET Core applications in Visual Studio and on command-line. Targeting multiple frameworks is also covered.

ASP.NET 5: Running tests on K and Visual Studio

Using new ASP.NET tooling it is also very easy to run tests on command line. We don’t need Visual Studio to be installed on machine where we want to run tests and we can use this fancy K-stuff to make tests run. This post will show you how to write and run tests using new Visual Studio and K.

Using Moq to mock ASP.NET MVC HttpContextBase

Here’s my little example about how to use Moq to mock HttpContextBase and it’s members to make controller tests pass. You can use this code when you are not allowed to use open-source or use-on-your-own-risk pieces of software that provide you this kind on initialization using built-in features. Also it is good exercise that introduces you how to solve mocking problems.

Quick introduction to Pex

Pex and Moles is new testing and code analysis technology that is created by Microsoft Research. Pex is powerful tool that helps you analyze your code, detect error situations and generate parameterized unit tests. In this posting I will give you quick and illustrated overview of Pex.

ChartResult: Testable ASP.NET MVC 3 controller actions that return Chart

Lately I blogged about charts support in ASP.NET MVC 3 beta. This posting showed how to get chart initialized and sent to client quickly. In this posting I will show you how to use Chart with ChartResult to make our chart operations testable.

ASP.NET MVC 3: Using HttpNotFoundResult in controller tests

Lately I blogged about HttpNotFoundResult and HttpStatusCodeResult action results that come with ASP.NET MVC 3. These results are ideal for controller tests as we don’t have to mess with HttpContext and Response objects anymore. In this posting I will show you how to use HttpNotFoundResult in controller tests to check if errors are given correctly to user.

Using dynamic type to test ASP.NET MVC controller actions returning JsonResult

I wrote unit tests for my ASP.NET MVC application that uses some jQuery AJAX-components. These components load data from server in JSON format. I needed to write tests for these methods to make sure that correct data is returned to client. In this posting I will show you how to use dynamic type to test […]

Invariant code contracts – using class-wide contracts

It is possible to define invariant code contracts for classes. Invariant contracts should always hold true whatever member of class is called. In this posting I will show you how to use invariant code contracts so you understand how they work and how they should be tested.

Code Contracts: Unit testing contracted code

Code contracts and unit tests are not replacements for each other. They both have different purpose and different nature. It does not matter if you are using code contracts or not – you still have to write tests for your code. In this posting I will show you how to unit test code with contracts.

How to configure Visual Studio 2010 code coverage for ASP.NET MVC unit tests

I just got Visual Studio 2010 code coverage work with ASP.NET MVC application unit tests. Everything is simple after you have spent some time with forums, blogs and Google. To save your valuable time I wrote this posting to guide you through the process of making code coverage work with ASP.NET MVC application unit tests.

The Mythical Man-Month

Yesterday I finished reading the classic project management book The Mythical Man-Month: Essays on Software Engineering by Frederick P. Brooks. Well… this book made me think a lot about nature of software projects, how primitive is our understanding about them and why managing such projects is usually hard fighting with a lot of different issues. The book has also interesting content from the past that is really interesting reading. To understand where you are you should know where you come from.

ExpectedException attribute in Visual Studio 2008 and Visual Studio 2010

Today I tried to write my first unit tests under Visual Studio 2010. Just to see if Visual Studio testing system can now also be used for unit tests. Visual Studio 2008 had some annoying problems with test and I preferred to use nUnit instead. Visual Studio 2010 brings some good news – tests work. Take a look at my example.

Problem when testing LINQ To SQL Classes objects

I am writing a small web shop application using ASP.NET MVC Framework. As a part of this project I also write unit test and integration tests. I am using LINQ To SQL Classes as a mapping solution in my project. I found one misleading behaviour of LINQ To SQL Classes when writing integration tests.

TechEd 2008 Developers – How to start testing

I visited Roy Osherove session at TechEd 2008 Developers (EMEA) where he spoke about how and why to test software. There was nothing new to me besides couple of things but I want to give you a little overview about the most painful topic for companies and developers – how to start testing. It was the best part of session I think and that’s why I decided to blog about it.

Sometimes integration tests are more important

There are some cases when integration tests are more protective than unit tests. Of course, there is no reason to compare these two kinds of tests but if we have to write them we have to set priorities and think what problems may arise during development. One special case when it is important to have integration tests early in place is when we are using O/R-mappers.

Testing sorting algorithms

Some time ago I had to deal with sorting algorithms. Besides my main task I found a good way how to test custom sorting algorithms. This blog entry is one of early birds, more about sorting algorihtms is coming soon. Hopefully some time after TechEd 2007 for Developers. The procedure I wrote to test sorting algorithms is simple and works. Of course, I am always opened for better ideas if somebody wants to suggest some. Here’s the little overview about what I’ve done.

Previous Posts