Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //creating objects for API classes to write messages on console or to the database.
            HelloWorldConsole hwc = new HelloWorldConsole();

            hwc.SetConsoleMsg("Hellow World!");
            hwc.displayConsoleMessage();

            //similary we can add a code to write messages to database
            HelloWorldDatabase hwd = new HelloWorldDatabase();

            hwd.SetConsoleMsg("Write Hellow World to database");
            hwd.DBWrite();

            //using configuation file to determine where to write the information
            switch (ConfigurationManager.AppSettings["AppType"])
            {
            case "Console":
                HelloWorldConsole hwcApp = new HelloWorldConsole();
                hwcApp.SetConsoleMsg("Hello World!");
                hwcApp.displayConsoleMessage();
                break;

            case "Database":
                HelloWorldConsole hwdApp = new HelloWorldConsole();
                hwdApp.SetConsoleMsg("Hello World!");
                hwdApp.DBWrite();
                break;

            default:
                Console.Write("Invalid option for AppType");
                break;
            }
            Console.ReadKey();
        }
        public void SetDatabaseMessage()
        {
            HelloWorldDatabase hwd = new HelloWorldDatabase();

            hwd.SetConsoleMsg("Hello World");

            Assert.IsNotNull(hwd);

            Assert.AreEqual("Hello World", hwd.consoleMsg);
        }
        public void CreateDatabaseBehaviorAndSetMessage()
        {
            //Arrange
            HelloWorldDatabase dbApp = new HelloWorldDatabase();

            //Act
            dbApp.SetMessage("Hello World");

            //Assert
            Assert.IsNotNull(dbApp);
            Assert.AreEqual("Hello World", dbApp.ConsoleMessage);
        }
Ejemplo n.º 4
0
        public void CreateDatabaseBehaviorAndSetMessage()
        {
            //Arrange
            HelloWorldDatabase dbApp = new HelloWorldDatabase();

            //Act
            dbApp.SetMessage("Hello World");

            //Assert
            Assert.IsNotNull(dbApp);
            Assert.AreEqual("Hello World", dbApp.ConsoleMessage);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("------- Abstract Class Version (strategy pattern)--------");
            HelloWorldConsole conApp = new HelloWorldConsole();

            conApp.SetMessage("Hello World");
            conApp.ConsoleDisplay();

            HelloWorldDatabase dbApp = new HelloWorldDatabase();

            dbApp.SetMessage("Hello World");
            dbApp.ConsoleDisplay();


            Console.WriteLine("\n------- Interface Version (strategy pattern) --------");
            App newApp      = new App();
            var appBehavior = ConfigurationManager.AppSettings["ProgramBehavior"];

            switch (appBehavior)
            {
            case "Console":
                newApp.setBehavior(new ConsoleBehavior());
                newApp.setMessage("Hello World");
                newApp.WriteMessage();
                break;

            case "Database":
                newApp.setBehavior(new DatabaseBehavior());
                newApp.setMessage("Hello World");
                newApp.WriteMessage();
                break;

            default:
                newApp.setBehavior(new ConsoleBehavior());
                newApp.setMessage("Hello World");
                newApp.WriteMessage();
                break;
            }

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("------- Abstract Class Version (strategy pattern)--------");
            HelloWorldConsole conApp = new HelloWorldConsole();
            conApp.SetMessage("Hello World");
            conApp.ConsoleDisplay();

            HelloWorldDatabase dbApp = new HelloWorldDatabase();
            dbApp.SetMessage("Hello World");
            dbApp.ConsoleDisplay();

            Console.WriteLine("\n------- Interface Version (strategy pattern) --------");
            App newApp = new App();
            var appBehavior = ConfigurationManager.AppSettings["ProgramBehavior"];

            switch (appBehavior)
            {
                case "Console":
                    newApp.setBehavior(new ConsoleBehavior());
                    newApp.setMessage("Hello World");
                    newApp.WriteMessage();
                    break;
                case "Database":
                    newApp.setBehavior(new DatabaseBehavior());
                    newApp.setMessage("Hello World");
                    newApp.WriteMessage();
                    break;
                default:
                    newApp.setBehavior(new ConsoleBehavior());
                    newApp.setMessage("Hello World");
                    newApp.WriteMessage();
                    break;
            }

            Console.ReadKey();
        }