Пример #1
0
 public ShipmentInfo(Guid notificationId, ShipmentPeriod shipmentPeriod, int numberOfShipments, ShipmentQuantity shipmentQuantity)
 {
     NotificationId = notificationId;
     UpdateQuantity(shipmentQuantity);
     UpdateShipmentPeriod(shipmentPeriod, NotificationStatus.NotSubmitted);
     UpdateNumberOfShipments(numberOfShipments);
 }
Пример #2
0
 public ShipmentInfo(Guid notificationId, ShipmentPeriod shipmentPeriod, int numberOfShipments, ShipmentQuantity shipmentQuantity)
 {
     NotificationId = notificationId;
     UpdateQuantity(shipmentQuantity);
     UpdateShipmentPeriod(shipmentPeriod, NotificationStatus.NotSubmitted);
     UpdateNumberOfShipments(numberOfShipments);
 }
        private ShipmentInfo GetTestShipmentInfo(ShipmentQuantityUnits unit)
        {
            var shipmentPeriod   = new ShipmentPeriod(DateTime.Now, DateTime.Now.AddMonths(12), true);
            var shipmentQuantity = new ShipmentQuantity(1.0m, unit);

            return(new ShipmentInfo(notificationId, shipmentPeriod, 100, shipmentQuantity));
        }
Пример #4
0
        private ShipmentInfo CreateShipmentInfo(int maxNumberOfMovements)
        {
            var anyShipmentPeriod = new ShipmentPeriod(new DateTime(2015, 3, 1), new DateTime(2016, 1, 1), true);
            var anyQuantity       = new ShipmentQuantity(5m, Core.Shared.ShipmentQuantityUnits.Tonnes);

            return(new ShipmentInfo(NotificationId, anyShipmentPeriod, maxNumberOfMovements, anyQuantity));
        }
Пример #5
0
        public void UpdateShipmentPeriod(ShipmentPeriod shipmentPeriod, NotificationStatus status)
        {
            if (shipmentPeriod.FirstDate < SystemTime.UtcNow.Date && status == NotificationStatus.NotSubmitted)
            {
                throw new InvalidOperationException(string.Format(
                                                        "The start date cannot be in the past on shipment info {0}", Id));
            }

            ShipmentPeriod = shipmentPeriod;
        }
Пример #6
0
        public void UpdateShipmentPeriod(ShipmentPeriod shipmentPeriod, NotificationStatus status)
        {
            if (shipmentPeriod.FirstDate < SystemTime.UtcNow.Date && status == NotificationStatus.NotSubmitted)
            {
                throw new InvalidOperationException(string.Format(
                    "The start date cannot be in the past on shipment info {0}", Id));
            }

            ShipmentPeriod = shipmentPeriod;
        }
        public void CanCreateShipmentInfo()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            Assert.NotNull(shipmentInfo);
        }
Пример #8
0
        public void PreconsentedNotificationDatesCanBeInside36Months()
        {
            var firstDate      = new DateTime(2015, 01, 01);
            var lastDate       = new DateTime(2017, 12, 31);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(1, ShipmentQuantityUnits.Kilograms));

            Assert.NotNull(shipmentInfo);
        }
Пример #9
0
        public void CanCreateShipmentInfo()
        {
            var firstDate      = new DateTime(2015, 01, 01);
            var lastDate       = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            Assert.NotNull(shipmentInfo);
        }
        public void QuantityCantBeZero()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            Action createShipmentInfo = () => new ShipmentInfo(AnyGuid, shipmentPeriod, 1,
                new ShipmentQuantity(0, ShipmentQuantityUnits.Kilograms));

            Assert.Throws<ArgumentOutOfRangeException>(createShipmentInfo);
        }
        public void NumberOfShipmentsCantBeNegative()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);
            var shipmentQuantity = new ShipmentQuantity(100, ShipmentQuantityUnits.Kilograms);

            Action createShipmentInfo = () => new ShipmentInfo(AnyGuid, shipmentPeriod, -5, shipmentQuantity);

            Assert.Throws<ArgumentOutOfRangeException>(createShipmentInfo);
        }
