Internals Visible To in *.csproj

Making internal methods and properties visible in tests gives a finer level granularity of tests hopefully making them less coupled and more cohesive as well as more focused on what they are testing. This is without making the API visible to the outside. In the older days, we used add into the 'Assembly.cs'

But ... Read more Internals Visible To in *.csproj

Deconstructing KeyValuePair into a tuple in a foreach - Fun C# Code 4

Did you know you can deconstruct in a foreach loop? Suppose you have a dictionary

If used a lot, it might be worth adding it to System namespace; thereby avoiding adding using statements everywhere.

Using LocalDB for Integration/Unit Tests

Long did I hold this perception that integration tests are hard. With EF core, they are actually really easy. Instead of using SQL Sever, we can substitute with LocalDB. Run this before running the tests and you'll have your db setup. After calling EnsureCreated you can add things into the database.

Adding custom type converter to MongoDB in C#

I covered how to impelement a custom type converter for MongoDB in my previous article. In this article, I want to cover adding a serializer to MongoDB 'serializer'. There are couple of tricks you can use to make your life easier. Unlike EF Core with its IEntityTypeConfiguration<TType>, MongoDB driver is more static. You can specify ... Read more Adding custom type converter to MongoDB in C#

Custom type converters for MongoDB

I always try to keep my models seperate from the implementation or configuration. EF Core 2.1 added great support for custom type converters with HasConversion. MongoDB also has a support for custom type conversion, though it is not quite as well documented. The basic premise revolves around implementing IBsonSerializer<TType>. Let's suppose I have a Bitrate ... Read more Custom type converters for MongoDB

Clean Architecture in .NET Core 3.0 by Jason Taylor

This video is truly one of the best ones I've ever seen. I am not fully sold on using EF Context everywhere. There are quite a few databases (e.g. MongoDB, ElasticSearch) that do not have an EF Driver. However, since .NET Core has amazing support for integration testing and each handler is nicely isolated, so ... Read more Clean Architecture in .NET Core 3.0 by Jason Taylor

ToByteArrayAsync() - a more 'efficient' approach to converting Streams

Frequently, there is a need to convert a stream into an array of bytes. I came across this problem when uploading files in ASP.NET Core. StackOverflow has certainly a number of answers. In most cases, these answers require copying the array, which is no longer needed. .NET Core 2.0 introduced the concept of Span<T> and ... Read more ToByteArrayAsync() - a more 'efficient' approach to converting Streams