public void ParseAdd_CallWithNullValue_NothingAdded()
        {
            MockHeaders headers = new MockHeaders();
            HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers);

            collection.ParseAdd(null);
            Assert.Equal(0, collection.Count);
            Assert.Equal(string.Empty, collection.ToString());
        }
        public void ParseAdd_CallWithNullValue_NothingAdded()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers);

            collection.ParseAdd(null);
            Assert.False(collection.IsSpecialValueSet);
            Assert.Equal(0, collection.Count);
            Assert.Equal(String.Empty, collection.ToString());
        }
        public void TryParseAdd_UseSpecialValue_Added()
        {
            MockHeaders headers = new MockHeaders();
            HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers,
                                                                                             specialValue);

            Assert.True(collection.TryParseAdd(specialValue.AbsoluteUri));

            Assert.True(collection.IsSpecialValueSet);
            Assert.Equal(specialValue.ToString(), collection.ToString());
        }
示例#4
0
        /// <summary>
        /// Retrieves OAuth endpoint url. See http://msdn.microsoft.com/en-us/library/dn531009.aspx#bkmk_oauth_discovery for details
        /// </summary>
        /// <returns></returns>
        private async Task <string> DiscoverAuthority()
        {
            string oAuthUrl = null;

            if (string.IsNullOrEmpty(this.ServiceUrl))
            {
                return(null);
            }

            try
            {
                HttpResponseMessage httpResponse = await OrganizationServiceProxy.Current.DiscoverAuthority(this.ServiceUrl);

                HttpHeaderValueCollection <AuthenticationHeaderValue> wwwAuthenticateHeaderValueCollection = httpResponse.Headers.WwwAuthenticate;
                if (wwwAuthenticateHeaderValueCollection != null)
                {
                    // Sample
                    // Production:     Bearer authorization_uri=https://login.windows.net/00000000-0000-0000-0000-000000000000/oauth2/authorize
                    // Pre-production: Bearer authorization_uri=https://login.windows-ppe.net/00000000-0000-0000-0000-000000000000/oauth2/authorize, resource_id = https://xxxxxxxxxxxx.crm.crmlivetie.com/
                    string wwwAuthenticateHeader = wwwAuthenticateHeaderValueCollection.ToString().Replace("Bearer", "").Trim();
                    string authorizationUriToken = wwwAuthenticateHeader.Split(',').FirstOrDefault(p => p.Trim().StartsWith("authorization_uri")).Trim();

                    // For phone, we don't need oauth2/authorize part
                    oAuthUrl = authorizationUriToken.Substring("authorization_uri=".Length, authorizationUriToken.Length - "oauth2/authorize".Length - "authorization_uri=".Length);
                }
                else
                {
                    oAuthUrl = null;
                }
            }
            catch
            {
#if DEBUG
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
#endif
                oAuthUrl = null;
            }

            return(oAuthUrl);
        }
        public void TryParseAdd_UseSpecialValue_Added()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            Assert.True(collection.TryParseAdd(specialValue.AbsoluteUri));

            Assert.True(collection.IsSpecialValueSet);
            Assert.Equal(specialValue.ToString(), collection.ToString());
        }
        public void ParseAdd_CallWithNullValue_NothingAdded()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            collection.ParseAdd(null);
            Assert.False(collection.IsSpecialValueSet);
            Assert.Equal(0, collection.Count);
            Assert.Equal(String.Empty, collection.ToString());
        }