Click here to Skip to main content
15,905,612 members
Home / Discussions / C#
   

C#

 
Questionreading game port in visual c# 2.0 [modified] Pin
Japjeet Singh6-Oct-06 5:14
Japjeet Singh6-Oct-06 5:14 
AnswerRe: reading game port in visual c# 2.0 Pin
shabonaa6-Oct-06 7:18
shabonaa6-Oct-06 7:18 
GeneralRe: reading game port in visual c# 2.0 Pin
Japjeet Singh6-Oct-06 7:58
Japjeet Singh6-Oct-06 7:58 
Questionsolution explorer Pin
Parshant Verma6-Oct-06 5:05
Parshant Verma6-Oct-06 5:05 
AnswerRe: solution explorer Pin
Amar Chaudhary6-Oct-06 8:21
Amar Chaudhary6-Oct-06 8:21 
AnswerRe: solution explorer Pin
asator6-Oct-06 9:17
asator6-Oct-06 9:17 
GeneralRe: solution explorer Pin
Amar Chaudhary6-Oct-06 9:28
Amar Chaudhary6-Oct-06 9:28 
QuestionUnit testing Database problem[VS2005] Pin
Snowjim6-Oct-06 4:44
Snowjim6-Oct-06 4:44 
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<br />
    {<br />
        private databaseHandler dbHandler = new databaseHandler();<br />
<br />
        public bool createUser(string inFirstName, string inLastName)<br />
        {<br />
            try<br />
            {<br />
                if(dbHandler.createUser(inFirstName, inLastName) > 0)<br />
                    return true;<br />
<br />
                return false;<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Console.WriteLine("Error in " + this.ToString() + ".createUser : " + ex.Message);<br />
                return false;<br />
            }<br />
        }<br />
    }


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()]<br />
        public static void MyClassInitialize(TestContext testContext)<br />
        {<br />
            ServiceConfig config = new ServiceConfig();<br />
            config.Transaction = TransactionOption.RequiresNew;<br />
            ServiceDomain.Enter(config);<br />
        }<br />
<br />
        [ClassCleanup()]<br />
        public static void MyClassCleanup()<br />
        {<br />
            if (ContextUtil.IsInTransaction)<br />
                ContextUtil.SetAbort();<br />
<br />
            ServiceDomain.Leave();<br />
        }<br />
<br />
        [TestMethod()]<br />
        public void createUser()<br />
        {<br />
            string firstName = "Olle";<br />
            string lastName = "Svensson";<br />
<br />
            userHandler tmpUSHandler = userFactory();<br />
<br />
            Assert.AreEqual(tmpUSHandler.createUser(firstName, lastName),true,"User not created");<br />
        }<br />
<br />
        private userHandler userFactory()<br />
        {<br />
            return new userHandler();<br />
        }


I am here trying to make the userHandler class work with in a serten context that I have the possiblility to rollback.

I know that there is nothing wrong with my TestMethod.

When the SqlConnection.open is executed in the DAL I get the following exception:

Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.

What am I doing wrong? And is this the way to solve the problem?
Questionmdi forms Pin
shabonaa6-Oct-06 4:21
shabonaa6-Oct-06 4:21 
AnswerRe: mdi forms Pin
Ranjan Banerji6-Oct-06 5:45
Ranjan Banerji6-Oct-06 5:45 
GeneralRe: mdi forms Pin
shabonaa6-Oct-06 7:13
shabonaa6-Oct-06 7:13 
AnswerRe: mdi forms Pin
Amar Chaudhary6-Oct-06 8:16
Amar Chaudhary6-Oct-06 8:16 
QuestionTcpClient overhead Pin
Wjousts6-Oct-06 4:01
Wjousts6-Oct-06 4:01 
AnswerRe: TcpClient overhead Pin
WillemM6-Oct-06 4:39
WillemM6-Oct-06 4:39 
QuestionHandling multiple keys Pin
Bekjong6-Oct-06 3:58
Bekjong6-Oct-06 3:58 
Questionhow to change tempo of midi file Pin
Amar Chaudhary6-Oct-06 3:58
Amar Chaudhary6-Oct-06 3:58 
QuestionFormatException Pin
123456uio6-Oct-06 3:45
123456uio6-Oct-06 3:45 
AnswerRe: FormatException Pin
Martin#6-Oct-06 4:03
Martin#6-Oct-06 4:03 
GeneralRe: FormatException Pin
Guffa6-Oct-06 4:54
Guffa6-Oct-06 4:54 
GeneralRe: FormatException Pin
Martin#6-Oct-06 8:20
Martin#6-Oct-06 8:20 
GeneralRe: FormatException Pin
Guffa6-Oct-06 10:21
Guffa6-Oct-06 10:21 
Questionhi how can use c++ program in C#.net2003 application Pin
premkamalg6-Oct-06 3:23
premkamalg6-Oct-06 3:23 
AnswerRe: hi how can use c++ program in C#.net2003 application Pin
shabonaa6-Oct-06 4:15
shabonaa6-Oct-06 4:15 
Generalhi, i want use some c++ function in C#.net2003 Pin
premkamalg6-Oct-06 17:32
premkamalg6-Oct-06 17:32 
QuestionOpen a form? Pin
Wolf926-Oct-06 3:14
Wolf926-Oct-06 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.