Пример #12
0
        public Shipment(Guid importNotificationId, ShipmentPeriod period, ShipmentQuantity quantity, int numberOfShipments)
        {
            Guard.ArgumentNotDefaultValue(() => importNotificationId, importNotificationId);
            Guard.ArgumentNotNull(() => period, period);
            Guard.ArgumentNotNull(() => quantity, quantity);
            Guard.ArgumentNotZeroOrNegative(() => numberOfShipments, numberOfShipments);

            ImportNotificationId = importNotificationId;
            Period            = period;
            Quantity          = quantity;
            NumberOfShipments = numberOfShipments;
        }
Пример #13
0
        public void QuantityTonnesMoreThan4DecimalPlacesRoundsUp()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate  = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(1.23446m, ShipmentQuantityUnits.Tonnes));

            Assert.Equal(1.2345m, shipmentInfo.Quantity);
        }
Пример #14
0
        public Shipment(Guid importNotificationId, ShipmentPeriod period, ShipmentQuantity quantity, int numberOfShipments)
        {
            Guard.ArgumentNotDefaultValue(() => importNotificationId, importNotificationId);
            Guard.ArgumentNotNull(() => period, period);
            Guard.ArgumentNotNull(() => quantity, quantity);
            Guard.ArgumentNotZeroOrNegative(() => numberOfShipments, numberOfShipments);

            ImportNotificationId = importNotificationId;
            Period = period;
            Quantity = quantity;
            NumberOfShipments = numberOfShipments;
        }
Пример #15
0
        public void NumberOfShipmentsCantBeZero()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate  = new DateTime(2015, 12, 01);

            var shipmentPeriod   = new ShipmentPeriod(firstDate, lastDate, true);
            var shipmentQuantity = new ShipmentQuantity(100, ShipmentQuantityUnits.Kilograms);

            Action createShipmentInfo = () => new ShipmentInfo(AnyGuid, shipmentPeriod, 0, shipmentQuantity);

            Assert.Throws <ArgumentOutOfRangeException>(createShipmentInfo);
        }
Пример #16
0
        public void QuantityCantBeNegative()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate  = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            Action createShipmentInfo = () => new ShipmentInfo(AnyGuid, shipmentPeriod, 1,
                                                               new ShipmentQuantity(-5, ShipmentQuantityUnits.Kilograms));

            Assert.Throws <ArgumentOutOfRangeException>(createShipmentInfo);
        }
Пример #17
0
        public void QuantityKilogramsMoreThan1DecimalPlaceRoundsDown()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate  = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(1.23m, ShipmentQuantityUnits.Kilograms));

            Assert.Equal(1.2m, shipmentInfo.Quantity);
        }
Пример #18
0
        public void CanUpdateNumberOfShipments()
        {
            var firstDate      = new DateTime(2015, 01, 01);
            var lastDate       = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            shipmentInfo.UpdateNumberOfShipments(50);

            Assert.Equal(50, shipmentInfo.NumberOfShipments);
        }
Пример #19
0
        public void CanUpdateShipmentQuantity()
        {
            var firstDate      = new DateTime(2015, 01, 01);
            var lastDate       = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            shipmentInfo.UpdateQuantity(new ShipmentQuantity(2.0M, ShipmentQuantityUnits.Kilograms));

            Assert.Equal(2.0M, shipmentInfo.Quantity);
            Assert.Equal(ShipmentQuantityUnits.Kilograms, shipmentInfo.Units);
        }
