How to do unit testing for a function which returns a datatable in Visual Studio 2010

Posted by Dotnetrajanikanth under Visual Studio on 9/26/2012 | Points: 10 | Views : 2043 | Status : [Member] | Replies : 0

I am trying to test a function which returns a datatable using visual studio 2010 testing tool. I am not able to find a correct way to do that. Can anybody help me in doing that?

I am using the below code for testing a datatable

TestMethod(), _
HostType("ASP.NET"), _
AspNetDevelopmentServerHost("<PathOmitted>/<SolutionName>"), _
UrlToTest("http://localhost:2600/<SolutionName>"), _
DeploymentItem("<Dll>")> _
Public Sub GetDivisionCodeTest()

Dim divDt As New DataTable
divDt.TableName = "GetDivCode"
Dim row As DataRow = divDt.NewRow
'divDt.Rows.Add("", "")
divDt.Rows.Add("51", "HR departments51")
divDt.Rows.Add("25", "Service Center1")
divDt.Rows.Add("24", "Testing")
divDt.Rows.Add("23", "Product")
divDt.Rows.Add("22", "Dot Net")
divDt.Rows.Add("21", "Application")
divDt.Rows.Add("20", "Management")
divDt.Rows.Add("50", "Sales")
divDt.Rows.Add("54", "HRT")
divDt.Rows.Add("37", "Division")
divDt.Rows.Add("75", "Section 75")
divDt.Rows.Add("58", "DivDivision")
divDt.Rows.Add("52", "Sales Department")
divDt.Rows.Add("89", "skills")
divDt.Rows.Add("87", "ski")
divDt.Rows.Add("98", "Division Data")
divDt.Rows.Add("56", "Training New batch 101")
divDt.Rows.Add("90", "Department HRD")
divDt.Rows.Add("35", "Training New batch")
divDt.Rows.Add("45", "Center")
divDt.Rows.Add("12", "HR departments1")
divDt.Rows.Add("99", "software service Center")
divDt.Rows.Add("64", "Department346")
divDt.Rows.Add("97", "division9797")

Dim target As IDRSMaintenance = ServiceLocator.Resolve(Of IDRSMaintenance)() ' TODO: Initialize to an appropriate value
Dim expected As DataTable = divDt ' TODO: Initialize to an appropriate value
Dim actual As DataTable
actual = target.GetDivisionCode()
Assert.AreEqual(expected, actual)
End Sub

I am getting the following error.

Assert.AreEqual failed. Expected:<getdivcode>. Actual:<getdivcode>.</getdivcode></getdivcode>

I am fetching the actual datatable from my actual code.



(No response found.)

Login to post response