Ejemplo n.º 1
0
        public void Add_duplicate_parameter_in_different_casing_throws_argument_exception()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "home");
            link.Parameters.Add("up", "up");

            // When, Then
            Assert.Throws<ArgumentException>(() => link.Parameters.Add("UP", "UP"));
        }
Ejemplo n.º 2
0
        public void Links_in_different_casing_should_be_considered_equal()
        {
            // Given
            var first = new HttpLink("http://NANCYFX.ORG/", "home");
            var second = new HttpLink("http://nancyfx.org/", "home");

            // When
            var equal = first.Equals(second);

            // Then
            equal.ShouldBeTrue();
        }
Ejemplo n.º 3
0
        public void Add_duplicate_parameter_in_different_casing_throws_argument_exception()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "home");
            link.Parameters.Add("up", "up");

            // When
            var exception = Assert.Throws<ArgumentException>(() => link.Parameters.Add("UP", "UP"));

            // Then
            exception.Message.ShouldEqual("An item with the same key has already been added.");
        }
Ejemplo n.º 4
0
        public async Task Download(HttpLink link)
        {
            using (var httpClient = _http.CreateClient())
            {
                var response = await httpClient.GetAsync(link.ToString());

                response.EnsureSuccessStatusCode();

                var data = await response.Content.ReadAsStreamAsync();

                await _folder.WriteFile(link, data);
            }
        }
Ejemplo n.º 5
0
        public void ToString_link_with_extension_parameter_should_exist_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up");

            link.Parameters.Add("ext", "extension-param");

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"; ext=\"extension-param\"");
        }
Ejemplo n.º 6
0
        public void Add_duplicate_parameter_in_different_casing_throws_argument_exception()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "home");

            link.Parameters.Add("up", "up");

            // When
            var exception = Assert.Throws <ArgumentException>(() => link.Parameters.Add("UP", "UP"));

            // Then
            exception.Message.ShouldEqual("An item with the same key has already been added.");
        }
Ejemplo n.º 7
0
        public void Links_with_relations_in_different_casing_should_have_same_hash_code()
        {
            // Given
            var first  = new HttpLink("http://nancyfx.org/", "home");
            var second = new HttpLink("http://nancyfx.org/", "HOME");

            // When
            var firstHashCode  = first.GetHashCode();
            var secondHashCode = second.GetHashCode();

            // Then
            firstHashCode.ShouldEqual(secondHashCode);
        }
Ejemplo n.º 8
0
        public void ToString_link_with_boolean_parameter_should_exist_without_value_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up");

            link.Parameters.Add("parameter", null);

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"; parameter");
        }
Ejemplo n.º 9
0
        public void ToString_link_with_empty_parameter_should_not_exist_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up");

            link.Parameters.Add(string.Empty, null);

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"");
        }
Ejemplo n.º 10
0
        public void Links_in_different_casing_should_have_same_hash_code()
        {
            // Given
            var first = new HttpLink("http://NANCYFX.ORG/", "home");
            var second = new HttpLink("http://nancyfx.org/", "home");

            // When
            var firstHashCode = first.GetHashCode();
            var secondHashCode = second.GetHashCode();

            // Then
            firstHashCode.ShouldEqual(secondHashCode);
        }
Ejemplo n.º 11
0
        protected override void ConfigureRequestContainer(ILifetimeScope container, NancyContext context)
        {
            base.ConfigureRequestContainer(container, context);

            var module = new BuilderModule();

            module.Register(c => new WebApiCall(
                                HttpLink.From(context.Request.Url.ToString()),
                                HttpAuthorization.From(context.Request.Headers.Authorization),
                                WebApiCallBody.From(context.Request.Headers.ContentType, () => context.Request.Body)))
            .InstancePerRequest();

            module.Update(container.ComponentRegistry);
        }
Ejemplo n.º 12
0
        public void Links_with_different_parameters_should_not_be_considered_equal()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");
            first.Parameters.Add("a", "b");

            var second = new HttpLink("http://nancyfx.org/", "home");
            second.Parameters.Add("x", "y");

            // When
            var equal = first.Equals(second);

            // Then
            equal.ShouldBeFalse();
        }
Ejemplo n.º 13
0
 public Dealer(
     Id id,
     string code,
     string name,
     string region,
     string hostname,
     HttpLink manifestLink)
 {
     Id           = id;
     Code         = code;
     Name         = name;
     Region       = region;
     Hostname     = hostname;
     ManifestLink = manifestLink;
 }
Ejemplo n.º 14
0
            HttpLink ExpandLink(XElement creativeXml)
            {
                var link = HttpLink.From(HttpHost.FromHttp(_dealer.Hostname));

                var resource = GetLinkResource(
                    (string)creativeXml.Attribute("Link"),
                    (string)creativeXml.Attribute("Model") ?? "");

                if (resource != null)
                {
                    link = link.Then(HttpResource.From(resource));
                }

                return(link);
            }
