Category Archives

14 Articles
Integration testing with selenuim, headless Chrome and net core

Integration testing with selenuim, headless Chrome and net core

When automated Selenium Integration UI tests such as Regression tests or Smoke tests runs, the controlled browser window never failed to annoy me. This forced me to do some research on automated tests using Headless browsers.

I started writing tests using amazing phantomJS , sooner found out that the maintainer of PhantomJS announced that he is stepping down as maintainer in favour of Google Chrome Headless.

Google added support for headless testing in Version 59.

Download source code for this article

The source code is available in Github repository., the readme file contains additional information about setting up your environment and running tests.

Build and Test status

This github repository uses Travis CI
Link to travis ci build page

What is headless Integration testing

Headless testing is basically running UI integration tests on a browser without the Head a.k.a User interface.
Read More

Most useful mocking tricks for MOQ and C#

Most useful mocking tricks for MOQ and C#

The following list is my most used mocking techniques to create, setup and verifies injected dependencies.

Create

This section lists all the most used ways of creating a mocked object of a dependancy

Create a mocked object of a dependency

var mockedSystemUnderTest = new Mock();

Setup

This section lists all the most used ways of setting up behaviors of a dependancy

Setup all properties in a mocked dependency

mockedSystemUnderTest.SetAllProperties();

Setup a specific property in a dependency

mockedSystemUnderTest.SetGet(prop=>prop.SomeProperty).Returns("SomeValue");

Read More

Update Asp net core 2 Angular SPA template to work with Angular 5

Update Asp net core 2 Angular SPA template to work with Angular 5

The source code of this project is added into GitHub, you can download, clone or submit your changes to this repository.
Link to GitHub repository
https://github.com/shibut12/ng5-netcore

The project is added to Travis CI to auto build.
Tavis ci build status

My system configuration

  • @angular/cli: version 1.5.5
  • Node: Version 6.11.0
  • npm: Version 3.10.10
  • dotnet: Version 2.0.2

First things first

Before you begin creating a project and updating, let’s look into preparing the environment before we create the project. Run following commands in Command Prompt or shell.

mkdir ng-netcore
cd ng5-netcore
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest
npm install -g npm-check-updates

Read More

Dotnet core 2 Angular 5 : Error “app.browser.module.ngfactory” while publishing

Dotnet core 2 Angular 5 : Error “app.browser.module.ngfactory” while publishing

This article talks about ” Can’t resolve ‘./../$$_gendir/ClientApp/app/app.browser.module.ngfactory'” error while publishing a dot net core 3, angular 5 application created from SPA template and how to fix it.
When I was building my aspnet core web applciation, I got following errors in my Gitlab CI pipeline, in this article, we will try to resolve them.

  • Module not found : error : Can’t resolve ‘./../$$_gendir/ClientApp/app/app.browser.module.ngfactory’
  • error MSB3073: The command “node node_modules/webpack/bin/webpack.js –env.prod” exited with code 2.

My setup

@angular/cli - Version 1.5.5
Node: Version 8.2.1
npm: Version 5.5.1
dotnet code: Version 2.1.1-preview-007165

Step 1: Create a new Dotnet core 2 Angular application from SPA

Run following commands in a shell

mkdir ng5-app
cd ng5-app
dotnet new angular
npm install

Step 2. Verify the angular version and upgrade to angular 5

At the command prompt, run following command to install a utility to check outdated packages (Note: to run these commands, you should have npm installrun as explained in step 1).
Read More

Use Material 2 with Dotnet core 2 Angular 4 spa template

Use Material 2 with Dotnet core 2 Angular 4 spa template

With Dotnet core 2, Microsoft included new Single-Page-Application (SPA) templates for client-side javascript frameworks like Angular, React etc.. In this blog post, I’m going over the steps that require integrating Angular Material 2 into the Angular 4 web application created using dot net core 2.0 angular spa template.

TypeScript

The web applications that created from Dotnet core spa templates (anglar, react etc..) contain a folder called “ClientApp”. This folder holds all the javascript framework components. These applications use TypeScript by default.

Webpack

Webpack is a module bundler, it takes modules with dependencies and generates static assets representing those modules. Read more about Webpack in this link

The SPAs now support webpack module bundler right out of the box. Web pack runs as part of the build and it does minifications of Javascript and css files as well.
In dotnet core spa template, webpack.config.vendor.js defines all the modules that are relevant to the application. You can add your own css/javascript files to this configuration file. We will use this file to include material javascript components and material theme files. The webpack.config.js file defines all the rules for bundling file, you can add your own rule here as well.
Read More

Mocking objects with Moq and XUnit in .Net Core

Mocking objects with Moq and XUnit in .Net Core

Moq library 4.5 and above supports mocking objects in net Core. This article explains the step by step process that needed to Moq an object in net core. Mocking objects comes in handy when unit testing data store, where a Database can be mocked so that no data is added or modified in Database while unit testing source code.

Creating a test project

For the simplicity of explaining, I’m started with creating a XUnit test project in Visual Studio 2017 15.3

Add Moq package into the project

Read More

Uninstall Dot net core Preview 2 in Ubuntu 16.04 LTS

Uninstall Dot net core Preview 2 in Ubuntu 16.04 LTS

Though the instructions at Microsoft website is really easy to follow to install Dotnet core 2.0, I realized that the web page does not have instructions that can be easily followed to remove Dotnet core preview 2.

https://www.microsoft.com/net/core#linuxubuntu

Run the following commands to removed Dotnet core 2.

sudo apt --installed list

sudo apt --installed list | grep "dotnet-sdk"

sudo apt-get remove dotnet-sdk-2.0.0-preview2-006497

dotnet --version

 

ASP.Net Core MVC request life cycle – Routing

Routing bridges middleware and MVC framework by mapping incoming Http requests into controller action method. There are two different routing available in MVC.

Routes are evaluated in the order they are defined in the program. The more important routes should be defined first.
Following diagram explain the login flow of routing mechanism in Asp.Net core MVC.

asp.net core mvc routing high level overview


Read More

Comparing Asp.Net core middleware with Http Modules and Handlers

Http Modules & Http Handlers

1. In the older version of Asp.Net, the Http modules hooked into Application lifecycle events to provide reusable services.

2. In the older version of Asp.Net, the Http Handlers were responsible for Generating responses for Http requests.

3. Order of execution of Http modules and Http Handlers are driven by Asp.net life cycle events

Asp.Net core middleware

1. generates responses for requests.

2. Provides application level services and features.

3. Order of execution of Asp.Net core middleware are driven by the order it is added into middleware pipeline.

4. Middlewares are available in Asp.Net web api (.Net 4.5) and .Net core

ASP.Net Core MVC request life cycle – Middleware Pipeline

Middleware Pipeline

ASP Net Core MVC is built on top of a concept called Middleware. Middleware pipeline is a chain of modular components that provide essential building block of how your application handles HTTP request. These components are generating a response for an incoming request directly or with help of a framework such as MVC.

Features like Routing, sessions, CORS, Authentication, Caching etc are implemented as middleware.

Example of asp net core middleware pipeline

Read More