Archive for September, 2011

Simple Silverlight Image Editor – Snap Tweak 1.0

Simple Silverlight Image Editor – Snap Tweak 1.0

Simple and Friendly interface With Basic Image Manipulations

Hi all,

I’m always passionate about fancy stuffs in programming and WPF is a ultimate platform to go crazy with fancy in C#. Silverlight opens so many ways to create amazing web components and interfaces. So finally i decided to use Silverlight to build a simple Photo Editing Tools which is capable of doing some basic image manipulations. You can see the demo  of  Snap Tweak 1.0.

Snap Tweak 1.0 Capable of

  • Converting Image Formats (Jpeg, Png)
  • Rotating
  • Applying Image Filters
You can see more functionalities in future versions.
This is just a quick post to introduce the working copy. I’ll try to cover the implementation details and publish the source code in another post.
Happy Image Editing :)
September 25, 2011 0 comments
Unit Testing Private Static Method – C#

Unit Testing Private Static Method – C#

Let’s see how to test a Private Static Method in C#. It’s better to take a small example and explain. So i’ll go with a very simple code snip.

Let’s Create a Simple Private Static “Addition” Method in  a “Math” Class.

class Math
{
   Private Static int Addtion (int val1, int val2)
   {
      return (val1 + val2)
   }
}

Now we need to test this method. We can’s use the normal approach here because we can’t access the method from our test project because it’s private. So any other way ? Yep There is a way to do this. :) Microsoft Unit Testing Framework (MS Test) provided a class called “PrivateType”. Let’s make use of that.

[TestMethod()]
public void AddtionTest()
{
   //creating private type object for Math Class
   PrivateType privateTypeObject = new PrivateType(typeof(Math));
   //Invoke the Private Method and Passing the method Arguments
   object obj = privateTypeObject.InvokeStatic("Addtion", 2, 3);
   //Comapre the results
   Assert.AreEqual(5, (int)obj);
}

Yes. We are done.

If you are new to Unit Testing please read the  Getting Started With Unit Testing in VS 2010

September 23, 2011 1 comment
Getting Started With Unit Testing in VS 2010

Getting Started With Unit Testing in VS 2010

What is Unit Testing ?

Unit testing is testing the basic functionality of modules (methods) to ensure that they are performing as expected.

Why Unit Testing ?

Unit Test is important in the process of software development to ensure the accuracy of basic functionality during the development period.

Unit Testing in VS 2010

Visual Studio 2010 got a very user friendly Unit Testing environment. The Unit Testing frame work used by VS 2010 is Ms-test. Let’s look one simple example here.

Create a simple project 

Let’s create a very minimal project with a class called “Calculator” and a method called “Add” to add two integer values.

So Finally the simple class will appear like

class Calculator
    {
        public static int Add(int val1, int val2)
        {
            return (val1 + val2);
        }
    }

Create a Test Project

Now we have to create a Test Project in Visual Studio 2010

1) Go to Menu “Test” and click “New Test

2) Now “Add New Test” will appear.

"Add New Test" Dialog Box

3) Now click “Unit Test Wizard” and click “Ok“.

4) Then “Create Unit Test” wizard will appear on screen.

"Create Unit Test" Wizard

This wizard is where you are going to specify the classes and methods you need test.

5) Carefully select the classes and methods and hit “Ok

Now you should be able to see a new test project in the Solution Explorer.

Main Project and Test Project in Solution Explorer

Preparing the Test Method

Now you can explore and see for Test Methods Stubs created by Visual Studio automatically. But still the test implementation is remains uncompleted.

My Test Method Stub for Add Method is appearing like

        [TestMethod()]
        public void AddTest()
        {
            int val1 = 0; // TODO: Initialize to an appropriate value
            int val2 = 0; // TODO: Initialize to an appropriate value
            int expected = 0; // TODO: Initialize to an appropriate value
            int actual;
            actual = Calculator.Add(val1, val2);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

As you can see here visual studio created some sample code as well. But just delete them all. We will add our own fresh test implementation. Then it’s easy to understand ;)
So our implementation will look some thing like below

        [TestMethod()]
        public void AddTest()
        {
            int ExpectedValue = 10;
            int ActualValue =  Calculator.Add(5,5);
            Assert.AreEqual(ExpectedValue,ActualValue,"Test Case Failed");
        }

In a simple test case there will be 3 things.

  • Expected Value
  • Actual Value
  • Assert Comparison
So in our example we are expecting 10 from our add method.
 int ExpectedValue = 10;

And in out Actual Value we are calling the actual method implementation by passing two value ( 5+5 = 10)

 int ActualValue =  Calculator.Add(5,5);

And Finally we are Comparing Actual And Expected value with the “Assert.AreEqual()” Method of MS Test Framework.

  Assert.AreEqual(ExpectedValue,ActualValue,"Test Case Failed");

Running the Test Cases

Now just right click on the test case method and click “Run Tests” option.

Now you should see your test result in Test Results Window.

Test Result

Test Fail Messages

Assert.AreEqual(ExpectedValue,ActualValue,"Test Case Failed");

You may noticed some text like “Test Case Failed” in the AssertEqual() method. These are Failure Messages. In case of a test method failure these messages will give detailed description of the failure. It is a good practice to write failure messages.

We are done. I’ll dig into unit testing in my following posts as well. and i love to here from you back as well so put your comments and corrections. :)

Happy Testing :D

Download Source Code Example

September 10, 2011 11 comments
Arduino

Arduino

After writting about .NET Gadgeteer in one of my previous post recognized that i did not say anything about one my favorite hardware prototyping kit (Arduino) to you. I got to know about this prototyping kit from one my colleague and i bought one from ebay (cheap in ebay ;) ).

What is Arduino ?

Arduino ?  What is that ?  Hmm, Simply it’s a electronic interface board with USB connectivity. Arduino Duemilanove is the mostly used Arduino Board. There are several types of boards. You can choose one according to your need. Arduino Duemilanove has  a  ATmega168 programmable microcontroller.

Plug and Play Modules

There are several modules available in the market which can extend the functionality of the interface board. For example GSM Module, Touch Screen, Ethernet and much more.

Programming

Programming the Microcontroller  Not a rocket science at all :D

  • Install the Arduino IDE
  • Plug the USB Cable
  • Select the COM Port
  • Write your Simple Hello World
  • Upload

Are you interested ?

Are you interested ? just go and grab a cheap one from ebay and start your killer embedded programming now onward.

Links

Arduino Home Page

Arduino IDE Download

Arduino Projects

Good Luck !

Happy Embedding :D

September 6, 2011 1 comment
.NET Gadgeteer

.NET Gadgeteer

Once again some thing interesting to play with .Net ;) .NET Gadgeteer, It’s an embedded hardware device from Microsoft. .NET Gadgeteer enables object oriented programming and solderless hardware assembly. This kit is some thing similar to Arduino hardware development kit. Arduino develped based on java and .NET Gadgeteer is .Net.

.NET Gadgeteer is built on top of .Net Micro Framework which allows programming in C# language and also to make use of Visual Studio and debugging tools. .NET Gadgeteer several plug and play module which extend the functionality in various ways. LCD, Bluetooth, Infrared. Network and etc are some of the necessary modules.

Microsoft .NET Gadgeteer Kit

September 6, 2011 1 comment