public void WithFragment_ShouldSetPreExistingFragment() { var result = FluentUriBuilder.New("http://host:1234/test#frag") .Build().ToString(); Assert.Equal("http://host:1234/test#frag", result); }
public void ToStringReturnsTheSameStringAsUriAbsoluteUri() { var builder = FluentUriBuilder.From(TestData.Uri); var uri = new Uri(TestData.Uri); builder.ToString().Should().Be(uri.AbsoluteUri); }
public void WithHost_ShouldUpdateHost() { var result = FluentUriBuilder.New("http://host:1234/test") .WithHost("newhost").Build(); Assert.Equal(new Uri("http://newhost:1234/test"), result); }
public void GetsQueryParamValueUsingFrom() { FluentUriBuilder.From(fullTestUri) .GetParam("somekey") .Should() .Be("some%2bvalue"); }
public void New_ShouldBuildBasicUriFromStringInput() { var result = FluentUriBuilder.New("http://thehost").Build(); Assert.Equal("thehost", result.Host); Assert.Equal("http", result.Scheme); }
/// <summary> /// Build the request URI /// </summary> /// <param name="subscriptionId">ISV Azure subscription id</param> /// <param name="resourceGroup">ISV Azure resource group</param> /// <param name="deploymentName"></param> /// <returns></returns> private Uri GetRequestUri( string subscriptionId, string resourceGroup, string deploymentName = default ) { var requestUri = String.IsNullOrEmpty(deploymentName) ? FluentUriBuilder.Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId) .AddPath("resourceGroups") .AddPath(resourceGroup) .AddQuery("api-version", _apiVersion) : FluentUriBuilder.Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId) .AddPath("resourcegroups") .AddPath(resourceGroup) .AddPath("providers/Microsoft.Resources/deployments") .AddPath(deploymentName) .AddQuery("api-version", _apiVersion); return(requestUri.Uri); }
/// <summary> /// Searchs products. /// </summary> /// <param name="productsByProgramRuns">The productsByProgramRuns.</param> /// <returns>Task{List{ProductResponseModel}}.</returns> public async Task <List <ProductResponseModel> > SearchProducts(List <ProductsByProgramRun> productsByProgramRuns) { try { string providerName = _appSettings.ProductProvider2Api.ProviderName; string requestUri = _appSettings.ProductProvider2Api.RequestUri; FluentUriBuilder request = CreateRequest(requestUri); var provider2Request = new Provider2Request { CustomerId = 832, PageNum = 0, PageSize = productsByProgramRuns.Count, SortOrder = new List <ProductSortOrderRequestDto>() { new ProductSortOrderRequestDto() { Position = 1, SortColumn = "department", SortDirection = "ASC" } }, ItemId = new List <int>(), ItemNum = new List <int>(), UpcList = productsByProgramRuns.Select(p => p.ProductCode).ToList(), BrandName = new List <string>(), DepartmentId = new List <int>(), SubDept1Id = new List <int>(), SubDept2Id = new List <int>(), TprType = "", PromoInd = "", Status = "A", CustomFields = new List <CustomFieldsDto>(), PrimaryBarcode = "Y", DisplayMhSummary = true, DisplayAttributeSummary = true, DisplayBrandSummary = true }; Provider2Response response = await PostAsync <Provider2Request, Provider2Response>( $"Search Products {requestUri}", request.Uri, provider2Request, CancellationToken.None, DataInterchangeFormat.Json, providerName, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); List <ProductResponseModel> productResponses = ConvertToProductResponses(productsByProgramRuns, response); return(productResponses); } catch (Exception e) { _logger.LogError($"{nameof(SearchProducts)} Unknown error encountered when reading an object ex {e}"); } return(ConvertToProductResponses(productsByProgramRuns, null)); }
public void WithPathSegment_ShouldSetSegmentForTemplate() { var result = FluentUriBuilder.New("http://host:1234/{seg1}") .WithSegment("seg1", "segmentone") .Build(); Assert.Equal("http://host:1234/segmentone", result.ToString()); }
public void ExistingFragmentIsDeletedIfRemoveFragmentIsCalled() { FluentUriBuilder.From(fullTestUri) .RemoveFragment() .ToUri() .Fragment .Should().Be(string.Empty); }
public void ExistingFragmentIsDeletedIfEmptyFragmentSpecified() { FluentUriBuilder.From(fullTestUri) .Fragment(string.Empty) .ToUri() .Fragment .Should().Be(string.Empty); }
public void ExistingSchemeIsUpdated(UriScheme scheme, string expectedScheme) { FluentUriBuilder.From(fullTestUri) .Scheme(scheme) .ToUri() .Scheme .Should().Be(expectedScheme); }
public void ExistingPathIsDeletedIfRemovePathCalled() { FluentUriBuilder.From(fullTestUri) .RemovePath() .ToUri() .LocalPath .Should().Be("/"); }
public void ExistingPathIsDeletedIfEmptyFragmentSpecified() { FluentUriBuilder.From(fullTestUri) .Path(string.Empty) .ToUri() .LocalPath .Should().Be("/"); }
public void AddQuery_ShouldAddQueryParameter() { var result = FluentUriBuilder.New("http://host:1234/test") .AddQuery("myparam", "myvalue") .Build().ToString(); Assert.Equal("http://host:1234/test?myparam=myvalue", result); }
public void ExistingCredentialsAreDeletedIfRemoveCredentialsIsCalled() { FluentUriBuilder.From(TestData.Uri) .RemoveCredentials() .ToUri() .UserInfo .Should().Be(string.Empty); }
public void ExistingPortIsDeletedIfRemovePortCalled() { FluentUriBuilder.From("ftp://example.com:9999") .RemovePort() .ToUri() .Port .Should().Be(21); }
public void ProtocolDefaultPortIsUsedIfPortIsMinus1() { FluentUriBuilder.From(TestData.Uri) .Port(-1) .ToUri() .Port .Should().Be(80); }
public void ExistingPortIsDeletedIfProtocolDefaultPortSpecified() { FluentUriBuilder.From("ftp://example.com:9999") .DefaultPort() .ToUri() .Port .Should().Be(21); }
public void WithPath_ShouldAddPathToUriWithPath() { var result = FluentUriBuilder.New("http://host") .WithPath("mypath/hello") .Build(); Assert.Equal("/mypath/hello", result.AbsolutePath); }
public void WithScheme_ShouldChangeScheme() { var result = FluentUriBuilder.New("http://host") .WithScheme("test") .Build(); Assert.Equal("test", result.Scheme); }
public void New_ShouldBuildUriFromStringInputWithPath() { var result = FluentUriBuilder.New("http://thehost/thepath").Build(); Assert.Equal("thehost", result.Host); Assert.Equal("http", result.Scheme); Assert.Equal("http://thehost/thepath", result.ToString()); }
public void New_ShouldBuildUriFromStringInputWithPathAndPortAndQueryString() { var result = FluentUriBuilder.New("http://thehost:8945/thepath?id=54").Build(); Assert.Equal("thehost", result.Host); Assert.Equal("http", result.Scheme); Assert.Equal("http://thehost:8945/thepath?id=54", result.ToString()); }
public void WithPort_ShouldSetPort() { var result = FluentUriBuilder.New("http://host/path") .WithPort(1234) .Build(); Assert.Equal(1234, result.Port); Assert.Equal("http://host:1234/path", result.ToString()); }
public void SchemeIsUsedIfSpecified(UriScheme scheme, string expectedScheme) { FluentUriBuilder.Create() .Scheme(scheme) .Host("example.com") .ToUri() .Scheme .Should().Be(expectedScheme); }
public void EmptyQueryParamsDictionaryAddsNoQueryParams() { var uri = "http://example.com/"; FluentUriBuilder.From(uri) .QueryParams(new Dictionary <string, object>()) .ToString() .Should().Be(uri); }
public void EmptyQueryParamsObjectAddsNoQueryParams() { var uri = "http://example.com/"; FluentUriBuilder.From(uri) .QueryParams(new { }) .ToString() .Should().Be(uri); }
public void AddPathTemplate_ShouldHandleSlashesCorrectlyWhenTemplateBeginsWithSlash() { var result = FluentUriBuilder.New("http://host:1234/test") .AddPathTemplate("/{test}/whatever/{test2}") .WithSegment("test", "karl") .WithSegment("test2", "karl2") .Build(); Assert.Equal(new Uri("http://host:1234/test/karl/whatever/karl2"), result); }
public void ExistingPortIsUpdated() { var port = 1337; FluentUriBuilder.From(TestData.Uri) .Port(port) .ToUri() .Port .Should().Be(port); }
public void WithQueries_ShouldAddMultipleQueryParamerters2() { var result = FluentUriBuilder.New("http://host:1234/test") .AddQueries(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("what", "hey"), new KeyValuePair <string, string>("no", "yes") }) .Build(); Assert.Equal(new Uri("http://host:1234/test?what=hey&no=yes"), result); }
public void Explore() { var result = FluentUriBuilder.New("http://host:1234/test") .AddPathTemplate("/{test}/whatever/{test2}") .WithSegment("test", "karl") .WithSegment("test2", "karl2") .Build(); Assert.Equal(new Uri("http://host:1234/test/karl/whatever/karl2"), result); }