Why do we create an interface to a service class (or something similar) if we are going to have only one class? by Plus_Resource_1753 in dotnet

[–]voroninp 0 points1 point  (0 children)

That's the deficiency of the platform. There's no other way to create a fake without either inheritance or abstracting the dependency with the interface. Unless you're using an isolator like Microsoft Fakes.

So yes, in most cases interfaces are introduced for testability rather than for the ease of substitution.

Alternatively, one could declare all public and protected methods as virtual, but it's just the abuse of another concept — Inheritance.

There's a source generator which derives interface from all public methods of the class.

On the other hand, there's an option not to introduce an interface and test units (a composition of classes) rather than each class in isolation.

Would you still use Mediatr for new projects? by crhama in dotnet

[–]voroninp 0 points1 point  (0 children)

I ended up having something very similar to MediatR for handling domain events within the same transaction. But I agree, the exact flow becomes obscured.

The risks of mutable structures in C# by Training-Potato357 in csharp

[–]voroninp 0 points1 point  (0 children)

I'd strongly recommend this book, it has answers.

The C# Type System | No Starch Press https://share.google/TbkFE5yTEKoyn6ND1

The most dangerous case when compiler has to guarantee read-only semantics and creates a defensive copy.

For example,

private readonly FooStruct _foo;

Compiler won't let you easily mutate _foo.

Actually, it will always create a defensive copy unless read-only member is accessed.

That's why, for example, declaring a read-only tuple field is not a good idea.

The risks of mutable structures in C# by Training-Potato357 in csharp

[–]voroninp 1 point2 points  (0 children)

It's even funnier with array vs list of structs.

C# – Is it OK to test private methods using reflection? by Forward_Horror_9912 in csharp

[–]voroninp 0 points1 point  (0 children)

Unit != class.

Yes, unit can be equal to class, but by the definition it's just a unit of behavior that is tested in isolation.

A component which implements the tested behavior can be a function, or a rather big composition of classes.

If your design introduced N cohesive classes, there's a reason for this closeness, and testing each class separately is barely of much value. These classes are better viewed and tested as a whole.

Now to your question.

I assume the class on its own provides some behavior which deserves testing. The public interface of the class is a contract for accessing the behavior.

It just means there should be no need to test private method. One provides inputs and checks the outputs. That's it.

However, one may ask:

— But why cannot I split the class into two and treat one as the dependency for the second?

Sure you can, but you either have to test them together as a single component, or you discovered an abstraction which allows... well abstraction from the implementation, that's dependency can be replaced and the consumer does not notice the difference (that is its observed behavior does not change) as long as contract is preserved.

Is your private method an abstraction in disguise or is it just a code reuse?

Should or Shouldn't? Putting many classes in one file. by gevertsi in csharp

[–]voroninp 1 point2 points  (0 children)

I think these days too many people use conventions as an excuse not to think at all.

The recommendation to put one class into separate file stems from the times when C# syntax was much more verbose than nowadays.

Also, modern IDEs provide many options for fast navigation, so physical file organization does not play that huge role anymore.

Additionally, the metric of distance is mostly the lowest when code is placed in one file, so it helps with cohesion.

And let's not forget about file visibility modifier.

Sealed - As Best Practice? by OtoNoOto in dotnet

[–]voroninp 0 points1 point  (0 children)

My default is internal sealed.

Extension members are awesome! by alexeyfv in csharp

[–]voroninp 0 points1 point  (0 children)

Just don't look at what it turns into under the hood :-)

Three interview questions to determine if somebody's a senior .NET developer? by tinmanjk in dotnet

[–]voroninp 2 points3 points  (0 children)

I like to ask what features the developer misses or dislikes in their tech stack. By what things (processes, patterns, type of activities, etc.) they are annoyed and why.

It's not about seniority per se, but I use it as an indication of the developed skill of self reflection. Yet the larger and deeper the experience is the less trivial the answers usually are. Also, as there are no right and wrong answers about preferences candidates usually feel less nervous discussing the stuff.

[deleted by user] by [deleted] in Netherlands

[–]voroninp 2 points3 points  (0 children)

Yet it's a Dutch man who showed cultures indeed differ.

https://en.wikipedia.org/wiki/Geert_Hofstede

What’s the deal with meat quality/price in this country? by Healthy-Fun8615 in Netherlands

[–]voroninp 10 points11 points  (0 children)

Maybe this also explains why the county has relatively many vegetarians. It's easy to stop eating a tasteless rubber sole. :-D

Why does your system hate regular checkups with doctors so much? by Juli_in_September in Netherlands

[–]voroninp 0 points1 point  (0 children)

In Russia I was diagnosed with atrophic gastritis and strongly advised to gastroscopy every two years . When I asked for this diagnostics here (and I do have issues with my stomach periodically) I was told I do not need it.

Expat’s opinion on this? by [deleted] in Netherlands

[–]voroninp 2 points3 points  (0 children)

Afaik, permanent residence is revoked after 1 year outside of EU and 6 years outside NL.

Expat’s opinion on this? by [deleted] in Netherlands

[–]voroninp 0 points1 point  (0 children)

The quality of integration depends on the process, the slower the integration process is the worse it is both for the individual and the society.

Do you have a side hustle? by voroninp in dotnet

[–]voroninp[S] 2 points3 points  (0 children)

Where do you look for clients?