Note that there are some explanatory texts on larger screens.

plurals
  1. POerror in testing dataset in C#
    primarykey
    data
    text
    <p>I have written a project by ASP.NET and C# which uses dataset for connecting to database. I want to test my code by when I create a unit test for my classes which use dataset I get following error: <br></p> <pre><code>Test method Test.CommodityRepositoryTest.GetCommoditiesTest threw exception: System.NullReferenceException: Object reference not set to an instance of an object. at Terminal.Database.TransportCo.TransportCoTableAdapters.ConfigurationTableAdapter.InitConnection() in TransportCoDataSet.Designer.cs: line 12259 at Terminal.Database.TransportCo.TransportCoTableAdapters.ConfigurationTableAdapter.get_Connection() in TransportCoDataSet.Designer.cs: line 12144 at Terminal.Database.TransportCo.TransportCoTableAdapters.ConfigurationTableAdapter.InitAdapter() in TransportCoDataSet.Designer.cs: line 12227 at Terminal.Database.TransportCo.TransportCoTableAdapters.ConfigurationTableAdapter.get_Adapter() in TransportCoDataSet.Designer.cs: line 12133 at Terminal.Database.TransportCo.TransportCoTableAdapters.ConfigurationTableAdapter.GetData() in TransportCoDataSet.Designer.cs: line 12290 </code></pre> <p>I have to mention that I use singleton repository but it does not change anything in the error.</p> <p>does anyone has any idea?</p> <p>these are my code and its test:</p> <pre><code>public List&lt;Commodity&gt; GetCommodities() { var commoditySet=new CommodityTableAdapter(); var commoditys = commoditySet.GetCommdity().ToList(); if (commoditys.Count() == 0) throw new UserInterfaceException("هیچ کالایی در سیستم ثبت نشده است"); var commoditiesName = new List&lt;Commodity&gt;(); for (int i = 0; i &lt; commoditys.Count(); i++) commoditiesName.Add(ConvertcommodityRowTocommodity(commoditys[i])); return commoditiesName; } [TestMethod()] public void GetCommoditiesTest() { var target = CommodityRepository.GetInstance(); // TODO: Initialize to an appropriate value var expected = new List&lt;Commodity&gt; {new Commodity() {HSCode = "323423", ID = 19}}; // TODO: Initialize to an appropriate value List&lt;Commodity&gt; actual = target.GetCommodities(); Assert.AreEqual(expected[0].ID, actual[0].ID); //Assert.Inconclusive("Verify the correctness of this test method."); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload