예제 #1
0
        public void IsCoinAllowed_VerifyScenario(float coinValue, bool expectedOutput)
        {
            // Setup
            EuropeanParking europeanParking = new EuropeanParking();

            // Act
            var actualResult = europeanParking.IsCoinAllowed(coinValue);

            // Assert
            Assert.AreEqual(expectedOutput, actualResult);
        }
예제 #2
0
        public void IsParkingFree_VerifyScenario(DateTime dateTime, bool expectedOutput)
        {
            // Setup
            EuropeanParking europeanParking = new EuropeanParking();

            // Act
            var actualResult = europeanParking.IsParkingFree(dateTime);

            // Assert
            Assert.AreEqual(expectedOutput, actualResult);
        }
예제 #3
0
        public void CalculateTime_VerifyScenario(float money, DateTime expectedOutput)
        {
            // Setup
            EuropeanParking europeanParking = new EuropeanParking();

            // Act
            var actualResult = europeanParking.CalculateTime(money);

            // Assert
            Assert.AreEqual(expectedOutput.Date, actualResult.Date);
            Assert.AreEqual(expectedOutput.Hour, actualResult.Hour);
            Assert.AreEqual(expectedOutput.Minute, actualResult.Minute);
        }
예제 #4
0
        static void Main(string[] args)
        {
            IParkingCalculator parkingCalculator = new EuropeanParking();

            // Check for free parking
            void CheckForFreeParking()
            {
                if (parkingCalculator.IsParkingFree())
                {
                    ClearAndPrint(new[] { " Parking is free! Enjoy!" });
                    Console.ReadKey();
                    Environment.Exit(0);
                }
            }

            CheckForFreeParking();

            // Get user input
            ClearAndPrint(new[] { " Enter Coin : " });
            string rawInput = Console.ReadLine();

            // Run contineously till user choose to quit
            while (rawInput.ToLower() != "q")
            {
                // Check if parking is free
                CheckForFreeParking();

                var coinValue = float.Parse(rawInput);

                // Get the result
                var      isCoinAllowed = parkingCalculator.IsCoinAllowed(coinValue);
                DateTime result        = parkingCalculator.CalculateTime(isCoinAllowed ? coinValue : 0);

                ClearAndPrint(new[]
                {
                    !isCoinAllowed ? $" {coinValue} is not a valid coin! Please try again!\n\r" : "",
                    $" Total money collected : {parkingCalculator.TotalCollection}",
                    $" You can park your vehicle till : {result}",
                    " Enter coin : "
                });

                rawInput = Console.ReadLine();
            }
        }