Esempio n. 1
0
        public async void ShouldGetStarshipsFromSwApi()
        {
            var mockedData = _fixture.MockedData();

            var mockedResponse1 = new Mock <IRestResponse <PagedList <Starship> > >();

            mockedResponse1.SetupGet(x => x.StatusCode).Returns(HttpStatusCode.OK);
            mockedResponse1.SetupGet(x => x.Data).Returns(new PagedList <Starship>()
            {
                Next    = "page2",
                Count   = 20,
                Results = mockedData.Take(1)
            });

            var mockedResponse2 = new Mock <IRestResponse <PagedList <Starship> > >();

            mockedResponse2.SetupGet(x => x.StatusCode).Returns(HttpStatusCode.OK);
            mockedResponse2.SetupGet(x => x.Data).Returns(new PagedList <Starship>()
            {
                Next    = null,
                Count   = 20,
                Results = mockedData.Skip(1)
            });

            _restClientMock.SetupSequence(x => x.ExecuteGetAsync <PagedList <Starship> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockedResponse1.Object)
            .ReturnsAsync(mockedResponse2.Object);

            SwApiClient swApiClient = new SwApiClient(_configurationMock.Object, _restClientMock.Object);

            var data = await swApiClient.GetStarshipsAsync();

            data.Should().NotBeEmpty().And.HaveCount(mockedData.Count());
        }
Esempio n. 2
0
        public static async Task Main(string[] args)
        {
            if (!args.Any())
            {
                throw new ApplicationException("Missing distance argument! Please provide a distance for the starthips to travel.");
            }

            if (!int.TryParse(args.First(), out var distance))
            {
                throw new ApplicationException("Cannot parse distance argument. Distance needs to be an integer.");
            }

            var client        = new SwApiClient();
            var calculator    = new Calculator();
            var shipsAndStops = calculator.CalculateStops(client.GetStarships(), distance);

            await foreach (var(Ship, Stops) in shipsAndStops)
            {
                Console.WriteLine($"{Ship.Name}: {GetStopsString(Stops)}");
            }
        }