Monday, 29 August 2016

Choosing an IoC Container talk at Israeli .NET Developers User Group

Last week I had the honor to hold a talk at the Israeli .NET Developers User Group. The subject was "Choosing an IoC Container", but the main goal was not to choose the best container ever, rather to present different features of IoC Containers and provide the tools to compare between them. Based on the feedback I received from the survey, it achieved the goal.

I would like to share the slides and the code samples presented during the talk.



Friday, 29 April 2016

How to verify that a class is serializable?

Recently I've came into investigating a failing End-to-End test that was failing inside the WCF service with an exception. The exception was related to WCF serialization of the return type of the service. As usually I decided to tackle this issue in the TDD way:

  1. Write a fialing test that reproduces the issue
  2. Write the minimum amount of code to make the test pass
  3. Refactor if needed

I already had a failing End to End test that was failing, but it was a heavy and complex test. All I wanted to a small, fast, isolated and reproducible test that would test only the serialization of that class. We're using FluentAssertions library for readable and intuitive assertions in our unit tests I checked whether it contains a way to verify whether a class would be successfully serialized in WCF. Unfortunately, it had two similar methods:

I need to explain what these methods exactly do for those who are not familiar with them:

  1. Serialize the instance using the selected serialization method: binary or XML
  2. Deserialize the result of the above serialization
  3. Compare the values of the resulted instance with the original one
It was exactly what I needed, but these methods use different serialization methods than WCF. WCF uses DataContract serialization. I decided to contribute to FluentAssertions library and to add the required method. Dennis Doomen generously accepted my pull request and the new method is available in the official nuget package starting from version 4.5.0. Here how it looks like with the new method:


Last but not least: if you encounter into WCF serialization issues, take a look at my post from 2010 with some WCF Serialization Tips.


Thursday, 3 December 2015

How to access TeamCity REST API from C#?

If you work with JetBrains TeamCity as your Continuous Integration server, you probably know that it has rich REST API that allows querying builds, their configuration, builds queue and also perform CRUD operation on them. It might be extremely useful for building custom monitor, triggering builds, cleaning builds queue and many other activities.

In this post I would like to present FluentTc: an easy to use library for all the above operations. When I started working on this library, I had in mind, that it should has fluent, easy to discover API. That's what I like in libraries I consume, so I developed a library that looks like I like it and I hope that you r will find it also usable and easy to use.

In order to get started to use it, you need to install the recent package from Manage Nuget packages -> Search FluentTc

or typing the below in your Package Manager Console of

install-package FluentTc 

So now, having the reference, let's get to the code.

In order to get all the build of specific Build Configuration, you can simply use:


If you are familiar with TeamCity REST API you might know that when retrieving list of entities, it returns only some basic properties of those entities, Id, Name and some Href. It also provides an option to retrieve additional properties. And this is how it can be done using FluentTc:



The above methods return default amount of builds as retrieved from TeamCity REST API. If there is large amount of builds, you'd probably prefer retrieving them with paging, i.e. a few builds each time. This is how it can be achieved with FluentTc:



Of course you can apply different query filters when retrieving your builds. For example, in order to retrieve not personal, pinned, successful builds, that ran during the recent day under specific build configuration, use this:


Credits:
FluentTc was inspired by Paul Stack's TeamCitySharp library.

For questions/suggestions feel free to comment below.

Sunday, 15 November 2015

How to add some fun to software development?

A few days ago I gave a talk titled "10 ways to add fun to development process" at the ALM User Group in Microsoft Raanana. I would like to thank Elad Avneri, the group organizer, for inviting me to the group. During the talk I mentioned some tools and extensions and in this post I will summarize them.

For those of you, who missed the session, here a brief overview of it:

The development process is tedious and complex, we are trying to solve problems in different domains in limited time frames. So a little bit fun and sense of humor can relax the atmosphere in the team and make the work more productive.

Here are some tools that may help you to add some fun to your development process:





Tuesday, 4 August 2015

How to mock file system in tests?

You are probably familiar with System.IO namespace in .NET Framework. It contains useful API for file system operations. Unfortunately, most of its methods are static and thus it is impossible to mock them. In this post I would like to show how we write testable code that works with file system.

Let's see the below simple class that copies a file to a destination directory. If the destination directory does not exist, it creates the directory and then copies the file to the destination.



In order to make our code testable we'll use System.IO.Abstractions library which can be installed from nuget:

package-install System.IO.Abstractions

It provides IFileSystem interface with all the useful interfaces on it:
It will allow us to refactor our class by injecting the IFileSystem into our constructor: As you can see from the above code, all the classes and methods on the System.IO.Abstractions are similar to those on the System.IO. So the transition is very smooth. You also noticed that the IFileSystem is injected via internal constructor, which we'll use in unit tests shortly. Public constructor will be used in our real code and it injects actual implementation of IFileSystem which is FileSystem class. The last part is the unit test. There is complementary library that contains in memory implementation of IFileSystem interface. It can be installed from nuget as well:
Install-Package System.IO.Abstractions.TestingHelpers

In addition to the implementation of IFileSystem interface, it contains convenient methods for adding files and directories (in memory, of course). So let's see how our unit test looks like: We can even assert, that the file was copied and it exists in the destination folder. The library also works well with all existing stream Read/Write operations.
Credits for the library go to: Tatham Oddie

Enjoy coding, Boris Modylevsky