Esempio n. 1
0
        public void WithFragment_ShouldSetPreExistingFragment()
        {
            var result = FluentUriBuilder.New("http://host:1234/test#frag")
                         .Build().ToString();

            Assert.Equal("http://host:1234/test#frag", result);
        }
Esempio n. 2
0
        public void ToStringReturnsTheSameStringAsUriAbsoluteUri()
        {
            var builder = FluentUriBuilder.From(TestData.Uri);
            var uri     = new Uri(TestData.Uri);

            builder.ToString().Should().Be(uri.AbsoluteUri);
        }
Esempio n. 3
0
        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");
 }
Esempio n. 5
0
        public void New_ShouldBuildBasicUriFromStringInput()
        {
            var result = FluentUriBuilder.New("http://thehost").Build();

            Assert.Equal("thehost", result.Host);
            Assert.Equal("http", result.Scheme);
        }
Esempio n. 6
0
        /// <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));
        }
Esempio n. 8
0
        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("/");
 }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
 public void ExistingCredentialsAreDeletedIfRemoveCredentialsIsCalled()
 {
     FluentUriBuilder.From(TestData.Uri)
     .RemoveCredentials()
     .ToUri()
     .UserInfo
     .Should().Be(string.Empty);
 }
Esempio n. 16
0
 public void ExistingPortIsDeletedIfRemovePortCalled()
 {
     FluentUriBuilder.From("ftp://example.com:9999")
     .RemovePort()
     .ToUri()
     .Port
     .Should().Be(21);
 }
Esempio n. 17
0
 public void ProtocolDefaultPortIsUsedIfPortIsMinus1()
 {
     FluentUriBuilder.From(TestData.Uri)
     .Port(-1)
     .ToUri()
     .Port
     .Should().Be(80);
 }
Esempio n. 18
0
 public void ExistingPortIsDeletedIfProtocolDefaultPortSpecified()
 {
     FluentUriBuilder.From("ftp://example.com:9999")
     .DefaultPort()
     .ToUri()
     .Port
     .Should().Be(21);
 }
Esempio n. 19
0
        public void WithPath_ShouldAddPathToUriWithPath()
        {
            var result = FluentUriBuilder.New("http://host")
                         .WithPath("mypath/hello")
                         .Build();

            Assert.Equal("/mypath/hello", result.AbsolutePath);
        }
Esempio n. 20
0
        public void WithScheme_ShouldChangeScheme()
        {
            var result = FluentUriBuilder.New("http://host")
                         .WithScheme("test")
                         .Build();

            Assert.Equal("test", result.Scheme);
        }
Esempio n. 21
0
        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());
        }
Esempio n. 22
0
        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());
        }
Esempio n. 23
0
        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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        public void ExistingPortIsUpdated()
        {
            var port = 1337;

            FluentUriBuilder.From(TestData.Uri)
            .Port(port)
            .ToUri()
            .Port
            .Should().Be(port);
        }
Esempio n. 29
0
        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);
        }
Esempio n. 30
0
        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);
        }