/// <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 ConsumablesToHours_ValidInput_ConvertsToHours() { // Assert Assert.Equal((ulong)52560, StarshipManager.ConsumablesToHours("6 years")); Assert.Equal((ulong)8760, StarshipManager.ConsumablesToHours("1 year")); Assert.Equal((ulong)4320, StarshipManager.ConsumablesToHours("6 months")); Assert.Equal((ulong)720, StarshipManager.ConsumablesToHours("1 month")); Assert.Equal((ulong)144, StarshipManager.ConsumablesToHours("6 days")); Assert.Equal((ulong)24, StarshipManager.ConsumablesToHours("1 day")); Assert.Equal((ulong)6, StarshipManager.ConsumablesToHours("6 hours")); Assert.Equal((ulong)1, StarshipManager.ConsumablesToHours("1 hour")); }
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); }
public void CalculateResupplyFrequency() { StarshipManager.Distance = "1000000"; string resupply = (Convert.ToInt32(StarshipManager.Distance) / (105 * 120)).ToString(); Starship milleniumFalcon = new Starship() { Consumables = "5 days", MGLT = "105", Name = "TIE Advanced x1", }; Assert.AreEqual(resupply, StarshipManager.CalculateNumberofResupply(milleniumFalcon)); }
public void ConsumablesToHours_InputContainsUnknownMetric_ThrowsArgumentException() { // Assert Assert.Throws <ArgumentException>(() => StarshipManager.ConsumablesToHours("1 second")); }
public void ConsumablesToHours_InvalidInput_ThrowsFormatException() { // Assert Assert.Throws <FormatException>(() => StarshipManager.ConsumablesToHours("fadfasf")); }
public void ConsumablesToHours_InputIsEmptyString_ThrowsArgumentNullException() { // Assert Assert.Throws <ArgumentNullException>(() => StarshipManager.ConsumablesToHours(string.Empty)); }
public void ConsumablesToHours_InputIsNull_ThrowsArgumentNullException() { // Assert Assert.Throws <ArgumentNullException>(() => StarshipManager.ConsumablesToHours(null)); }