Ejemplo n.º 1
0
        public void TestCalculate_WhenValidDimensions_ExpectCheapestEstimation(
            ParcelDimensions dimensions,
            CostEstimation expectedEstimation)
        {
            // Arrange
            var dimensionsCollection = new[] { dimensions };

            // Act
            var result = _service.Calculate(dimensionsCollection);

            // Assert
            Assert.Equal(expectedEstimation, result);
        }
Ejemplo n.º 2
0
        private static Parcel.ParcelSize GetParcelSize(ParcelDimensions dimensions)
        {
            var largestDimension = GetLargestDimension(dimensions);
            var parcelSize       = Parcel.ParcelSize.XL;

            if (largestDimension < 10)
            {
                parcelSize = Parcel.ParcelSize.Small;
            }
            else if (largestDimension < 50)
            {
                parcelSize = Parcel.ParcelSize.Medium;
            }
            else if (largestDimension < 100)
            {
                parcelSize = Parcel.ParcelSize.Large;
            }

            return(parcelSize);
        }
        public ParcelProperties GetCost(ParcelDimensions parcelDimension)
        {
            var lstparcelProperties = ReadFile();

            var costOnHeight = lstparcelProperties.Find(h => Convert.ToInt32(parcelDimension.Height) >= Convert.ToInt32(h.MinHeight) &&
                                                        Convert.ToInt32(h.Height) >= Convert.ToInt32(parcelDimension.Height));

            var costOnBreadth = lstparcelProperties.Find(h => Convert.ToInt32(parcelDimension.Breadth) >= Convert.ToInt32(h.MinBreadth) &&
                                                         Convert.ToInt32(h.Breadth) >= Convert.ToInt32(parcelDimension.Breadth));

            var costOnLength = lstparcelProperties.Find(h => Convert.ToInt32(parcelDimension.Length) >= Convert.ToInt32(h.MinLength) &&
                                                        Convert.ToInt32(h.Length) >= Convert.ToInt32(parcelDimension.Length));

            if (costOnHeight == null || costOnBreadth == null || costOnLength == null)
            {
                return(null);
            }

            if (Convert.ToDecimal(costOnHeight.Cost) >= Convert.ToDecimal(costOnBreadth.Cost) &&
                Convert.ToDecimal(costOnHeight.Cost) >= Convert.ToDecimal(costOnLength.Cost) &&
                Convert.ToDecimal(costOnHeight.Weight) >= Convert.ToDecimal(parcelDimension.Weight))
            {
                return(costOnHeight);
            }

            if (Convert.ToDecimal(costOnBreadth.Cost) >= Convert.ToDecimal(costOnHeight.Cost) &&
                Convert.ToDecimal(costOnBreadth.Cost) >= Convert.ToDecimal(costOnLength.Cost) &&
                Convert.ToDecimal(costOnBreadth.Weight) >= Convert.ToDecimal(parcelDimension.Weight))
            {
                return(costOnBreadth);
            }

            if (Convert.ToDecimal(costOnLength.Cost) >= Convert.ToDecimal(costOnBreadth.Cost) &&
                Convert.ToDecimal(costOnLength.Cost) >= Convert.ToDecimal(costOnHeight.Cost) &&
                Convert.ToDecimal(costOnLength.Weight) >= Convert.ToDecimal(parcelDimension.Weight))
            {
                return(costOnLength);
            }

            return(null);
        }
Ejemplo n.º 4
0
        private static double GetLargestDimension(ParcelDimensions dimensions)
        {
            var dimensionsArray = new[] { dimensions.Length, dimensions.Height, dimensions.Width };

            return(dimensionsArray.Max());
        }
Ejemplo n.º 5
0
        private Parcel GetParcel(ParcelDimensions dimensions)
        {
            var parcelSize = GetParcelSize(dimensions);

            return(_parcelRepository.Get(parcelSize));
        }