예제 #1
0
        public void Test_PrintPerformancesAtDefinedTheatre_ShouldReturnMessageWithAllPerformances()
        {
            theatreDatabase.AddTheatre("Theatre Sofia");
            theatreDatabase.AddTheatre("Theatre 199");
            theatreDatabase.AddPerformance(
                "Theatre Sofia",
                "Bella Donna",
                new DateTime(2015, 01, 20, 22, 00, 00),
                new TimeSpan(0, 1, 0, 0),
                12);
            theatreDatabase.AddPerformance(
                "Theatre 199",
                "Baba Vuna",
                new DateTime(2015, 11, 5, 10, 00, 00),
                new TimeSpan(0, 2, 0, 0),
                12);
            theatreDatabase.AddPerformance(
                "Theatre Sofia",
                "Ali Raza",
                new DateTime(2015, 01, 20, 20, 00, 00),
                new TimeSpan(0, 1, 0, 0),
                12);
            string expectedOutput =
                "(Ali Raza, Theatre Sofia, 20.01.2015 20:00), (Bella Donna, Theatre Sofia, 20.01.2015 22:00)";
            string actualOutput = string.Join(", ", theatreDatabase.ListPerformances("Theatre Sofia"));

            Assert.AreEqual(expectedOutput, actualOutput);
        }
예제 #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);
        }
        public static string ExecutePrintPerformances(string[] parameters)
        {
            var theatre           = parameters[0];
            var performancesCount = PerformanceDatabase.ListPerformances(theatre).Count();

            if (performancesCount > 0)
            {
                var performances = PerformanceDatabase
                                   .ListPerformances(theatre)
                                   .OrderBy(p => p.Date)
                                   .Select(p => string.Format(
                                               "({0}, {1})", p.Title, p.Date.ToString(Constants.DateTimeFormat)))
                                   .ToList();

                return(String.Join(", ", performances));
            }

            return(Constants.NoPerformancesMessage);
        }
예제 #4
0
        public static void ExecutePrintPerformancesCommand(string theatreName)
        {
            var performances = theatresDatabase.ListPerformances(theatreName);

            if (performances.Any())
            {
                string performancesResult = FormatTheatrePerformancesForPrinting(performances);
                PrintOutput(performancesResult);
            }
            else
            {
                Console.WriteLine(Constants.NoPerformancesMessage);
            }
        }
예제 #5
0
        private static string ExecutePrintPerformancesCommand(string[] parameters)
        {
            string theatre      = parameters[0];
            var    performances = performanceDb.ListPerformances(theatre)
                                  .Select(p => string.Format(
                                              "({0}, {1})", p.Title, FormatDateTime(p.StartDateTime)))
                                  .ToList();

            if (performances.Any())
            {
                return(string.Join(", ", performances));
            }

            return(Constants.NoPerformancesMsg);
        }
        private static string ExecutePrintPerformancesCommand(string[] commandParameters)
        {
            string theatre      = commandParameters[0];
            var    performances = performanceDB
                                  .ListPerformances(theatre)
                                  .Select(p => string.Format("({0}, {1})",
                                                             p.PerformanceTitle,
                                                             p.PerformanceDateStart.ToString("dd.MM.yyyy HH:mm")))
                                  .ToList();

            if (performances.Any())
            {
                return(string.Join(", ", performances));
            }
            return("No performances");
        }
예제 #7
0
        private static string ExecutePrintPerformancesCommand(IReadOnlyList <string> parameters)
        {
            string theatre      = parameters[0];
            var    performances = Universal.ListPerformances(theatre).Select(p =>
            {
                string startTime = p.StartDateTime.ToString("dd.MM.yyyy HH:mm");
                return(string.Format("({0}, {1})", p.Title, startTime));
            }).ToList();

            if (!performances.Any())
            {
                return("No performances");
            }

            return(string.Join(", ", performances));
        }
예제 #8
0
        private static string ExecutePrintPerformancesCommand(string[] parameters)
        {
            string theatre = parameters[0];
            string commandResult;

            var performances = performanceDatabase.ListPerformances(theatre).Select(p =>
            {
                string date = p.StartDateTime.ToString(Constants.DateTimeFormat);
                return(string.Format("({0}, {1})", p.PerformanceTitle, date));
            }).ToList();

            if (performances.Any())
            {
                commandResult = string.Join(", ", performances);
            }
            else
            {
                commandResult = Constants.NoPerformancesMsg;
            }

            return(commandResult);
        }
