private string GetFullApiUrl(ExternalApiPathName externalApiPathName) { var apiUrl = _externalApiPathProvider.GetApiPath(externalApiPathName); var token = _configProvider.GetConfigValue(ConfigKeys.Token); var fullApiUrl = $"{apiUrl}?token={token}"; return(fullApiUrl); }
private string GetRelativePath(ExternalApiPathName apiPathName) { switch (apiPathName) { case ExternalApiPathName.GetProducts: return("/api/resource/products"); case ExternalApiPathName.GetShopperHistory: return("/api/resource/shopperhistory"); case ExternalApiPathName.CalculateTrolley: return("/api/resource/trolleycalculator"); default: throw new NotSupportedException(); } }
public void GetApiPath_WhenApiPathNameIsValid_ReturnsCorrectUrl(string baseUrl, ExternalApiPathName apiPathName, string expectedUrl) { // Arrange var mockConfigProvider = new Mock <IConfigProvider>(); mockConfigProvider .Setup(o => o.GetConfigValue(ConfigKeys.BaseUrl)) .Returns(baseUrl); var sutExternalApiPathProvider = new ExternalApiPathProvider(mockConfigProvider.Object); // Act var result = sutExternalApiPathProvider.GetApiPath(apiPathName); // Assert result.Should().Be(expectedUrl); }
public string GetApiPath(ExternalApiPathName apiPathName) { return($"{_baseUrl.TrimEnd('/')}/{GetRelativePath(apiPathName).TrimStart('/')}"); }
private ExternalApiCallException GetExternalApiCallException(ExternalApiPathName externalApiPathName, HttpStatusCode statusCode) { return(new ExternalApiCallException($"Error in calling '{externalApiPathName}' API. StatusCode = {statusCode}")); }