Refactor Code

  • Gravatar
    Refering to a Single Entity in the List

    by azamsharp on 7/29/2008 1:01:06 PM
  • I have two entities Employee and TimeCard. Employee can have multiple time cards. TimeCard has properties like CheckInTime and CheckOutTime.. When the employee check-in CheckInTime is updated with current time. When the employee check-out the same timecard CheckOutTime is update to the current time. Since, at given time an employee can only have one active time card I decided to use the following syntax to access the timcard. employee.TimeCards[0]; But I did not liked this approach so I chose a different approach as shown below.
  • public TimeCard CurrentTimeCard
    {
    get { return TimeCards[0]; }
    }

    // I run the tests like this:
    // sam is an employee
    [Test]
    [RollBack]
    public void a_time_card_is_created()
    {
    _repository.CheckIn(_sam);
    Assert.IsNotNull(_sam.CurrentTimeCard);
    }
  • Refactor it!
Please log in to refactor the code! Login