Esempio n. 1
0
        public void Start_ShouldInvokeUserInterfaceWriteLineWithCorrectMessage_WhenCommandIsNotFound()
        {
            var startIndex      = 0;
            var commandsStrings = new List <string>()
            {
                "NotExistingCommand 1 2 3",
                "End"
            };

            var userInterface = new Mock <IUserInterfaceProvider>();

            userInterface.Setup(ui => ui.ReadLine()).Returns(() =>
            {
                return(commandsStrings[startIndex++]);
            });

            var commandProvider = new Mock <ICommandProvider>();

            commandProvider.Setup(cp => cp.FindCommandExecutorWithName(It.IsAny <string>())).Returns(() => null);

            var engine = new SchoolSystemEngine(userInterface.Object, commandProvider.Object);

            engine.Start();

            userInterface.Verify(ui => ui.WriteLine("The passed command is not found!"), Times.Once());
        }
Esempio n. 2
0
        public void Start_ShouldInvokeCommandProviderFindCommandWithName_WithCorrectParameter(string command, string commandName)
        {
            var startIndex      = 0;
            var commandsStrings = new List <string>()
            {
                command,
                "End"
            };

            var userInterface = new Mock <IUserInterfaceProvider>();

            userInterface.Setup(ui => ui.ReadLine()).Returns(() =>
            {
                return(commandsStrings[startIndex++]);
            });

            var commandProvider = new Mock <ICommandProvider>();

            commandProvider.Setup(cp => cp.FindCommandExecutorWithName(It.IsAny <string>())).Returns(new Mock <ICommand>().Object);

            var engine = new SchoolSystemEngine(userInterface.Object, commandProvider.Object);

            engine.Start();

            commandProvider.Verify(cp => cp.FindCommandExecutorWithName(commandName), Times.Once());
        }
Esempio n. 3
0
        public void Start_ShouldInvokeUserInterfaceWriteLine_WithCorrectMessageWhenCommandHasExecutedCorrectly()
        {
            var expectedMessage = "expected message";

            var startIndex      = 0;
            var commandsStrings = new List <string>()
            {
                "CreateTeacher 1 2 3",
                "End"
            };

            var userInterface = new Mock <IUserInterfaceProvider>();

            userInterface.Setup(ui => ui.ReadLine()).Returns(() =>
            {
                return(commandsStrings[startIndex++]);
            });

            var mockCommand = new Mock <ICommand>();

            mockCommand.Setup(command => command.Execute(It.IsAny <IList <string> >(), It.IsAny <ISchoolSystemEngine>()))
            .Returns(expectedMessage);

            var commandProvider = new Mock <ICommandProvider>();

            commandProvider.Setup(cp => cp.FindCommandExecutorWithName(It.IsAny <string>())).Returns(mockCommand.Object);

            var engine = new SchoolSystemEngine(userInterface.Object, commandProvider.Object);

            engine.Start();

            userInterface.Verify(ui => ui.WriteLine(expectedMessage), Times.Once());
        }
Esempio n. 4
0
        public void Start_ShouldInvokeTheCommand_WithCorrectParameters()
        {
            var startIndex      = 0;
            var commandsStrings = new List <string>()
            {
                "NotExistingCommand 1 2 3",
                "End"
            };

            var commandParameters = new List <string>()
            {
                "1", "2", "3"
            };

            var userInterface = new Mock <IUserInterfaceProvider>();

            userInterface.Setup(ui => ui.ReadLine()).Returns(() =>
            {
                return(commandsStrings[startIndex++]);
            });

            var mockCommand     = new Mock <ICommand>();
            var commandProvider = new Mock <ICommandProvider>();

            commandProvider.Setup(cp => cp.FindCommandExecutorWithName(It.IsAny <string>())).Returns(mockCommand.Object);

            var engine = new SchoolSystemEngine(userInterface.Object, commandProvider.Object);

            engine.Start();

            mockCommand.Verify(command => command.Execute(commandParameters, It.IsAny <ISchoolSystemEngine>()), Times.Once());
        }
