Unit Vs Integration Testing with Files

Here is the original link.

It is better to write unit tests to test your logic without touching any external resources. Two options:

  1. You need to use abstraction layer to isolate your logic from external dependencies such as the file system. You can easily stub or mock (by hand or with help of constrained isolation framework such as NSubstitute, FakeItEasy or Moq) this abstractions in unit tests. I prefer this option, because in this case tests push you to a better design.
  2. For Legacy code (only in this case), you can use one of the unconstrained isolation frameworks (such as TypeMock Isolator, JustMock or Microsoft Fakes) that can stub/mock pretty much everything (for instance, sealed and static classes, non-virtual methods). But they costs money. The only “free” option is Microsoft Fakes unless you are the happy owner of Visual Studio 2012/2013 Premium/Ultimate.

In unit tests you don’t need to test the logic of external libraries such as MEF.

Secondly, if you want to write integration tests, then you need to write “happy path” test (when everything is OK) and some tests that testing your logic in boundary cases (file or directory not found). Unlike @Sergey Berezovskiy, I recommend creating separate folders for each test case. The main advantages is:

  1. you can give your folder meaningful names that more clearly express your intentions;
  2. you don’t need to write complex (i.e. fragile) setup/teardown logic.
  3. even if you decide later to use another folder structure, then you can change it more easily, because you will already have working code and tests (refactoring under test harness is much easier).

For both, unit and integration tests, you can use ordinary unit testing frameworks (like NUnit or xUnit.NET). With this frameworks is pretty easy to launch your tests in Continuous integration scenarios on your Build server.

If you decide to write both kinds of tests, then you need to separate unit tests from integration tests (you can create separate projects for every kind of tests). Reasons for it:

  1. unit tests is a safety net for developers. They must provide quick feedback about expected behavior of system units after last code changes (bug fixes, new features). If they are run frequently, then developer can quickly and easily identify piece of code, that broke the system. Nobody wants to run slow unit tests.
  2. integration tests are generally slower than unit tests. But they have different purpose. They check that units works as expected with real dependencies.

Bundle and minify static assets in ASP.NET Core (the Microsoft Solution)

Here is the link

By Scott Addie and David Pine

This article explains the benefits of applying bundling and minification, including how these features can be used with ASP.NET Core web apps.

What is bundling and minification

Bundling and minification are two distinct performance optimizations you can apply in a web app. Used together, bundling and minification improve performance by reducing the number of server requests and reducing the size of the requested static assets.

Bundling and minification primarily improve the first page request load time. Once a web page has been requested, the browser caches the static assets (JavaScript, CSS, and images). Consequently, bundling and minification don’t improve performance when requesting the same page, or pages, on the same site requesting the same assets. If the expires header isn’t set correctly on the assets and if bundling and minification isn’t used, the browser’s freshness heuristics mark the assets stale after a few days. Additionally, the browser requires a validation request for each asset. In this case, bundling and minification provide a performance improvement even after the first page request.

Bundling

Bundling combines multiple files into a single file. Bundling reduces the number of server requests that are necessary to render a web asset, such as a web page. You can create any number of individual bundles specifically for CSS, JavaScript, etc. Fewer files means fewer HTTP requests from the browser to the server or from the service providing your application. This results in improved first page load performance.

Minification

Minification removes unnecessary characters from code without altering functionality. The result is a significant size reduction in requested assets (such as CSS, images, and JavaScript files). Common side effects of minification include shortening variable names to one character and removing comments and unnecessary whitespace.

Simplifying Bundling and Minification in ASP.NET Core

Here is the link to a very good article

The decisions around what to use for packaging client side libraries is still a length discussion. Mostly, if not always, will start and stop with “It Depends…”.

However, getting started with something and being able to build upon that is a good starting point rather than what some call “Paralysis through analysis”.