Beispiel #1
0
 public static Package CreateNew(
     PackageSize size,
     int weight,
     bool isFragile,
     decimal?valueToPay,
     string countryCode,
     int countryISOCode,
     string areaCode,
     Shipment shipment)
 {
     return(new Package(
                id: Guid.NewGuid(),
                size: size,
                weight: weight,
                isFragile: isFragile,
                valueToPay: valueToPay ?? 0,
                trackingCode: GenerateTrackingCode(
                    countryCode: countryCode,
                    countryISOCode: countryISOCode,
                    areaCode: areaCode,
                    receivedDate: shipment.ReceivedDate),
                shipment,
                null,
                createdAt: DateTime.UtcNow,
                updatedAt: null));
 }
Beispiel #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (PackageId.Length != 0)
            {
                hash ^= PackageId.GetHashCode();
            }
            if (PackageSize != 0UL)
            {
                hash ^= PackageSize.GetHashCode();
            }
            if (knownSince_ != null)
            {
                hash ^= KnownSince.GetHashCode();
            }
            if (SourceDescription.Length != 0)
            {
                hash ^= SourceDescription.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes new instance of <see cref="EstimateQuery"/>.
        /// </summary>
        /// <param name="shipmentLeg">Shipment leg parameter <see cref="ShipmentLeg"/>.</param>
        /// <param name="packageSize">Package size parameter <see cref="PackageSize"/>.</param>
        /// <param name="additionalParameters">Additional parameters.</param>
        public EstimateQuery(
            ShipmentLeg shipmentLeg,
            PackageSize packageSize,
            params IQueryParameter[] additionalParameters)
        {
            if (shipmentLeg == null)
            {
                throw new ArgumentNullException("shipmentLeg");
            }
            if (packageSize == null)
            {
                throw new ArgumentNullException("packageSize");
            }
            var parameters = additionalParameters.ToList();

            parameters.ForEach(x =>
            {
                if (x == null)
                {
                    throw new ArgumentException("additionalParameters contains null item", "additionalParameters");
                }
            });


            Items = new NameValueCollection
            {
                shipmentLeg.Items,
                packageSize.Items
            };

            parameters
            .ForEach(x => Items.Add(x.Items));
        }
        private static PackageSize CreatePackageSize(Shipment shipment, IEnumerable <LineItem> shipmentLineItems)
        {
            var weight = shipmentLineItems
                         .Select(item => item.GetWeight() * Shipment.GetLineItemQuantity(shipment, item.Id))
                         .Sum() * 1000; // KG to grams

            return(PackageSize.InGrams((int)weight));
        }
Beispiel #5
0
        private PackageSize CreatePackageSize(IEnumerable <ILineItem> shipmentLineItems)
        {
            var weight = shipmentLineItems
                         .Select(item => item.GetWeight() * item.Quantity)
                         .Sum() * 1000; // KG to grams

            return(PackageSize.InGrams((int)weight));
        }
        public static PackageSize GetPackageSize(Row row, int usageId)
        {
            var packageSize = new PackageSize
            {
                UsageId = usageId,
                Name    = row["Paketin koko (kpl/min/Mt)"]
            };

            return(packageSize);
        }
        public static IPriceService GetPriceService(PackageSize packageSize)
        {
            var discountService = new AccumulatedDiscountService();

            return(packageSize switch
            {
                PackageSize.S => new LowestPriceService(discountService),
                PackageSize.M => new StandardPriceService(discountService),
                PackageSize.L => new FreePriceService(discountService),
                _ => null
            });
Beispiel #8
0
 public Package(
     string id,
     PackageSize size,
     double weight,
     string tag)
 {
     this.Id     = id;
     this.Size   = size;
     this.Weight = weight;
     this.Tag    = tag;
 }
Beispiel #9
0
        public async Task it_returns_result()
        {
            var settings = new ShippingSettings(new Uri("http://test.localtest.me"));
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600"),
                PackageSize.InGrams(2500));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            actual.Estimates.Should().NotBeEmpty();
        }
Beispiel #10
0
        public async Task it_returns_result()
        {
            var clientUri = new Uri("http://test.localtest.me");

            var settings = new ShippingSettings(clientUri, "*****@*****.**", "20b22ed6-2aa7-48c9-9561-b49fe85ce118");
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600", "NO", "NO"),
                PackageSize.InGrams(2500),
                new Products(Product.Servicepakke));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            actual.Estimates.Should().NotBeEmpty();
        }
Beispiel #11
0
        private static IEnumerable <PackageSize> GetPackageSizes(BringRatesSampleBlockView view)
        {
            if (view.Weight.HasValue)
            {
                yield return(PackageSize.InGrams(view.Weight.Value));
            }

            if (view.Volume.HasValue)
            {
                yield return(PackageSize.InVolume(view.Volume.Value));
            }

            if (view.Length.HasValue && view.Width.HasValue && view.Height.HasValue)
            {
                yield return(PackageSize.InDimensions(view.Length.Value, view.Width.Value, view.Height.Value));
            }
        }
