Sunday, July 14, 2013

Simple TypeScript Unit Test Project Templates

Inspired by John V. Petersen's latest post http://codebetter.com/johnvpetersen/2013/07/05/a-simple-jquery-qunit-based-javascript-unit-test-project-template/ I thought that TypeScript needed Unit Test project templates to.

I prefer using the Jasmine test framework, but knows that Qunit is popular, so I decided to make a project template for each of them. I have published them on the visualstudiogallery.

TypeScript Qunit Test Project
TypeScript Jasmine Test Project

After installing your preferred Test Project you can find it by choosing new project and go to "other langauges => TypeScript"














The basic structure for the jasmine project looks like this:



The Quint look almost the same, the only different is that I have installed the qunit.d.ts file via nuget instead of the jasmine.d.ts.
The reason for the d.ts files is placed in this structure "Scripts/typings/jasmine/jasmine.d.ts" is that, this is the basic structure when you install TypeScript definition files from nuget.

To get it working you also needs to install the chutzpah javascript runner

When this is done, the test will show up in the VS test explorer window.


Thanks John, for the inspiration. I now don't need to copy paste my TypeScript test projects.

Wednesday, July 3, 2013

2013 Microsoft® MVP Award! in Visual C#

A couple of month’s back I’ve got an email from Microsoft that I have been nominated for a MVP award, the only thing I should do was to fill out a word document. First I thought it was a spam mail and reread the mail. When I was sure it wasn’t spam I filled out the document, and then forgot all about it.
Then a few days ago I’ve got an email “Congratulations 2013 Microsoft MVP!”



I couldn’t believe it! And I still really can’t!.. But my MVP award should arrive on Monday, and when I have the award in my hand I’m sure that I believe it :o)

Today, there are more than 4,000 MVPs worldwide. They represent more than 90 countries, speak over 40 languages, answer more than 10 million questions a year, and are awarded in almost 90 Microsoft technologies.

And I must thanks for those that have nominated me and how proud I am to be a MVP.

Thursday, March 14, 2013

Brewing beer Kata 1st. draft

I am giving a 15min. lightning talk at @brewww "TypeScript kata: The TDD style" Friday 22. of marts.

And thougt I would make a brewing beer kata to the talk, though I'm not sure the following kata is good enough as a standard Kata, please give comment to improvements. Ill promise to post the final Kata in TypeScript later :-)

First draft of the kata:
  1. Create a simple Brewary with a method IBeer Brew()
    1. The method take 0 parameters but needs to return an IBeer
    2. The Beer should be of type lager
  2. Allow the Brew method to handle a brewingTemperature and a fermentationInDays argument
    1. If brewingTemperature is less than 5 throw exception “Temperature is to low”
    2. If brewingTemperature is greater than 4 and less than 11 return a beer of type lager
    3. If fermentationInDays is less than 7 and greater than 14 throw exception “fermentation for lager beers should be between 7 and 14 days”
  3. Add optional ingredients of type string as “roasted malt” and “barley” to make a stout
    1. If fermentationInDays less than 5 and greater than 6 throw exception “fermentation for stouts beers should be 5 or 6 days”
    2. brewingTemperature not equal 20 throw exception
    3. Expect result to be of type Stout
    4. Expect beers alcohol to be 7percent if fermentationInDays is 5
    5. Expect beers alcohol to be 8percent if fermentationInDays is 6

Tuesday, February 19, 2013

Declaration source files and google analytics

What is Declaration source files?

Declaration source files are restricted to contain declarations only. Declaration source files can be used to declare the static type information associated with existing JavaScript and expose their behavior.

I have started to implement TypeScript in my projects at work :-)

In that case I had to implement google analytics but ran into the problem, that I did not have intellisence for the that.

I googled a bit and could not find any declaration file for that, so I made my own.
I can now acces ga, _gaq, _gat and the Tracker object with intellicense in my TypeScript file, nice...

Example

describe("tester Google Analytics Code  _gaq object", () => {
    it("can create _push", () => {
        _gaq.push(['_setAccount', 'UA-XXXXXXX-YY']);
        _gaq.push(['_gat._anonymizeIp']);
        _gaq.push(['_trackPageview']);

        _gaq.push(() => {
                var tracker = _gat._getTrackerByName('UA-65432-1');
                tracker._trackPageview();
            }
        );
    });  
});

I have pushed it to https://github.com/borisyankov/DefinitelyTyped but until it is merged you can get the files here https://github.com/RonnieHegelund/DefinitelyTyped/tree/master/google.analytics



Sunday, February 17, 2013

TeaCrunch - CodeCoverage for Typescript

When working in .NET and writing unit test, I really like the green dots NCrunch gives me. I think its a great way to show what code you have test coverage on.

I would love to have this in TypeScript to, but haven't found any, so I have started making a prove of concept my self.



The prove of concept works, but is very unstable and have to rewrite the code, and need to find out how I can read the results from the test explorer. The biggest problem is to find the time to rewrite my code :-)

Saturday, February 16, 2013

TypeScript - The rest parameter

Rest parameter in TypeScript has nothing todo with REST (REpresentational State Transfer)

If you are familiar with C# params keyword, The rest parameter is the same. The rest parameter lets you specify a function parameter that takes an argument where the number of arguments is variable.

An example could be a function that make a Sum of a variable length of numbers:


Sum(1,2,3,4);

C# example

public int Sum(params int[] list)
{
  int sum = 0;
  foreach (int i in list)
    sum += i;
  return sum;
}
TypeScript example

public Sum(...list Number[]) : number
{
    return list.reduce( 
        (a,b) => { a + b }
    );
}
And the result when compiled to JavaScript

function sum() {
    var numbers = [];
    for (var _i = 0; _i < (arguments.length - 0); _i++) {
        numbers[_i] = arguments[_i + 0];
    }
    return numbers.reduce(function (a, b) {
        return a + b;
    });
}


Wednesday, February 13, 2013

Update to the book content has changed a bit


Update to the book content has changed a bit.

Introduction to enterprise design
    What is enterprise design?
        Design priciples
            Reliability
            Sepreation Of Concern
            Flexibility
            Maintainablitiy
            Reuseablity
            S.O.L.I.D
                Single responsibility principle
                Open/closed principle
                Liskov substitution principle
                Interface segregation principle
                Dependency inversion principle
        Design patterns
            Working with design patterns
            The benefits of patterns
            Antipatterns

The road to enterprise 
    Testing strategies.
        Unit tests
        Components Tests
        Integrations tests
        System tests
        Manual tests
    Acceptance test
    Test driven development     
        What is TDD
        TDD Kata as an example
    Testing frameworks
        jasmineJS
        QUnit
        Selenium - automated browser tests
    Continous Integration
        Teamcity
            Setting up automated tests
            Setting up automated deployment
        Continous Delivery

Design patterns in action
    View patterns
        MVVM
            Knockout as an example
        MVC
            Backbone as an example

TypeScript Fundamentals
    What is TypeScript
    TypeScript keywords
    Types
        Primitive Types
            The String type
            The Number type
            The Boolean type
            The Null type
            The Undefefined type
    Interfaces
    Classes
    Functions
        Functions arguments
        Arrow Functions
        Extension methods
            What is code smell?
    Inheritance
    Modules
    Generics (not supported yet) .
    Declaration Source Files

TypeScript Tools
    Visual Studio
    Web Essentials
    Sublime text