Exemplo n.º 1
0
    public JObject ExecuteJson(string endpointUrl, HttpMethod method, IDictionary <string, string> headers, JObject payload)
    {
        var request = (HttpWebRequest)WebRequest.Create(WebUri.ToString() + endpointUrl);

        request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + AccessToken);
        request.Method      = method.Method;
        request.Accept      = "application/json;odata=verbose";
        request.ContentType = "application/json;odata=verbose";
        if (payload != null)
        {
            using (var writer = new StreamWriter(request.GetRequestStream()))
            {
                writer.Write(payload);
                writer.Flush();
            }
        }
        using (var response = (HttpWebResponse)request.GetResponse())
        {
            using (var responseStream = response.GetResponseStream())
            {
                using (var reader = new StreamReader(responseStream))
                {
                    var result = reader.ReadToEnd();
                    return(JObject.Parse(result));
                }
            }
        }
    }
Exemplo n.º 2
0
        public void FilmSearchRowsHtmlDocDetailWebSiteTest()
        {
            //Arrange
            var html   = CreateSearchRowsHtmlDocDetailWebSite();
            var search = new SearchRowsDetail();
            var webUri = new WebUri(HOST);

            //Act
            search.Process(html, webUri);
            var searchRows = search.SearchRows;

            var row1 = searchRows.ElementAt(0);
            var row2 = searchRows.ElementAt(1);

            //Assert
            Assert.Equal(2, searchRows.Count);

            Assert.Equal(TITLE_1, row1.Title);
            Assert.Equal(YEAR_1, row1.Year);
            Assert.Equal(DURATION_1, row1.Duration);
            Assert.Equal(RELEASE_1, row1.Release);
            Assert.Equal(HOST + LINK_1, row1.Link);

            Assert.Equal(TITLE_2, row2.Title);
            Assert.Equal(YEAR_2, row2.Year);
            Assert.Equal(DURATION_2, row2.Duration);
            Assert.Equal(RELEASE_2, row2.Release);
            Assert.Equal(HOST + LINK_2, row2.Link);
        }
Exemplo n.º 3
0
        public void UriCorrected()
        {
            //Act
            var webUri = new WebUri("https://microsoft.com");

            //Assert
            Assert.True(webUri.AbsoluteUriCorrected);
            Assert.NotNull(webUri.AbsoluteUri);
        }
Exemplo n.º 4
0
        public void CalculateHost(string uri)
        {
            //Arrange
            //Act
            var webUri = new WebUri(uri);

            //Assert
            Assert.Equal("https://www.www.pl", webUri.Host);
        }
Exemplo n.º 5
0
        public void UriNotCorrected()
        {
            //Act
            var webUri = new WebUri("microsoft.com");

            //Assert
            Assert.False(webUri.AbsoluteUriCorrected);
            Assert.Null(webUri.AbsoluteUri);
        }
Exemplo n.º 6
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            var other = obj as HostAddress;

            return(other != null && WebUri.IsSameHost(other.WebUri) && ApiUri.IsSameHost(other.ApiUri));
        }
Exemplo n.º 7
0
        public void GoodRequest()
        {
            //Arrange
            var webUri  = new WebUri("https://microsoft.com");
            var request = new Request(webUri);

            //Act
            var response = request.Send();

            //Asset
            Assert.True(response is IStatusOkResponse);
        }
Exemplo n.º 8
0
        public void BadRequest()
        {
            //Arrange
            var webUri  = new WebUri("https://micrasfasfasfasosoftm");
            var request = new Request(webUri);

            //Act
            var response = request.Send();

            //Assert
            Assert.False(response is IStatusOkResponse);
        }
Exemplo n.º 9
0
        public void LinkSearchRowSubDetailTest()
        {
            //Arrange
            var link   = new LinkSearchRowSubDetail();
            var webUri = new WebUri(HOST);

            //Act
            link.Process(firstSearchRow, webUri);

            //Assert
            Assert.Equal(HOST + LINK_1, link.Link);
        }
Exemplo n.º 10
0
        public static async Task MWMS_Rewrite(HttpContext context)
        {
            UrlMapping u1 = new UrlMapping();

            u1.Path = "2222";
            Uri    url = new Uri(context.Request.Scheme + "://" + context.Request.Host + context.Request.Path);
            WebUri u   = new WebUri()
            {
                MainMobileUrl = "",
            };

            u.AddMapping(new UrlMapping()
            {
                Path         = "/acf/",
                PcDomain     = "/pc2/",
                MobileDomain = "/m/"
            });
            u.AddMapping(new UrlMapping()
            {
                Path         = "/",
                PcDomain     = "/",
                MobileDomain = "/m/"
            });
            u.AddMapping(new UrlMapping()
            {
                Path         = "mwms",
                PcDomain     = "www.mwms4.com",
                MobileDomain = "m.mwms4.com"
            });
            RequestUrl requestUrl = u.Build(url, context.Request.Headers["User-Agent"]);

            if (requestUrl.IsMobileBrowser && !requestUrl.IsMobileUrl)
            {
                //跳转至手机地址
            }
            context.Response.WriteAsync("");
        }
Exemplo n.º 11
0
 public override int GetHashCode()
 {
     return((WebUri?.GetHashCode() ?? 0) ^ (ApiUri?.GetHashCode() ?? 0));
 }