Beispiel #12
0
        public async Task it_returns_error_when_unauthenticated()
        {
            var clientUri = new Uri("http://test.localtest.me");

            var settings = new ShippingSettings(clientUri, (string)null, null);
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600", "NO", "NO"),
                PackageSize.InGrams(2500));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            var responseErrors = actual.Errors.OfType <ResponseError>();

            Assert.Single(responseErrors);
        }
Beispiel #13
0
        public async Task it_returns_error_when_no_product_in_estimate_query()
        {
            var clientUri = new Uri("http://test.localtest.me");

            var settings = new ShippingSettings(clientUri, "*****@*****.**", "20b22ed6-2aa7-48c9-9561-b49fe85ce118");
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600", "NO", "NO"),
                PackageSize.InGrams(2500));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            var fieldErrors = actual.Errors.OfType <FieldError>()
                              .Where(x => x.Code.Equals("INVALID_ARGUMENT"));

            Assert.Single(fieldErrors);
        }
Beispiel #14
0
        public void TrackDurationToHashPackage_TracksDuration()
        {
            const string PackageId            = "a";
            const string NormalizedVersion    = "b";
            const long   PackageSize          = 3;
            Guid         validationTrackingId = new Guid();
            const string HashAlgorithm        = "c";
            const string StreamType           = "d";

            var expectedReturnValue = Mock.Of <IDisposable>();

            _telemetryClient.Setup(
                x => x.TrackMetric(
                    It.IsNotNull <string>(),
                    It.IsAny <double>(),
                    It.IsNotNull <IDictionary <string, string> >()))
            .Callback((string metricName, double value, IDictionary <string, string> properties) =>
            {
                Assert.Equal("Orchestrator.DurationToHashPackageSeconds", metricName);
                Assert.True(value > 0);
                Assert.NotEmpty(properties);
                Assert.Equal(new Dictionary <string, string>()
                {
                    { "PackageId", PackageId },
                    { "NormalizedVersion", NormalizedVersion },
                    { "ValidationTrackingId", validationTrackingId.ToString() },
                    { "PackageSize", PackageSize.ToString() },
                    { "HashAlgorithm", HashAlgorithm },
                    { "StreamType", StreamType }
                }, properties);
            });

            using (_telemetryService.TrackDurationToHashPackage(
                       PackageId,
                       NormalizedVersion,
                       validationTrackingId,
                       PackageSize,
                       HashAlgorithm,
                       StreamType))
            {
            }

            _telemetryClient.VerifyAll();
        }
Beispiel #15
0
 public PackageResult(
     PackageSize size,
     int weight,
     bool isFragile,
     decimal valueToPay,
     string trackingCode,
     ShipmentResult shipmentResult,
     DateTime createdAt,
     Guid version)
 {
     Size           = size;
     Weight         = weight;
     IsFragile      = isFragile;
     ValueToPay     = valueToPay;
     TrackingCode   = trackingCode;
     ShipmentResult = shipmentResult;
     CreatedAt      = createdAt;
     Version        = version;
 }
Beispiel #16
0
        /// <summary>
        /// This function is called whenever graphs shall be updated
        /// </summary>
        public void updateDataGraphs()
        {
            PackagesPerCountry.Clear();
            FileSizePerCountry.Clear();
            UsedProtocols.Clear();
            PackageSize.Clear();

            foreach (var c in Countries)
            {
                PackagesPerCountry.Add(new DataClass()
                {
                    Category = c.Key, Number = c.Value
                });
            }

            foreach (var p in Protocols)
            {
                UsedProtocols.Add(new DataClass()
                {
                    Category = p.Key, Number = p.Value
                });
            }

            foreach (var s in SizePerCountry)
            {
                FileSizePerCountry.Add(new DataClass()
                {
                    Category = s.Key, Number = (float)Math.Round(s.Value, 2)
                });
            }

            foreach (var s in Size)
            {
                PackageSize.Add(new DataClass()
                {
                    Category = s.Key, Number = s.Value
                });
            }
        }
Beispiel #17
0
 public Package(
     Guid id,
     PackageSize size,
     int weight,
     bool isFragile,
     decimal valueToPay,
     string trackingCode,
     Shipment shipment,
     Guid?version,
     DateTime createdAt,
     DateTime?updatedAt)
 {
     PackageId    = id;
     Size         = size;
     Weight       = weight;
     IsFragile    = isFragile;
     ValueToPay   = valueToPay;
     TrackingCode = trackingCode;
     Shipment     = shipment;
     Version      = version;
     CreatedAt    = createdAt;
     UpdatedAt    = updatedAt;
 }
Beispiel #18
0
 public Package(int id, PackageSize size)
 {
     Id   = id;
     Size = size;
 }