protected override void OnValidate()

in src/Microsoft.Azure.NotificationHubs/AdmCredential.cs [153:203]


        protected override void OnValidate(bool allowLocalMockPns)
        {
            if (Properties == null ||
                (string.IsNullOrEmpty(Properties[ClientIdName]) && string.IsNullOrEmpty(Properties[ClientSecretName])))
            {
                throw new InvalidDataContractException(string.Format(SRClient.RequiredPropertiesNotSpecified, RequiredPropertiesList));
            }

            if (string.IsNullOrEmpty(Properties[ClientIdName]))
            {
                throw new InvalidDataContractException(string.Format(SRClient.RequiredPropertyNotSpecified, ClientIdName));
            }

            if (string.IsNullOrEmpty(Properties[ClientSecretName]))
            {
                throw new InvalidDataContractException(string.Format(SRClient.RequiredPropertyNotSpecified, ClientSecretName));
            }

            if (Properties.Count > 2 &&
                Properties.Count > Properties.Keys.Intersect(
                    new[] { ClientIdName, ClientSecretName, SendUrlTemplateName, AuthTokenUrlName }).Count())
            {
                throw new InvalidDataContractException(string.Format(SRClient.OnlyNPropertiesRequired, 2, RequiredPropertiesList));
            }

            Uri uri;

            if (!Uri.TryCreate(AuthTokenUrl, UriKind.Absolute, out uri) || (
                !string.Equals(AuthTokenUrl, ProdAuthTokenUrl, StringComparison.OrdinalIgnoreCase) &&
                !string.Equals(AuthTokenUrl, MockIntAuthTokenUrl, StringComparison.OrdinalIgnoreCase) &&
                !(allowLocalMockPns && string.Equals(AuthTokenUrl, MockAuthTokenUrl, StringComparison.OrdinalIgnoreCase))))
            {
                throw new InvalidDataContractException(SRClient.InvalidAdmAuthTokenUrl);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(SendUrlTemplate) ||
                    !Uri.TryCreate(string.Format(CultureInfo.InvariantCulture, SendUrlTemplate, "AdmRegistrationId"), UriKind.Absolute, out uri) ||
                    (!string.Equals(SendUrlTemplate, ProdSendUrlTemplate, StringComparison.OrdinalIgnoreCase) &&
                     !string.Equals(SendUrlTemplate, MockIntSendUrlTemplate, StringComparison.OrdinalIgnoreCase) &&
                     !(allowLocalMockPns && string.Equals(SendUrlTemplate, MockSendUrlTemplate, StringComparison.OrdinalIgnoreCase))))
                {
                    throw new InvalidDataContractException(SRClient.InvalidAdmSendUrlTemplate);
                }
            }
            catch (FormatException)
            {
                throw new InvalidDataContractException(SRClient.InvalidAdmSendUrlTemplate);
            }
        }