Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Unit testing Database problem[VS2005]

Unit testing Database problem[VS2005]

Scheduled Pinned Locked Moved C#
helpdatabasecomtestingbeta-testing
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Snowjim
    wrote on last edited by
    #1

    Hey! I have looked allover the internet after a way to do unit testing against a database with rollback as easy and flexible as possible. I found this article: http://msdn.microsoft.com/msdnmag/issues/05/06/UnitTesting/[^] (http://msdn.microsoft.com/msdnmag/issues/05/06/UnitTesting/default.aspx?loc=&fig=true#fig5[^]) And I have tried to do the exact thing that roy Osherove shows. I have two projects(dbContextTest(class library) and dbContextTest_Test(Test project)) The following class are placed within the dbContextTest class and is that class that I want to test: public class userHandler { private databaseHandler dbHandler = new databaseHandler(); public bool createUser(string inFirstName, string inLastName) { try { if(dbHandler.createUser(inFirstName, inLastName) > 0) return true; return false; } catch (Exception ex) { Console.WriteLine("Error in " + this.ToString() + ".createUser : " + ex.Message); return false; } } } As you can see, I am here contacting the DAL(Database handler(dbHandler)) to add a user to the database. In my test project I have a userTest class where I have my test methods: [ClassInitialize()] public static void MyClassInitialize(TestContext testContext) { ServiceConfig config = new ServiceConfig(); config.Transaction = TransactionOption.RequiresNew; ServiceDomain.Enter(config); } [ClassCleanup()] public static void MyClassCleanup() { if (ContextUtil.IsInTransaction) ContextUtil.SetAbort(); ServiceDomain.Leave(); } [TestMethod()] public void createUser() { string firstName = "Olle"; string lastName = "Svensson"; userHandler tmpUSHandler = userFactory();

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups