473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C#: Help with Empty Collections Unit test

55 New Member
I have a C# program that returns an empty collection and a Unit test that test to see if the name of an element in the empty returned collection is the same as an object I have.I'm asserting that that a string comparison of both elments should be 0 but the test never fails,what am i doing wrong?:
[Test]
public void testGetProjects()
{
Project1 = new Project(1);
Project1.Name = "PHS";

string tester;
tester = "PHS";

ReturnedProjects = PAgent.SearchProjects(tester);

foreach (Project Proj in ReturnedProjects)
{
string nameOfProject;
string projectNameToCompare;

projectNameToCompare = Proj.Name;
nameOfProject = Project1.Name;
Assert.IsTrue(String.Compare(nameOfProject, projectNameToCompare) == 0);


}




}
Jun 7 '07 #1
2 1675
Plater
7,872 Recognized Expert Expert
I am curious as to why you went to all these great lengths, I woulda just done this:
Expand|Select|Wrap|Line Numbers
  1. // [Test]
  2.         public void testGetProjects()
  3.         {
  4.           Project1 = new Project(1);
  5.           Project1.Name = "PHS";
  6.           ReturnedProjects = PAgent.SearchProjects(tester);
  7.  
  8.           foreach (Project Proj in ReturnedProjects)
  9.           {
  10.                 if (proj.Name==Project1.Name)
  11.                 {
  12.                      //you have found if it is in there
  13.                      //do whatever you want here
  14.                      // then      break;
  15.                 }
  16.           }
  17.         }
  18.  
That will tell you if the any project returned in the collection has the same name as the project.

If you wanted to know if a particular instance of the project object was in the collection, you could just do
if (Proj == Project1)
{
}
Jun 7 '07 #2
Motoma
3,237 Recognized Expert Specialist
I have changed the title of this thread to better match the subject matter. Please, in the future, use descriptive titles. Doing so will ensure you get the help you are looking for.
Jun 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Roy Smith | last post by:
In the old days, if I wanted to return a sequence of items, I'd return a list, and loop over it like this: for thing in getListOfThings (): do something With iterators, I'm doing: for...
3
by: steven | last post by:
Hi, Anyone was using pmock for unit testing with python? I met a problem and hope someone to help me. For short, the pmock seems can not mock a iterator object. For example, the tested...
2
by: Naveen Mukkelli | last post by:
Hi, Currently, I've got all my unit tests in a separate class in the same project. Instead of this, I'm planning to move all my tests in a separate project in a single solution. For...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
0
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page which loads a user control in page.onInit like...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
3
by: Phil C. | last post by:
Hi. I need to translate the C# statement: if( this.validatorAssignments != null && this.validatorAssignments.HasKeys() ) where validatorAssignments is an instance of...
4
by: PSL | last post by:
Hi, I am going through the training C# For Programmers made by TestOut and like the presentation. The only problem is that this tutorial has a nastie bug that renders this software practically...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.