Shibu Thannikkunnath

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

Secure Web API RESTful services using Bearer tokens

Secure Web API RESTful services using Bearer tokens

This article talk s about securing ASP.net Restful web services, this is the first article of the series “Securing asp.net web applications”. This article talks about implementing Bearer Token-based Authentication and Authorization.

Authentication

Is the process of identifying the user and validating their credentials. If we map the Authentication to the example in this article, the process of validating user credentials and generating an access token is called Authorization.

Authorization

Is the process of determining if the user can access the requested resource. If we map the Authentication to the example in this article, the process of reading given Authorization token and determining if the user has access to requested Web API controller/ action is called Authorization.

Whats wrong with cookies? Why do we need token based authorization?

There is nothing wrong with cookies. Cookies are only usable in browser-based web applications. The RESTful web services (Web API) can be used on every platform that has an internet connection. Cookies might not be the right fit for those platforms (e.g. mobile applications). Embedding information in an interchangeable data format is far better than using Cookies to store user information.

Step 1. Create an Asp.Net Web API application

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

How to check if an object is null in C#?

How to check if an object is null in C#?

Usual methods to check a type is null will result in Null reference exception if an object is checked for null. This post compiles all good and bad methods.

Following methods of checking if an object is null will result in a NullreferenceException.

Wrong method #1

object simpleObject = null;
If(string.IsNullOrEmpty(simpleObject.toString())
{
 // do something if object is null
}
else
{
 //do somethingif object is not null
}

Wrong method #2

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