Article on WCF configuration

27 06 2008

Based on some of my significant recent deep dives into WCF, I have written an article that talks about configuring WCF services.  Here is a link to the article.

http://www.devx.com/dotnet/Article/38407.

More readable version is here





Service Oriented Scrum Sprint Planning

19 10 2007

Scrum works well. when its only one project and sprint planning is really focused to that one projects. However the reality in most companies is that many of them are going towards a some kind of service based architecture.

In these cases or in cases where a number of projects are being developed at the same time, scrum planning gets confusing. Since each team is so focused on the current sprint and back log only, it becomes very tough to build dependencies between systems or services at the same time.

Enterprise SOA Sprint planning - ESOP just a fancy name conceived is based on restructuring projects and run dependent projects on the same sprint time line.

All projects will go to sprint planning the same day. The dependent stories are discussed in a common spring planning meeting where both teams are present and then the teams split to plan other stories.

This brings in awareness in all teams and they are aware of the service contract they need to fulfill as a part of this sprint. At the end of the sprint these contracts get fulfilled.

The product owners of each project are typically so focused on thier own project that often they tend to put cross service stories at a lesser priority than thier own stories. The parallel sprint planning would allow them to look at the big picture and plan the stories well.

This also is a fun event. At the end of the sprint the two systems are indeed talking to each other instead of building them in some kind of step approach.

Another fun thing to do is for the scrum masters to switch as moderators of the two teams in the planning meeting. Especially after a few sprints these planning meetings become fairly boring exercise. Switching scrum masters for the spring planning brings about a fresh breadth of air.

Powered by ScribeFire.





System.InvalidOperationException : Previous method ‘XYZ..;’ require a return value or an exception to throw.

8 10 2007

System.InvalidOperationException : Previous method ‘XYZ..;’ require a return value or an exception to throw. If this is haunting you, i may have the answer for that

having used NMock for a while,I have been wanting to try out Rhino Mock framework. Rhinomock is a typed library unlike other mock framworks which use string based paramaters.

However the very first time i used a rather simple implementation I was taken by surprise.

Here is the stub code. When i ran the test i got an error..

System.InvalidOperationException : Previous method ‘XYZ..;’ require a return value or an exception to throw.

Trying to figure this out took a while, onece it worked i felt really stupid. Hence this post so that someone else can save a few hours of
unwanted stress and agony

[Test] [Category("UnitTest")]

public void TestTheCallToService()

{

RequestContract request = new RequestContract();

MockRepository mocks = new MockRepository();

MyService service = new MyService();

MyServiceAgent.IAgent serviceAgent = (MyServiceAgent.IAgent)mocks.CreateMock(typeof(MyServiceAgent.IAgent));

List returnString=null ;

Expect.Call(serviceAgent.GetList()).Return(returnString);

service.GetList(request, serviceAgent);

mocks.ReplayAll();

}
Note the line mocks.ReplayAll();

This should be called before calling the service.GetList

In Rhinomock first we need to set up the expectations like any other framwork. Then we need to replay those lines from the times the recording starts . ( MockRepository mocks = new MockRepository() ;)

After the repay call, all the mock objects are in the correct state and the actual call to the layer, in this case a business component would actually work.

The code after the change should look like this

[Test]

[Category("UnitTest")]

public void TestTheCallToService()

{

RequestContract request = new RequestContract();

MockRepository mocks = new MockRepository();

MyService service = new MyService();

MyServiceAgent.IAgent serviceAgent = (MyServiceAgent.IAgent)mocks.CreateMock(typeof(MyServiceAgent.IAgent));

List returnString=null ;

Expect.Call(serviceAgent.GetList()).Return(returnString);

mocks.ReplayAll();

service.GetList(request, serviceAgent);

If i have saved you even a minute of time, Do let me know :)
}

   

Powered by ScribeFire.





Agile Programmer toolkit

18 09 2007