Ejemplo n.º 15
0
        public void Links_with_different_parameters_should_not_have_same_hash_code()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");
            first.Parameters.Add("a", "b");

            var second = new HttpLink("http://nancyfx.org/", "home");
            second.Parameters.Add("x", "y");

            // When
            var firstHashCode = first.GetHashCode();
            var secondHashCode = second.GetHashCode();

            // Then
            firstHashCode.ShouldNotEqual(secondHashCode);
        }
Ejemplo n.º 16
0
        public void Links_with_equal_parameters_in_different_casing_should_be_considered_equal()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");

            first.Parameters.Add("param", "value");

            var second = new HttpLink("http://nancyfx.org/", "home");

            second.Parameters.Add("PARAM", "value");

            // When
            var equal = first.Equals(second);

            // Then
            equal.ShouldBeTrue();
        }
Ejemplo n.º 17
0
        public void Links_with_different_parameters_should_not_be_considered_equal()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");

            first.Parameters.Add("a", "b");

            var second = new HttpLink("http://nancyfx.org/", "home");

            second.Parameters.Add("x", "y");

            // When
            var equal = first.Equals(second);

            // Then
            equal.ShouldBeFalse();
        }
Ejemplo n.º 18
0
        public void Links_with_equal_parameters_should_have_same_hash_code()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");

            first.Parameters.Add("param", "value");

            var second = new HttpLink("http://nancyfx.org/", "home");

            second.Parameters.Add("param", "value");

            // When
            var firstHashCode  = first.GetHashCode();
            var secondHashCode = second.GetHashCode();

            // Then
            firstHashCode.ShouldEqual(secondHashCode);
        }
        public void OpenUrl()
        {
            HttpLink httpPageLinkToParse = _settings.HttpPageLinkToParse;

            if (!httpPageLinkToParse.HasValue)
            {
                throw new ArgumentException("Failed to open empty link.", nameof(_settings));
            }

            if (StringComparer.OrdinalIgnoreCase.Equals(_webDriver.Url, httpPageLinkToParse))
            {
                _logger.Warning("Trying to open the same URL. Use Refresh method instead.");
                return;
            }

            _logger.Info($"Opening URL: '{httpPageLinkToParse.Value}'.");
            _webDriver.Navigate().GoToUrl(httpPageLinkToParse.Value);
        }
Ejemplo n.º 20
0
        public void Links_with_different_parameters_should_not_have_same_hash_code()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");

            first.Parameters.Add("a", "b");

            var second = new HttpLink("http://nancyfx.org/", "home");

            second.Parameters.Add("x", "y");

            // When
            var firstHashCode  = first.GetHashCode();
            var secondHashCode = second.GetHashCode();

            // Then
            firstHashCode.ShouldNotEqual(secondHashCode);
        }
Ejemplo n.º 21
0
        private static void TestSkipSongRequest(IReadOnlyList <string> args)
        {
            HttpLink httpLink = ParseIntputLink(args);

            var settings = TestSettings.MockSettings(httpLink);

            using var scrapper = HttpWebScrapperFactory.Create(settings, Logger);

            scrapper.OpenUrl();

            var result = scrapper.Skip(shouldSkipAll: true);

            if (result.IsSuccess)
            {
                Logger.Info("Song requests were skipped successfully!");
            }
            else
            {
                Logger.Error($"Failed to skip song requests: {result.Description}");
            }
        }
Ejemplo n.º 22
0
        async Task <Many <Manifest.Dealer> > ReadDealers(XElement xml)
        {
            var manifestDealers =
                from dealer in xml.Element("CAMDealerWrapper").Elements()
                select new
            {
                Code = ((string)dealer.Attribute("DealerCode")).PadLeft(5, '0'),
                Link = HttpLink.From((string)dealer.Attribute("ManifestURL"))
            };

            return(Many.Of(
                       from dbDealer in await _eligibleDealerDb.GetEligibleDealers()
                       join manifestDealer in manifestDealers on dbDealer.Code equals manifestDealer.Code
                       select new Manifest.Dealer(
                           dbDealer.Id,
                           manifestDealer.Code,
                           dbDealer.Name,
                           dbDealer.Region,
                           dbDealer.Hostname,
                           manifestDealer.Link)));
        }
Ejemplo n.º 23
0
        void Given(ManifestDownloaded e)
        {
            if (e.RemovedDealerIds.Contains(Id))
            {
                ThenDone();
            }
            else
            {
                DealerId = Id;

                var dealer = e.AddedDealers
                             .Concat(e.UpdatedDealers)
                             .Where(d => d.Id == Id)
                             .First();

                Code         = dealer.Code;
                Name         = dealer.Name;
                Region       = dealer.Region;
                Hostname     = dealer.Hostname;
                ManifestLink = dealer.ManifestLink;
            }
        }
