About me

Name : Rujith Anand

Month List

Page List

    Tag cloud

      Agile–new approaches to Risk

      clock April 30, 2012 21:29 by author Rujith Anand |

       

      Read an interesting article about approaches to Risk in ‘Agile’ way..

       

      http://www.agilemanagement.net/index.php/blog/Agile_2009_-_New_Approaches_to_Risk/



      Injecting mock to a singleton instance’s property

      clock April 12, 2012 20:42 by author Rujith Anand |

       

      So the scenario is, I have a singleton manager class( I know what you are thinking..bad design.. agree… I have excuses..).

      For my tests I need to inject a mock object to a property on this singleton instance. I don't want to make major design or code changes to production code, which is working fine now.

      My solution was to use Unity to do the property injection. This is easy with a non-singleton class, I am not using configuration files for Unity.

      The sample below is the proof of my solution.

       

      This is the singleton manager

         1:      public class ConnectionManager : IConnectionManager
         2:      {
         3:          private static IConnectionManager _instance;
         4:   
         5:          private ConnectionManager()
         6:          {
         7:              //The prod code always use the concrete implementation(default)
         8:              ConfigStore = new UserConfig();
         9:          }
        10:   
        11:          public static IConnectionManager Instance
        12:          {
        13:              get
        14:              {
        15:                  //simple singleton
        16:                  return _instance ?? (_instance = new ConnectionManager());
        17:              }
        18:          }
        19:   
        20:          //The property needs to be injected
        21:   
        22:          public IUserConfig ConfigStore { get; set; }
        23:   
        24:   
        25:          public bool CanConnect()
        26:          {
        27:              //if config exits then it can connect
        28:              return ConfigStore.ConfigExists();
        29:          }
        30:      }

       

      I have extracted an interface of this class(the other way around)

      public interface IConnectionManager
      {
             IUserConfig ConfigStore { get; set; }
             bool CanConnect();
      }

       

      This is the type of the property

      public interface IUserConfig
      {
          bool ConfigExists();
      }

      and default implementation of the property that the production code will use

      class UserConfig : IUserConfig
      {
          public bool ConfigExists()
          {
              Console.WriteLine("Checking config exists");
              return false;
          }
      }

       

      In my test fixture I am creating a mock for the IUserConfig and registering that instance in the container.

      var userConfigMock = new Mock<IUserConfig>();
      //mocking the IUserConfig and returns true on ConfigExits call
      userConfigMock.Setup(u => u.ConfigExists()).Returns(true);
      
      //register the mock in container
      _container.RegisterInstance<IUserConfig>(userConfigMock.Object);

       

      Now registering interface for the singleton mentioning it to user property injector which the container will resolve.

      _container.RegisterType<IConnectionManager>(new InjectionProperty("ConfigStore",
                                                                        new ResolvedParameter<IUserConfig>()));

      Using the BuidUp extension of Unity I am asking the container to attach to an existing instance.

      IConnectionManager singletonInstance = ConnectionManager.Instance;
      IConnectionManager connectionManager = _container.BuildUp(singletonInstance);

       

      The full test fixture is below

         1:      public class ConnectionManagerFixture
         2:      {
         3:          private IUnityContainer _container;
         4:   
         5:          [SetUp]
         6:          public void Setup()
         7:          {
         8:              _container = new UnityContainer();
         9:   
        10:              var userConfigMock = new Mock<IUserConfig>();
        11:              //mocking the IUserConfig and returns true on ConfigExits call
        12:              userConfigMock.Setup(u => u.ConfigExists()).Returns(true);
        13:   
        14:              //register the mock in container
        15:              _container.RegisterInstance(userConfigMock.Object);
        16:   
        17:              _container.RegisterType<IConnectionManager>(new InjectionProperty("ConfigStore",
        18:                                                                                new ResolvedParameter<IUserConfig>()));
        19:          }
        20:   
        21:          [Test]
        22:          public void Tester()
        23:          {
        24:              IConnectionManager singletonInstance = ConnectionManager.Instance;
        25:              IConnectionManager connectionManager = _container.BuildUp(singletonInstance);
        26:              //the mock return true.
        27:              Assert.IsTrue(connectionManager.CanConnect());
        28:          }
        29:      }

       

      Remember this is a sample I used to prove my solution.

      Things to note here are

      • The application design has minimum impact, its still using singleton etc. I have extracted an Interface, and in this case I have changed field to a auto property.
      • If you are using Unity with mapping configuration you don’t have to use the InjectionProperty you can specify them in the configuration.
      • While registering the singleton type, you have to use the Interface instead of class.

       

      Hope this helps…

      Feel free to ask question if you have any…



      .NET framework versioning

      clock April 2, 2012 21:39 by author Rujith Anand |

       

      .NET framework versioning has been becoming complex after the release of .net 3.5… I still remember if you install 3.0 beta, Microsoft has released a tool to uninstall/remove it.. that was so messy.. .

      When I started to learn about .net(in the days of pre .net 1.0 or so called beta), the MS idea was framework will  support multiple version(ie. multiple version of framework can co-exists), also framework will be released for different OS etc.. those concepts are gone in air now..

      With the release of .NET 4.5 , Windows 8 etc I think the .NET framework versioning is getting more complicated.

      .NET 4.5 will replace your .NET 4.0, but the runtime version will be 4.0.. bhah!… what ???

       

      have a look the links below for more details.

      http://www.west-wind.com/weblog/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40

      http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx



      Importance of Standups

      clock April 1, 2012 09:38 by author Rujith Anand |

       

      Have a look at this.. the important of stand ups in Sprint

       

      http://saintgimp.org/2011/09/01/why-the-standup-meeting-is-important/

       

      Edit

      Found Martin Fowler’s suggestions on Stand up

      http://martinfowler.com/articles/itsNotJustStandingUp.html



      Scrum and XP free book

      clock March 25, 2012 09:45 by author Rujith Anand |

       

      Found a nice free book, best for starters on Scrum and XP

       

      Scrum and XP from the Trenches



      Migrated from Dasblog to BlogEngine

      clock March 8, 2012 21:17 by author Rujith Anand |

       

      Finally I managed to migrate my blog (in Dasblog) to Blogengine.net (2.5). It was rather easy than I expected.

      I have a VPC running in laptop for the blog set up etc. Basically that’s my sandbox for testing the changing before I publish to website.

      The steps I followed.

      1. Export the Dasblog posts to BlogML format. It easy to find a tool for this in internet. The most popular one is here. And to be honest it is a really good one
      2. Download and install the latest BlogEngine . If you are downloading the ‘web’ version then installation is simple extract, copy and setting up the IIS etc, and follow the instructions on your ‘example blog’ to setup users, permissions etc.
      3. Once you start the blogengine site, login and go to setting, you can see the import/export tab. Import blogs from your BlogML file(exported in step 1).
      4. Thats it you are ready to go.
      5. I have changed the theme, widgets etc to give a ‘look and feel’ that I like Smile

      There are couple of minor things to take care of

      1. When you export the blogML the post author name comes as ‘admin’. So depending on the theme you use in your blogengine.net the post author name may appear as ‘Administrator’. Do a find a replace before you import the file.
      2. My hosting provider is DiscountASP.net. I had Windows2003 with IIS6, .net 2.0 etc. I had to migrate to Windows 2008/IIS7/.NET 4.0. But that was easy, DiscountASP.net control panel gives you the option to migrate, it took around 30 mins for me, but its something you can start and forget you will get notified once its done. There were some configuration errors when i was using .net 2.0 with this version of BlogEngine.net


        Spouse is added as additional driver for free when you rent through Avis USA

        clock November 3, 2011 09:19 by author Rujith Anand |

         

        I just found out that if you rent a car through Avis USA, your spouse is automatically added as additional driver at no additional cost. That’s so cool… for past couple of weeks I have been renting through Hertz USA and they always charge at least $20 per day for adding my spouse as additional driver.

        But please confirm with your local centre before confirming the booking. I saw this in Avis USA website and the local centre also confirmed it.

        Have a safe driving.



        MS DOS - Deleting files older than x days

        clock November 26, 2010 13:58 by author Rujith Anand |

         

        I don't think we can ever say good by to our good old MS-DOS. My first intimate interaction with Micro Computer(the original name of PC ) was through MS-DOS. Now in the advanced age of computer still I am using DOS, this time as part of one the build scripts. Our continuous integration creates an installer every night(early morning to be exact – this is a cheat, I'll describe it later). We want to keep them for 2 weeks and delete afterwards. Now to do this I can create a simple .net console app, which will be more efficient in error handling etc. But I like to do it in the good old way :).

        Found a command line utility –ForFiles- comes with WinXP command line.

        (If you don't have installed by default – in most of the case no- you can download it from the MS FTP server. You may want to place it to C:\WINDOWS\system32 or update the PATH variable accordingly)

        forfiles -p "C:\SearchFolder" -s -m*.msi -d-14 -c "cmd /c del @path"

        -p : path to search for
        -s : include subdirectories
        -m : search mask (*.msi files here)
        -d : files older than days (14 in my case), you can use dates instead
        -c : the command to execute on the files

        also checkout the help for 'forfiles'. If you have forgotten how to do it, its forfiles/?... uh it doesn't work ? simply type forfiles :)

         

        The following variables can be used in Command : (@path is already used in the above example)
        @FILE, @FNAME_WITHOUT_EXT, @EXT, @PATH, @RELPATH, @ISDIR, @FSIZE, @FDATE, @FTIME

         

        hope this helps...

         

        edit

         

        found a nice website with WinXP command lines



        Hard reset HTC Desire Z

        clock November 22, 2010 04:44 by author Rujith Anand |

        How to hard reset HTC Desire to factory setting, some call it factory reset.

        I have an HTC Desire Z, I had to hard reset the phone couple of times because of all junk apps I install.

        Steps to hard reset, may be helpful for you…

        HARD RESET WILL WIPE ALL YOUR PERSONAL DATA, so please do a backup before you start

        Turn off your phone,
        1. With the phone turned off, press and hold the VOLUME DOWN button, and then briefly press the POWER button.
        2. Wait for the screen with the three Android images to appear, and then release the VOLUME DOWN button..
        3. Press VOLUME DOWN to select CLEAR STORAGE, and then press POWER.
        4. Press VOLUME UP to start the factory reset.

         

        I think this is different from what you do thorugh the ‘factory reset’ menu option in setting. ( I am not sure though)



        Good tutorial to start learning about WPF style and templates

        clock November 20, 2010 21:20 by author Rujith Anand |

         

        Found a good place for a short but precise tutorial about the WPf sytles and templates…

        here on Csharp online