예제 #1
0
        public RoadStatusService(IRestApiCallService restApiCallService, IOptions <TflApiSettings> tflApiSettings)
        {
            this._restApiCallService = restApiCallService ?? throw new ArgumentNullException(paramName: nameof(restApiCallService),
                                                                                             message: $"A valid {nameof(restApiCallService)} must be supplied");

            this._tflApiSettings = tflApiSettings.Value ?? throw new ArgumentNullException(paramName: nameof(tflApiSettings),
                                                                                           message: $"A valid {nameof(tflApiSettings)} must be supplied");
        }
예제 #2
0
        public RoadCorridorService(IHttpClientFactory httpClientFactory, IOptions <TflApiSettings> tflApiSettings, ILogger <RoadCorridorService> logger)
        {
            Guard.Against <ArgumentNullException>(httpClientFactory == null, "httpClientFactory is null");
            Guard.Against <ArgumentNullException>(logger == null, "logger is null");
            Guard.Against <ArgumentNullException>(tflApiSettings == null, "tflApiSettings is null");

            _httpClientFactory = httpClientFactory;
            _tflApiSettings    = tflApiSettings?.Value;
            _logger            = logger;


            Guard.Against <ArgumentNullException>(string.IsNullOrEmpty(_tflApiSettings?.ApiId), "ApiId is null");
            Guard.Against <ArgumentNullException>(string.IsNullOrEmpty(_tflApiSettings?.ApiKey), "ApiKey is null");
        }
예제 #3
0
        public RoadServiceTests()
        {
            this._mockRestApiCallService = new Mock <IRestApiCallService>();

            this._dummytflApiSettings = new TflApiSettings()
            {
                BaseUrl        = "https://api.tfl.gov.uk/",
                Authentication = new Authentication()
                {
                    UsernameIdentifier = "api_id",
                    Username           = "******",
                    PasswordIdentifier = "api_key",
                    Password           = "******"
                },
                Resources = new List <Resource>()
                {
                    new Resource {
                        Name = "road", Value = "road/{roadId}"
                    }
                }
            };

            this._validResponseForA2 = new RestApiResponse()
            {
                Content = JsonConvert.SerializeObject(
                    new RoadStatusLookupSuccessResponse[1]
                {
                    new RoadStatusLookupSuccessResponse()
                    {
                        Type                      = "Tfl.Api.Presentation.Entities.RoadCorridor, Tfl.Api.Presentation.Entities",
                        Id                        = "a2",
                        DisplayName               = "A2",
                        Bounds                    = "[[-0.0857,51.44091],[0.17118,51.49438]]",
                        Envelope                  = "[[-0.0857,51.44091],[-0.0857,51.49438],[0.17118,51.49438],[0.17118,51.44091],[-0.0857,51.44091]]",
                        StatusSeverity            = "Good",
                        StatusSeverityDescription = "No Exceptional Delays",
                        Url                       = "/Road/a2"
                    }
                }
                    ),
                StatusCode = System.Net.HttpStatusCode.OK
            };

            this._notFoundResponseForA233 = new RestApiResponse()
            {
                Content = JsonConvert.SerializeObject(
                    new RoadStatusLookupErrorResponse()
                {
                    Type           = "Tfl.Api.Presentation.Entities.RoadCorridor, Tfl.Api.Presentation.Entities",
                    ExceptionType  = "EntityNotFoundException",
                    HttpStatusCode = 404,
                    HttpStatus     = "NotFound",
                    RelativeUri    = "/Road/A233",
                    Message        = "The following road id is not recognised: A233",
                    TimestampUtc   = DateTime.Parse("2017-11-21T14:37:39.7206118Z")
                }
                    ),
                StatusCode = System.Net.HttpStatusCode.NotFound
            };

            var options = Options.Create(_dummytflApiSettings);

            this._sut = new RoadStatusService(_mockRestApiCallService.Object, options);
        }