TGIMBA .NET Core Upgrade – JSTest.Net mocking manual style

NOTICE: The TGIMBA git hub repository has been corrupted and I had to start over.  The link to the repository is here -> Git  Code Commit

Today we are marching towards our login screen which will be the first of functionality restore for the .NET Core The Globe In My BucketList Application (TGIMBA) upgrade.

It kinda bugged me how I was not able to easily inject items to be tested. The JSTest.NET github page says it supports 2-3 differet mocking libraries. However, it also looks like this repository is unmaintained and I was not able to easily find examples on how to set up the mocks. So, based on my analysis of the project code, I am going set up my own mocking library (of sorts…more like a manual mock for each method I care to test).

There are two methods I want to test in Global.js – Init() and Load(divId). 1

If you remember from a few posts back, Init() is called HomeController.cs -> HtmlVanillaJsIndex() -> HtmlVanillaJsIndex.cshtml.

3

I started with Load(divId) first since Init() was just a wrapper call to Load(divId).  Using the documentation supplied with JSTest.net (reference #1), I used the AppendBlock(arg) to append my mock.  This manual mock places the expected dependencies for the normal load action – document.getElementById(id) returns the target div and ServerCall() simplify verifies that it was called with the expected arguments.

2

For Init(), I realized there was a lot of duplicate code.  So, I simplified it to this for both tests.

1

I removed common functionality related to InitTests.cs to private methods at the bottom.

1

The evaluation of true in this case I moved to BaseTest.cs.

2

I add additional tests for the non happy path routes.

1

Next post will be the login screen!

Stay tuned!

Reference

  1. https://archive.codeplex.com/?p=jstest
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s