If you are into XP practices and wonder what are some tools that can make your agility grow, here is a starter kit.

 
1) You need a tool to code - Eclipse or if you are a .NET dev, some version of VS
2) You need a good refactoring tool - Eclipse has a very decent refactoring tool. If is VS land try resharper.
3) If you are a command line person, you can customize anything you repeat. Programmers are lazy by choice. Automate any command you do often
4) You need to get NotePad ++ or some such intelligent editor
5) If you are into webservice development you  have to get Soap UI
6) You need a sql generator so that you can script out database. If using SQL server , try
7) Dont forget a code generator - Try mygeneration or codesmith
8) You need a code repository. Nothing beats subversion
9) You need a way to get to the code repository - Try tortoise SVN
10) You have to do continous integration - Use Cruise Control
11) You will need cctray ( This is a small notifier that notifies build status, get this from your Cruise control install
12) If you do TDD - you need Junit or NUNIt
13) If you want to acceptance test - Try fitnesse
14) For Load test  - try JMeter
15) A tool to view database - Try webyog for MySQL or in the Microsoft world, SQL management studio works well
16) A place to store requirements - Run to walmart and get some index cards

 

Powered by ScribeFire.





Setting Static Port for a web project in Visual Studio

11 09 2007

Problem:

When adding a reference to a web project using Cassini server, its a problem if each time it launches the browser in a new port.

Solution:

Hit the f4 key when mousing over the web project. Change the setting set dynamic ports to false and pick a port number

You are done. Every time you say start with debugging the server will launch the URL on the same port

Powered by ScribeFire.





mstest -Command line webtests / Cruisecontrol

20 03 2007

If you are using Visual Studio team test edition, there is a feature called webtest. These tests can easily be recorded in Visual studio and then be played back on a server.

1) Just write your test in visual studio in the test project. If you dont see the web test menu, you don’t have team test

2) You can generate code from any web test . Once you are in the code you have access to everything.

3) If you have multiple developers in a project, fix the port number of you web project to same port. This way all developers will run the same port and your web test will also run. If you are running under IIS, then you are ok.

4) You can launch the inbuilt Visual Studio server with this command

start /B webdev.webserver.exe /port:3799 /path:ACTUAL PATH OF WEB PROJECT /VPATH:/WEBROOT

ex start /B webdev.webserver.exe /port:3234 /path:C:\projects\src\XYZWeb /VPATH:/XYZWeb

Your URL might have looked like

http://localhost:3234/XYZWeb

5) Then cd to the root of the source , where you see a vsmdi file. This will be where your solution file is. and run mstest

MSTest /testmetadata:XYZ.vsmdi /testlist:mytests

testlist are a way to arrange the tests you want to run. You will see these under the test menu in Visual Studio.

There are some issues around the way mstest produces output directories. If you want to merge the output to your cruisecontrol server, you could just pipe the output to a text file. Make sure you delete any old directories. Look at mstest /help.

6) The visual studio server ( that icon you see on the taskbar ) is actually a windows application and I havefound noeasy way to kill this from command line I mean there is no /stop option

The only way i found was

taskkill /IM webdev.webserver.exe





Mock objects not compile aware

28 02 2007

When I use mock objects in this case NMock, I would really like to have compile time check that passing the paramters to the expectation as strings

Example

Expect.Once.On(dbHelper).Method(”GetRequestsForUser”)
.With(userID).Will(Return.Value(requests));

In case in point above I am expecting that when i call the helper in that a method called GetRequestsForUser with userId
will return something

The problem is the mock framework is quite dumb until invoked.

When i want to refactor by adding a new parameter to the method GetRequestsForUser, the compiler has no clue that i have to change the test above.

Does anyone know the intent behind choosing such a design for the mock framework. Is there something more smart out there.

Update: Found out from one of my friends about Rhino mock. A typed mock framework. I haven’t used it yet, but plan to try it out soon.





An interesting article on Build automation

20 01 2007

A good friend of mine Geoff has a very interesting take on Build automation .

The biggest benefit i see of automation is that you can catch issues before it they start becoming expensive both in time wise and cost wise to fix.

The feedback loop provided by tools like cctray when things break is enough reasons to just do it. Its also the fun part of programming. To catch others when they lazily check in code without testing the impact.

Another very important aspect of automation is the ability to always demonstrate to the folks who foot the bill, whats cooking in the oven.

What better way to show off than actually showing code that works. Nothing can get you closer to this than automation.





Unit tests are the heart beat of your system. don’t let the beat stop!

5 01 2007

So whats the hardest part of writing unit tests beyong writing the first test.

