Esempio n. 1
0
        public void Execute_ExampleFound_RunsExample()
        {
            var exampleCommand = new ExampleCommand(this.examplesMock.Object);

            typeof(ExampleCommand)
            .GetProperty(nameof(ExampleCommand.ExampleName))
            .SetValue(exampleCommand, "Found");
            exampleCommand.Execute(CancellationToken.None);
            this.exampleMock.Verify(e => e.Run(It.IsAny <CancellationToken>()));
        }
Esempio n. 2
0
        static void CommandPattern()
        {
            Console.WriteLine("\n\nCommandPattern Pattern");
            var history        = new History();
            var exampleService = new ExampleService("Initial value");
            var exampleCommand = new ExampleCommand(history, exampleService);
            var undoCommand    = new UndoCommand <string>(history);

            Console.WriteLine(exampleService.GetContent());
            exampleCommand.Execute();
            Console.WriteLine(exampleService.GetContent());
            undoCommand.Execute();
            Console.WriteLine(exampleService.GetContent());
        }
Esempio n. 3
0
        public void Execute_ExampleNotFound_WritesNotFound()
        {
            var exampleCommand = new ExampleCommand(this.examplesMock.Object);

            typeof(ExampleCommand)
            .GetProperty(nameof(ExampleCommand.ExampleName))
            .SetValue(exampleCommand, "NotFound");
            string outputString;

            using (var newOut = new StringWriter(CultureInfo.InvariantCulture))
            {
                var previousOut = Console.Out;
                Console.SetOut(newOut);

                exampleCommand.Execute(CancellationToken.None);

                Console.SetOut(previousOut);
                outputString = newOut.ToString();
            }

            Assert.That(
                outputString,
                Is.EqualTo("Could not find example named 'NotFound'." + Environment.NewLine));
        }