In our toy-world of the Mixin Hotel, it happens that all rooms are not only occupied, but also often reserved in advance; interested parties and their reservations must be sent away. However, often reservations are canceled, so it is a good idea to put people who can't reserve a room on a waiting list and call them back when a matching reservation is canceled.

This slice is a supplement to the reservation slice (see above).

The class QueueMixinMixin provides the logic for the queue slice.

In code:

    [OverrideTarget]
    public virtual IReservationInfo Reserve (string name, int week)
    {
      try
      {
        var reservationInfo = Base.Reserve (name, week);
        return reservationInfo;
      }
      catch (NoRoomException)
      {
        _queueInfoRepository.Add (new QueueInfo (name, week));
        Console.WriteLine ("No more rooms. Name {0} added to queue.", name);
        return null;
      }
    }

    [OverrideTarget]
    public virtual IReservationInfo Cancel (string name, int week)
    {
      var reservationInfo = Base.Cancel (name, week);
      var queueInfo = _queueInfoRepository.Find ().FirstOrDefault<IQueueInfo> (resInfo => resInfo.Week == week);
      if (queueInfo != null)
      {
        var reply = _yesNoHandler.YesNo (string.Format ("please notify {0} for a room for week {1}. Does he/she accept?", queueInfo.Name, queueInfo.Week));
        if (reply)
        {
          _queueInfoRepository.Remove (queueInfo);
          Base.Reserve (queueInfo.Name, queueInfo.Week);
        }
      }
      return reservationInfo;
    }

Two extra methods exist:

A yes/no-handler returns true ("yes") or false ("no"). It is intended to be a user-interface element for returning whether the queued party on the phone replied "yes" or "no" to the concierge's question whether the party wants to be unqueued and enforce its reservation.

For automatic testing we want to plug in one of two fakes:

These yes/no-handlers are implemented in the Hotel.Tests project.

(For completeness, here is the implementation for such a yes/no-handler, for a TTY user interface.)