public void Test_GetMarsRovers(int expectedRoverCount, int expectedCuriosityCameras)
        {
            var logger = new NullLogger <NasaApiClient>();

            INasaApiSettings settings = new NasaApiSettings()
            {
                NasaApiUrl   = "https://api.nasa.gov",
                MarsRoverApi = "mars-photos/api/v1/rovers",
                NasaApiKey   = "b4rSDXQkrk4eKsUcU8zBfXykwe9cktbqg78Nmg3x"
            };

            using (HttpClient _httpClient = new HttpClient())
            {
                INasaApiClient client = new NasaApiClient(_httpClient, logger, settings);

                NasaMarsRovers nasaMarsRovers = client.GetRoversAsync().Result;

                Assert.NotNull(nasaMarsRovers);
                Assert.NotNull(nasaMarsRovers.Rovers);
                Assert.Equal(expectedRoverCount, nasaMarsRovers.Rovers.Count);
                if (nasaMarsRovers.Rovers.Count > 0)
                {
                    Assert.Equal("Curiosity", nasaMarsRovers.Rovers[0].Name);
                    Assert.Equal(expectedCuriosityCameras, nasaMarsRovers.Rovers[0].Cameras.Count);
                }
            }
        }
        public void Test_GetPhotos02(string roverName, string date, int page, int expectedCount)
        {
            var logger = new NullLogger <NasaApiClient>();

            INasaApiSettings settings = new NasaApiSettings()
            {
                NasaApiUrl   = "https://api.nasa.gov",
                MarsRoverApi = "mars-photos/api/v1/rovers",
                NasaApiKey   = "b4rSDXQkrk4eKsUcU8zBfXykwe9cktbqg78Nmg3x"
            };

            using (HttpClient _httpClient = new HttpClient())
            {
                INasaApiClient client = new NasaApiClient(_httpClient, logger, settings);

                IList <NasaMarsPhoto> nasaMarsPhotos = client.GetRoverPhotosAsync(roverName, date, page).Result;

                Assert.NotNull(nasaMarsPhotos);
                Assert.True(nasaMarsPhotos.Count < expectedCount);
                if (nasaMarsPhotos.Count > 0)
                {
                    Assert.Equal(date, nasaMarsPhotos[0].EarthDate);
                }
            }
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <MarsRoverDbContext>(options =>
            {
                options.UseSqlite(Configuration.GetConnectionString("SqlLiteConnection"));
            });

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "MarsRoverApi", Version = "v1"
                });
            });


            INasaApiSettings nasaApiSettings = new NasaApiSettings();

            Configuration.GetSection("NasaApi").Bind(nasaApiSettings);
            services.AddSingleton(nasaApiSettings);

            IImagePaths imagePaths = new ImagePaths();

            Configuration.GetSection("ImagePaths").Bind(imagePaths);
            services.AddSingleton(imagePaths);

            services.AddHttpClient <INasaApiClient, NasaApiClient>(httpClient =>
            {
                httpClient.BaseAddress = new Uri(nasaApiSettings.NasaApiUrl);
                httpClient.Timeout     = TimeSpan.FromSeconds(45);
            });

            // Initializing service
            services.AddTransient <InitializationService>();

            services.AddSingleton <IImageProviderSettings, ImageProviderSettings>(serviceProvider =>
            {
                var webHostEnvironment = serviceProvider.GetRequiredService <IWebHostEnvironment>();
                ImageProviderSettings imageProvider = new ImageProviderSettings()
                {
                    FileProvider = webHostEnvironment.ContentRootFileProvider
                };

                return(imageProvider);
            });

            // Services
            services.AddScoped <IImageService, ImageService>();
            services.AddScoped <IMarsPhotoRetrievalService, MarsPhotoRetrievalService>();
            services.AddScoped <IDateService, DateService>();
            services.AddScoped <IMarsRoverDbRepository, MarsRoverDbRepository>();

            // Automapper
            services.AddAutoMapper(
                options => options.AddProfile <MappingProfile>());
        }
Example #4
0
 public NasaApiProxy(IHttpClientFactory httpClientFactory, IOptions <NasaApiSettings> options)
 {
     _settings = options.Value;
     _client   = new FlurlClient
     {
         Settings =
         {
             HttpClientFactory = httpClientFactory
         }
     }
     .WithTimeout(TimeSpan.FromSeconds(30));
 }
        public void Test_GetImage01(string imgSrc)
        {
            var logger = new NullLogger <NasaApiClient>();

            INasaApiSettings settings = new NasaApiSettings()
            {
                NasaApiUrl   = "https://api.nasa.gov",
                MarsRoverApi = "mars-photos/api/v1/rovers",
                NasaApiKey   = "b4rSDXQkrk4eKsUcU8zBfXykwe9cktbqg78Nmg3x"
            };

            using (HttpClient _httpClient = new HttpClient())
            {
                INasaApiClient client = new NasaApiClient(_httpClient, logger, settings);

                byte[] images = client.GetRoverPhotoAsync(imgSrc).Result;

                Assert.NotNull(imgSrc);
            }
        }