Exemple #1
0
        public void Test_AddPerformance_ShouldAddThePerformance()
        {
            theatreDatabase.AddTheatre("Theatre Sofia");
            theatreDatabase.AddPerformance(
                "Theatre Sofia",
                "Bella Donna",
                new DateTime(2015, 01, 20, 20, 30, 00),
                new TimeSpan(0, 1, 0, 0),
                12);
            string expectedOutput = "(Bella Donna, Theatre Sofia, 20.01.2015 20:30)";
            string actualOutput   = string.Join(", ", theatreDatabase.ListAllPerformances());

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Exemple #2
0
        public static string ExecuteProcessCommand(string commandLine)
        {
            string[] commandParts = commandLine.Split('(');
            string   command      = commandParts[0];
            string   commandResult;

            string[] commandParameters = ExtractCommandParameters(commandLine);

            try
            {
                switch (command)
                {
                case "AddTheatre":
                    commandResult = ExecuteAddTheatreCommand(commandParameters);
                    break;

                case "PrintAllTheatres":
                    commandResult = ExecutePrintAllTheatresCommand();
                    break;

                case "AddPerformance":
                    string   theatreName      = commandParameters[0];
                    string   performanceTitle = commandParameters[1];
                    DateTime startDateTime    =
                        DateTime.ParseExact(commandParameters[2], "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
                    TimeSpan duration = TimeSpan.Parse(commandParameters[3]);
                    decimal  price    = decimal.Parse(commandParameters[4], NumberStyles.Float);

                    PerformanceDatabase.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
                    commandResult = "Performance added";
                    break;

                case "PrintAllPerformances":
                    commandResult = Engine.ExecutePrintAllPerformancesCommand();
                    break;

                case "PrintPerformances":
                    string theatre      = commandParameters[0];
                    var    performances = PerformanceDatabase.ListPerformances(theatre)
                                          .Select(p => {
                        string startTime = p.StartDateTime.ToString("dd.MM.yyyy HH:mm");
                        return(string.Format("({0}, {1})", p.Name, startTime));
                    })
                                          .ToList();
                    commandResult = performances.Any() ? string.Join(", ", performances) : "No performances";
                    break;

                default:
                    commandResult = "Invalid command!";
                    break;
                }
            }
            catch (Exception ex)
            {
                commandResult = "Error: " + ex.Message;
            }

            return(commandResult);
        }
        private static string ExecuteAddPerformanceCommand(string[] parameters)
        {
            string   theatreName      = parameters[0];
            string   performanceTitle = parameters[1];
            DateTime startDateTime    = ParseDateTime(parameters[2]);
            TimeSpan duration         = ParseDuration(parameters[3]);
            decimal  price            = ParseNumber(parameters[4]);

            performanceDb.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
            return(Constants.PerformanceAddedMsg);
        }
        private static string ExecuteAddPerformanceCommand(string[] commandParameters)
        {
            string   theatreName      = commandParameters[0];
            string   performanceTitle = commandParameters[1];
            DateTime startDateTime    = DateTime.ParseExact(commandParameters[2], "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
            TimeSpan duration         = TimeSpan.Parse(commandParameters[3]);
            decimal  price            = decimal.Parse(commandParameters[4], CultureInfo.InvariantCulture);

            performanceDB.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
            return("Performance added");
        }
        public static string ExecuteAddPerformanceCommand(string[] parameters)
        {
            string   theatre   = parameters[0];
            string   title     = parameters[1];
            DateTime startDate = DateTime.ParseExact(parameters[2], Constants.DateTimeFormat, CultureInfo.InvariantCulture);
            TimeSpan duration  = TimeSpan.Parse(parameters[3]);
            decimal  price     = decimal.Parse(parameters[4]);

            PerformanceDatabase.AddPerformance(theatre, title, startDate, duration, price);
            return(Constants.PerformanceAddedMessage);
        }
        public static string ExecuteAddPerformanceCommand(IPerformanceDatabase dataBase, AddPerformanceCommand command)
        {
            dataBase.AddPerformance(
                command.Theatre,
                command.Performance,
                command.Date,
                command.Duration,
                command.Price);

            return "Performance added";
        }
Exemple #7
0
        private static string ExecuteAddPerformanceCommand(string[] parameters)
        {
            string   theatreName      = parameters[0];
            string   performanceTitle = parameters[1];
            DateTime startDateTime    = ParseDateTime(parameters[2]);
            TimeSpan duration         = TimeSpan.Parse(parameters[3]);
            decimal  price            = decimal.Parse(parameters[4], NumberStyles.Float);

            performanceDatabase.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
            string commandResult = Constants.PerformanceAddedMsg;

            return(commandResult);
        }
Exemple #8
0
        private string ExecuteAddPerformanceCommand(string[] commands)
        {
            ITheatre theatre          = new Theatre(commands[1]);
            string   performanceTitle = commands[2];
            DateTime startDateTime    = DateTime.ParseExact(commands[3], "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
            TimeSpan duration         = TimeSpan.Parse(commands[4]);
            decimal  price            = decimal.Parse(commands[5], NumberStyles.Float);

            database.AddPerformance(theatre, performanceTitle, startDateTime, duration, price);
            string successMessage = "Performance added";

            return(successMessage);
        }
Exemple #9
0
        private static string ExecuteAddPerformanceCommand(IReadOnlyList <string> parameters)
        {
            string   theatreName      = parameters[0];
            string   performanceTitle = parameters[1];
            DateTime result           = DateTime.ParseExact(parameters[2], "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
            DateTime startDateTime    = result;
            TimeSpan result2          = TimeSpan.Parse(parameters[3]);
            TimeSpan duration         = result2;
            decimal  result3          = decimal.Parse(parameters[4], NumberStyles.Float);
            decimal  price            = result3;

            Universal.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
            const string output = "Performance added";

            return(output);
        }
Exemple #10
0
        public static string ExecuteAddPerformanceCommand(string[] commandParams, IPerformanceDatabase database)
        {
            string   theatreName      = commandParams[0];
            string   performanceTitle = commandParams[1];
            DateTime startDateTime    = DateTime.ParseExact(commandParams[2],
                                                            "dd.MM.yyyy HH:mm",
                                                            CultureInfo.InvariantCulture);
            TimeSpan duration = TimeSpan.Parse(commandParams[3]);
            decimal  price    = decimal.Parse(commandParams[4], NumberStyles.Float);

            database.AddPerformance(theatreName,
                                    performanceTitle,
                                    startDateTime,
                                    duration,
                                    price);

            return("Performance added");
        }
Exemple #11
0
        public static string ExecuteAddPerformanceCommand(string[] commandParams, IPerformanceDatabase database)
        {
            string theatreName = commandParams[0];
            string performanceTitle = commandParams[1];
            DateTime startDateTime = DateTime.ParseExact(commandParams[2],
                "dd.MM.yyyy HH:mm",
                CultureInfo.InvariantCulture);
            TimeSpan duration = TimeSpan.Parse(commandParams[3]);
            decimal price = decimal.Parse(commandParams[4], NumberStyles.Float);

            database.AddPerformance(theatreName,
                performanceTitle,
                startDateTime,
                duration,
                price);

            return "Performance added";
        }
Exemple #12
0
        protected static void Main()
        {
            while (true)
            {
                var input = Console.ReadLine();

                if (input == null)
                {
                    return;
                }

                if (input != string.Empty)
                {
                    var    tokens     = input.Split(new[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);
                    var    command    = tokens[0];
                    var    parameters = tokens.Skip(1).Select(p => p.Trim()).ToArray();
                    string message;

                    try
                    {
                        switch (command)
                        {
                        case "AddTheatre":
                            var theatreName = parameters[0];
                            Database.AddTheatre(theatreName);
                            message = "Theatre added";
                            break;

                        case "PrintAllTheatres":
                            var theatres = Database.ListTheatres().ToList();
                            message = string.Join(", ", theatres);
                            break;

                        case "AddPerformance":
                            theatreName = parameters[0];
                            var performanceTitle = parameters[1];
                            var startDateTime    = DateTime.ParseExact(
                                parameters[2],
                                "dd.MM.yyyy HH:mm",
                                CultureInfo.InvariantCulture);
                            var duration = TimeSpan.Parse(parameters[3]);
                            var price    = decimal.Parse(parameters[4], NumberStyles.Float);
                            Database.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
                            message = "Performance added";
                            break;

                        case "PrintAllPerformances":
                            var performances = Database.ListAllPerformances().ToList();
                            message = string.Join(", ", performances);
                            break;

                        case "PrintPerformances":
                            theatreName = parameters[0];
                            var performancesPerTheatre = Database.ListPerformances(theatreName).ToList();
                            message = string.Join(", ", performancesPerTheatre);
                            break;

                        default:
                            message = "Invalid command!";
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        message = "Error: " + ex.Message;
                    }

                    Console.WriteLine(message);
                }
            }
        }
Exemple #13
0
 public static void ExecuteAddPerformanceCommand(string theatreName, string performanceTitle, DateTime startDateTime, TimeSpan duration, decimal price)
 {
     theatresDatabase.AddPerformance(theatreName, performanceTitle, startDateTime, duration, price);
 }