Writing the second, third, fourth …

Another important factor is that if there are not enough tests, the developers are not having the comfort zone to make changes, refactor etc. When the trust factor on unit tests goes down, developers don,t keep it up to date and soon unit tests are just dead code never to be run again. This is seen quite often in projects today. This translates to more hours debugging, wasted down times , more cost and slip in schedules.

HEre are some symptoms that your code is dying and there is not enough active healthy test coverage. I say healthy because its not enough to just check for null values and collections, its going beyond the basics, using it as a tool to write the code that make all the difference. The code is only as good as the tests are.

Symptoms

1) It takes for ever getting even small pieces of funtionality out of the door

2) Bugs that were fixed few releases ago, keep crawling up

3) There is a resistance from developers to make any kind to change to major parts of the system.

4) Your developers work crazy hours on code and have no idea when they will get finished . The only thing they know is that they are working hard.

5) There is a blame game between QC and development. Sort of a throw it over the wall mentality. Where developers ship code to QC , QC starts finding silly defects which could have been easily found during development. The stress levels are high between the two groups. Development has the big brother mentality.

Avoiding all these are quite easy if developers are motivated and unit test culture is built into the culture of your organization. Critical to this is management support and an understanding that it takes time and money to produce good tests. This is not something that can be done in as much time as just writing code. It pays of in the long run for a health y product and goes a long way during maintenance.

It is very important to keep these tests running on every build. Continuous test integration. Running all tests every check in. ( It does not take much if the tests are structured correctly)

Unit test Category tags in NUNIT ( for example ) provide a great way to seperate unit test , integration test, long running tests and so on.

The # 1 Mantra of writing tests is Test independence. Test in every layer should run without depending on the other layer. Mock objects, Object databases, in memory databases, Test driven development can really help this cause. This process actually makes the design better and allows for better encapsulated systems that are not interdependent.

Test independence means

1) Every class / component should be testable by itself

2) When you test a class, lets say in the business layer, (that calls the database layer) , you should be able to test the business layer without the database being there ie Mock the database. These may be part of your test category Unit Test

3) The database layer ( if you are unfortunate to use a relational database) should also be unit tested. This becomes part of you Integration Category.

4) You could use a mock or a stub( Look on Fowler’s site for an excellent discussion on the difference) to test dependent layers.

5) Anything that touches a physical system like a database, file system, external systems are all Unit tests but could be treated as a different category. Many time developers treat this as integration test and dont think they have to run it at all times. its your code your team is responsible for its test health and code quality.

6) Follow the 15 - 30 minute agile coding cycle .

  • Get code from repository,
  • Work on one task at a time ( Most men are really bad at multitasking, if you are a women then may be you can work on a few at a time)
  • Write few Tests from a list of tests that you have planned to write for that task,
  • Write the Code,
  • Make the Tests pass,
  • Update code again from code repository,
  • Build and Run all the tests ( build database if needed - if it takes too much time) then run all unit tests at category Unit Test,
  • Checkin code
  • Start again

It is very tough to start walking this road of writing tests and code to support it. Its like a new years resolution to lose weight and be healthy.Not many do it, but those who do, Do live longer :)





Wierd issue: Could not load file or assembly nunit.core

2 01 2007

Today when i was working on some test code, i suddenly started getting this errorcould not load file or assembly nunit.core ( look in the end of the entry for the actual stack trace). This was only happening on the build server.

The build server is based on Cruise control and pulls code from subversion. Initially i did the standard Microsoft approach. Reboot :) that did not work. Then i tried Reinstalling NUnit and that did not work.

It turned out to be a config file ( app.config) file issue. Subversion had written merge tags in the app config file. NUnit instread of telling that the issue was about an invalid config, file chokes completelya and gives a completely clueless message.

Once i cleaned up the app config things started working again like a charm :)

Here is the actual stack stace in case some else googles in the future for something similar

System.IO.FileNotFoundException…

at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)

at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)

at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)

at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)

at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)

at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)

at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)

at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)

at NUnit.Util.TestDomain.MakeRemoteTestRunner(AppDomain runnerDomain)

at NUnit.Util.TestDomain.Load(String assemblyFileName, String testFixture)

at NUnit.Util.TestLoader.LoadTest(String testName)