Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

At my job I am currently working on a Finger Printing application which will authenticate users using their finger prints. I decided to write some unit tests for the application but I did not wanted to scan my finger for every test. So, I scanned my finger once and created a fake finger print and saved it in the binary file. Now, I added the binary file to my test project and every time I needed to get the finger print I simply read the binary file.

The problem using the binary file was that if I try to run the tests on a different machine then I had to transfer the file to the new machine. This might also involes changing the file path and stuff. So, I finally decided to use the binary fake finger print as an embedded resource. This way I don't have to deal with the moving of the file and other issues.

Now, I can run my tests and I can use the embedded finger print to fake out the object.

 [Test]
        [RollBack]
        public void test_can_save_finger_print_in_the_database()
        {
            Assembly ass = Assembly.Load(assemblyName);
            Stream stream = ass.GetManifestResourceStream(fakeFingerPrintResourceName);
            fakeFingerImage = new byte[(int)stream.Length];

            stream.Read(fakeFingerImage, 0, fakeFingerImage.Length);
            stream.Close();

            IFPTemplate sample = new FPTemplateClass();
            sample.Import(fakeFingerImage);

            FingerPrint.Domain.FingerPrint finger = new FingerPrint.Domain.FingerPrint() { FingerImage = fakeFingerImage, InstanceID = sample.InstanceID, UserName = userName };

           FingerPrintRepository.Save(finger);       

 FingerPrint.Domain.FingerPrint vFinger = FingerPrintRepository.GetById(finger.FingerPrintID);

            Assert.AreEqual(finger.FingerImage, vFinger.FingerImage);         
            
        }

Posted on Friday, January 18, 2008 4:44 AM | Back to top


Comments on this post: Finger Printing Application and Unit Testing

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net