/// <summary> /// convert shipment to view model /// </summary> /// <param name="shipment"></param> /// <returns></returns> public ShipmentViewModel ConvertToView(Shipment shipment) { ShipmentViewModel model = new ShipmentViewModel(); var _vesselRepository = new VesselRepository(); var _portRepository = new PortRepository(); var _bolRepository = new BillOfLadingRepository(); var vessel = _vesselRepository.GetVessel(shipment.VesselId); var port = _portRepository.GetPort(shipment.PortId); var bols = _bolRepository.GetBillOfLadings().Where(x => x.ShipmentId == shipment.ShipmentId).ToList(); model.ShipmentId = shipment.ShipmentId; model.CarrierId = shipment.CarrierId; model.VesselId = shipment.VesselId; model.PortId = shipment.PortId; model.DepartureDate = shipment.DepartureDate; model.EstArrivalDate = (shipment.EstArrivalDate != null) ? shipment.EstArrivalDate : DateTime.MinValue; model.ShipmentNotes = (!string.IsNullOrEmpty(shipment.Notes)) ? shipment.Notes : "N/A"; model.VesselName = (vessel != null && !string.IsNullOrEmpty(vessel.Name)) ? vessel.Name : "N/A"; model.PortName = (port != null && !string.IsNullOrEmpty(port.Name)) ? port.Name : "N/A"; model.DepartureDateStr = shipment.DepartureDate.ToShortDateString(); model.EstArrivalDateStr = (shipment.EstArrivalDate != null) ? shipment.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.IsComplete = shipment.IsComplete; model.CompletedDate = (shipment.CompletedDate != null) ? shipment.CompletedDate : DateTime.MinValue; model.CompletedDateStr = (shipment.CompletedDate != null) ? shipment.CompletedDate.Value.ToShortDateString() : "N/A"; model.CreatedDate = (shipment.CreatedDate != null) ? shipment.CreatedDate : DateTime.MinValue; if (bols != null && bols.Count > 0) { model.BillsOfLading = new List <BillOfLadingViewModel>(); foreach (var bol in bols) { BillOfLadingViewModel convertedModel = new BillOfLadingConverter().ConvertToView(bol); model.BillsOfLading.Add(convertedModel); } } if (_vesselRepository != null) { _vesselRepository.Dispose(); _vesselRepository = null; } if (_portRepository != null) { _portRepository.Dispose(); _portRepository = null; } if (_bolRepository != null) { _bolRepository.Dispose(); _bolRepository = null; } return(model); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldSkipReservedPorts() internal virtual void ShouldSkipReservedPorts() { PortRepository portRepository = mock(typeof(PortRepository)); PortProvider portProvider = new CoordinatingPortProvider(portRepository, port => false); when(portRepository.ReserveNextPort("foo")).thenReturn(40, 41, 43); assertThat(portProvider.GetNextFreePort("foo"), @is(40)); assertThat(portProvider.GetNextFreePort("foo"), @is(41)); assertThat(portProvider.GetNextFreePort("foo"), @is(43)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldReservePorts() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldReservePorts() { PortRepository portRepository1 = new PortRepository(TemporaryDirectory(), EphemeralPortMinimum); int port1 = portRepository1.ReserveNextPort("foo"); int port2 = portRepository1.ReserveNextPort("foo"); int port3 = portRepository1.ReserveNextPort("foo"); assertThat((new HashSet <>(asList(port1, port2, port3))).Count, @is(3)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldProvideUniquePorts() internal virtual void ShouldProvideUniquePorts() { PortRepository portRepository = mock(typeof(PortRepository)); PortProvider portProvider = new CoordinatingPortProvider(portRepository, port => false); when(portRepository.ReserveNextPort("foo")).thenReturn(40, 41); int port1 = portProvider.GetNextFreePort("foo"); int port2 = portProvider.GetNextFreePort("foo"); assertThat(port1, @is(not(equalTo(port2)))); }
public MockService(bool ignoreUnusedHandlers = false) { _portNumber = PortRepository.GetFreePortNumber(); _handlers = new List <Tuple <Expression <Func <IOwinContext, bool> >, Func <IOwinContext, Task> > >(); _unusedHandlers = new List <Expression <Func <IOwinContext, bool> > >(); _ignoreUnusedHandlers = ignoreUnusedHandlers; MockServiceRepository.Register(_portNumber, this); _host = WebApp.Start <MockStartup>(GetBaseAddress()); }
/// <summary> /// convert bol to list model /// </summary> /// <param name="bol"></param> /// <returns></returns> public BillOfLadingViewModel ConvertToListView(BillOfLading bol) { BillOfLadingViewModel model = new BillOfLadingViewModel(); var _shipmentRepository = new ShipmentRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _vesselRepository = new VesselRepository(); var _portRepository = new PortRepository(); var shipment = _shipmentRepository.GetShipment(bol.ShipmentId); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(bol.FoundryId); var vessel = _vesselRepository.GetVessel((shipment != null) ? shipment.VesselId : Guid.Empty); var port = _portRepository.GetPort((shipment != null) ? shipment.PortId : Guid.Empty); model.BillOfLadingId = bol.BillOfLadingId; model.ShipmentId = bol.ShipmentId; model.BolNumber = (!string.IsNullOrEmpty(bol.Number)) ? bol.Number : "N/A"; model.FoundryName = (dynamicsFoundry != null) ? dynamicsFoundry.VENDSHNM : "N/A"; model.Description = (!string.IsNullOrEmpty(bol.Description)) ? bol.Description : "N/A"; model.VesselName = (vessel != null && !string.IsNullOrEmpty(vessel.Name)) ? vessel.Name : "N/A"; model.PortName = (port != null && !string.IsNullOrEmpty(port.Name)) ? port.Name : "N/A"; model.DepartureDate = (shipment != null && shipment.DepartureDate != null) ? shipment.DepartureDate : DateTime.MinValue; model.DepartureDateStr = (shipment != null) ? shipment.DepartureDate.ToShortDateString() : "N/A"; model.EstArrivalDate = (shipment != null && shipment.EstArrivalDate != null) ? shipment.EstArrivalDate : DateTime.MinValue; model.EstArrivalDateStr = (shipment != null) ? shipment.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.HasBeenAnalyzed = bol.HasBeenAnalyzed; model.CreatedDate = bol.CreatedDate; if (_shipmentRepository != null) { _shipmentRepository.Dispose(); _shipmentRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_vesselRepository != null) { _vesselRepository.Dispose(); _vesselRepository = null; } if (_portRepository != null) { _portRepository.Dispose(); _portRepository = null; } return(model); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCoordinateUsingFileSystem() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldCoordinateUsingFileSystem() { Path temporaryDirectory = temporaryDirectory(); PortRepository portRepository1 = new PortRepository(temporaryDirectory, EphemeralPortMinimum); PortRepository portRepository2 = new PortRepository(temporaryDirectory, EphemeralPortMinimum); int port1 = portRepository1.ReserveNextPort("foo"); int port2 = portRepository1.ReserveNextPort("foo"); int port3 = portRepository1.ReserveNextPort("foo"); int port4 = portRepository2.ReserveNextPort("foo"); int port5 = portRepository2.ReserveNextPort("foo"); int port6 = portRepository1.ReserveNextPort("foo"); assertThat((new HashSet <>(asList(port1, port2, port3, port4, port5, port6))).Count, @is(6)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotOverrun() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotOverrun() { PortRepository portRepository1 = new PortRepository(TemporaryDirectory(), 65534); portRepository1.ReserveNextPort("foo"); portRepository1.ReserveNextPort("foo"); try { portRepository1.ReserveNextPort("foo"); fail("Failure was expected"); } catch (System.InvalidOperationException e) { assertThat(e.Message, @is("There are no more ports available")); } }
static PortAuthority() { string portAuthorityDirectory = System.getProperty("port.authority.directory"); if (string.ReferenceEquals(portAuthorityDirectory, null)) { _portProvider = new SimplePortProvider(new DefaultPortProbe(), PORT_RANGE_MINIMUM); } else { try { Path directory = Paths.get(portAuthorityDirectory); Files.createDirectories(directory); PortRepository portRepository = new PortRepository(directory, PORT_RANGE_MINIMUM); PortProbe portProbe = new DefaultPortProbe(); _portProvider = new CoordinatingPortProvider(portRepository, portProbe); } catch (IOException e) { throw new ExceptionInInitializerError(e); } } }
internal CoordinatingPortProvider(PortRepository portRepository, PortProbe portProbe) { this._portRepository = portRepository; this._portProbe = portProbe; }