/// <summary> /// Creates the schedule for the provided user input. /// </summary> /// <param name="uiTransactionData">The user input.</param> public static void CreateScheduleFor(ref UserInterfaceTransactionData uiTransactionData) { try { // Validate the user provided input ValidateUserInput(ref uiTransactionData); // Check whether the user input has any faults and proceed accordingly if (uiTransactionData.HasFaults == false) { // Get the length of the talk in expected data type int durationOfTalk = 0; int.TryParse(uiTransactionData.LengthOfTalk, out durationOfTalk); // Create a new talk Talk newTalk = new Talk(uiTransactionData.TalkTitle, durationOfTalk); // Add the talk to one of the available tracks if (AddTalkToTrack(newTalk) == false) { // If the talk could not be added, induce an error into the user input uiTransactionData.Faults.Add(new Fault() { Message = "Talk could not be scheduled.", Code = "Talk" }); } } } catch (Exception exception) { uiTransactionData.Faults.Add(new Fault() { Message = exception.Message, Code = exception.Source }); } }
public void Schedule_a_talk(string title, string lengthOfTalk, bool isValidTitle, bool isValidDurationOfTalk) { UserInterfaceTransactionData userInput = new UserInterfaceTransactionData(title, lengthOfTalk); ConferenceManager.CreateScheduleFor(ref userInput); if (isValidTitle == false && isValidDurationOfTalk == false) { userInput.HasFaults.Should().BeTrue(); userInput.Faults.Count.Should().Be(2); } else if ((isValidTitle && isValidDurationOfTalk == false) || (isValidTitle == false && isValidDurationOfTalk)) { userInput.HasFaults.Should().BeTrue(); userInput.Faults.Count.Should().Be(1); } else if (isValidTitle && isValidDurationOfTalk) { userInput.HasFaults.Should().BeFalse(); ConferenceManager.Tracks.Count.Should().BeGreaterThan(0); } }
/// <summary> /// Validates the user input. /// </summary> /// <param name="uiTransactionData">The user input.</param> public static void ValidateUserInput(ref UserInterfaceTransactionData uiTransactionData) { // Check whether the title of the talk input by the user is valid, // otherwise add the error into the user input instance if (!Talk.IsValidTitle(uiTransactionData.TalkTitle)) { Fault newError = new Fault() { Message = "The title of the talk should not contain any numbers", Code = "userInput.TalkTitle" }; uiTransactionData.Faults.Add(newError); } // Check whether the length of the talk input by the user is valid, // otherwise add the error into the user input instance int result = 0; if (!Regex.IsMatch(uiTransactionData.LengthOfTalk, @"^\d+$") && !int.TryParse(uiTransactionData.LengthOfTalk, out result)) { Fault newError = new Fault() { Message = "The duration of the talk should be numbers only", Code = "userInput.LengthOfTalk" }; uiTransactionData.Faults.Add(newError); } }