Development (37)

DateTime Pitfalls

If you find some of these things in your application you should double check if your application works correctly with dates and times: Usages of non-UTC aligned date and time Usages of GETDATE() in SQL with the dates from the client without adjustments User input without time zone adjustments Calculations on dates without time zone adjustments […]




List of Time Zones

The list of all time zones present on PC (Windows 10 Home). This is what you’ll get with the operation TimeZoneInfo.GetSystemTimeZones() in C#.



Dependency Injection Frameworks: configuration via code

Many times I was asking myself what’s better IoC container for this or that project. Their performance is the one side of choice. You can find the complete performance comparison here. Another side of the choice is the simplicity and speed to learn. So I decided to compare several containers from this perspective and took Autofac, Simple Injector, Structure Map, […]




Replacing connection string for different environments

I’m using AppVeyor CI for my small open-source projects and bumped into an issue with integration tests which need a different connection string in different environments. I’ll describe how this can be solved in two ways. The 1st is a similar to web.config XML transformation. The 2nd one is a workaround for AppVeyor using and approach which is […]




How C# built-in types are implemented internally?

This is a quick guide to internal implementation of such C# types as Dictionary, Hashtable, List and others.




Equals & GetHashCode: Why is it important to override both?

It is important if your item will be used as a key in a dictionary, or HashSet, etc – since this is used to group items into buckets (in the absence of a custom IEqualityComparer). If the hash-code for two items does not match, they may never be considered equal and Equals() will never be called. […]




How To: Inject custom HTTP headers with Fiddler

When you’re testing a web service or web site with authentication credentials posted via HTTP headers, you might want a way to inject testing credentials without login in. Fiddler could help with that, but its rules need to be configured. Below I’ll describe how to do that Fiddler v4.5 (did not experiment in earlier versions).




How To: Refresh POCO entity from DbContext

If you notice that the context returns the same entity even if it is already changed one line before, you probably what the following

You can use it right after obtaining an entity with a statement like follows:

 




Executing SQL script with GO statement from C# code

In the middle of a project you might want to automate DB restoring and upgrading  by means of existing SQL scripts which may contain GO-statements. If you are that person who is attempting to execute scripts at runtime with GO-statements, this article describes how to do that.




Data-driven test with xUnit

In some cases it’s very challenging to recreate all data for some use case. It much easier to run the application, create some starting point: people, products, orders, prices, amounts, etc. and use such DB during tests. Automated tests should restore such DB in a test sandbox, run tests and drop the DB. All test frameworks have possibility to run some […]