Ejemplo n.º 1
0
        public async Task returns_empty_installation_object_when_api_response_is_null()
        {
            // Arrange
            const string response      = null;
            var          webClientMock = new Mock <IWebClientAdapter>();

            webClientMock.Setup(_ => _.DownloadStringTaskAsync(It.IsAny <string>()))
            .ReturnsAsync(response);

            webClientMock.SetupProperty(_ => _.Headers, new WebHeaderCollection());

            var airlyInstallationDownloader
                = new AirlyInstallationDownloader(_config, webClientMock.Object);

            // Act
            var installation = await airlyInstallationDownloader
                               .DownloadAirQualityData(_installationId);

            // Assert
            Assert.NotNull(installation);
        }
Ejemplo n.º 2
0
        public async Task calls_download_string_method_once()
        {
            // Arrange
            const string response      = "{}";
            var          webClientMock = new Mock <IWebClientAdapter>();

            webClientMock.Setup(_ => _.DownloadStringTaskAsync(It.IsAny <string>()))
            .ReturnsAsync(response);

            webClientMock.SetupProperty(_ => _.Headers, new WebHeaderCollection());

            var airlyInstallationDownloader
                = new AirlyInstallationDownloader(_config, webClientMock.Object);

            // Act
            var installation = await airlyInstallationDownloader
                               .DownloadAirQualityData(_installationId);

            // Assert
            webClientMock.Verify(
                _ => _.DownloadStringTaskAsync(It.IsAny <string>()), Times.Once());
        }
Ejemplo n.º 3
0
        public async Task returns_not_null_installation_object_when_api_response_is_correct_json_object()
        {
            // Arrange
            string response      = AirlyApiUtilities.GetTestAirlyInstallationJson();
            var    webClientMock = new Mock <IWebClientAdapter>();

            webClientMock.Setup(_ => _.DownloadStringTaskAsync(It.IsAny <string>()))
            .ReturnsAsync(response);

            webClientMock.SetupProperty(_ => _.Headers, new WebHeaderCollection());

            var airlyInstallationDownloader
                = new AirlyInstallationDownloader(_config, webClientMock.Object);

            // Act
            var installation = await airlyInstallationDownloader
                               .DownloadAirQualityData(_installationId);

            // Assert
            Assert.NotNull(installation);
            Assert.NotNull(installation.Address);
            Assert.NotNull(installation.Location);
            Assert.NotNull(installation.Sponsor);
        }