Domanda

I am using NUnit with Visual Studio Express Edition 2010 for C#, Now, normally test works fine. But whenever I try to use Massive.cs, which is open source api to access database. Test fails from that file only. Now, if I run the application, api is working fine. I have created a different library file to access data base.

I seriously don't understand the error. It is just giving error that object reference is not set to an object. But if I run the code, it works fine. I am using dynamic keyword as shown in link of api above. Does that making problem with NUnit ?

Is there any other way to test in this type of Scenarios?

Here are the further details of the code,

Test class is like this

dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });

var items = item.All();

Assert.AreEqual("Maggi", items.FirstOrDefault().Name);

Now, I have put test here. Which gives error like shown in image, Error coming while testing with NUnit

Now if I run code in console application, then code is working fine, code snippet is given below

dynamic item = new Item();
        item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });


        var result = item.All();

        foreach (var i in result)
        {
            Console.WriteLine(i.Name + i.Description);
        }

        Console.Read();

Here, code is working and same thing is not working with NUnit Test. Please have a look and help me out. Please let me know if any further information is needed from my side.

È stato utile?

Soluzione 2

Solved... There is a issue with NUnit Testing. It was not taking config file pefectly. So, I made two changes. Changes I have done in Project setting.

First change is to change Application Base to bin\debug just give application base as this and then config file to .config to .exe.config and things are up and running. :)

Altri suggerimenti

Most probable explanation is that you haven't set up your connection string in the test project.
If you are using NUnit, just put it in app.config of your test project.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top