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();
        }
Exemplo n.º 2
0
        public void ServicesInitializedSuccessfullyTest()
        {
            //Arrange
            var weatherServiceStore = new WeatherServiceStore();

            //Act
            var services = weatherServiceStore.Services;

            //Assert
            services.Should().BeEmpty("No services added");
        }
        public void GetWeatherAverageWindSpeedValuesAreCorrectTest(double kph, double mph, double averageKph, double averageMph)
        {
            //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()
                {
                    WindSpeedKph = kph,
                    Location = location
                });

            stubWeatherRespository.Stub(x => x.Get(Arg<WeatherServiceDetail>.Is.Equal((servicesStore.Services[1])), Arg<string>.Is.Anything))
                .Return(new WeatherServiceResponse()
                {
                    WindSpeedMph = mph,
                    Location = location
                });

            var weatherAggregatorService = container.Get<IWeatherAggregatorService>();

            //Act
            var result = weatherAggregatorService.GetAggregatedWeatherFromRegisteredServices(location);

            //Assert
            result.AverageWindSpeedKph.Should().Be(averageKph);
            result.AverageWindSpeedMph.Should().Be(averageMph);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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);
        }