public void ExclaimWillWriteCorrectMessageToMessageWriter()
 {
     // Fixture setup
     var writerMock = new Mock<IMessageWriter>();
     var sut = new Salutation(writerMock.Object);
     // Exercise system
     sut.Exclaim();
     // Verify outcome
     writerMock.Verify(w => w.Write("Hello DI!"));
     // Teardown
 }
Esempio n. 2
0
        private static void Main()
        {
            /* Replace the hard-coded initialization of ConsoleMessageWriter with the below three
             * statements to use an example of Constrained Construction late binding. */
            //var typeName = 
            //    ConfigurationManager.AppSettings["messageWriter"];
            //var type = Type.GetType(typeName, true);
            //IMessageWriter writer = 
            //    (IMessageWriter)Activator.CreateInstance(type);

            /* Replace the hard-coded initialization of ConsoleMessageWriter with the below two
             * statements to use an example of a Decorator. */
            //Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            //IMessageWriter writer = 
            //    new SecureMessageWriter(
            //        new ConsoleMessageWriter());

            IMessageWriter writer = new ConsoleMessageWriter();
            var salutation = new Salutation(writer);
            salutation.Exclaim();
        }
Esempio n. 3
0
        private static void Main()
        {
            /* Replace the hard-coded initialization of ConsoleMessageWriter with the below three
             * statements to use an example of Constrained Construction late binding. */
            //var typeName =
            //    ConfigurationManager.AppSettings["messageWriter"];
            //var type = Type.GetType(typeName, true);
            //IMessageWriter writer =
            //    (IMessageWriter)Activator.CreateInstance(type);

            /* Replace the hard-coded initialization of ConsoleMessageWriter with the below two
             * statements to use an example of a Decorator. */
            //Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            //IMessageWriter writer =
            //    new SecureMessageWriter(
            //        new ConsoleMessageWriter());

            IMessageWriter writer     = new ConsoleMessageWriter();
            var            salutation = new Salutation(writer);

            salutation.Exclaim();
        }