Пример #1
0
        public void TestReadTransportersTimeInvalid2()
        {
            BestTransporterView btr     = new BestTransporterView();
            Tuple <int, string> tupTime = btr.ValidateTime("15:60");

            Assert.IsTrue(tupTime.Item1 == -1, "Time entered is invalid");
            Assert.IsTrue(tupTime.Item2.Length > 0, "should be error msg");
        }
Пример #2
0
        public void TestReadTransportersTime4()
        {
            BestTransporterView btr     = new BestTransporterView();
            Tuple <int, string> tupTime = btr.ValidateTime("23:59");

            Assert.IsTrue(tupTime.Item1 == 1439, "Time entered should be 23*60 + 59 = 1439 mins = 23:59 or 11:59pm");
            Assert.IsTrue(tupTime.Item2.Length == 0, "should be no error with zero length error msg");
        }
Пример #3
0
        public void TestReadTransportersTimeWithNoLeadingZero()
        {
            BestTransporterView btr     = new BestTransporterView();
            Tuple <int, string> tupTime = btr.ValidateTime("9:00");

            Assert.IsTrue(tupTime.Item1 == 540, "Time entered should be 9*60 = 540 mins = 9am");
            Assert.IsTrue(tupTime.Item2.Length == 0, "should be no error with zero length error msg");
        }
Пример #4
0
        public void TestReadTransportersRefridgeInvalid2()
        {
            BestTransporterView  btr    = new BestTransporterView();
            Tuple <bool, string> tupRef = btr.ValidateRefridgerationRequired("");

            Assert.IsTrue(tupRef.Item1 == false, "Refridge Required should be false");
            Assert.IsTrue(tupRef.Item2.Length > 0, "should be no error with zero length error msg");
        }
Пример #5
0
        public void TestReadTransportersTime3()
        {
            BestTransporterView btr     = new BestTransporterView();
            Tuple <int, string> tupTime = btr.ValidateTime("00:00");

            Assert.IsTrue(tupTime.Item1 == 0, "Time entered should be 12 midnight or the start of a new day");
            Assert.IsTrue(tupTime.Item2.Length == 0, "should be no error with zero length error msg");
        }
Пример #6
0
        public void TestReadTransportersTime2()
        {
            BestTransporterView btr     = new BestTransporterView();
            Tuple <int, string> tupTime = btr.ValidateTime("09:12");

            Assert.IsTrue(tupTime.Item1 == 552, "Time entered should be 9*60 + 12 = 552 mins = 9:12am");
            Assert.IsTrue(tupTime.Item2.Length == 0, "should be no error with zero length error msg");
        }
Пример #7
0
        public void TestReadTransportersDistanceZeroTest()
        {
            BestTransporterView btr     = new BestTransporterView();
            Tuple <int, string> tupDist = btr.ValidateDistance("-3");

            Assert.IsTrue(tupDist.Item1 == -1, "Distance should be -1 miles");
            Assert.IsTrue(tupDist.Item2.Length > 0, "should be an error msg");
        }
Пример #8
0
        public void TestReadTransportersAllInvalid()
        {
            BestTransporterView  btr = new BestTransporterView();
            TransporterViewInput tqi = new TransporterViewInput();

            tqi.Time     = "25:01";
            tqi.Distance = "5";
            tqi.RefrigerationRequired = "Y";
            Tuple <TransporterQueryInput, string> tup = btr.ValidateAll(tqi);

            Assert.IsTrue(tup.Item1.Time == -1, "Time should be invalid");
            Assert.IsTrue(tup.Item1.Distance == 5, "Dist should be 5");
            Assert.IsTrue(tup.Item1.RefrigerationRequired == true, "Refridge should be true");
            Assert.IsTrue(tup.Item2.Length > 0, "should be an invliad msg");
        }
Пример #9
0
        public void TestReadTransportersAll()
        {
            BestTransporterView  btr = new BestTransporterView();
            TransporterViewInput tqi = new TransporterViewInput();

            tqi.Time     = "14:01";
            tqi.Distance = "5";
            tqi.RefrigerationRequired = "Y";
            Tuple <TransporterQueryInput, string> tup = btr.ValidateAll(tqi);

            Assert.IsTrue(tup.Item1.Time == 841, "Time should be 841 or 2:01pm");
            Assert.IsTrue(tup.Item1.Distance == 5, "Dist should be 5");
            Assert.IsTrue(tup.Item1.RefrigerationRequired == true, "Refridge should be true");
            Assert.IsTrue(tup.Item2.Length == 0, "should be no error with zero length error msg");
        }
Пример #10
0
        /*
         * Entry point for SweetTreats application.
         *
         * Sweet Treats store is now open for deliveries direct to your door.  Sweet Treats has three contracted cycle-couriers who deliver products to customers. The couriers charge different rates, have different working hours and different facilities available.  Sweet Treats needs to select the most appropriate courier for the job:
         *
         *  Bobby works 9am to 1pm, will deliver up to 5 miles and has a refrigerated box on his bike. He charges $1.75 per mile
         *  Martin works 9am-5pm, will deliver up to 3 miles with no refrigerated box available. He charges $1.50 per mile
         *  Geoff works 10am – 4pm, will deliver up to 4 miles and has a refrigerated box on his bike.  He charges $2.00 per mile.
         *
         *
         *  Sweet Treats needs to select the cheapest courier based on:
         *
         *  Working hours of the courier
         *  The distance between the store and the customers location
         *  Is refrigeration is required
         *
         *
         *  Create an application to help Sweet Treats select the best courier. Inputs to the application are:
         *
         *  time of day the order is ready to be shipped
         *  the distance of the required delivery
         *  an indicator as to whether refrigeration is required
         *
         * ASSUMPTIONS:
         * 1. We will allow time to be entered for any time of the day, even times when there are no transporters. If a time is enter for which we don't have a transporter, the program will report this after we attempt to find a transporter.
         * 2. We will not allow input of a distance less than 1
         * 3. The courier/transporter is able to process a delivery as long as the order sent within the time range that they work. So If their time range is between 9am-5pm it is assumed that if they receive an order at 5pm they can still deliver it.
         */
        static void Main(string[] args)
        {
            // load up app settings file and create a controller for a command line
            IConfigurationRoot        config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            BestTransporterController btc    = new BestTransporterController(config);

            Console.WriteLine("Hello World! This is SweetTreats");
            Console.WriteLine("Enter input or press CTRL-C to exit");
            Console.WriteLine();

            // loop until user types CTRL-C
            while (true)
            {
                // Collect input from the user
                BestTransporterView  btv       = new BestTransporterView();
                TransporterViewInput userInput = btv.GetInput();

                // Validate the user's input
                Tuple <TransporterQueryInput, string> tup = btv.ValidateAll(userInput);
                if (tup.Item2.Length == 0) //check for errors returned in the string of the Tuple
                {
                    // Take the data that was converted into a binary from from the user input and find the best transporter
                    BestTransporter bestTrans = btc.GetBestTransporter(tup.Item1);
                    if (bestTrans.FoundTransporterToUse)
                    {
                        //report the best transporter
                        Console.WriteLine("The best transporter to use is " + bestTrans.Name + " for a cost of $" + bestTrans.Cost);
                    }
                    else
                    {
                        //show error with the results -- IE no transporter is available for the time selected.
                        Console.WriteLine(bestTrans.Error);
                    }
                }
                else
                {
                    //show the error for the input data -- IE invalid data entry for TIME, DISTANCE or REFRIDGE REQ.
                    Console.WriteLine(tup.Item2);
                }
                Console.WriteLine();
            }
        }