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)); }
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 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); }
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 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); }
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; }
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); }
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); }
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); }
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); }
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 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); }
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 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); }