public void GetServiceFailedExceptionThrownTest()
        {
            //Arrange
            var container = new Container();
            var stubRestClient = MockRepository.GenerateStub<IRestClientAdapter>();
            var stubJsonConverter = MockRepository.GenerateStub<IJsonConvertAdapter>();

            container.RegisterInstance(stubRestClient);
            container.RegisterInstance(stubJsonConverter);
            container.Register<IWeatherRepository, WeatherRepository>();

            var weatherRepository = container.Get<IWeatherRepository>();
            var restClientResponse = new RestClientResponse()
            {
                Content = "TestContent",
                ResponseStatus = RestResponseStatus.Failure
            };
            var weatherServiceDetail = new WeatherServiceDetail()
            {
                Resource = "TestResource",
                ServiceUrl = "TestUrl"
            };
            const string location = "TestLocation";

            stubRestClient.Stub(x => x.Get(Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<Dictionary<string, string>>.Is.Anything))
                .Return(restClientResponse);

            //Act
            Action action = () => weatherRepository.Get(weatherServiceDetail, location);

            //Assert
            action.ShouldThrow<WeatherServiceException>()
                .WithMessage("Service failed");
        }
        public void GetDependenciesCalledWithCorrectParamsTest()
        {
            //Arrange
            const string location = "TestLocation";
            var container = new Container();
            var stubRestClient = MockRepository.GenerateStub<IRestClientAdapter>();
            var stubJsonConverter = MockRepository.GenerateStub<IJsonConvertAdapter>();

            container.RegisterInstance(stubRestClient);
            container.RegisterInstance(stubJsonConverter);
            container.Register<IWeatherRepository, WeatherRepository>();

            var weatherRepository = container.Get<IWeatherRepository>();
            var restClientResponse = new RestClientResponse()
            {
                Content = "TestContent"
            };
            var weatherServiceDetail = new WeatherServiceDetail()
            {
                Resource = "TestResource",
                ServiceUrl = "TestUrl"
            };
            var urlSegment = new Dictionary<string, string> {{"location", location}};

            stubRestClient.Stub(x => x.Get(Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<Dictionary<string, string>>.Is.Anything))
                .Return(restClientResponse);

            //Act
            weatherRepository.Get(weatherServiceDetail, location);

            //Assert
            stubRestClient.AssertWasCalled(x => x.Get(weatherServiceDetail.ServiceUrl, weatherServiceDetail.Resource, urlSegment));
            stubJsonConverter.AssertWasCalled(x => x.DeserializeObject<WeatherServiceResponse>(restClientResponse.Content));
        }
 private WeatherServiceResponse GetWeatherFromRegisteredService(string location, WeatherServiceDetail weatherService)
 {
     try
     {
         return _weatherRepository.Get(weatherService, location);
     }
     catch (WeatherServiceException ex)
     {
         Debug.WriteLine(ex.Message);
     }
     return null;
 }
        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);
        }
Esempio n. 5
0
 public void RegisterService(WeatherServiceDetail weatherServiceDetail)
 {
     Services.Add(weatherServiceDetail);
 }