Navigate / search

EntityFramework – asynchronous queries unit tests

Sometime ago I described how we can use Moq to unit tests elements of DbContext – please check post Mocking DbContext and DbSet with Moq. Unfortunate that post didn’t covered all issues related to that topic. I didn’t write about unit tests asynchronous queries. Today I want to come back to this issue.

We can treat a previous post as a starting point. We already have some code that help us to mock DbSet<T>. And right now we will extend that code to support asynchronous queries. It is very easy. We need only to implement IDbAsyncQueryProvider interface:

public class InMemoryAsyncQueryProvider<TEntity> : IDbAsyncQueryProvider
  private readonly IQueryProvider innerQueryProvider;
  internal InMemoryAsyncQueryProvider(IQueryProvider innerQueryProvider)
    this.innerQueryProvider = innerQueryProvider;

  public IQueryable CreateQuery(Expression expression)
    return new InMemeoryAsyncEnumerable<TEntity>(expression);

  public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
    return new InMemeoryAsyncEnumerable<TElement>(expression);

  public object Execute(Expression expression)
    return this.innerQueryProvider.Execute(expression);
  public TResult Execute<TResult>(Expression expression)
    return this.innerQueryProvider.Execute<TResult>(expression);

  public Task<object> ExecuteAsync(Expression expression, CancellationToken cancellationToken)
    return Task.FromResult(Execute(expression));

  public Task<TResult> ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
    return Task.FromResult(Execute<TResult>(expression));

Read more

Get Noticed! – Short introduction

A few days ago second edition Get Noticed! has started. From the beginning I wanted to be part of this competition community. The idea is great! Unfortunate as usual taking decision was not so easy. The main blocker was my calendar. In that time all of my weekends are busy. Moreover I am planning two foreign trips. One of them will be longer. Finally I decided to take part in it – a small motivation factor was that I tried to convince Jurka to take part in this competition. Finally I decided to take part in it. It seems that it will be the first time when I will take a laptop with me on holidays. I hope I will manage to survive to end of competition.

Let’s switch to issue that I would like to solve.

We can look at this from two perspectives. First – motivation. From over a year I am trying to switch into web technologies. In general I am getting better with it. But still I haven’t started any project from scratch jet. I always joined to project that were already ongoing. And this completion can be great possibility to go through all stages of application creation. Also, I would like to move out from my comfort zone and try new technologies. I am planning to use ASP.NET Core as backend and Angular2 (maybe Angular4) as frontend. Of course, everything will be hosted on Azure.

And finally – the idea. I would like to build an application that will provide information about NuGet package downloads. Also is should be possible to place some kind of button / picture on GitHub that will inform about current number of downloads of our package.

Upgrade from ASP.NET Core 1.0.x to 1.1

New version of .NET Core 1.1 has been published on 17th November. Together with it new versions of ASP.NET and EntityFramework have been introduced. I wanted to update my application to new framework. I thought that it will be very easy. Unfortunate my application didn’t start after update. Moreover it didn’t even compile.

Let’s start from the beginning. The first thing you need to do is downloading and installing new SDK and Runtime. You will find installers on .NET Core Downloads webpage.

Read more

Speeding up AutoFixture

I already mentioned about AutoFixture in one of the posts – Lightning talk – Autofixture. Main goal of this library is to help us with reduction of Arrange part of unit tests. With this library we can focus on the main scenario of unit test instead of focusing on building objects that are needed for test. Moreover AutoFixture will protect us against modification of classes that are being used in our unit tests.

But it is not perfect. Sometimes duration of unit tests can increase dramatically. Especially when you are creating objects used by EntityFramework. Read more

.net DD 2016 – materials

Since few weeks ago it is possible to watch sessions from .NET DeveloperDays 2016 on YouTube channel. I think that the best speaker of that conference edition was Ted Neward. I recommend his closing keynote session. It was really great. It is hard to say that this session was technical one. I would rather say that it was more philosophical. During it Ted showed importance of context in scope of taking correct decisions. He provided a lot examples that showed difficultness of taking this one correct solution / decision. It is hard to describe it. I recommend you to watch it.


I would like to introduce a new small library that I published – FluentValidation.Validators.UnitTestExtension. Main purpose of this library is to extend and simplify possibilities of testing code that is using FluentValidation package.

You can install it by nuget:

Install-Package FluentValidation.Validators.UnitTestExtension

or download it from GithHub.

One of approach of testing Fluent rules is presented in FluentValidation wiki page. You can find there information that FluentValidation comes with two extension methods ShouldHaveValidationErrorFor and ShouldNotHaveValidationErrorFor that can make it easier to write unit tests for validators. Read more

Unit tests – materials from trainings for quality engineers

I would like to invite you to familiarize with materials from training about unit tests. This training has been prepared as part of my work duties in Objectivity Bespoke Software Specialists. The main goal of this training was to learn quality engineers that work in Objectivity how to write unit tests.

The training has been divided into two parts:

  1. Unit Tests – The Beginning – this is an introduction to unit tests; you will learn:
    • what unit tests are,
    • how to develop them correctly,
    • how you can cooperate in project to build better unit tests,
    • how unit tests work.
  2. Unit Test – Let’s write some code – in second part of training you will learn how to begin your adventure with writing unit tests. In main part of training you will find information about xUnit test framework and Moq. Together with that you will also find short introduction to other test frameworks (nUnit and MS Test), NSubstitute and tools that calculate test coverage. Moreover you will gain practical knowledge how to run and debug unit tests.

All materials can be found on GitHub:

  1. Unit Tests – The Beginning
  2. Unit Test – Let’s write some code

I hope that everybody will find something interesting even that this training has been especially prepared for quality engineers.

.NET DeveloperDays 2016

Last week I took part in .NET DeveloperDays 2016. Unfortunate I didn’t manage to attend to workshops and I took part only in conference. I wondered how I could summarize this event. I decided that this time I will not describe presentations but I will focus on main reason why I attended to such event. Few years ago this main reason would be presentations. Right now I went there to meet people. And presentations are something like a bonus to networking.

In this sense conference was very successful. You could find a lot of space where you could talk to each other. Even when I stood in middle of area / path I felt quite comfortable. It is because hall was very big. In this area 3 conference rooms have been prepared. In other area you could find places with coffee machines, cookies, fruits and also XBoxes. There was only a bit crowdy during lunch breaks – then in the hall you could found long queues of hungry software developers. Read more