public void CollectData_CallingReadkey_WithEnteredKey_Once()
        {
            var console = new Mock <IConsoleWrapper>();

            var sut = new MainMenuBuilder().WithConsoleWrapper(console).Build();

            sut.CollectData();
            console.Verify(c => c.ReadKey(), Times.Once);
        }
        public void CollectData_ReadKeyShouldBeCalled_OneTime_ToGetUserInput()
        {
            // Arange
            var consoleWrapper = Substitute.For <IConsoleWrapper>();
            var mm             = new MainMenuBuilder().WithConsoleWrapper(consoleWrapper).Build();

            // Act
            mm.CollectData();

            // Assert
            consoleWrapper.Received(1).ReadKey();
        }
        public void CollectData_CallingLoadData_Once()
        {
            var            loader  = new Mock <IStudentDataProcessor>();
            var            console = new Mock <IConsoleWrapper>();
            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo('E', ConsoleKey.Enter, false, false, false);

            console.Setup(c => c.ReadKey()).Returns(keyInfo);
            var sut = new MainMenuBuilder().WithConsoleWrapper(console).WithStudentDataProcessor(loader).Build();

            sut.CollectData();
            loader.Verify(l => l.LoadData(It.IsAny <string>()), Times.Once);
        }
        public void CollectData_CallingReadLine_Once()
        {
            var            console = new Mock <IConsoleWrapper>();
            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo('E', ConsoleKey.Enter, false, false, false);

            console.Setup(c => c.ReadKey()).Returns(keyInfo);
            var sut = new MainMenuBuilder().WithConsoleWrapper(console).Build();

            sut.CollectData();

            console.Verify(c => c.ReadLine(), Times.Once);
        }
        public void CollectData_CallingConsoleWrappedWriteLine_WithGetHelloText_Once()
        {
            var console   = new Mock <IConsoleWrapper>();
            var constants = new Mock <IConstants>();

            constants.Setup(c => c.GetHelloText).Returns("Hello");

            var sut = new MainMenuBuilder().WithConstants(constants).WithConsoleWrapper(console).Build();

            sut.CollectData();
            console.Verify(c => c.WriteLine("Hello"), Times.Once);
        }
        public void CollectData_CallingEndOfProgramFromIfStatement_Once()
        {
            var constant = new Mock <IConstants>();

            constant.Setup(c => c.GetExitText).Returns("Exit");
            var console = new Mock <IConsoleWrapper>();

            var sut = new MainMenuBuilder().WithConsoleWrapper(console).WithConstants(constant).Build();

            sut.CollectData();

            console.Verify(c => c.WriteLine("Exit"), Times.Once);
        }
        public void CollectData_CallingConsoleWrappedWriteLine_GetImportFileText_Once()
        {
            ConsoleKeyInfo keyInfo   = new ConsoleKeyInfo('E', ConsoleKey.Enter, false, false, false);
            var            console   = new Mock <IConsoleWrapper>();
            var            constants = new Mock <IConstants>();

            constants.Setup(c => c.GetImportFileText).Returns("HI");
            console.Setup(c => c.ReadKey()).Returns(keyInfo);
            var sut = new MainMenuBuilder().WithConsoleWrapper(console).WithConstants(constants).Build();

            sut.CollectData();
            console.Verify(c => c.WriteLine("HI"), Times.Once);
        }
        public void CollectData_CallingEndOfProgramFromClass_Once()
        {
            ConsoleKeyInfo keyInfo  = new ConsoleKeyInfo('E', ConsoleKey.Enter, false, false, false);
            var            constant = new Mock <IConstants>();

            constant.Setup(c => c.GetExitText).Returns("Exit");
            var console = new Mock <IConsoleWrapper>();

            console.Setup(c => c.ReadKey()).Returns(keyInfo);

            var sut = new MainMenuBuilder().WithConsoleWrapper(console).WithConstants(constant).Build();

            sut.CollectData();

            console.Verify(c => c.WriteLine("Exit"), Times.Once);
        }
        public void CollectData_GetUserPath_IfPassedEnter_ElseNo(bool passed)
        {
            // Arange
            int nTimes = passed ? 1 : 0;

            var consoleWrapper = Substitute.For <IConsoleWrapper>();

            consoleWrapper.ReadKey().Returns(enteredKey(passed));

            var mm = new MainMenuBuilder().WithConsoleWrapper(consoleWrapper).Build();

            // Act
            mm.CollectData();

            // Assert
            consoleWrapper.Received(nTimes).ReadLine();
        }
        public void CollectData_WriteLineShouldBeCalled_WithGetHelloText_ToInformUserWhatToDo()
        {
            // Arange
            string text           = "Hello, please import the students file. To import the file, press Enter. To exit the application press any Key.";
            var    consoleWrapper = Substitute.For <IConsoleWrapper>();

            var constants = Substitute.For <IConstants>();

            constants.GetHelloText.Returns(text);

            var mm = new MainMenuBuilder().WithConstants(constants).WithConsoleWrapper(consoleWrapper).Build();

            // Act
            mm.CollectData();

            // Assert
            consoleWrapper.Received(1).WriteLine(constants.GetHelloText);
        }
        [InlineData(false)] // diffrent key
        public void CollectData_WriteLineFromEndProgramShouldBeCalled_WithGetExitText_OneTime_EvenIfIsEnterKeyOrNot(bool passed)
        {
            // Arange
            string text = "Thank you for work. The program will close.";

            var consoleWrapper = Substitute.For <IConsoleWrapper>();

            consoleWrapper.ReadKey().Returns(enteredKey(passed));

            var constants = Substitute.For <IConstants>();

            constants.GetExitText.Returns(text);

            var mm = new MainMenuBuilder().WithConstants(constants).WithConsoleWrapper(consoleWrapper).Build();

            // Act
            mm.CollectData();

            // Assert
            consoleWrapper.Received(1).WriteLine(constants.GetExitText);
        }
        public void CollectData_CallsLoadData_IfPassedEnter_ElseNo(bool passed)
        {
            // Arange
            string path   = "path";
            int    nTimes = passed ? 1 : 0;

            var consoleWrapper = Substitute.For <IConsoleWrapper>();

            consoleWrapper.ReadKey().Returns(enteredKey(passed));
            consoleWrapper.ReadLine().Returns(path);

            var loader = Substitute.For <IStudentDataProcessor>();

            var mm = new MainMenuBuilder().WithConsoleWrapper(consoleWrapper).WithLoader(loader).Build();

            // Act
            mm.CollectData();

            // Assert
            loader.Received(nTimes).LoadData(path);
        }
        public void CollectData_WriteLineShouldBeCalled_WithGetImportFileText_OneTime_IfIsEnterKey_ElseNoCalls(bool passed)
        {
            // Arange
            string text   = "Insert path for student data Excel file";
            int    nTimes = passed ? 1 : 0;

            var consoleWrapper = Substitute.For <IConsoleWrapper>();

            consoleWrapper.ReadKey().Returns(enteredKey(passed));

            var constants = Substitute.For <IConstants>();

            constants.GetImportFileText.Returns(text);

            var mm = new MainMenuBuilder().WithConstants(constants).WithConsoleWrapper(consoleWrapper).Build();

            // Act
            mm.CollectData();

            // Assert
            consoleWrapper.Received(nTimes).WriteLine(constants.GetImportFileText);
        }