Posts

Verify ILogger calls with Moq.ILogger

Moq is by far the most used mocking library for .NET.It provides objects to either mimic real services implementations or to verify if they were called in a certain way by the Service Under Test.Often teams work hard to have meaningful logs in order to help with investigations, to have the possibility to define alarms based on the content of the logs, or even to help with instrumentation. If there is a log entry that resembles as an exception, then a notification might be sent to a Teams/Slack channel, an email, or even to randomly start the alarms on your team's members' cars (joking, don't do that, you know everyone ignores that Slack channel).There are many situations when an investigation ends up with no resolution, and with a promise to the client that the missing logging lines will soon be added. This it translates into development costs, reputation loss, and maybe most importantly having a missed opportunity to learn about the system's behavior in the production…

Invest in learning now!

Image
I worked for several years in a very unique setup with me being the only developer. There was me, the supplier and a guy good with CSS. This supplier had a bunch of small customers, but nothing a developer couldn't handle in a several months span. Also, I couldn't bill more than 5 hours/day in a month, but it was fine, as the rate was good.

Being a solo developer comes with some advantages like you get to choose your tools, libraries, frameworks, patterns or technologies and you get to work on all layers. As long as I delivered under the constrained budget and time, the supplier didn't really care how I did it. A big disadvantage was my only available friend when I was in trouble was StackOverflow and often wasn't much. I remember spending days and even nights to solve odd problems when it would have helped to have an experienced colleague to ask or even an extra pair of eyes to look into that missing semicolon.
I somehow successfully managed to deliver those solution…

Programmer Procrastination

Is when you have to do a quick fix, decide to do it, but refactor something unrelated, then read an article which mentions about Erlang; install the shell, try it, remember about the goroutines and channels concepts in Go; read the wiki for a quick refresh... check the clock, it's 5:00 pm and you don't know how the time passed in the last 3 hours. Let's hope is just a quick fix

(of course I also read the news, saw some random youtube videos, lurked on reddit, but that doesn't sound good, isn't it :) )
The Grape exists and I regret I didn't go there today. Had a great time in the past three weeks.

pseudo brainfuck with the help of C# operator overloading

Linq To Objects Extension: Full Outer Join

Image
I need a report which shows a comparison of the sales of each service with the previous year. Some services might be new and they don't appear in the previous year, others might be put off and so there are no sales for them in the current year. There can be services sold in both periods.

SelectMany - projecting the index of the result

There are 4 overloads of the SelectMany method. Two of them project the index of each source element, for example:

string[] sentenceSequences = new string[] {"The quick brown", "fox jumped over","the lazy dog."};
sentenceSequences.SelectMany(
// index - the position of the sequence in the sentenceSequences array
(sequence, index) =>
// check if index is on odd position and if so call ToUpper()
// ... put the sequence in other array, as the result
index % 2 == 0 ? new [] {sequence.ToUpper()} : new [] { sequence }
)
.Dump();


But there is no overload for projecting the index of the result also (the index of the element in the result sequence). So here an implementation of it:


public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, int, TResult> resultSelector)
{

Inside job or when your developer decides to make public your sa password

Image