public void GetWeatherTest() { //Arrange var container = new Container(); var weatherServices = new WeatherServiceStore(); weatherServices.RegisterService(new WeatherServiceDetail() { ServiceUrl = "http://localhost:18888/api", Resource = "Weather/{location}" }); weatherServices.RegisterService(new WeatherServiceDetail() { ServiceUrl = "http://localhost:17855/api", Resource = "Weather/{location}" }); container.Register<IWeatherAggregatorService, WeatherAggregatorService>(); container.Register<IWeatherRepository, WeatherRepository>(); container.Register<IWeatherUnitConverterService, WeatherUnitConverterService>(); container.Register<IRestClientAdapter, RestClientAdapter>(); container.Register<IJsonConvertAdapter, JsonConvertAdapter>(); container.RegisterInstance<IWeatherServiceStore>(weatherServices); var weatherAggregatorService = container.Get<IWeatherAggregatorService>(); const string location = "TestLocation"; //Act var result = weatherAggregatorService.GetAggregatedWeatherFromRegisteredServices(location); //Assert result.Should().NotBeNull(); }
public void GetWeatherAverageTemperatureValuesAreCorrectTest(double celsius, double fahrenheit, double averageCelsius, double averageFahrenheit) { //Arrange const string location = "TestLocation"; var container = new Container(); var stubWeatherRespository = MockRepository.GenerateStub<IWeatherRepository>(); var servicesStore = new WeatherServiceStore(); container.RegisterInstance(stubWeatherRespository); container.RegisterInstance<IWeatherServiceStore>(servicesStore); container.Register<IJsonConvertAdapter, JsonConvertAdapter>(); container.Register<IRestClientAdapter, RestClientAdapter>(); container.Register<IWeatherUnitConverterService, WeatherUnitConverterService>(); container.Register<IWeatherAggregatorService, WeatherAggregatorService>(); servicesStore.RegisterService(new WeatherServiceDetail() { ServiceUrl = "Test1", Resource = "Weather" }); servicesStore.RegisterService(new WeatherServiceDetail() { ServiceUrl = "Test2", Resource = "Weather" }); stubWeatherRespository.Stub(x => x.Get(Arg<WeatherServiceDetail>.Is.Equal((servicesStore.Services[0])), Arg<string>.Is.Anything)) .Return(new WeatherServiceResponse() { TemperatureCelsius = celsius, Location = location }); stubWeatherRespository.Stub(x => x.Get(Arg<WeatherServiceDetail>.Is.Equal((servicesStore.Services[1])), Arg<string>.Is.Anything)) .Return(new WeatherServiceResponse() { TemperatureFahrenheit = fahrenheit, Location = location }); var weatherAggregatorService = container.Get<IWeatherAggregatorService>(); //Act var result = weatherAggregatorService.GetAggregatedWeatherFromRegisteredServices(location); //Assert result.AverageTemperatureCelsius.Should().Be(averageCelsius); result.AverageTemperatureFahrenheit.Should().Be(averageFahrenheit); }
private static IWeatherServiceStore GetRegisteredServices() { var servicesStore = new WeatherServiceStore(); servicesStore.RegisterService(new WeatherServiceDetail() { ServiceUrl = "http://localhost:18888/api", Resource = "Weather/{location}" }); servicesStore.RegisterService(new WeatherServiceDetail() { ServiceUrl = "http://localhost:17855/api", Resource = "Weather/{location}" }); return servicesStore; }
public void RegisterRegistersServiceSuccessfullyTest() { //Arrange var weatherServiceStore = new WeatherServiceStore(); var weatherServiceDetail = new WeatherServiceDetail() { Resource = "Test", ServiceUrl = "Test2" }; //Act weatherServiceStore.RegisterService(weatherServiceDetail); var services = weatherServiceStore.Services; //Assert services.Should().HaveCount(1, "1 service registered"); services[0].ShouldBeEquivalentTo(weatherServiceDetail); }