예제 #9
0
        public static string ExecutePrintPerformancesCommand(IPerformanceDatabase dataBase,
            PrintPerformancesCommand command)
        {
            string result = String.Empty;
            var performances = dataBase.ListPerformances(command.TheatreName)
                            .Select(p =>
                            {
                                var result1 = p.Date.ToString("dd.MM.yyyy HH:mm");
                                return string.Format("({0}, {1})", p.PefrofmanceName, result1);
                            })
                            .ToList();

            if (performances.Any())
            {
                result = string.Join(", ", performances);
            }
            else
            {
                result = "No performances";
            }
            return result;
        }
예제 #10
0
        private static string PrintPerformances(string[] commandParams)
        {
            string commandResult;
            string theatre = commandParams[0];

            var performances = universal.ListPerformances(theatre)
                               .Select(p =>
            {
                string result1 = p.DateAndTime.ToString("dd.MM.yyyy HH:mm");
                return(string.Format("({0}, {1})", p.ThisPerformance, result1));
            })
                               .ToList();

            if (performances.Any())
            {
                commandResult = string.Join(", ", performances);
            }
            else
            {
                commandResult = "No performances";
            }

            return(commandResult);
        }
예제 #11
0
        protected static void Main()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");

            while (true)
            {
                string chiHuyLine = Console.ReadLine();
                if (chiHuyLine == null)
                {
                    return;
                }

                if (chiHuyLine != string.Empty)
                {
                    string[] chiHuyParts = chiHuyLine.Split('(');
                    string   chiHuy      = chiHuyParts[0];
                    string   chiHuyResult;
                    try
                    {
                        switch (chiHuy)
                        {
                        case "AddTheatre":
                            chiHuyParts = chiHuyLine.Split('(');
                            chiHuy      = chiHuyParts[0];
                            string[] chiHuyParts1 = chiHuyLine.Split(
                                new[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);
                            string[] chiHuyParams1 = chiHuyParts1.Skip(1).Select(p => p.Trim()).ToArray();
                            string[] chiHuyParams  = chiHuyParams1;
                            chiHuyResult = Class1.ExecuteAddTheatreCommand(chiHuyParams);
                            break;

                        case "PrintAllTheatres":
                            chiHuyResult = Class1.ExecutePrintAllTheatresCommand();
                            break;

                        case "AddPerformance":
                            chiHuyParts = chiHuyLine.Split('(');

                            chiHuy       = chiHuyParts[0];
                            chiHuyParts1 = chiHuyLine.Split(new[] { '(', ',', ')' },
                                                            StringSplitOptions.RemoveEmptyEntries);
                            chiHuyParams1 = chiHuyParts1.Skip(1).Select(p => p.Trim()).ToArray();

                            chiHuyParams = chiHuyParams1;
                            string   theatreName      = chiHuyParams[0];
                            string   performanceTitle = chiHuyParams[1];
                            DateTime result           = DateTime.ParseExact(chiHuyParams[2], "dd.MM.yyyy HH:mm",
                                                                            CultureInfo.InvariantCulture);

                            DateTime startDateTime = result;
                            TimeSpan result2       = TimeSpan.Parse(chiHuyParams[3]);
                            TimeSpan duration      = result2;
                            decimal  result3       = decimal.Parse(chiHuyParams[4], NumberStyles.Float);
                            decimal  price         = result3;

                            NhaHat.universal.AddPerformance(theatreName, performanceTitle, startDateTime, duration,
                                                            price);
                            chiHuyResult = "Performance added";
                            break;

                        case "PrintAllPerformances":
                            chiHuyResult = ExecutePrintAllPerformancesCommand();
                            break;

                        case "PrintPerformances":
                            chiHuyParts = chiHuyLine.Split('(');
                            chiHuy      = chiHuyParts[0];

                            chiHuyParts1  = chiHuyLine.Split(new[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);
                            chiHuyParams1 = chiHuyParts1.Skip(1).Select(p => p.Trim()).ToArray();
                            chiHuyParams  = chiHuyParams1;
                            string theatre = chiHuyParams[0];

                            var performances = universal.ListPerformances(theatre).Select(p =>
                            {
                                string result1 = p.s2.ToString("dd.MM.yyyy HH:mm");
                                return(string.Format("({0}, {1})", p.tr32, result1));
                            })
                                               .ToList();
                            if (performances.Any())
                            {
                                chiHuyResult = string.Join(", ", performances);
                            }
                            else
                            {
                                chiHuyResult = "No performances";
                            }
                            break;

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

                    Console.WriteLine(chiHuyResult);
                }
            }
        }
예제 #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);
                }
            }
        }