// ReSharper disable once AsyncConverter.AsyncMethodNamingHighlighting private static async Task Main() { var starshipService = new StarshipService(AutoMapperConfig.Config()); System.Console.Write("Please type the distance in MGLU: [Default: 1000000] "); var input = System.Console.ReadLine(); System.Console.WriteLine(); if (!long.TryParse(input, out var distanceInMglu)) { distanceInMglu = 1_000_000L; } System.Console.WriteLine("Calculating for the distance {0}.", distanceInMglu); var starships = await starshipService.ListStarshipsAndStopsAsync(distanceInMglu); foreach (var starship in starships) { System.Console.WriteLine("{0, -30}{1, 10}", starship.Name, starship.Stops); } System.Console.ReadLine(); }
public async void ShouldRetrieveStarships() { var mockedData = _fixture.MockedData(); _swApiClient.Setup(x => x.GetStarshipsAsync()).ReturnsAsync(mockedData); var _starshipService = new StarshipService(_swApiClient.Object, _calculator.Object); IEnumerable <Starship> starships = await _starshipService.GetAsync(); starships.Should().NotBeEmpty().And.HaveCount(mockedData.Count()); _swApiClient.Verify(x => x.GetStarshipsAsync(), Times.Once); }
public async Task Test_get_api() { var starShipsTest = new StarshipService(mapperService, redisService); var starshipsReturned = starShipsTest.GetAllFromApi(); //logger.Received().Info("Total of " + starshipsReturned.Count + " Starships returned from API."); result = starshipsReturned.Count > 0 ? true : false; Assert.IsTrue(result); }
public async void ExpectRetrieveAllStarshipsAndItsNumberOfStops() { int distance = 100000; var mockedData = _fixture.MockedData(); _swApiClient.Setup(x => x.GetStarshipsAsync()).ReturnsAsync(mockedData); var _starshipService = new StarshipService(_swApiClient.Object, _calculator.Object); IEnumerable <StarshipResupplyStopsResponse> response = await _starshipService.ProcessAllStarshipsTotalResupplyStopsAsync(distance); response.Should().NotBeEmpty().And.HaveCount(mockedData.Count()); response.All(x => x.Starship != null).Should().BeTrue(); response.All(x => !x.NumberOfStops.HasValue || x.NumberOfStops >= 0).Should().BeTrue(); response.All(x => x.Distance == distance).Should().BeTrue(); _swApiClient.Verify(x => x.GetStarshipsAsync(), Times.Once); }
public List <ResultDTO> CalculateStops(long distance) { StarshipService starshipService = new StarshipService(); var result = new List <ResultDTO>(); var starships = starshipService.GetAllStarships(); foreach (var starship in starships) { var resultToAdd = new ResultDTO(); int MGLT = 0; long stops = 0; if (starship.MGLT == "unknown") { resultToAdd.Unknown = true; } else { MGLT = Convert.ToInt32(starship.MGLT); } string[] consumablesParsing = starship.Consumables.Split(' '); if (consumablesParsing.Length == 2 && MGLT != 0) { int consumableNumber = Convert.ToInt32(consumablesParsing[0]); // get the consumables lemits for the the star ship string strTime = consumablesParsing[1]; // Get the Start time form consumable int consumablesDays = getDays(consumableNumber, strTime); int movimentInOneDay = MGLT * 24; int distanceUntilNextStop = movimentInOneDay * consumablesDays; stops = distance / distanceUntilNextStop; } resultToAdd.StarshipName = starship.Name; resultToAdd.NumberOfStops = stops; result.Add(resultToAdd); } return(result); }
static void Main(string[] args) { bool repeat = true; while (repeat) { Console.Clear(); Console.WriteLine("Author: Igor Abílio Santana Santos"); Console.WriteLine("Created: 21/03/2018"); Console.WriteLine(); Console.WriteLine(); int distance = 0; bool success = false; Console.Write("Could you inform a distance between 2 planets in MGLT: "); while (!success) { try { distance = Convert.ToInt32(Console.ReadLine()); success = true; } catch (Exception ex) { Console.WriteLine("The distance needs to be a integer."); Console.WriteLine(); Console.Write("Please inform a distance between 2 planets in MGLT: "); } } Console.WriteLine(); Console.WriteLine("Result:"); Conversion conversion = new Conversion(); StarshipService starshipService = new StarshipService(); try { var starships = starshipService.GetAllStarships(); foreach (var starship in starships) { var hours = conversion.CalculateHours(starship.consumables); var result = distance / (hours * Convert.ToInt32(starship.MGLT)); Console.WriteLine($"-> { starship.name }: { result } stop(s)"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); Console.WriteLine(); Console.Write("Would you like to make another simulation? If YES press Y or press ENTER to exit... "); ConsoleKeyInfo answer = Console.ReadKey(); if (!answer.KeyChar.ToString().ToUpper().Equals("Y")) { repeat = false; } } }
public StarshipServiceTests() { fixture = new Fixture(); starshipGateway = Substitute.For <IStarshipGateway>(); starshipService = new StarshipService(starshipGateway); }
public Worker(ILogger <Worker> logger, IConfiguration configuration, StarshipService starshipService) { _logger = logger; _configuration = configuration; _starshipService = starshipService; }
public Tests() { APIURL = GetApiUrl(Path.GetFullPath(@"..\..\..\..\App")); // gets api url from APP console application _starshipService = new StarshipService(APIURL); }
public async Task WhenIPressEnterAsync() { var service = new StarshipService(AutoMapperConfig.Config()); _actualStarshipStops = await service.ListStarshipsAndStopsAsync(_distanceInMglu); }
public StarshipsViewController(IntPtr handle) : base(handle) { _starshipService = new StarshipService(); }