/// <summary>
        /// Initializes a new instance of the <see cref="SPOEmulationContext"/> class.
        /// </summary>
        /// <param name="isolationLevel">The level.</param>
        /// <param name="connectionInformation">The connection informations for the target web.</param>
        public SPOEmulationContext(IsolationLevel isolationLevel, ConnectionInformation connectionInformation)
        {
            this._isolationLevel = isolationLevel;

            switch (isolationLevel)
            {
                case IsolationLevel.Fake:
                    // create shim context
                    _shimsContext = ShimsContext.Create();

                    // initialize all simulated types
                    _clientContext = InitializeSimulatedAPI(connectionInformation.Url);
                    break;
                case IsolationLevel.Integration:
                    // create shim context
                    _shimsContext = ShimsContext.Create();
                    Connect(connectionInformation);
                    break;
                case IsolationLevel.None:
                    Connect(connectionInformation);
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }
        private void Connect(ConnectionInformation connectionInformation)
        {
            try
            {
                _clientContext = new ClientContext(connectionInformation.Url.AbsoluteUri);

                if (!string.IsNullOrWhiteSpace(connectionInformation.UserName))
                {
                    if (connectionInformation.ConnectionType == ConnectionType.O365)
                    {
                        _clientContext.Credentials = new SharePointOnlineCredentials(connectionInformation.UserName, connectionInformation.Password);
                    }
                    else
                    {
                        _clientContext.Credentials = new NetworkCredential(connectionInformation.UserName, connectionInformation.Password);
                    }
                }

                _clientContext.ExecuteQuery();
            }
            catch (Exception ex)
            {
                var msg = "Error connecting to the {0} site {1} with the given credentials. {2}";
                var format = string.Format(msg, connectionInformation.ConnectionType, connectionInformation.Url.AbsoluteUri, ex.Message);
                throw new InvalidOperationException(format);
            }
        }