/// <summary> /// API Wrapper generator /// </summary> /// <param name="source">Selected API Enum Value</param> /// <returns></returns> public IWeatherApi Make(int source) { // We get the current source's options var option = _optionsAccessor.Value.WeaherApiOption[source]; if (!option.Name.Equals(((Source) source).ToString())) throw new Exception("Badly Configured Parameters"); // Based on the source we initialize the desired wrapper and set it's KEY IWeatherApi implementation; switch ((Source) source) { case Source.ForecastIo: implementation = new ForecastIo.ForecastIo(_forecastClient); break; case Source.WeatherUnderground: implementation = new Wunderground.Wunderground(_wunderClient); break; case Source.WorldWeatherOnline: implementation = new WorldWeatherOnline.WorldWeatherOnline(_wwoClient); break; default: throw new ArgumentOutOfRangeException(nameof(source), source, null); } implementation.ApiKey = option.Key; return implementation; }
private async void WhenWorldWeatherOnlineMethodIsCalledRestClientGetLocalWeatherShouldBeCalled() { //Arrange var restClientMock = new Mock<IRestClient<EndPointResponse>>(); restClientMock.Setup(o => o.CallListEndPoint(It.IsAny<string>())) .ReturnsAsync(new EndPointResponse()); var worldWeatherOnline = new WorldWeatherOnline(restClientMock.Object) { ApiKey = "0" }; // Act await worldWeatherOnline.GetLocalWeather(0, 0); // Verify restClientMock.Verify(t => t.CallListEndPoint(It.IsAny<string>())); }