Example #1
0
        public void Run_writes_MaxNumberExceeded_to_console_when_FileNotFound3Times()
        {
            // arrange
            IConsole      console      = Substitute.For <IConsole>();
            ITripLogic    tripLogic    = Substitute.For <ITripLogic>();
            IStreamReader streamReader = Substitute.For <IStreamReader>();

            console.ReadLine().Returns("file");

            streamReader.FileExists(Arg.Any <string>()).Returns(false, false, false);

            // act
            Program.Run(tripLogic, console, streamReader);

            // assert
            console.Received().WriteLine("You have exceeded the maximum number of tries.\n");
        }
Example #2
0
        public static void Main(string[] args)
        {
            ServiceProvider serviceProvider = new ServiceCollection()
                                              .AddSingleton <ITripLogic, TripLogic>()
                                              .AddSingleton <IConsole, ConsoleWrapper>()
                                              .AddSingleton <IStreamReader, StreamReaderWrapper>()
                                              .BuildServiceProvider();

            ITripLogic tripLogic = serviceProvider.GetService <ITripLogic>();

            IConsole console = serviceProvider.GetService <IConsole>();

            IStreamReader reader = serviceProvider.GetService <IStreamReader>();

            Run(tripLogic, console, reader);

            console.WriteLine("Press any key to exit.");
            console.ReadKey();
        }
Example #3
0
        public void Run_writes_FileNotFoundMessage_to_console_when_FileNotFound()
        {
            // arrange
            IConsole      console      = NSubstitute.Substitute.For <IConsole>();
            ITripLogic    tripLogic    = Substitute.For <ITripLogic>();
            IStreamReader streamReader = Substitute.For <IStreamReader>();

            console.ReadLine().Returns("file");

            streamReader.FileExists(Arg.Any <string>()).Returns(false, true);

            tripLogic.CalculateResults(new List <Driver>(), new List <Trip>()).Returns(new List <string>());

            // act
            Program.Run(tripLogic, console, streamReader);

            // assert
            console.Received().WriteLine("File not found. Please try again.\n");
        }
Example #4
0
        public void Run_writes_DriverResults_to_console_when_DriverResultsExist()
        {
            // arrange
            IConsole      console      = Substitute.For <IConsole>();
            ITripLogic    tripLogic    = Substitute.For <ITripLogic>();
            IStreamReader streamReader = Substitute.For <IStreamReader>();

            var driverResults = new List <string>()
            {
                "test string",
            };

            console.ReadLine().Returns("file");

            streamReader.FileExists(Arg.Any <string>()).Returns(true);
            tripLogic.CalculateResults(new List <Driver>(), new List <Trip>()).ReturnsForAnyArgs(driverResults);

            // act
            Program.Run(tripLogic, console, streamReader);

            // assert
            console.Received().WriteLine(driverResults[0]);
        }
Example #5
0
        public static void Run(ITripLogic tripLogic, IConsole console, IStreamReader streamReader)
        {
            string filePath = PromptForFile(console);

            int attempts = 1;

            while (!streamReader.FileExists(filePath))
            {
                if (attempts < 3)
                {
                    console.WriteLine("File not found. Please try again.\n");

                    filePath = PromptForFile(console);
                }
                else
                {
                    console.WriteLine("You have exceeded the maximum number of tries.\n");
                    return;
                }

                attempts++;
            }

            streamReader.CreateReader(filePath);

            List <Driver> drivers = tripLogic.RegisterDrivers(streamReader);

            List <Trip> trips = tripLogic.RegisterTrips(streamReader, drivers);

            List <string> driverResults = tripLogic.CalculateResults(drivers, trips);

            if (driverResults != null && driverResults.Any())
            {
                driverResults.ForEach(console.WriteLine);
            }
        }
Example #6
0
 public HomeController(IStationLogic client, ITripLogic tripLogic)
 {
     _client    = client;
     _tripLogic = tripLogic;
 }
Example #7
0
 public CommandLogic(IDriverLogic personLogic, ITripLogic tripLogic)
 {
     _driverLogic = personLogic;
     _tripLogic   = tripLogic;
 }