Пример #20
0
        public void CanUpdateShipmentPeriod()
        {
            var firstDate      = new DateTime(2015, 01, 01);
            var lastDate       = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                                                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            var newFirstDate      = new DateTime(2015, 06, 01);
            var newLastDate       = new DateTime(2016, 05, 31);
            var newShipmentPeriod = new ShipmentPeriod(newFirstDate, newLastDate, true);

            shipmentInfo.UpdateShipmentPeriod(newShipmentPeriod, NotificationStatus.NotSubmitted);

            Assert.Equal(newFirstDate, shipmentInfo.ShipmentPeriod.FirstDate);
            Assert.Equal(newLastDate, shipmentInfo.ShipmentPeriod.LastDate);
        }
        public async Task <Guid> HandleAsync(SetIntendedShipmentInfoForNotification command)
        {
            var facilityCollection = await facilityRepository.GetByNotificationId(command.NotificationId);

            var shipmentInfo = await shipmentInfoRepository.GetByNotificationId(command.NotificationId);

            var status = await assessmentRepository.GetStatusByNotificationId(command.NotificationId);

            var shipmentPeriod = new ShipmentPeriod(
                command.StartDate,
                command.EndDate,
                facilityCollection.AllFacilitiesPreconsented.GetValueOrDefault());

            var shipmentQuantity = new ShipmentQuantity(
                command.Quantity,
                command.Units);

            if (shipmentInfo == null)
            {
                shipmentInfo = new ShipmentInfo(command.NotificationId,
                                                shipmentPeriod,
                                                command.NumberOfShipments,
                                                shipmentQuantity);

                context.ShipmentInfos.Add(shipmentInfo);
            }
            else
            {
                shipmentInfo.UpdateNumberOfShipments(command.NumberOfShipments);
                shipmentInfo.UpdateShipmentPeriod(shipmentPeriod, status);
                shipmentInfo.UpdateQuantity(shipmentQuantity);
            }

            await context.SaveChangesAsync();

            return(shipmentInfo.Id);
        }
        public void CanUpdateNumberOfShipments()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            shipmentInfo.UpdateNumberOfShipments(50);

            Assert.Equal(50, shipmentInfo.NumberOfShipments);
        }
        public void QuantityTonnesMoreThan4DecimalPlacesRoundsUp()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(1.23446m, ShipmentQuantityUnits.Tonnes));

            Assert.Equal(1.2345m, shipmentInfo.Quantity);
        }
Пример #24
0
 public ShipmentTests()
 {
     quantity = new ShipmentQuantity(50, ShipmentQuantityUnits.Tonnes);
     period = new ShipmentPeriod(new DateTime(2016, 1, 1), new DateTime(2017, 1, 1), true);
 }
        public void QuantityKilogramsMoreThan1DecimalPlaceRoundsDown()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);

            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(1.23m, ShipmentQuantityUnits.Kilograms));

            Assert.Equal(1.2m, shipmentInfo.Quantity);
        }
Пример #26
0
 public ShipmentTests()
 {
     quantity = new ShipmentQuantity(50, ShipmentQuantityUnits.Tonnes);
     period   = new ShipmentPeriod(new DateTime(2016, 1, 1), new DateTime(2017, 1, 1), true);
 }
 private ShipmentInfo CreateShipmentInfo(int maxNumberOfMovements)
 {
     var anyShipmentPeriod = new ShipmentPeriod(new DateTime(2015, 3, 1), new DateTime(2016, 1, 1), true);
     var anyQuantity = new ShipmentQuantity(5m, Core.Shared.ShipmentQuantityUnits.Tonnes);
     return new ShipmentInfo(NotificationId, anyShipmentPeriod, maxNumberOfMovements, anyQuantity);
 }
        public void PreconsentedNotificationDatesCanBeInside36Months()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2017, 12, 31);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(1, ShipmentQuantityUnits.Kilograms));

            Assert.NotNull(shipmentInfo);
        }
        public void CanUpdateShipmentPeriod()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            var newFirstDate = new DateTime(2015, 06, 01);
            var newLastDate = new DateTime(2016, 05, 31);
            var newShipmentPeriod = new ShipmentPeriod(newFirstDate, newLastDate, true);

            shipmentInfo.UpdateShipmentPeriod(newShipmentPeriod, NotificationStatus.NotSubmitted);

            Assert.Equal(newFirstDate, shipmentInfo.ShipmentPeriod.FirstDate);
            Assert.Equal(newLastDate, shipmentInfo.ShipmentPeriod.LastDate);
        }
        public void CanUpdateShipmentQuantity()
        {
            var firstDate = new DateTime(2015, 01, 01);
            var lastDate = new DateTime(2015, 12, 01);
            var shipmentPeriod = new ShipmentPeriod(firstDate, lastDate, true);

            var shipmentInfo = new ShipmentInfo(AnyGuid, shipmentPeriod, 10,
                new ShipmentQuantity(0.0001M, ShipmentQuantityUnits.Tonnes));

            shipmentInfo.UpdateQuantity(new ShipmentQuantity(2.0M, ShipmentQuantityUnits.Kilograms));

            Assert.Equal(2.0M, shipmentInfo.Quantity);
            Assert.Equal(ShipmentQuantityUnits.Kilograms, shipmentInfo.Units);
        }