public void AuthorizeUser_ShouldReturnWindowsLiveLoginUrl_WhenRequestUrlHasNoOAuthCode()
        {
            // Prepare
            HttpResponseMessage httpResponseMessage = null;
            using (ShimsContext.Create())
            {
                ShimHttpContext.CurrentGet = () => new ShimHttpContext();

                var httpRequest = new ShimHttpRequest();
                ShimHttpContext.AllInstances.RequestGet = httpContext => httpRequest;

                NameValueCollection queryStringCollection = new NameValueCollection();
                ShimHttpRequest.AllInstances.QueryStringGet = hr => queryStringCollection;

                ShimDiagnosticsProvider.AllInstances.WriteInformationTraceTraceEventIdString = (diagnosticsProvider, traceEventId, message) => { };

                var windowsLiveAuthorizationController = new WindowsLiveAuthorizationController();
                windowsLiveAuthorizationController.Request = new HttpRequestMessage(HttpMethod.Get, string.Empty);

                ShimHttpRequestMessageExtensions.GetQueryNameValuePairsHttpRequestMessage = httpRequestMessage =>
                {
                    var queryNameValuePairs = new List<KeyValuePair<string, string>>();
                    queryNameValuePairs.Add(new KeyValuePair<string, string>("callBackUrl", "somecallBackUrl"));
                    return queryNameValuePairs;
                };

                // Perform
                httpResponseMessage = windowsLiveAuthorizationController.AuthorizeUser();
            }

            // Assert
            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.Moved, "Stataus is not as expected(Moved)");
            Assert.AreEqual("https://login.live.com/oauth20_authorize.srf?client_id=00000000400ED482&scope=wl.skydrive_update+wl.offline_access&response_type=code&redirect_uri=http:%2f%2fdev-api-dataonboarding.cloudapp.net%2fapi%2fwindowsLiveAuthorization%2fAuthorizeUser%3fcallBackUrl%3dsomecallBackUrl",
                httpResponseMessage.Headers.Location.ToString());
        }
Example #2
0
        public void Setup()
        {
            _context = ShimsContext.Create();
            ShimWebControl.AllInstances.StyleGet = (x) =>
            {
                return(CreateCssStyleCollection());
            };
            ShimHttpCapabilitiesBase.AllInstances.BrowserGet = (x) => "IE";
            HttpRequest request = new ShimHttpRequest
            {
                BrowserGet = () => new HttpBrowserCapabilities()
            };

            ShimControl.AllInstances.PageGet = (x) =>
            {
                Page page = new ShimPage
                {
                    RequestGet      = () => request,
                    ClientScriptGet = () =>
                    {
                        return(new ShimClientScriptManager
                        {
                            GetWebResourceUrlTypeString = (type, ressourceName) => { return SampleImagePath; }
                        });
                    }
                };
                return(page);
            };
        }
Example #3
0
        public void OneTimeSetUp()
        {
            _shimsContext = ShimsContext.Create();
            ShimUserControl.AllInstances.RequestGet     = (userControl) => { return(_httpRequest); };
            ShimHttpRequest.AllInstances.QueryStringGet = (request) => { return(_queryStringCollection); };

            _shimHttpRequest        = new ShimHttpRequest();
            _emailProfileBaseObject = new emailProfile_base();
            _httpRequest            = _shimHttpRequest.Instance;
        }