Ejemplo n.º 24
0
 void Given(ManifestDownloaded e) =>
 _assetsLink = e.AssetsLink;
Ejemplo n.º 25
0
 public WebApiCall(HttpLink link, HttpAuthorization authorization, WebApiCallBody body)
 {
     Link          = link;
     Authorization = authorization;
     Body          = body;
 }
Ejemplo n.º 26
0
        public void ToString_link_with_type_should_exist_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up", "application/json");

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"; type=\"application/json\"");
        }
Ejemplo n.º 27
0
 public AssetImportsStarted(HttpLink link, Many <Id> assetIds)
 {
     Link     = link;
     AssetIds = assetIds;
 }
Ejemplo n.º 28
0
        public void Links_with_equal_parameters_should_have_same_hash_code()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");
            first.Parameters.Add("param", "value");

            var second = new HttpLink("http://nancyfx.org/", "home");
            second.Parameters.Add("param", "value");

            // When
            var firstHashCode = first.GetHashCode();
            var secondHashCode = second.GetHashCode();

            // Then
            firstHashCode.ShouldEqual(secondHashCode);
        }
Ejemplo n.º 29
0
        public void Links_with_equal_parameters_in_different_casing_should_be_considered_equal()
        {
            // Given
            var first = new HttpLink("http://nancyfx.org/", "home");
            first.Parameters.Add("param", "value");

            var second = new HttpLink("http://nancyfx.org/", "home");
            second.Parameters.Add("PARAM", "value");

            // When
            var equal = first.Equals(second);

            // Then
            equal.ShouldBeTrue();
        }
Ejemplo n.º 30
0
        public void ToString_link_with_boolean_parameter_should_exist_without_value_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up");
            link.Parameters.Add("parameter", null);

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"; parameter");
        }
Ejemplo n.º 31
0
        public void ToString_link_with_extension_parameter_should_exist_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up");
            link.Parameters.Add("ext", "extension-param");

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"; ext=\"extension-param\"");
        }
Ejemplo n.º 32
0
        public static ExecutionResultLink SignalROrHttp(
            string hubUrl,
            string httpUrl,
            IHttpContextAccessor accessor)
        {
            var signalr = RemoteLinks.SignalR(cancellationToken =>
            {
                var connection = new HubConnectionBuilder()
                                 .AddJsonProtocol(options =>
                {
                    options
                    .PayloadSerializerOptions
                    .Converters
                    .Add(new ObjectDictionaryConverter());
                })
                                 .WithUrl(hubUrl, configure =>
                {
                    configure.AccessTokenProvider = () =>
                    {
                        var token = accessor.HttpContext
                                    ?.User
                                    .FindFirstValue("access_token");

                        return(Task.FromResult(token));
                    };
                })
                                 .Build();

                return(Task.FromResult(connection));
            });

            var http = RemoteLinks.Http(
                httpUrl,
                transformRequest: operation =>
            {
                var request = HttpLink.DefaultTransformRequest(operation);
                request.Headers.Authorization = new AuthenticationHeaderValue(
                    "Bearer",
                    accessor.HttpContext?.User.FindFirstValue("access_token"));

                return(request);
            },
                transformResponse: response =>
            {
                return(HttpLink.DefaultTransformResponse(response));
            });

            return(async(document, variables, token) =>
            {
                var hasQueryOrMutation = document.OperationDefinitions
                                         .Any(op => op.Operation != OperationType.Subscription);

                if (hasQueryOrMutation)
                {
                    var result = await http(document, variables, CancellationToken.None);

                    return result;
                }

                return await signalr(document, variables, token);
            });
        }
Ejemplo n.º 33
0
 public ManifestFile(HttpLink link, IHttpClientFactory http, IEligibleDealerDb eligibleDealerDb)
 {
     _link             = link;
     _http             = http;
     _eligibleDealerDb = eligibleDealerDb;
 }
Ejemplo n.º 34
0
 public Manifest(HttpLink assetsLink, Many <Dealer> dealers)
 {
     AssetsLink = assetsLink;
     Dealers    = dealers;
 }
Ejemplo n.º 35
0
        public void ToString_link_with_whitespace_parameter_should_not_exist_in_string()
        {
            // Given
            var link = new HttpLink("http://nancyfx.org/", "up");
            link.Parameters.Add("    ", null);

            // When
            var stringValue = link.ToString();

            // Then
            stringValue.ShouldEqual("<http://nancyfx.org/>; rel=\"up\"");
        }