public async Task GetTest_NoRecord() { var WeatherInfoController = new WeatherInfoController(); var info = await WeatherInfoController.Get("12343"); Assert.IsNotNull(info); Assert.AreEqual("No record found for given City Id", info.Name); }
public async Task GetTest() { var WeatherInfoController = new WeatherInfoController(); var info = await WeatherInfoController.Get("4229546"); Assert.IsNotNull(info); Assert.AreEqual("Washington", info.Name); }
public async Task GetAllTest() { var WeatherInfoController = new WeatherInfoController(); var resp = await WeatherInfoController.GetAll(); var expectedResponse = new HttpResponseMessage(); Assert.AreEqual(expectedResponse.IsSuccessStatusCode, resp.IsSuccessStatusCode); }
public void Test_GetCountries_It_Should_Return_List_Of_all_countries() { //Arrange Mock <IGlobalWeatherProvider> mockedGlobalWeatherProvider = new Mock <IGlobalWeatherProvider>(); List <Country> _mockedCountryList = new List <Country>(); _mockedCountryList.Add(new Country { ID = "Australia", Name = "Australia" }); mockedGlobalWeatherProvider.Setup(x => x.GetCountries()).Returns(_mockedCountryList); WeatherInfoController objWeatherInfoController = new WeatherInfoController(mockedGlobalWeatherProvider.Object); //Act IHttpActionResult actionResult = objWeatherInfoController.GetCountries().Result; ///Assert Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <List <Country> >)); Assert.IsNotNull(actionResult as OkNegotiatedContentResult <List <Country> >); OkNegotiatedContentResult <List <Country> > r = actionResult as OkNegotiatedContentResult <List <Country> >; Assert.AreNotEqual(0, r.Content.Count); }
public void Setup() { _moockLogger = new Mock <ILogger <WeatherInfoController> >(); _mockinsurwaveWeatherInfoService = new Mock <IInsurwaveWeatherInfoService>(); _mockmapper = new Mock <IMapper>(); _current = new Current { TempC = "11.0", TempF = "54.3" }; _location = new Location { Name = "London", Country = "United Kingdom", Localtime = "2020-11-16 13:02", Region = "City of London, Greater London" }; _currentDetail = new CurrentDetail { Current = _current, Location = _location }; _astronomyDetail = new AstronomyDetail { Astronomy = new Astronomy { Astro = new Astro { Sunrise = "07:21 AM", Sunset = "04:09 PM" } }, Location = _location }; _city = "London"; _date = DateTime.UtcNow; _cityWeatherInfo = new CityWeatherInfo { City = _currentDetail.Location.Name, Country = _currentDetail.Location.Country, LocalTime = _currentDetail.Location.Localtime, Region = _currentDetail.Location.Region, Temperature = _currentDetail.Current.TempC }; _cityDetailWithTempUnit = new CityDetailWithTempUnit { City = _currentDetail.Location.Name, Country = _currentDetail.Location.Country, LocalTime = _currentDetail.Location.Localtime, Region = _currentDetail.Location.Region }; WeatherApiHttpClientResponse = new WeatherApiHttpClientResponse { Data = JsonConvert.SerializeObject(_currentDetail), IsSuccessFull = true, StatusCode = HttpStatusCode.OK }; AstronomyWeatherApiHttpClientResponse = new WeatherApiHttpClientResponse { Data = JsonConvert.SerializeObject(_astronomyDetail), IsSuccessFull = true, StatusCode = System.Net.HttpStatusCode.OK }; _mockinsurwaveWeatherInfoService.Setup(x => x.GetLocalWeatherInfo(_city)).Returns(Task.FromResult(WeatherApiHttpClientResponse)); _mockinsurwaveWeatherInfoService.Setup(x => x.GetAstronomyInfo(_city, _date)).Returns(Task.FromResult(AstronomyWeatherApiHttpClientResponse)); _mockinsurwaveWeatherInfoService.Setup(x => x.GetAstronomyInfo(_city, null)).Returns(Task.FromResult(AstronomyWeatherApiHttpClientResponse)); // _moockLogger.Setup(x => x.LogError(It.IsAny<string>(), It.IsAny<Object>())); _mockmapper.Setup(x => x.Map <CityWeatherInfo>(It.IsAny <CurrentDetail>())).Returns(_cityWeatherInfo); _mockmapper.Setup(x => x.Map <CityDetailWithTempUnit>(It.IsAny <CurrentDetail>())).Returns(_cityDetailWithTempUnit); SUT = new WeatherInfoController(_moockLogger.Object, _mockinsurwaveWeatherInfoService.Object, _mockmapper.Object); }