/// <summary> /// Adds the session. /// </summary> /// <param name="session">The session.</param> /// <exception cref="System.ArgumentNullException">session;An empty or null session cannot be added to a track.</exception> /// <exception cref="System.InvalidOperationException">The provided session cannot be added to this track, as a session for the time of the day already exists.</exception> public void AddSession(Session session) { if (session == null) { throw new ArgumentNullException("session", "An empty or null session cannot be added to a track."); } if (!this.CanAdd_a_Session(session)) { throw new ArgumentException("The provided session cannot be added to this track, as a session for the time of the day already exists."); } this._sessions.Add(session); }
public void Check_threshold_of_total_permissible_length_of_Session(TimeOfDay sessionType, int totalPossibleDuration) { this.session = new Session(sessionType); int sumOfTheLengthOfTalksAdded = 0; try { this.session.AddTalk(new Talk("sample talk I", 60)); sumOfTheLengthOfTalksAdded += 60; this.session.AddTalk(new Talk("sample talk II", 45)); sumOfTheLengthOfTalksAdded += 45; this.session.AddTalk(new Talk("sample talk III", 60)); sumOfTheLengthOfTalksAdded += 60; this.session.AddTalk(new Talk("sample talk IV", 45)); sumOfTheLengthOfTalksAdded += 45; this.session.AddTalk(new Talk("sample talk IV", 45)); sumOfTheLengthOfTalksAdded += 45; } catch (Exception) { this.session.TotalDuration.Should().Be(sumOfTheLengthOfTalksAdded); throw; } }
/// <summary> /// Adds the talk to a track. /// </summary> /// <param name="talk">The talk.</param> /// <returns><c>true</c> if the given talk was added into a session of a track, <c>false</c> otherwise</returns> private static bool AddTalkToTrack(Talk talk) { List<Track> _listOfTracks = GetListOfTracks(); // Whether the talk has already been accommodated into a session bool talkHasBeenAdded = false; // Check whether any of the tracks has a session with a slot left for the talk foreach (Track track in _listOfTracks) { // Check whether the track already has any sessions if (track.Sessions.Count == 0) { // Create a new session and add the talk into the session Session newSession = new Session(TimeOfDay.Morning); track.AddSession(newSession); } // Check whether the given talk can be accommodated in one of the sessions of the given track AddTalkToSession(track, talk, out talkHasBeenAdded); // If the talk has been accommodated in a session, // there is no need to check for slots in other tracks if (talkHasBeenAdded) { break; } } // If track has not been added yet, a new track has to be created if (talkHasBeenAdded == false) { // Add the given talk to one of the sessions of the new track Track newTrack = AddTalkToSession(new Track(), talk, out talkHasBeenAdded); // Update the list of tracks with the new track _tracks.Add(newTrack); } return talkHasBeenAdded; }
/// <summary> /// Determines whether this instance [can add_a_ session] the specified session. /// </summary> /// <param name="session">The session.</param> /// <returns><c>true</c> if this instance [can add_a_ session] the specified session; otherwise, <c>false</c>.</returns> private bool CanAdd_a_Session(Session session) { if (this._sessions.Count < 1) { return true; } if (this._sessions.Count > 1) { return false; } return !(this._sessions.Exists(existingSession => existingSession.TimeOfDay == session.TimeOfDay)); }
/// <summary> /// Determines whether this instance can accommodate the specified session. /// </summary> /// <param name="session">The session.</param> /// <returns><c>true</c> if this instance [can accommodate the specified session; otherwise, <c>false</c>.</returns> public bool CanAccommodateThis(Session session) { return this.CanAdd_a_Session(session); }
public void TestStartUp() { this.session = new Session(TimeOfDay.Morning); }