/// <summary> /// Gets list of all Starships with Resupply count for given distance. /// </summary> /// <param name="distance">The distance to destination planet in megalights.</param> public async Task <List <StarshipDto> > GetAllWithResupplyCountAsync(ulong distance) { if (distance <= 0) { throw new ArgumentException("Distance cannot be less than zero", nameof(distance)); } // get all starships var starships = await this.GetAllAsync(); // calculate the resupply count for each starship in the list var starshipListDto = from starship in starships select new StarshipDto { // TODO: Auto Mapper could be used for object to object mapping. Name = starship.Name, Model = starship.Model, StarshipClass = starship.StarshipClass, Manufacturer = starship.Manufacturer, CostInCredits = starship.CostInCredits, Length = starship.Length, Crew = starship.Crew, Passengers = starship.Passengers, MaxAtmospheringSpeed = starship.MaxAtmospheringSpeed, HyperdriveRating = starship.HyperdriveRating, MGLT = starship.MGLT, CargoCapacity = starship.CargoCapacity, Consumables = starship.Consumables, ResupplyCount = StarshipManager.CalculateResupplyCount(distance, starship.MGLT, starship.Consumables) }; return(starshipListDto.ToList()); }
public void CalculateResupplyCount_InvalidInputs_ThrowsExceptions() { // Assert Assert.Throws <ArgumentException>(() => StarshipManager.CalculateResupplyCount(0, null, null)); Assert.Throws <ArgumentNullException>(() => StarshipManager.CalculateResupplyCount(1, null, null)); Assert.Throws <ArgumentNullException>(() => StarshipManager.CalculateResupplyCount(1, string.Empty, null)); Assert.Throws <ArgumentNullException>(() => StarshipManager.CalculateResupplyCount(1, null, string.Empty)); Assert.Throws <ArgumentNullException>(() => StarshipManager.CalculateResupplyCount(1, string.Empty, string.Empty)); Assert.Throws <FormatException>(() => StarshipManager.CalculateResupplyCount(1, "123456a", "12 seconds")); Assert.Throws <ArgumentException>(() => StarshipManager.CalculateResupplyCount(1, "123456", "12 seconds")); }
public void CalculateResupplyCount_ValidInputs_ReturnsResupplyCount() { // Arrange ulong expectedResult = 74; ulong distance = 1000000; string megalight = "80"; string consumables = "1 week"; // Act ulong actualResult = StarshipManager.CalculateResupplyCount(distance, megalight, consumables); // Assert Assert.Equal(expectedResult, actualResult); }