locked
Asserting Whether Actual And Expected Datasets Are Equal RRS feed

  • Question

  • Hi,

     

    I have a test in which I need to check whether the data in a dataset is as expected (structure is not an issue) so I used an Assert.AreEqual and fed in this dataset and one created earlier (which was exactly the same in terms of type and contents). However, the assert failed to report that the two were identical and I have no idea why! Can anyone explain?

     

    If this is not possible using an Assert, is the best bet then to use standard dataset comaprison techniques (such as merging and then checking HasChanges or simply comparing xml string representations)?

     

    Cheers
    Dan

     

    Friday, June 6, 2008 10:54 AM

Answers

  • Hi Dan, you can't use Assert.Equals to compare content of DataSet/DataTable. Assert.AreEqual does not have an overload that takes instances of DataTable or DataSet, thus it binds to the Assert.AreEqual(object, object, ...) which calls object.Equals. I don't believe that DataSet/DataTable provides an Equals to compare the content, so it should use the default one, i.e. comparing just the references, e.g. object.ReferenceEquals. If you pass same references, the result would be true, otherwise even if the content is same, it would be false.

     

    There are multiple ways of comparing datasets. Try to ask on this forum for best recommendation.

     

    Thanks,

    Michael Koltachev, VS Team Test

     

    Sunday, June 8, 2008 1:03 AM

All replies

  • Hi Dan, you can't use Assert.Equals to compare content of DataSet/DataTable. Assert.AreEqual does not have an overload that takes instances of DataTable or DataSet, thus it binds to the Assert.AreEqual(object, object, ...) which calls object.Equals. I don't believe that DataSet/DataTable provides an Equals to compare the content, so it should use the default one, i.e. comparing just the references, e.g. object.ReferenceEquals. If you pass same references, the result would be true, otherwise even if the content is same, it would be false.

     

    There are multiple ways of comparing datasets. Try to ask on this forum for best recommendation.

     

    Thanks,

    Michael Koltachev, VS Team Test

     

    Sunday, June 8, 2008 1:03 AM
  • Thanks Michael, that makes sense to me! I will also ask the db forum as suggested.

     

    Cheers

    Dan

     

     

    Monday, June 9, 2008 8:54 AM