Esempio n. 5
0
        private static void Main()
        {
            var consoleReader  = new ConsoleReader();
            var consoleWriter  = new ConsoleWriter();
            var students       = new Dictionary <int, IStudent>();
            var teachers       = new Dictionary <int, ITeacher>();
            var commandFactory = new CommandFactory();
            var engine         = new SchoolSystemEngine(consoleReader, consoleWriter, teachers, students, commandFactory);

            engine.Start();
        }
Esempio n. 6
0
        public void Start_ShouldInvokeUserInterfaceReadLineOnce_IfTheFirstCommandIsEnd()
        {
            var commandsString = "End";
            var stringReader   = new StringReader(commandsString);

            var userInterface = new Mock <IUserInterfaceProvider>();

            userInterface.Setup(ui => ui.ReadLine()).Returns(stringReader.ReadLine());

            var commandProvider = new Mock <ICommandProvider>();

            var engine = new SchoolSystemEngine(userInterface.Object, commandProvider.Object);

            engine.Start();

            userInterface.Verify(ui => ui.ReadLine(), Times.Once());
        }
        public void Start_ShouldCallReadLineOnceAndReturn_WhenEndCommandIsRead()
        {
            var mockedWriter         = new Mock <IWriter>();
            var teachers             = new Dictionary <int, ITeacher>();
            var students             = new Dictionary <int, IStudent>();
            var mockedCommandFactory = new Mock <ICommandFactory>();

            var mockedReader = new Mock <IReader>();

            mockedReader.Setup(x => x.ReadLine()).Returns("End");

            var result = new SchoolSystemEngine(
                mockedReader.Object,
                mockedWriter.Object,
                teachers,
                students,
                mockedCommandFactory.Object);

            result.Start();

            mockedReader.Verify(x => x.ReadLine(), Times.Once());
        }
        public void Start_ShouldCallReadLineTwiceCreateACommandAndExecuteIt_WhenCommandIsPassed()
        {
            var teachers      = new Dictionary <int, ITeacher>();
            var students      = new Dictionary <int, IStudent>();
            var mockedCommand = new Mock <ICommand>();

            mockedCommand.Setup(x => x.Execute(It.IsAny <IList <string> >()))
            .Returns("EXECUTED!");

            var mockedWriter = new Mock <IWriter>();

            mockedWriter.Setup(x => x.WriteLine("EXECUTED!"));

            var mockedCommandFactory = new Mock <ICommandFactory>();

            mockedCommandFactory.Setup(x => x.CreateCommand(It.Is <string>(y => y == "CreateStudent")))
            .Returns(new Mock <ICommand>().Object);

            var mockedReader = new Mock <IReader>();

            mockedReader.SetupSequence(x => x.ReadLine())
            .Returns("CreateStudent FirstName LastName 1")
            .Returns("End");

            var result = new SchoolSystemEngine(
                mockedReader.Object,
                mockedWriter.Object,
                teachers,
                students,
                mockedCommandFactory.Object);

            result.Start();

            mockedCommandFactory.Verify(x => x.CreateCommand(It.Is <string>(y => y == "CreateStudent")), Times.Once());
            mockedReader.Verify(x => x.ReadLine(), Times.Exactly(2));
            mockedWriter.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Once());
        }
Esempio n. 9
0
        public void Start_ShouldInvokeUserInterfaceWriteLineWithCorrectMessage_WhenInputIsAnEmptyLine()
        {
            var startIndex      = 0;
            var commandsStrings = new List <string>()
            {
                "",
                "End"
            };

            var userInterface = new Mock <IUserInterfaceProvider>();

            userInterface.Setup(ui => ui.ReadLine()).Returns(() =>
            {
                return(commandsStrings[startIndex++]);
            });

            var commandProvider = new Mock <ICommandProvider>();

            var engine = new SchoolSystemEngine(userInterface.Object, commandProvider.Object);

            engine.Start();

            userInterface.Verify(ui => ui.WriteLine("The passed command is not found!"), Times.Once());
        }