Beispiel #1
0
        public static void Main()
        {
            IMessageWriter writer   = new ConsoleMessageWriter();
            var            salution = new Salutation(writer);

            salution.Exclaim();
        }
Beispiel #2
0
        //[Fact]
        /// <exception cref="MockException">The invocation was not performed on the mock.</exception>
        private static void Test_HELLO_DI () {
            var writeMock = new Mock<IMessageWriter> ();
            var sut = new Salutation (writeMock.Object);

            sut.Exclaim ();

            writeMock.Verify(w => w.Write ("Hello DI!"));
        }
Beispiel #3
0
        public void Exclaim_WhenCalled_ReturnsCorrectMessage()
        {
            var writer = new SpyMessageWriter();
            var sut    = new Salutation(writer);

            sut.Exclaim();
            Assert.Equal("Executing exclamation...", writer.WrittenMessage);
        }
        public void Test_Write()
        {
            var writer = new Mock <IMessager>();
            var sut    = new Salutation(writer.Object);

            sut.Exclaim();
            writer.Verify(w => w.Write("Hello DI"));
        }
Beispiel #5
0
        //[Fact]
        /// <exception cref="MockException">The invocation was not performed on the mock.</exception>
        private static void Test_HELLO_DI()
        {
            var writeMock = new Mock <IMessageWriter> ();
            var sut       = new Salutation(writeMock.Object);

            sut.Exclaim();

            writeMock.Verify(w => w.Write("Hello DI!"));
        }
Beispiel #6
0
        public void ExclaimWillWriteCorrectMessageToMessageWriter()
        {
            var writeMock = new Mock <IMessageWriter>();
            var sut       = new Salutation(writeMock.Object);

            sut.Exclaim();

            writeMock.Verify(w => w.Write("Hello DI!"));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            //Poor man's DI - create the writer and pass it to the salutation. No container is used.
            //IMessageWriter writer = new ConsoleMessageWriter(); //create concrete writer(Console)
            IMessageWriter writer = new FileMessageWriter();    //create concrete writer(File)
            //IMessageWriter writer = new DataBaseWriter();         //create concrete writer(DataBase)
            var salutation = new Salutation(writer);            //Inject it as dependency

            salutation.Exclaim();                               //Call the action
        }
Beispiel #8
0
 public static void Test_3()
 {
     try {
         IMessageWriter writer     = new SecureMessageWriter(new ConsoleMessageWriter());
         var            salutation = new Salutation(writer);
         salutation.Exclaim();
     }
     catch (UnauthorizedAccessException e) {
         Console.WriteLine(e);
     }
 }
Beispiel #9
0
 public static void Test_3()
 {
     try {
         IMessageWriter writer = new SecureMessageWriter(new ConsoleMessageWriter());
         var salutation = new Salutation(writer);
         salutation.Exclaim();
     }
     catch (UnauthorizedAccessException e) {
         Console.WriteLine(e);
     }
 }
Beispiel #10
0
        public void ExclaimWillWriteCorrectMessageToMessageWriter(string message)
        {
            var mockWriter = Substitute.For <IMessageWriter>();
            var salutation = new Salutation(mockWriter);

            salutation.Exclaim();

            mockWriter.Received().Write(message);

            Trace.WriteLine(String.Format("Testing Output in Unit Tests for {0}", message));
        }
Beispiel #11
0
        public void TestExclaim()
        {
            // arrange
            var writer     = new Mock <IMessageWriter>();
            var salutation = new Salutation(writer.Object);

            // act
            salutation.Exclaim();

            // assert
            writer.Verify(w => w.Write("Hello DI!"), Times.Once());
        }
Beispiel #12
0
        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
        }
Beispiel #13
0
 /// <exception cref="IOException">Произошла ошибка ввода-вывода. </exception>
 public static void Test_2 () {
     try {
         var typeName = ConfigurationManager.AppSettings["messageWriter"];
         var type = Type.GetType (typeName, true);
         var writer = (IMessageWriter) Activator.CreateInstance (type);
         var salutation = new Salutation (writer);
         salutation.Exclaim ();
     }
     catch (Exception e) {
         Console.WriteLine (e.ToString ());
     }
 }
Beispiel #14
0
        public void ExclaimWillWriteCorrectMessageToMessageWriter()
        {
            // Arrange
            var writer = new SpyMessageWriter();

            var sut = new Salutation(writer);

            // Act
            sut.Exclaim();

            // Assert
            Assert.Equal(expected: "Hello DI!", actual: writer.WrittenMessage);
        }
Beispiel #15
0
 /// <exception cref="IOException">Произошла ошибка ввода-вывода. </exception>
 public static void Test_2()
 {
     try {
         var typeName   = ConfigurationManager.AppSettings["messageWriter"];
         var type       = Type.GetType(typeName, true);
         var writer     = (IMessageWriter)Activator.CreateInstance(type);
         var salutation = new Salutation(writer);
         salutation.Exclaim();
     }
     catch (Exception e) {
         Console.WriteLine(e.ToString());
     }
 }
Beispiel #16
0
        private static void Main(string[] args)
        {
            var salutation = new Salutation(new SecureMessageWriter(new ConsoleMessageWrite(), WindowsIdentity.GetCurrent()));

            salutation.Exclaim();
        }
Beispiel #17
0
        private static void UseConsoleMessageWrite()
        {
            var salutation = new Salutation(new ConsoleMessageWrite());

            salutation.Exclaim();
        }
Beispiel #18
0
 /// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
 public static void Test_1 () {
     IMessageWriter writer = new ConsoleMessageWriter ();
     var salutation = new Salutation (writer);
     salutation.Exclaim ();
 }