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.º 2
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.º 3
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.º 4
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();
        }