Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try {
                int value = -1;
                if (args.Length == 1 && int.TryParse(args[0], out value))
                {
                    // This is a single AppController
                    // For applications with multiple commands this can be extracted
                    // to an interface and select depending on the commands
                    // A Dependency Injection strategy can be applied
                    var appController = new PrimeNumbersAppController(
                        new PrimeTableGenerator(new PrimeNumberGenerator()),
                        new ConsoleOutputWriter());

                    appController.Run(value);
                }
                else
                {
                    Error("Please use an integer, between 1 and 10, as parameter to run this application.");
                }
            }
            catch (Exception ex)
            {
                Error($"The application found an error:\n{ex.Message}");
            }

            Console.Read();
        }
        public void PrimeNumbersAppController_Run(int value)
        {
            // Arrange
            var m_PrimeTableGenerator = new Mock<IPrimeTableGenerator>();
            m_PrimeTableGenerator.Setup(x => x.Generate(3))
                .Returns(new[,] { { (int?)null, 2, 3, 5 }, { 2, 4, 6, 10 }, { 3, 6, 9, 15 }, { 5, 10, 15, 25 } });

            var testObject = new PrimeNumbersAppController(m_PrimeTableGenerator.Object, m_outputWriter.Object);

            // Act
            testObject.Run(value);

            // Assert
            Assert.AreEqual(
                "--------------------\n" +
                "¦    ¦  2 ¦  3 ¦  5 ¦\n" +
                "--------------------\n" +
                "¦  2 ¦  4 ¦  6 ¦ 10 ¦\n" +
                "--------------------\n" +
                "¦  3 ¦  6 ¦  9 ¦ 15 ¦\n" +
                "--------------------\n" +
                "¦  5 ¦ 10 ¦ 15 ¦ 25 ¦\n" +
                "--------------------\n",
                m_outputWriter_string.ToString());
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try {
                int value = -1;
                if (args.Length == 1 && int.TryParse(args[0], out value))
                {
                    // This is a single AppController
                    // For applications with multiple commands this can be extracted
                    // to an interface and select depending on the commands
                    // A Dependency Injection strategy can be applied
                    var appController = new PrimeNumbersAppController(
                        new PrimeTableGenerator(new PrimeNumberGenerator()),
                        new ConsoleOutputWriter());

                    appController.Run(value);
                }
                else
                {
                    Error("Please use an integer, between 1 and 10, as parameter to run this application.");
                }
            }
            catch(Exception ex)
            {
                Error($"The application found an error:\n{ex.Message}");
            }

            Console.Read();
        }