Wednesday, 2 March 2016

TFS running javascript tests

As JavaScript development becomes more first class citizen so does its testing.
I have started to write more JavaScript code and want to be sure that I have not broke anything and prove that the code does what expected without hidden traps

I am attempting to do so on configuration:
TFS 2012
VisualStudio 2012
Windows

Assumptions
You know how to write unit test using jasmine test runner
You can create successful build on your tfs

Structure:
Here you will be able to see my code structure for this project.




I have wrote a sample tests

Now I need to make it run on TFS

I had to create a location shared code that contain jasmine resource this resource is added as follows




 In Team Explorer, go to the Builds section and Edit your Build Definition which will run the javascript tests.
- Click on the Process tab
 - Select the row named Automated Tests.
 - Click on … button next to the value.
 Select the Tests to Run and click Edit. Change the Test assembly specification to **\*.js




Tuesday, 23 February 2016

Debug MEF



Nice article about debugging MEF

http://ihadthisideaonce.com/2012/01/31/stop-guessing-about-mef-composition-and-start-testing/

And would it be nice if you can run composition testing?
here is sample example how to do this:
http://ihadthisideaonce.com/2012/06/12/mef-composition-tests-redux/

Sunday, 26 July 2015

Reading emails using c# and POP3

I wanted to write my own automated behaviour after I receive new email and for that I needed to read emails that I get.

I have used OpenPop Nuget package.

Here is my package.config file

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="OpenPop.NET" version="2.0.6.1116" targetFramework="net45" />
</packages> 


Now after installing the package I have needed to add implementation that I took from
https://github.com/foens/hpop/blob/master/OpenPopExamples/Examples.cs to read emails.

Here is my code with configuration.

 // The client disconnects from the server when being disposed
            using (Pop3Client client = new Pop3Client())
            {
                // Connect to the server
                client.Connect("pop.gmail.com", 995, true);

                // Authenticate ourselves towards the server
                client.Authenticate("email@gmail.com", "password");

                // Get the number of messages in the inbox
                int messageCount = client.GetMessageCount();

                // Most servers give the latest message the highest number
                for (int i = messageCount; i > 0; i--)
                {
                    var msg = client.GetMessage(i);
                   Console.WriteLine(msg.Headers.Subject));
                }
            }

Now the issue is that email does not allow me to read the emails.
And the reading fill fail with exception.
If you drill into the exception you will be able to find following link

https://www.google.com/settings/security/lesssecureapps

This will give you configuration option to configure this


Now when I run the code I get my emails through.


Thursday, 23 July 2015

Installing underscore into angular and typescipt

I wanted to know how difficult it is to install underscore js library to project using typescript and angular js into my MVC Application

Turns out you need to download and install underscore.js (Read more about underscore)

using nuget search for "underscore.js"
After installation of this nuget package you will find in your packages.config line such as
<package id="underscore.js" version="1.8.2" targetFramework="net451" />

Note: 

This may differ based on version or framework but the important part is <package id="underscore.js"

Now we have installed underscore.
The directory where the package will be installed is /Scripts/

We need to add reference to our view

<script type="text/javascript" src="~/Scripts/underscore.min.js"></script>

So far this is standard way of using javascript.

Now I have created my typescript. I have named it index.ts

Now typescript does need definitions for it to recognise methods that library exposes and this is done in definition files. You can download definitions from Boris Yankov collection shared on github : https://github.com/borisyankov

File that you are looking for is named: underscore.d.ts

Put the file to same location where you have your underscore js file in my case or with all of your definitions.

Insert following path on top of your file.
/// <reference path="../../underscore.d.ts" />

Why is underscore path: "../../underscore.d.ts"?

it is because of my typescript lives in "/Scripts/App/Index/index.ts" which needs to go two directories up.

After this all we can go to your typescipt file and start using underscore in typescript





Sunday, 28 June 2015

Parse date from yyyy-MM-dd string

Often developer needs to parse formatted string to object.

Here is example I am commonly using:

I have a date time string:

var myString = "2015-06-05"

I need to parse it into DateTime variable 

var myString = "2015-06-05";
var parsedDateTime = DateTime.ParseExact(myString, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None);