Esempio n. 1
0
        static void Main(string[] args)
        {
            List <Parcel> totalParcelList = new List <Parcel>();

            Console.WriteLine("Please enter size of package (cms) separated by commas : ");
            var userInput = Console.ReadLine();

            Console.WriteLine("Would you like to opt in for speedy shipping? (y/n) : ");
            var speedyShippingInput = Console.ReadLine();

            string[]         parcelSizes = userInput.Split(",");
            ParcelCalculator calculator  = new ParcelCalculator();

            for (int i = 0; i < parcelSizes.Length; i++)
            {
                if (int.TryParse(parcelSizes[i], out int sizeOfPkg))
                {
                    totalParcelList.Add(calculator.CalculateCheapestCost(sizeOfPkg));
                }
                else
                {
                    Console.WriteLine($"Invalid output: {parcelSizes[i]}. This is excluded from the total cost.");
                }
            }

            PrintOutput(totalParcelList);
            if (speedyShippingInput.ToLower().Equals("y"))
            {
                PrintSpeedyShippingOutput(totalParcelList.CalculateDoubleParcelCost());
            }
        }
Esempio n. 2
0
        public void WhenSizeIsAnInteger_ExpectSmallParcelSizeToBeReturned()
        {
            //Arrange
            ParcelCalculator calc = new ParcelCalculator();
            int input             = 0;

            //Act
            var result = calc.CalculateCheapestCost(input);

            //Assert
            Assert.IsTrue(result is Parcel);
            Assert.IsTrue(result.Name.Equals(AvailableParcelSizes.SmallParcel.Name));
            Assert.IsTrue(result.Cost.Equals(AvailableParcelSizes.SmallParcel.Cost));
        }
Esempio n. 3
0
        public void WhenSizeIsInMaxBoundarySizeLike49_ExpectMediumParcelToBeReturned()
        {
            //Arrange
            ParcelCalculator calc = new ParcelCalculator();
            int input             = 49;

            //Act
            var result = calc.CalculateCheapestCost(input);

            //Assert
            Assert.IsTrue(result is Parcel);
            Assert.IsTrue(result.Name.Equals(AvailableParcelSizes.MediumParcel.Name));
            Assert.IsTrue(result.Cost.Equals(AvailableParcelSizes.MediumParcel.Cost));
        }