Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Monday, 07 March 2011
[TestMethod]
public void when_adding_two_different_copies_of_the_same_movie_it_should_store_only_1_copy_in_the_collection()
{
MovieLibrary movieLibrary = new MovieLibrary(movie_collection);
Movie speed_racer = new Movie { title = "Speed Racer" };
Movie another_copy_of_speed_racer = new Movie { title = "Speed Racer" };

movieLibrary.add(speed_racer);
movieLibrary.add(another_copy_of_speed_racer);

Assert.AreEqual(1, movie_collection.Count);
}
 
Here is MovieLibrary:
public void add(Movie movie)
{
// .Contains is from List
// Actually uses .Equals method to see if any movies in collection is .Equal to the new one
if (!_list_of_movies_passed_to_us.Contains(movie))
_list_of_movies_passed_to_us.Add(movie);
}

And here is Movie, with the shorter way commented out with a longer way working

public class Movie : IEquatable<Movie>
{
// Properties
public string title { get; set; }
public ProductionStudio production_studio { get; set; }
public Genre genre { get; set; }
public int rating { get; set; }
public DateTime date_published { get; set; }

// Method
public bool Equals(Movie other)
{
//return other == null ? false : other.title == this.title;
if (other == null)
return false;
else if (other.title == this.title)
return true;
else
return false;
}
}

| | #