Pages

Wednesday, September 26, 2012

System.InvalidOperationException in NUnit with RhinoMocks

To solve the above exception while running unit tests, you need to make sure that all the mocked methods are using "virtual" keyword in method signature.
Ex: Public virtual method(int a, int b)

The reason for this issue is, Rhino mocks creates a proxy class when you call StrictMock (or any type) using  MockRepository. Then, it needs to extend your type.

By making the methods as virtual we let RhinoMocks know that they can override and inherit it for their mocking purposes.

Sunday, September 23, 2012

Convert clockwise angles to anti-clockwise angles in Construct2

By default, angles in Construct2 facing right and increments clockwise.

Angles in Construct2

To change this behavior, to anti-clockwise do the following:
 
Anti-clockwise angle = - ( Clockwise angle)

To display clockwise angle as anti-clockwise angle use the following calculation,
Anti-clockwise angle = 360 degrees - clockwise angle

Ex: Clockwise angle 45 degrees = Anticlockwise angle 315 degrees and equals to -45

Thursday, September 20, 2012

Test Driven Development(TDD) and Unit Tests

The idea of TDD is to focus on the requirements and the design first before go into implementation detail.

Unit tests are written to test a small piece of code in isolation.

When we write unit tests in TDD, we need to write the tests before doing the development, rather than writing the code and the writing unit tests like in traditional development.

First, all the unit tests should fail as implementation is not available. Once the implementation is done, we execute the tests again and then all the tests should pass.

This encourages the incremental/ evolutionary design by providing automatic regression testing for the design of the API.