Having difficulties using Is.EquivelentTo() too compare two collections

"Ryan Andrus" <[email protected]> Thu, 7 Aug 2008 12:14:13 -0500
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <DAE51619533F482195B6009B67EECED1@RyanLaptop>
Hi,

I'm having difficulties using Is.EquivelentTo() too compare two collections.
My collections are the same which I've manually verified from the output of
the Assert but the Assert is throwing an exception stating that they are not
the same. I'm comparing two list of PeltonMessages and I've set a break
point in the Equals method for the various types of pelton messages in my
test and the break point is never hit so I'm a bit confused about how this
comparison is done. Can someone please explain how the comparison is done so
that I can determine if we need to update our business objects? Or please
review my code and let me know if I'm just using this constraint wrong?

Code
---------------------------------------------------------------
      [Test]
      //[Ignore("Under developement")]
      public void MergeSendParamsRequests_NoMatches()
      {
         // Old singler request
         Ion.LisdCore.SourceControllers.PeltonRequestType oldRequestType 
            = Ion.LisdCore.SourceControllers.PeltonRequestType.SendParams;
         PeltonRequestPriority oldPriority = PeltonRequestPriority.High;
         List<PeltonMessage> oldMessages = new List<PeltonMessage>();
         SourceControllerNumber oldSrcId = (SourceControllerNumber)2;
         CommandSentNotification oldCallback = new
CommandSentNotification(On_CommandSentNotification);
         oldMessages.Add(new VibratorIdPeltonMessage());
         oldMessages.Add(new SweepStartPeltonMessage());
         oldMessages.Add(new SweepAbortPeltonMessage());
         oldMessages.Add(new EndPeltonMessage());

         // New single request
         Ion.LisdCore.SourceControllers.PeltonRequestType newRequestType 
            = Ion.LisdCore.SourceControllers.PeltonRequestType.SendParams;
         PeltonRequestPriority newPriority = PeltonRequestPriority.High;
         List<PeltonMessage> newMessages = new List<PeltonMessage>();
         SourceControllerNumber newSrcId = (SourceControllerNumber)2;
         CommandSentNotification newCallback = new
CommandSentNotification(On_CommandSentNotification);
         newMessages.Add(new VibratorIdPeltonMessage());
         newMessages.Add(new HelloPeltonMessage());
         newMessages.Add(new StartCodePeltonMessage());
         newMessages.Add(new EndPeltonMessage());

         // Expected SingleRequest.Messages
         List<PeltonMessage> expectedMessages = new List<PeltonMessage>();
         expectedMessages.Add(new VibratorIdPeltonMessage());
         expectedMessages.Add(new SweepStartPeltonMessage());
         expectedMessages.Add(new SweepAbortPeltonMessage());
         expectedMessages.Add(new HelloPeltonMessage());
         expectedMessages.Add(new StartCodePeltonMessage());
         expectedMessages.Add(new EndPeltonMessage());
         
         SingleRequest oldSingleRequest = new SingleRequest(oldRequestType,
oldPriority, 
                                                   oldMessages, oldSrcId,
null, null, null, oldCallback);
         SingleRequest newSingleRequest = new SingleRequest(newRequestType,
newPriority, 
                                                   newMessages, newSrcId,
null, null, null, newCallback);

         SingleRequest.MergeSendParamsRequests(oldSingleRequest,
newSingleRequest);

         Assert.That(oldSingleRequest.messages,
Is.EquivalentTo(expectedMessages), 
                        "oldSingleRequest.messages didn't match the expected
values.");
      }

Error Messsage
---------------------------------------------------------------
------ Test started: Assembly: SourceControllerTests.dll ------

TestCase
'SourceControllerTests.CollisionManagementBaseTests.MergeSendParamsRequests_
NoMatches'
failed: 
  oldSingleRequest.messages didn't match the expected values.
  Expected: equivalent to < <   MsgId =32
   Name =VibratorIdPeltonMessage
   Port =0
   Startchar =163
   MsgId =32
   AddrOffset =0
   SendOverSecondaryChannel =False
   CrewNumber =0
   Radio =False
   MsgCount =2
   Vibrators =4294967295
>, <   MsgId =11
   Name =SweepStartPeltonMessage
   Port =0
   Startchar =163
   MsgId =11
   AddrOffset =0
   SendOverSecondaryChannel =False
   filler0 =S
   filler1 =W
   filler2 =E
   filler3 =E
   filler4 =P
   filler5 =S
   filler6 =T
   filler7 =A
   filler8 =R
   filler9 =T
>, <   MsgId =12
   Name =SweepAbortPeltonMessage
   Port =0
   Startchar =163
   MsgId =12
   AddrOffset =0
   SendOverSecondaryChannel =False
   filler0 =A
   filler1 =B
   filler2 =O
   filler3 =R
   filler4 =T
   filler5 =S
   filler6 =W
   filler7 =E
   filler8 =E
   filler9 =P
>, <   MsgId =8
   Name =HelloPeltonMessage
   Port =0
   Startchar =163
   MsgId =8
   AddrOffset =0
   SendOverSecondaryChannel =False
   EncoderNumber =0
   UnitSerial =0
   DSP =
   MCU =
   OperatingMode =0
   ModemInfo =
   ModemSerial =0
   ModemSetup =0
   ModemPSS =0
>, <   MsgId =10
   Name =StartCodePeltonMessage
   Port =0
   Startchar =163
   MsgId =10
   AddrOffset =0
   SendOverSecondaryChannel =False
   FleetNumber =0
   CrewNumber =0
   EncoderMode =Normal
   DelayedPSS =False
   DecoderSweepLen =0
   SweepID =0
   SweepNumber =0
   StoredSweep =False
   LowForce =False
   StartCodeNumber =0
   DecodersEnabled =0
   VibSimilarity =0
   EP =0
   ShotID =0
   Line =0
   Station =0
   LastSweepIndex =0
   LastEnabledDecoders =0
   NextSweepNumber =0
   RetransmitMissedPss =False
   RetransmitSweepIndex =0
   RetransmitDecoders =0
   SweepProfileNumber =1
   ZeroWaitPSS =True
   ExtraByte =False
>, <   MsgId =1
   Name =EndPeltonMessage
   Port =0
   Startchar =163
   MsgId =1
   AddrOffset =0
   SendOverSecondaryChannel =False
> >
  But was:  < <   MsgId =32
   Name =VibratorIdPeltonMessage
   Port =0
   Startchar =163
   MsgId =32
   AddrOffset =0
   SendOverSecondaryChannel =False
   CrewNumber =0
   Radio =False
   MsgCount =2
   Vibrators =4294967295
>, <   MsgId =11
   Name =SweepStartPeltonMessage
   Port =0
   Startchar =163
   MsgId =11
   AddrOffset =0
   SendOverSecondaryChannel =False
   filler0 =S
   filler1 =W
   filler2 =E
   filler3 =E
   filler4 =P
   filler5 =S
   filler6 =T
   filler7 =A
   filler8 =R
   filler9 =T
>, <   MsgId =12
   Name =SweepAbortPeltonMessage
   Port =0
   Startchar =163
   MsgId =12
   AddrOffset =0
   SendOverSecondaryChannel =False
   filler0 =A
   filler1 =B
   filler2 =O
   filler3 =R
   filler4 =T
   filler5 =S
   filler6 =W
   filler7 =E
   filler8 =E
   filler9 =P
>, <   MsgId =8
   Name =HelloPeltonMessage
   Port =0
   Startchar =163
   MsgId =8
   AddrOffset =0
   SendOverSecondaryChannel =False
   EncoderNumber =0
   UnitSerial =0
   DSP =
   MCU =
   OperatingMode =0
   ModemInfo =
   ModemSerial =0
   ModemSetup =0
   ModemPSS =0
>, <   MsgId =10
   Name =StartCodePeltonMessage
   Port =0
   Startchar =163
   MsgId =10
   AddrOffset =0
   SendOverSecondaryChannel =False
   FleetNumber =0
   CrewNumber =0
   EncoderMode =Normal
   DelayedPSS =False
   DecoderSweepLen =0
   SweepID =0
   SweepNumber =0
   StoredSweep =False
   LowForce =False
   StartCodeNumber =0
   DecodersEnabled =0
   VibSimilarity =0
   EP =0
   ShotID =0
   Line =0
   Station =0
   LastSweepIndex =0
   LastEnabledDecoders =0
   NextSweepNumber =0
   RetransmitMissedPss =False
   RetransmitSweepIndex =0
   RetransmitDecoders =0
   SweepProfileNumber =1
   ZeroWaitPSS =True
   ExtraByte =False
>, <   MsgId =1
   Name =EndPeltonMessage
   Port =0
   Startchar =163
   MsgId =1
   AddrOffset =0
   SendOverSecondaryChannel =False
> >
	
C:\code\Firefly\Trunk_CollisionManagementTesting\CSC\Common.NET\SourceContro
llerTests\CollisionManagementBaseTests.cs(78,0): at
SourceControllerTests.CollisionManagementBaseTests.MergeSendParamsRequests_N
oMatches()


0 passed, 1 failed, 0 skipped, took 6.08 seconds.




-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/