Example #1
0
        public void Constructor_NoArguments_NotNull()
        {
            // Pretty unecessary test, but there's not really
            // a way for me to validate that the empty ctor "works"
            var result = new ApodClient();

            Assert.NotNull(result);
        }
Example #2
0
        public ApodClientTests()
        {
            // Initialize mocks
            _httpRequester      = new Mock <IHttpRequester>();
            _httpResponseParser = new Mock <IHttpResponseParser>();
            _errorHandler       = new Mock <IErrorHandler>();

            // Initialize client
            _client = new ApodClient(_apiKey, _httpRequester.Object, _httpResponseParser.Object, _errorHandler.Object);
        }
Example #3
0
        static async Task <bool> StartApodAsync(string apiKey, int resultCount)
        {
            var apodClient   = new ApodClient(apiKey);
            var mediaOfToday = await apodClient.GetAsync(resultCount);

            if (mediaOfToday != null)
            {
                DisplayMedia(mediaOfToday);
                return(false);
            }
            return(true);
        }
        public async Task <IEnumerable <Apod> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default)
        {
            if (!IsGridLoaded)
            {
                ApodList   = new List <Apod>();
                LastUpdate = DateTimeOffset.UtcNow;
                client     = new ApodClient();
                ApodList   = await client.FetchApodListAsync(DateTimeOffset.Now.AddDays(-20), DateTimeOffset.UtcNow.AddDays(-1)).ConfigureAwait(false);

                LastUpdate   = DateTimeOffset.Now.AddDays(-20);
                IsGridLoaded = true;
            }
            else
            {
                ApodList.Clear();
                ApodList = await client.FetchApodListAsync(LastUpdate.AddDays(-20), LastUpdate.AddDays(-1)).ConfigureAwait(false);

                var updatedDate = LastUpdate;
                LastUpdate = updatedDate.AddDays(-20);
            }
            return(ApodList.OrderByDescending(o => o.Date));
        }
        public static async Task Main(string[] args)
        {
            CultureInfo.CurrentCulture = new CultureInfo("en-GB", false);

            try
            {
                if (args.Length < 1 || (args[0] != "apod" && args[0] != "neows"))
                {
                    ThrowOnInvalidInput();
                }

                _config = new ConfigurationBuilder()
                          .AddJsonFile(ConfigFile)
                          .Build();
                string apiKey = _config["ApiKey"];

                if (args[0] == "apod")
                {
                    if (args.Length < 2)
                    {
                        ThrowOnInvalidInput();
                    }
                    if (!int.TryParse(args[1], out int count))
                    {
                        ThrowOnInvalidInput();
                    }
                    var            nasaClient = new ApodClient(apiKey);
                    MediaOfToday[] res        = await nasaClient.GetAsync(count);

                    foreach (MediaOfToday media in res)
                    {
                        Console.WriteLine($"{media}{Environment.NewLine}");
                    }
                }
                else
                {
                    string startDate = _config["NeoWs:StartDate"];
                    string endDate   = _config["NeoWs:EndDate"];

                    AsteroidRequest request;
                    if (args.Length < 2 || !int.TryParse(args[1], out int count))
                    {
                        request = new AsteroidRequest(startDate, endDate);
                    }
                    else
                    {
                        request = new AsteroidRequest(startDate, endDate, count);
                    }

                    var nasaClient       = new NeoWsClient(apiKey);
                    AsteroidLookup[] res = await nasaClient.GetAsync(request);

                    foreach (AsteroidLookup asteroid in res)
                    {
                        Console.WriteLine($"- {asteroid}{Environment.NewLine}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #6
0
        public NasaServiceProvider()
        {
            var jsonConfig = JsonConfigurationReader.GetJsonConfigurationWithMyTokens();

            _apodClient = new ApodClient(jsonConfig.NasaToken);
        }