Example #4
0
        private ShimPage GetMockOfPage(string browser)
        {
            var shimPage                    = new ShimPage();
            var shimHttpRequest             = new ShimHttpRequest();
            var shimHttpBrowserCapabilities = new ShimHttpBrowserCapabilities();

            ShimHttpCapabilitiesBase.AllInstances.BrowserGet = (obj) => browser;
            ShimHttpRequest.AllInstances.BrowserGet          = (obj) => shimHttpBrowserCapabilities.Instance;
            ShimPage.AllInstances.RequestGet      = (obj) => shimHttpRequest.Instance;
            ShimPage.AllInstances.ClientScriptGet = (obj) => new ShimClientScriptManager().Instance;
            ShimClientScriptManager.AllInstances.GetWebResourceUrlTypeString = (obj, type, url) => DummyString;
            return(shimPage);
        }
        public void AuthorizeUser_ShouldReturnWindowsLiveTokens_WhenRequestUrlHasOAuthCode()
        {
            // Prepare
            HttpResponseMessage httpResponseMessage = null;
            using (ShimsContext.Create())
            {
                ShimHttpContext.CurrentGet = () => new ShimHttpContext();

                var httpRequest = new ShimHttpRequest();
                ShimHttpContext.AllInstances.RequestGet = httpContext => httpRequest;

                NameValueCollection queryStringCollection = new NameValueCollection();
                ShimHttpRequest.AllInstances.QueryStringGet = hr => queryStringCollection;
                //TODO Ram
               queryStringCollection.Add(SkyDriveConstants.OAuth_Code, "SomeCode");

                ShimDiagnosticsProvider.AllInstances.WriteInformationTraceTraceEventIdString = (diagnosticsProvider, traceEventId, message) => { };

                var windowsLiveAuthorizationController = new WindowsLiveAuthorizationController();
                windowsLiveAuthorizationController.Request = new HttpRequestMessage(HttpMethod.Post, string.Empty);

                ShimHttpRequestMessageExtensions.GetQueryNameValuePairsHttpRequestMessage = httpRequestMessage =>
                {
                    var queryNameValuePairs = new List<KeyValuePair<string, string>>();
                    queryNameValuePairs.Add(new KeyValuePair<string, string>(SkyDriveConstants.OAuth_Code, "somecode"));
                    queryNameValuePairs.Add(new KeyValuePair<string, string>("callBackUrl", "http://dev-api-dataonboarding.cloudapp.net/api/windowsLiveAuthorization/AuthorizeUser"));
                    return queryNameValuePairs;
                };

                ShimWindowsLiveAuthorizationController.AllInstances.GetWindowsLiveTokensStringString = (wlac, code, redirectUrl) =>
                    new OAuthToken()
                    {
                        AccessToken = "AccessToken",
                        AuthenticationToken = "AuthenticationToken",
                        ExpiresIn = "ExpiresIn",
                        RefreshToken = "RefreshToken",
                        Scope = "Scope",
                        TokenExpiresOn = new DateTime(2013, 8, 15)
                    };

                // Perform
                httpResponseMessage = windowsLiveAuthorizationController.AuthorizeUser();
            }

            // Assert
            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.Moved, "Stataus is not as expected(Moved)");
            Assert.AreEqual("http://dev-api-dataonboarding.cloudapp.net/api/windowsLiveAuthorization/AuthorizeUser?accessToken=AccessToken&refreshToken=RefreshToken&tokenExpiresOn=8/15/2013 12:00:00 AM",
                httpResponseMessage.Headers.Location.ToString());
        }
        public void OneTimeSetUp()
        {
            _shimsContext = ShimsContext.Create();
            ShimUserControl.AllInstances.RequestGet     = (userControl) => { return(_httpRequest); };
            ShimHttpRequest.AllInstances.QueryStringGet = (request) => { return(_queryStringCollection); };
            ShimSqlConnection.Constructor           = (sqlConnection) => { };
            ShimSqlConnection.ConstructorString     = (sqlConnection, connString) => { };
            ShimSqlConnection.AllInstances.Open     = (sqlConnection) => { _connectionState = ConnectionState.Open; };
            ShimSqlConnection.AllInstances.Close    = (sqlConnection) => { _connectionState = ConnectionState.Closed; };
            ShimSqlConnection.AllInstances.StateGet = (sqlConnection) => { return(_connectionState); };

            _shimHttpRequest = new ShimHttpRequest();
            _emailProfileUDFHistoryObject = new emailProfile_UDFHistory();
            _httpRequest = _shimHttpRequest.Instance;
        }
Example #7
0
        private void SetupForPageLoad()
        {
            var requestFormCollection = new Dictionary <string, string>()
            {
                ["Server"]   = RequestServer,
                ["DB"]       = RequestDb,
                ["Username"] = RequestUserName,
                ["Password"] = RequestPassword,
                ["WEBAPP"]   = RequestWebApp
            };

            var shimHttpServerUtility = new ShimHttpServerUtility();
            var shimHttpRequest       = new ShimHttpRequest();

            shimHttpRequest.ItemGetString =
                key => requestFormCollection.ContainsKey(key)
                       ? requestFormCollection[key]
                       : string.Empty;

            ShimPage.AllInstances.ServerGet  = _ => shimHttpServerUtility;
            ShimPage.AllInstances.RequestGet = _ => shimHttpRequest;

            var shimSpApplicationPool = new ShimSPApplicationPool();
            var shimSpProcessIdentity = new ShimSPProcessIdentity(shimSpApplicationPool);

            shimSpProcessIdentity.UsernameGet = () => ApplicationPoolUserName;

            var shimSpWebApplication = new ShimSPWebApplication();

            shimSpWebApplication.ApplicationPoolGet = () => shimSpApplicationPool;

            var shimSpWebApplicationCollection  = new ShimSPWebApplicationCollection();
            var shimSpPersistedObjectCollection = new ShimSPPersistedObjectCollection <SPWebApplication>(shimSpWebApplicationCollection);

            shimSpPersistedObjectCollection.ItemGetGuid = _ => shimSpWebApplication;

            var shimSpWebService = new ShimSPWebService();

            shimSpWebService.WebApplicationsGet = () => shimSpWebApplicationCollection;
            ShimSPWebService.ContentServiceGet  = () => shimSpWebService;
        }
Example #8
0
        private ShimPage GetMockOfPage(string browser)
        {
            var shimPage                    = new ShimPage();
            var shimHttpRequest             = new ShimHttpRequest();
            var shimHttpBrowserCapabilities = new ShimHttpBrowserCapabilities();

            ShimHttpCapabilitiesBase.AllInstances.BrowserGet = (obj) => browser;
            ShimHttpRequest.AllInstances.BrowserGet          = (obj) => shimHttpBrowserCapabilities.Instance;
            ShimPage.AllInstances.RequestGet      = (obj) => shimHttpRequest.Instance;
            ShimPage.AllInstances.ClientScriptGet = (obj) => new ShimClientScriptManager().Instance;
            ShimClientScriptManager.AllInstances.GetWebResourceUrlTypeString = (obj, type, url) => DummyString;
            ShimHttpRequest.AllInstances.ParamsGet = (obj) =>
            {
                var collection = new NameValueCollection();
                collection.Add("__EVENTARGUMENT", "DELETEFILE:");
                return(collection);
            };
            ShimNameObjectCollectionBase.AllInstances.CountGet = (obj) => 1;
            ShimHttpRequest.AllInstances.FilesGet     = (obj) => new ShimHttpFileCollection();
            ShimPage.AllInstances.TraceGet            = (obj) => new TraceContext(new ShimHttpContext());
            ShimTraceContext.AllInstances.WriteString = (obj, str) => { };
            return(shimPage);
        }