public void Setup() { this.appConfig = new AppConfig(); this.authenticationProvider = new MockAuthenticationProvider(); this.authenticationProvider.Setup(provider => provider.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession())); this.authenticationProvider.Setup(provider => provider.AppendAuthHeaderAsync(It.IsAny<HttpRequestMessage>())).Returns(Task.FromResult(0)); this.credentialCache = new MockCredentialCache(); this.serializer = new MockSerializer(); this.httpResponseMessage = new HttpResponseMessage(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.serviceInfo = new ServiceInfo { AuthenticationProvider = this.authenticationProvider.Object, }; this.serviceInfoProvider = new MockServiceInfoProvider(this.serviceInfo); this.webUi = new MockWebAuthenticationUi(); this.oneDriveClient = new OneDriveClient( this.appConfig, this.credentialCache.Object, this.httpProvider.Object, this.serviceInfoProvider.Object) { BaseUrl = string.Format(Constants.Authentication.OneDriveConsumerBaseUrlFormatString, "v1.0"), ServiceInfo = this.serviceInfo, }; }
public void Setup() { this.credentialCache = new MockAdalCredentialCache(); this.httpResponseMessage = new HttpResponseMessage(); this.serializer = new MockSerializer(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.authenticationProvider = new MockAuthenticationProvider(); this.authenticationProvider.Setup(provider => provider.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession())); }
public void Setup() { this.authenticationProvider = new MockAuthenticationProvider(); this.serializer = new MockSerializer(); this.httpResponseMessage = new HttpResponseMessage(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.oneDriveClient = new OneDriveClient( "https://api.onedrive.com/v1.0", this.authenticationProvider.Object, this.httpProvider.Object); }
public void Setup() { this.authenticationProvider = new MockAuthenticationProvider(); this.serializer = new MockSerializer(); this.httpResponseMessage = new HttpResponseMessage(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.oneDriveClient = new Mock<IOneDriveClient>(MockBehavior.Strict); this.oneDriveClient.SetupAllProperties(); this.oneDriveClient.SetupGet(client => client.AuthenticationProvider).Returns(this.authenticationProvider.Object); this.oneDriveClient.Setup(client => client.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession())); this.oneDriveClient.SetupGet(client => client.HttpProvider).Returns(this.httpProvider.Object); this.progress = new MockProgress(); this.asyncMonitor = new ItemCopyAsyncMonitor(this.oneDriveClient.Object, AsyncMonitorTests.monitorUrl); }
public virtual void Setup() { this.httpResponseMessage = new HttpResponseMessage(); this.credentialCache = new MockCredentialCache(); this.serializer = new MockSerializer(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.webUi = new MockWebUi(); this.serviceInfo = new ServiceInfo { AppId = "12345", AuthenticationServiceUrl = "https://login.live.com/authenticate", CredentialCache = this.credentialCache.Object, HttpProvider = this.httpProvider.Object, ReturnUrl = "https://login.live.com/return", Scopes = new string[] { "scope1", "scope2" }, SignOutUrl = "https://login.live.com/signout", TokenServiceUrl = "https://login.live.com/token", WebAuthenticationUi = this.webUi.Object }; }
public async Task GetAccountSessionAsync_ReturnUri() { const string code = "code"; const string token = "token"; this.serviceInfo.ReturnUrl = "https://login.live.com/returnUrl"; this.signOut = false; this.webAuthenticationUi.responseValues = new Dictionary<string, string> { { Constants.Authentication.CodeKeyName, code } }; this.webAuthenticationUi.OnAuthenticateAsync = (Uri requestUri, Uri callbackUri) => { Assert.IsTrue(requestUri.ToString().Contains("response_type=code"), "Unexpected request Uri."); Assert.IsTrue(callbackUri.ToString().Equals(this.serviceInfo.ReturnUrl), "Unexpected callback Uri."); }; using (var httpResponseMessage = new HttpResponseMessage()) using (var responseStream = new MemoryStream()) using (var streamContent = new StreamContent(responseStream)) { httpResponseMessage.Content = streamContent; var mockSerializer = new MockSerializer(); mockSerializer.OnDeserializeObjectStream = (Stream stream) => { mockSerializer.DeserializeObjectResponse = new Dictionary<string, string> { { Constants.Authentication.AccessTokenKeyName, token } }; }; this.serviceInfo.HttpProvider = new MockHttpProvider(httpResponseMessage, mockSerializer) { OnSendAsync = (HttpRequestMessage requestMessage) => { Assert.IsTrue(requestMessage.RequestUri.ToString().Equals(this.serviceInfo.TokenServiceUrl), "Unexpected token request URL."); } }; var accountSession = await this.authenticationProvider.GetAccountSessionAsync(); Assert.IsNotNull(accountSession, "No account session returned."); Assert.AreEqual(token, accountSession.AccessToken, "Unexpected token returned."); } }