Replacement of Algorithm Testing with Testing of Effects Being Inserted

As I expected, Rule 8 from the article “Rules for Implementing TDD in Old Project” stating that we don’t need to test the algorithm of methods raised many “how” and “why” questions. When writing the previous article, it seemed obvious to me, so I did not go into much details on the matter. In this article, I provide a small sample code and two examples of how it could be tested.

(more…)

Rules for Implementing TDD in Old Project

The article “Sliding Responsibility of the Repository Pattern” raised several questions, which are very difficult to answer. Do we need a repository if the complete disregard of technical details is impossible? How complex must the repository be so that its addition can be regarded worth-while? The answer to these questions varies depending on the emphasis placed in the development of systems. Probably the most difficult question is the following: do you even need a repository? The problem of “flowing abstraction” and the growing complexity of coding with an increase in the level of abstraction do not allow to find a solution that would satisfy both sides of the fence. For example, in reporting, intention design leads to the creation of a large number of methods for each filter and sorting, and a generic solution creates a large coding overhead.

(more…)

Steps to Reduce Code Size after Use of Strategy Pattern

This article features a few tricks to reduce the size of the code resulting from the use of the ‘strategy’ pattern. As you can deduce from the title, all these tricks will be related to the usage of generic types.

1. Hierarchy of classes involved in magic rituals

Suppose we have an abstract ‘vehicle’ class that can move (the Move method). This class has 3 descendants: a car, a plane, and a rickshaw. Each of them implements the method in its own way: (more…)

Indicators of Problem Design

The concept of good or bad design is relative. At the same time, there are some programming standards, which in most cases guarantee effectiveness, maintainability, and testability. For example, in object-oriented languages, this is the use of encapsulation, inheritance, and polymorphism. There is a set of design patterns that in a number of cases have a positive or negative effect on the application design depending on the situation. On the other hand, there are opposites, following which sometimes leads to the problem design.

(more…)

Sliding Responsibility of the Repository Pattern

During numerous discussions about the applicability of the Repository pattern, I noticed that people are divided into two groups. In this article, I will call them abstractionists and concretists. The difference between them is in the way they treat the pattern value. The former believe that a repository is worthwhile, as it allows disregarding details of data storing. The latter suppose there is no way to disregard these details, therefore, the concept of repository makes no sense and its usage is a waste of time. The dispute between these two groups usually turns into a Holy War. (more…)

Events and Threads in .NET

I’d like to tell you straight off that this article will concern not threads in particular, but events in the context of threads in .NET.  So, I won’t try arranging threads correctly (with all blocks, callbacks, canceling, etc.) There are many articles on this subject.

All examples are written in C# for the framework version 4.0 (in 4.6, everything is slightly easier, but still, there are many projects in 4.0). I will also try to stick to C# version 5.0.

Firstly, I’d like to note that there are ready delegates for the .Net event system that I highly recommend to use instead of inventing something new. For example, I frequently faced the following 2 methods for organizing events. (more…)

Swashbuckle (Swagger) Customization for WebAPI

Who has ever tested their WebAPI knows such tools as Postman or Advanced REST (extensions for Chrome). These tools are convenient in every way, except that they are not able to recognize which models the API accepts, which ones it returns and do not provide information about all possible endpoints. The Swashbuckle package solves this disadvantage. It builds Swagger specification generation and UI in the project. In this article, I will briefly describe how to bind it to the project and provide some details about authorization and work with “overloaded” endpoints.

(more…)

DateTime to DateTimeOffset Transition

Imagine that you want to convert your system from one state to another. The initial state is when DateTime is used everywhere, both in C# code and in the database. The final state is when DateTimeOffset is used everywhere. You want to make the transition smooth and make as few changes as possible. This description can be the beginning of a very interesting problem with a dead end at the end.

(more…)