Inheritance: System.Web.Services.Protocols.SoapHttpClientProtocol
        /// <summary>
        /// Initialize some variables overridden.
        /// </summary>
        /// <param name="testSite">The instance of ITestSite Class.</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);

            string userName = Common.GetConfigurationPropertyValue("Sender", this.Site);
            string password = Common.GetConfigurationPropertyValue("SenderPassword", this.Site);
            string domain = Common.GetConfigurationPropertyValue("Domain", this.Site);
            string url = Common.GetConfigurationPropertyValue("ServiceUrl", this.Site);

            this.exchangeServiceBinding = new ExchangeServiceBinding(url, userName, password, domain, this.Site);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, this.Site);
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);
            Common.MergeConfiguration(testSite);

            this.username = Common.GetConfigurationPropertyValue("OrganizerName", this.Site);
            this.password = Common.GetConfigurationPropertyValue("OrganizerPassword", this.Site);
            this.domain = Common.GetConfigurationPropertyValue("Domain", this.Site);
            this.url = Common.GetConfigurationPropertyValue("ServiceUrl", this.Site);

            this.exchangeServiceBinding = new ExchangeServiceBinding(this.url, this.username, this.password, this.domain, this.Site);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, this.Site);
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);            
            Site.DefaultProtocolDocShortName = "MS-OXWSMSG";
            Common.MergeConfiguration(testSite);

            this.userName = Common.GetConfigurationPropertyValue("Sender", this.Site);
            this.password = Common.GetConfigurationPropertyValue("SenderPassword", this.Site);
            this.domain = Common.GetConfigurationPropertyValue("Domain", this.Site);
            this.url = Common.GetConfigurationPropertyValue("ServiceUrl", this.Site);

            this.exchangeServiceBinding = new ExchangeServiceBinding(this.url, this.userName, this.password, this.domain, this.Site);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, this.Site);
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function</param>
        public override void Initialize(TestTools.ITestSite testSite)
        {
            base.Initialize(testSite);
            testSite.DefaultProtocolDocShortName = "MS-OXWSATT";
            Common.MergeConfiguration(testSite);

            string userName = Common.GetConfigurationPropertyValue("UserName", testSite);
            string password = Common.GetConfigurationPropertyValue("UserPassword", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string url = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            this.exchangeServiceBinding = new ExchangeServiceBinding(url, userName, password, domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
        }
        /// <summary>
        /// Switch the current user to the new user, with the identity of the new role to communicate with server.
        /// </summary>
        /// <param name="userName">The userName of the user used to communicate with server</param>
        /// <param name="password">The password of the user used to communicate with server</param>
        /// <param name="domain">The domain of the user used to communicate with server</param>
        /// <param name="exchangeServiceBinding">An instance of Service Binding</param>
        /// <param name="site">An instance of ITestSite</param>
        public static void SwitchUser(string userName, string password, string domain, ExchangeServiceBinding exchangeServiceBinding, ITestSite site)
        {
            exchangeServiceBinding.Credentials = new System.Net.NetworkCredential(userName, password, domain);

            // Verify the credential of the exchange service binding.
            bool isVerified = false;
            Uri uri = new Uri(Common.GetConfigurationPropertyValue("ServiceUrl", site));
            NetworkCredential credential = exchangeServiceBinding.Credentials.GetCredential(uri, "basic");
            if (credential.Domain == domain && credential.UserName == userName)
            {
                isVerified = true;
            }

            site.Assert.IsTrue(isVerified, "Service binding should be successful");
        }
        /// <summary>
        /// Log on mailbox with specified user account.
        /// </summary>
        /// <param name="name">Name of the user.</param>
        /// <param name="userPassword">Password of the user.</param>
        /// <param name="userDomain">Domain of the user.</param>
        /// <param name="exchangeServiceBinding">An instance of Service Binding</param>
        /// <param name="site">An instance of ITestSite</param>
        /// <returns>If the user logs on mailbox successfully, return true; otherwise, return false.</returns>
        public static bool SwitchUser(string name, string userPassword, string userDomain, ExchangeServiceBinding exchangeServiceBinding, ITestSite site)
        {
            exchangeServiceBinding.Credentials = new NetworkCredential(name, userPassword, userDomain);

            // Verify the credential of the exchange service binding.
            bool isVerified = false;
            Uri uri = new Uri(Common.GetConfigurationPropertyValue("ServiceUrl", site));
            NetworkCredential credential = exchangeServiceBinding.Credentials.GetCredential(uri, "basic");
            if (credential.Domain == userDomain && credential.UserName == name)
            {
                isVerified = true;
            }

            return isVerified;
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(TestTools.ITestSite testSite)
        {
            // Initialize.
            base.Initialize(testSite);
            Common.MergeConfiguration(testSite);

            // Get the parameters from configuration files.
            string userName = Common.GetConfigurationPropertyValue("OrganizerName", testSite);
            string password = Common.GetConfigurationPropertyValue("OrganizerPassword", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string urlFormat = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            // Initialize service.
            this.exchangeServiceBinding = new ExchangeServiceBinding(urlFormat, userName, password, domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function</param>
        public override void Initialize(ITestSite testSite)
        {          
            base.Initialize(testSite);
            testSite.DefaultProtocolDocShortName = "MS-OXWSCORE";

            Common.MergeConfiguration(testSite);

            string userName = Common.GetConfigurationPropertyValue("User1Name", testSite);
            string password = Common.GetConfigurationPropertyValue("User1Password", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string url = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            this.exchangeServiceBinding = new ExchangeServiceBinding(url, userName, password, domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
            this.itemAdapter = Site.GetAdapter<IMS_OXWSITEMIDAdapter>(); 
        }
        /// <summary>
        /// Implements Microsoft.Protocols.TestTools.IAdapter.Initialize(Microsoft.Protocols.TestTools.ITestSite).
        /// </summary>
        /// <param name="testSite">The test site instance associated with the current adapter.</param>
        public override void Initialize(TestTools.ITestSite testSite)
        {
            base.Initialize(testSite);

            string commonConfigFileName = Common.GetConfigurationPropertyValue("CommonConfigurationFileName", testSite);

            Common.MergeGlobalConfig(commonConfigFileName, testSite);

            string userName = Common.GetConfigurationPropertyValue("UserName", testSite);
            string password = Common.GetConfigurationPropertyValue("UserPassword", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string url = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            this.exchangeServiceBinding = new ExchangeServiceBinding(url, userName, password, domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(TestTools.ITestSite testSite)
        {
            base.Initialize(testSite);
            testSite.DefaultProtocolDocShortName = "MS-OXWSBTRF";

            // Merge common configuration and SHOULD/MAY configuration files
            Common.MergeConfiguration(testSite);

            // Get the parameters from configuration files.
            this.userName = Common.GetConfigurationPropertyValue("UserName", testSite);
            this.password = Common.GetConfigurationPropertyValue("UserPassword", testSite);
            this.domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            this.url = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            this.exchangeServiceBinding = new ExchangeServiceBinding(this.url, this.userName, this.password, this.domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);
            testSite.DefaultProtocolDocShortName = "MS-OXWSTASK";

            // Execute the merge the configuration
            Common.MergeConfiguration(testSite);

            // Get the parameters from configuration files.
            string userName = Common.GetConfigurationPropertyValue("UserName", testSite);
            string password = Common.GetConfigurationPropertyValue("UserPassword", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string url = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);
            this.exchangeServiceBinding = new ExchangeServiceBinding(url, userName, password, domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
            this.exchangeServiceBinding.SoapVersion = SoapProtocolVersion.Soap11;
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(TestTools.ITestSite testSite)
        {
            base.Initialize(testSite);

            // Merge the common configuration into local configuration
            string commonConfigFileName = Common.GetConfigurationPropertyValue("CommonConfigurationFileName", testSite);
            Common.MergeGlobalConfig(commonConfigFileName, testSite);

            // Get the parameters from configuration files.
            string userName = Common.GetConfigurationPropertyValue("Sender", testSite);
            string password = Common.GetConfigurationPropertyValue("SenderPassword", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string urlFormat = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            // initialize service.
            this.exchangeServiceBinding = new ExchangeServiceBinding(urlFormat, userName, password, domain, testSite);

            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
        }
Beispiel #13
0
        /// <summary>
        /// Initialize the ExchangeServiceBinding.
        /// </summary>
        /// <param name="exchangeServiceBinding">An ExchangeServiceBinding instance.</param>
        /// <param name="site">An instance of interface ITestSite which provides logging, assertions, and adapters for test code onto its execution context.</param>
        public static void InitializeServiceBinding(ExchangeServiceBinding exchangeServiceBinding, ITestSite site)
        {
            TransportProtocol transportType = (TransportProtocol)Enum.Parse(typeof(TransportProtocol), Common.GetConfigurationPropertyValue("TransportType", site), true);

            // Avoid closing base connection
            if (transportType == TransportProtocol.HTTPS)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                Common.AcceptServerCertificate();
            }

            exchangeServiceBinding.SoapVersion = SoapProtocolVersion.Soap11;
            SutVersion sutVersion = GetSutVersion(site);

            exchangeServiceBinding.RequestServerVersionValue = new RequestServerVersion();
            switch (sutVersion)
            {
            case SutVersion.ExchangeServer2007:
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
                break;

            case SutVersion.ExchangeServer2010:
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP2;
                break;

            case SutVersion.ExchangeServer2013:
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2013;
                break;

            case SutVersion.ExchangeServer2016:
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2016;
                break;

            case SutVersion.ExchangeServer2019:
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2016;
                break;

            default:
                site.Assert.Fail(@"The SUT version ""{0}"" is invalid, the expected value is ""ExchangeServer2007"", ""ExchangeServer2010"", ""ExchangeServer2013"", ""ExchangeServer2016"" or ""ExchangeServer2019"".", sutVersion);
                break;
            }
        }
        /// <summary>
        /// Overrides IAdapter's Initialize() and sets default protocol short name of the testSite.
        /// </summary>
        /// <param name="testSite">Pass ITestSite to adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(TestTools.ITestSite testSite)
        {
            // Initialize.
            base.Initialize(testSite);

            testSite.DefaultProtocolDocShortName = "MS-OXWSFOLD";

            // Merge the common configuration into local configuration.
            Common.MergeConfiguration(testSite);

            // Get the parameters from configuration files.
            string userName = Common.GetConfigurationPropertyValue("User1Name", testSite);
            string password = Common.GetConfigurationPropertyValue("User1Password", testSite);
            string domain = Common.GetConfigurationPropertyValue("Domain", testSite);
            string urlFormat = Common.GetConfigurationPropertyValue("ServiceUrl", testSite);

            // Initialize service.
            this.exchangeServiceBinding = new ExchangeServiceBinding(urlFormat, userName, password, domain, testSite);
            Common.InitializeServiceBinding(this.exchangeServiceBinding, testSite);
        }
Beispiel #15
0
 /// <summary>
 /// Configure the SOAP header before calling operations.
 /// </summary>
 /// <param name="headerValues">Specify the values for SOAP header.</param>
 /// <param name="exchangeServiceBinding">An ExchangeServiceBinding instance.</param>
 public static void ConfigureSOAPHeader(Dictionary <string, object> headerValues, ExchangeServiceBinding exchangeServiceBinding)
 {
     foreach (KeyValuePair <string, object> soapHeader in headerValues)
     {
         exchangeServiceBinding.GetType().GetProperty(soapHeader.Key).SetValue(
             exchangeServiceBinding,
             Convert.ChangeType(soapHeader.Value, exchangeServiceBinding.GetType().GetProperty(soapHeader.Key).PropertyType),
             null);
     }
 }
        /// <summary>
        /// Overload .NET framework Invoke method to provide extra XML schema validation function.
        /// </summary>
        /// <param name="methodName">The name of the XML Web service method.</param>
        /// <param name="parameters">An array of objects that contains the parameters to pass to the XML Web service. The order of the values in the array corresponds to the order of the parameters in the calling method of the derived class.</param>
        /// <returns>An array of objects that contains the return value and any reference or out parameters of the derived class method.</returns>
        public new object[] Invoke(string methodName, object[] parameters)
        {
            this.rawRequestXml  = null;
            this.rawResponseXml = null;
            WebResponse webResponse = null;
            WebRequest  webRequest  = null;

            object[]      objArray;
            StringBuilder sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
            {
                Assembly        assembly    = Assembly.GetAssembly(typeof(ItemType));
                BaseRequestType requestInfo = (BaseRequestType)parameters[0];
                Type            type        = typeof(BaseRequestType);
                Type[]          types       = assembly.GetTypes();
                foreach (Type t in types)
                {
                    if (requestInfo.GetType().Equals(t))
                    {
                        type = t;
                    }
                }

                // Serialize the request.
                XmlSerializer xs = new XmlSerializer(type);
                xs.Serialize(sw, requestInfo);
            }

            try
            {
                // Creates a WebRequest for the specified uri.
                webRequest = this.GetWebRequest(this.baseURI.GetValue(this, null) as Uri);
                webRequest.PreAuthenticate = true;

                // Check PropertyInfo is null or not.
                Trace.Assert(this.basePendingSyncRequest != null, "PropertyInfo can not be NULL");

                // Sets the value of PendingSyncRequest.
                this.basePendingSyncRequest.SetValue(this, webRequest, null);

                // Invoke method of HttpWebClientProtocol.
                SoapClientMessage message       = this.InstanceInvokeBase("BeforeSerialize", webRequest, methodName, parameters) as SoapClientMessage;
                Stream            requestStream = webRequest.GetRequestStream();
                try
                {
                    Trace.Assert(this.setStream != null, "MethodInfo can not be NULL");
                    this.setStream.Invoke(message, new object[] { requestStream });
                    this.InstanceInvokeBase("Serialize", message);
                }
                finally
                {
                    requestStream.Close();
                }

                // Get the actual request xml by using xmlWriterHookInstance. The xmlWriterHookInstance is appended to the GetWriterForMessage method of the proxy class.
                string requestXmlString = this.xmlWriterHookInstance.Xml.ToString();

                // Load the actual request xml to an XmlElement
                if (!string.IsNullOrEmpty(requestXmlString))
                {
                    XmlDocument xmlDocOfReadRequest = new XmlDocument();
                    xmlDocOfReadRequest.LoadXml(requestXmlString);
                    this.rawRequestXml = xmlDocOfReadRequest.DocumentElement;
                    this.site.Log.Add(LogEntryKind.Debug, "The raw xml request message is:\r\n{0}", ((XmlElement)this.rawRequestXml).OuterXml);
                }

                webResponse = this.GetWebResponse(webRequest);
                HttpWebResponse httpWebResponse = (HttpWebResponse)webResponse;
                if (httpWebResponse.StatusCode != HttpStatusCode.OK)
                {
                    throw new WebException(httpWebResponse.StatusDescription);
                }

                Stream responseStream = null;
                try
                {
                    responseStream = webResponse.GetResponseStream();
                    string streamString = string.Empty;
                    using (StreamReader sr = new StreamReader(responseStream))
                    {
                        responseStream = null;

                        StringBuilder xmlString = new StringBuilder();
                        while (sr.Peek() > -1)
                        {
                            string strInput = sr.ReadLine();
                            xmlString.Append(strInput);
                        }

                        streamString = xmlString.ToString();
                        Trace.TraceInformation(streamString);
                    }

                    using (Stream streamObjRawXmlResponse = new MemoryStream(ASCIIEncoding.Default.GetBytes(streamString)))
                    {
                        XmlDocument responseXml = new XmlDocument();
                        responseXml.LoadXml(streamString);
                        this.rawResponseXml = responseXml.DocumentElement;
                        this.site.Log.Add(LogEntryKind.Debug, "The raw xml response message is:\r\n{0}", ((XmlElement)this.rawResponseXml).OuterXml);

                        objArray = this.InstanceInvoke("ReadResponse", message, webResponse, streamObjRawXmlResponse, false) as object[];

                        // Gets SOAP header from the response.
                        string soapHeader = this.GetSoapElement(responseXml, "Header");

                        // Gets SOAP body from the response.
                        string soapBody = this.GetSoapElement(responseXml, "Body");

                        this.XmlValidater(soapHeader, soapBody);

                        if (ExchangeServiceBinding.ServiceResponseEvent != null)
                        {
                            if (objArray[0] is BaseResponseMessageType)
                            {
                                ExchangeServiceBinding.ServiceResponseEvent(
                                    (BaseRequestType)parameters[0],
                                    (BaseResponseMessageType)objArray[0],
                                    this.IsSchemaValidated);
                            }
                        }
                    }
                }
                catch (XmlException exception)
                {
                    if (exception.Message.Contains("The following elements are not closed"))
                    {
                        throw new InvalidOperationException("The xml is not complete.", exception);
                    }
                    else
                    {
                        throw new InvalidOperationException("WebResponseBadXml", exception);
                    }
                }
                finally
                {
                    if (responseStream != null)
                    {
                        responseStream.Dispose();
                    }
                }
            }
            finally
            {
                if (webRequest == this.basePendingSyncRequest.GetValue(this, null) as WebRequest)
                {
                    if (this.basePendingSyncRequest.CanWrite)
                    {
                        this.basePendingSyncRequest.SetValue(this, null, null);
                    }
                }
            }

            return(objArray);
        }