Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET testing VB.NET , +
Hi,
 
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"
        divDt.Columns.Add("BU_CD")
        divDt.Columns.Add("BU_NM")
        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:. Actual:.

 
I am fetching the actual datatable from my actual code.
Posted 25-Sep-12 19:47pm
Edited 25-Sep-12 20:47pm
v4
Comments
Mehdi Gholam at 26-Sep-12 0:58am
   
What have you done so far?
rohith119 at 26-Sep-12 1:48am
   
I have updated my question

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What's the problem?? Arrange the method call, using Fakes if you have to, call it (Act), then Assert the resulting return value for the existance of an object, it's correct type, expected data, ... It's not much different from getting back a simple value type.
 
There's little else anyone else can say because you haven't described what you have to do to setup the call or what you're even having a hard time with.
  Permalink  
Comments
rohith119 at 26-Sep-12 2:52am
   
I am not getting what you are trying to tell.
Dave Kreskowiak at 26-Sep-12 8:14am
   
That much is obvious.
 
You can't compare two tables the way you are. They will never be equal because they are two different objects with two different addresses in memory. You are no comparing the contents of the data tables, you are comparing the tables themselves.
 
Building that datatable is a waste of time. All you do is look for those values in the table that's returned from the service.
rohith119 at 26-Sep-12 8:28am
   
Thank you Dave Kreskowiak,
 
Can you tell me how to compare just the values of the datatable?
Dave Kreskowiak at 26-Sep-12 18:30pm
   
Seriously?? You can't do:
 
If MyDataTable(rowNumber).Item(columnNumer) <> someValue Then...
 
Try reading the documentation. This is basic array handling.
rohith119 at 26-Sep-12 23:12pm
   
But this method will be a lengthy one rite..!!?? if there are lot of columns i have to write a line for each and every column.. any other way to do this?? i mean to compare all the column values at once??
Dave Kreskowiak at 26-Sep-12 23:42pm
   
You can "mean" to do that all you want. It's not going to happen unless you write code somewhere to build the table to comare to AND write more code to compare the fields one by one.
 
rohith119 at 27-Sep-12 0:05am
   
So in short I need to write more code.... :( and there is no short cut for this :(
 
Thanks Dave
Your explanation was good. Now i got a clear picture about the problem. Thank you for guiding me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100