Development, Testing

Mocking internal interfaces

Yesterday I’ve worked on connector library used to access data warehouses provided by two external vendors. In order for it to be easy to use I limited public members to:

  • library interface – can be used to aggregate connectors and testing
  • two connector classes that that provide public methods to retrieve prepared responses
  • DTO request and response classes

Continue reading

Standard
Development

Elipse and Circle inheritance problem

Recently I’ve been listening to Coding Blocks podcast, an episode which subject was software design anti-patterns. They described one of them, which is pretty well known: the Circle-Ellipse problem.

The problem goes like this: let’s assume we’re writing a program and we’ve created IShape interface (which might have methods to calculate circumstance and area of the shape). Now we create Ellipse, which implements IShape interface and follows that with Circle class. Now since Circle is a special case of Ellipse, and every circle is an Ellipse it naturally should inherit from Ellipse.

Continue reading

Standard
Development

I just wrote that without StackOverflow

In the life of many developers comes the moment, when you write something non-trivial and it just works. And you don’t have to google anything! It’s quite thrilling!

I have been creating a mock object for testing, that could store several graphs at the same time. The graph was very simple, it could have only root (portfolio) and leaves of several types. Linking was done from leaf to root, by setting two properties (a little redundant): parentId and parentName.

I figured that writing a function that would link it automatically without the need to repeat that every time could improve code quality. However, leaves were of different types. They just happen to have the same properties, but no way I could write a generic method that could use it.

Neither of them was inheriting from any other object, but I figured I should go with the interface anyway since I just required for two properties to be there and I know that some databases don’t like when types share a common ancestor:

public interface IPortfolioLinked
{
    string PortfolioId { get; set; }
    string PortfolioName { get; set; }
}

I had been using Ploeh.Autofixture before, so I just went with whatever it was providing me and I have created an extension method that would take builder, attach parent symbol to it and return builder of the same type

public static IPostprocessComposer<T> WithLinkedPortfolio<T>(
    this ICustomizationComposer<T> builder,
    PortfolioDTO parent) where T : IPortfolioLinked
{
    var parentId = PortfolioDTO.CreateId(parent);
    return builder
        .With(x => x.PortfolioId, parentId)
        .With(x => x.PortfolioName, parent.Name);
}

Overall it’s not impressive. But I’m quite excited about it because:

  1. I’ve just written it and everybody is excited about things they wrote
  2. I haven’t used any external sources. I just knew all of that quite intuitively. Yey!
Standard
Podcasts

Coding Blocks – great recommendation for beginners

Last week, our colleague Douglas (who hopefully is quite successful in combating dehydration and other threats during his trip to south-east Asia) recommended to me a  programming podcast Coding Blocks. And since object-oriented design patterns were never my strongest side I’ve decided to take some time and try to give it a try. So I immediately downloaded around 30 episodes, which totally clogged my weekly podcast queue.

I’m using BeyondPod podcast player, with an ability to prioritize certain feeds. In my case, those prioritized feeds are This Week in Tech and Security Now. I just enjoy rants about tech companies and weekly digest on new vulnerabilities and hacks. Everything else is thrown into one big bag and replayed from oldest episodes to newest.

So everything else is quite recent, I’ve just dumped a big pile of 3-year-old podcasts right into that bag. And I have hardly been listening to anything else this week.

11 episodes later and I must admit I quite like it. It’s a nice mix of general programming bits of advice and quite specific C# related tips and tricks. Usually, there are some tips how to make your life easier and I loved the episode about what kind of peripherals you should use.

The target audience for this podcast is junior and mid-level developers that would like to learn a new perspective and improve the quality of code they’re writing. I doubt there will be anything that senior dev could actually take away, other than SOLID principles are very confusing even to people that think are familiar with them.

Standard
Development, Testing

Mock – my favourite mock engine

When I try to unit test class one of the most important things is to eliminate all dependencies and replace them with proper mocks. Such mocks allow me to fully control inputs that object will access and verify that proper methods have been called.

Recently I’ve written one business logic class that manages SPA (Single Page Application) and uses four different repositories from which it pulls data and presents them as Web API.

Continue reading

Standard
Development, Testing

NCrunch – A plugin that makes TDD sexy

Before I started working at my current job I’ve never seen continuous testing tools. For me running unit test, despite being really useful, was a chore that I would do after modifying several files and (usually) writing few additional tests.

It shouldn’t come as a surprise, that several of them will be failing, enabling me to do what developers like the most – fixing errors in their code or, even more fun, fixing errors in somebody else’s code.

Continue reading

Standard