/// <summary> /// retrieves ship collection /// </summary> /// <param name="searchParameters">The search parameters.</param> /// <returns> /// returns List Result of Ship /// </returns> public async Task<ListResult<Ship>> ListAsync(ShipSearchParameter searchParameters) { var distinctShipIds = new List<string>(); var voyageList = await DIContainer.Instance.Resolve<VoyageClientRepository>().RetrieveVoyageListAsync(searchParameters.ShipIds); if (!string.IsNullOrWhiteSpace(searchParameters.PortId)) { if (voyageList.Items.Count > 0) { var voyageFilteredByPortId = voyageList.Items.Where(a => a.Itineraries.Any(b => b.PortId.Equals(searchParameters.PortId, StringComparison.OrdinalIgnoreCase))).Select(c => c).ToListResult(); distinctShipIds = voyageFilteredByPortId.Items.Select(a => a.ShipId).Distinct().ToList(); } } else { distinctShipIds = voyageList.Items.Select(a => a.ShipId).Distinct().ToList(); } if (distinctShipIds.Count > 0) { var ships = string.Empty; distinctShipIds.ForEach(id => { ships += CommaSeparator + id; }); searchParameters.ShipIds = ships.Trim(CommaSeparatorCharacter); var shipCollection = await this.shipRepository.ListAsync(searchParameters); shipCollection.TotalResults = shipCollection.Items.Count(); return shipCollection; } return new ListResult<Ship>(); }
/// <summary> /// Lists the asynchronous. /// </summary> /// <param name="searchParameters">The search parameters.</param> /// <returns> /// Return List Result of Ship /// </returns> public async Task<ListResult<Ship>> ListAsync(ShipSearchParameter searchParameters) { var shipResponse = await this.shipClientRepository.RetrieveShipListAsync(null, shipIds: searchParameters.ShipIds, pageNumber: searchParameters.PageNumber.RetrievePageNumber()); var shipList = ShipMapper.MapListAsync(shipResponse); if (shipList.Items != null && shipList.Items.Count > 0) { if (!string.IsNullOrWhiteSpace(searchParameters.BrandId)) { return shipList.Items.Where(a => a.BrandId.Equals(searchParameters.BrandId, System.StringComparison.OrdinalIgnoreCase)).Select(a => a).ToListResult(); } } return shipList; }
public async Task RetrieveShipListAsync() { var searchFilter = new ShipSearchParameter { BrandId = string.Empty, PortId = string.Empty, ShipIds = string.Empty }; this.SetupData(); Common.Dependencies.Register(); DIContainer.Instance.RegisterType<IVoyageClient, VoyageClient>(); DIContainer.Instance.Resolve<IApplicationSetting>().VoyageServiceBaseAddress = "http://Localhost/"; var result = await this.manager.ListAsync(searchFilter); Assert.IsNotNull(result); Assert.AreEqual("4562", result.Items.FirstOrDefault().BrandId); Assert.IsTrue(result.Items.Count == 2); }
public async Task RetrieveShipListAsyncTest() { try { var searchFilter = new ShipSearchParameter { BrandId = string.Empty, ShipIds = string.Empty, PortId = string.Empty, PageNumber = 1, MaxResults = 10 }; this.SetUpData(); var response = await this.controller.Get(searchFilter); var result = await response.ExecuteAsync(new CancellationToken(false)); Assert.IsTrue(result.IsSuccessStatusCode == true); Assert.IsTrue(result.StatusCode == HttpStatusCode.OK); } finally { this.Dispose(); } }
public async Task RetrieveShipListWithMismatchPortIdAsync() { var searchFilter = new ShipSearchParameter { BrandId = string.Empty, PortId = "50", ShipIds = "31" }; this.SetupData(); Common.Dependencies.Register(); DIContainer.Instance.RegisterType<IVoyageClient, VoyageClient>(); DIContainer.Instance.Resolve<IApplicationSetting>().VoyageServiceBaseAddress = "http://Localhost/"; var result = await this.manager.ListAsync(searchFilter); Assert.IsNotNull(result); }