Test Class Assert.AreEqual Fails

Test Class Assert.AreEqual Fails

Old forum URL: forums.lhotka.net/forums/t/7733.aspx


dentjas posted on Tuesday, October 06, 2009


I am creating a TestClass for a child business object.
I am using CSLA version 3.5

Parent Class: Survey
Collection of Children located on the Parent: QuestionnaireCollection
Child Class: Quesitonnaire

Here are the steps I take.

I create a new Survey called Parent
I create a new Questionnaire called target
I add this new questionnaire to the QuestionnaireCollection located on the Survey.

target = parent.Questionnaires.AddNew(parent.Id)

Now, I add the properties to the questionnaire and save the Survey to the database.

        Dim temp As Survey = parent.Clone()
        parent = temp.Save()
        target = parent.Questionnaires(0)

I set target = to the questionniare I just saved.

        target = parent.Questionnaires(0)

Now I get the info I just saved to the DB and store it in target2

        Dim getSurvey As Survey = Survey.GetSurvey(parent.Id)
        Dim target2 As Questionnaire = getSurvey.Questionnaires(0)

Now I call the following

Assert.AreEqual(target, target2, "New Questionnaire did not save correctly to the database")

For some reason the Assert.AreEqual always fails. When I do a DIFF on target and target2
_readresultcache and _WriteResutlCache variables never appear to be equal.

Not sure what these are for and why they would be different.

Any help would be much appreciated.

JoeFallon1 replied on Tuesday, October 06, 2009

I suggest comparing specific properties of the Questionnaire BOs to each other. Like ID and description or something. Rather than the entire BO.

Joe

 

dentjas replied on Thursday, October 08, 2009

Thanks for the suggestion. If I can't figure out how to fix it, I will need to go to this solution. However, it would be much simpler if I could figure out why it isn't working.
I have manually verified that everything that is saved and retrieved from the database (all the properties I have created for this business object) are equal. It is properties I didn't create or care about that are causing the problem.

Thanks

JoeFallon1 replied on Friday, October 09, 2009

In earlier versions of CSLA Rocky created GetIDValue so that he could provide overrides as base class methos for Equals among other simple methods. He had to abandon this concept when WPF came out as Microsoft changed the way they define Equals. If it was not the same reference then MS compared every single value of one object to the other (sounds like what you are experiencing.) Rocky argued forcefully for the concept of logical equality (two objects with the same ID property are Equal) but lost.

That is why I suggested you compare key property values yourself.

Joe

 

Copyright (c) Marimer LLC