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.appConfig = new BusinessAppConfig
     {
         ActiveDirectoryAppId = "12345",
         ActiveDirectoryReturnUrl = "https://localhost/return",
         ActiveDirectoryServiceResource = "https://resource/",
     };
     
     this.credentialCache = new MockAdalCredentialCache();
     this.httpProvider = new MockHttpProvider(null);
     this.serviceInfoProvider = new AdalServiceInfoProvider { UserSignInName = "12345" };
 }
        public void Setup()
        {
            this.appConfig = new AppConfig
            {
                MicrosoftAccountAppId = "12345",
                MicrosoftAccountClientSecret = "secret",
                MicrosoftAccountReturnUrl = "https://localhost/return",
                MicrosoftAccountScopes = new string[] { "scope" }
            };

            this.credentialCache = new MockCredentialCache();
            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage);
            this.webAuthenticationUi = new MockWebUi();
            this.serviceInfoProvider = new ServiceInfoProvider(this.webAuthenticationUi.Object);
        }
        public virtual void Setup()
        {
            this.credentialCache = new MockAdalCredentialCache();
            this.httpResponseMessage = new HttpResponseMessage();
            this.serializer = new Serializer();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer);

            this.serviceInfo = new ActiveDirectoryServiceInfo
            {
                AppId = "12345",
                AuthenticationServiceUrl = "https://login.live.com/authenticate",
                CredentialCache = this.credentialCache.Object,
                HttpProvider = this.httpProvider.Object,
                ReturnUrl = "https://login.live.com/return",
                SignOutUrl = "https://login.live.com/signout",
                TokenServiceUrl = "https://login.live.com/token"
            };
        }
        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 ProvidesCorrectApiHeaders()
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(string.Empty)));

                // Act
                await Service.GetBasicAsync();

                // Assert
                const string expectedKey   = "x-api-version";
                const string expectedValue = "2";

                MockHttpProvider
                .Verify(http => http.GetAsync(It.IsAny <string>(), It.Is <IDictionary <string, string> >
                                              (
                                                  response =>
                                                  response[expectedKey] != null &&
                                                  response[expectedKey] == expectedValue
                                              )));
            }
        public void Setup()
        {
            this.credentialCache     = new MockAdalCredentialCache();
            this.httpResponseMessage = new HttpResponseMessage();
            this.serializer          = new Serializer();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer);
            this.webAuthenticationUi = new MockWebAuthenticationUi();

            this.serviceInfo = new ActiveDirectoryServiceInfo
            {
                AppId = "12345",
                AuthenticationServiceUrl = "https://login.live.com/authenticate",
                CredentialCache          = this.credentialCache,
                HttpProvider             = this.httpProvider,
                ReturnUrl           = "https://login.live.com/return",
                SignOutUrl          = "https://login.live.com/signout",
                TokenServiceUrl     = "https://login.live.com/token",
                WebAuthenticationUi = this.webAuthenticationUi
            };

            this.authenticationProvider = new AdalAuthenticationProvider(this.serviceInfo);
        }
示例#11
0
        public async Task GetChanges_ReturnsCorrectDerivedClasses()
        {
            // ARRANGE
            var responseContent = ResourceManager.GetHttpResponseContent("GetChangesResponse.json");
            var responseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(responseContent),
            };
            var query = new ChangeQuery()
            {
                Add = true
            };

            var mockAuthProvider   = new MockAuthenticationProvider();
            var mockHttpProvider   = new MockHttpProvider(responseMessage, new Serializer());
            var graphServiceClient = new GraphServiceClient(mockAuthProvider.Object, mockHttpProvider.Object);

            // ACT
            var response = await graphServiceClient
                           .SharePointAPI(mockWebUrl)
                           .Web
                           .Request()
                           .GetChangesAsync(query);

            var actual = response.CurrentPage;

            responseMessage.Dispose();

            // ASSERT
            Assert.Equal(5, actual.Count);
            Assert.IsType <ChangeSite>(actual[0]);
            Assert.IsType <ChangeUser>(actual[1]);
            Assert.IsType <ChangeItem>(actual[2]);
            Assert.IsType <ChangeWeb>(actual[3]);
            Assert.IsType <ChangeList>(actual[4]);
        }
        public void MeEndpoint_GetMeInfo_MemberOf()
        {
            var              sth              = JsonConvert.DeserializeObject("{\"@odata.type\": \"#microsoft.graph.group\"}");
            string           requestUrl       = "https://graph.microsoft.com/v1.0/me/memberOf";
            MockHttpProvider mockHttpProvider = new MockHttpProvider();

            mockHttpProvider.Responses.Add("GET:" + requestUrl, new
            {
                value = new List <object>()
                {
                    new {
                        id = "d17a5f86-57f4-48f8-87a0-79761dc8e706",
                        createdDateTime = "2017-07-31T17:36:25Z",
                        description     = "Fashion events Channel ... everything you need to know all in one place. Announcements, Events, Information, and News.",
                        displayName     = "Fashion Events",
                        groupTypes      = new string[] { "Unified" },
                        mail            = "*****@*****.**",
                        mailEnabled     = true,
                        mailNickname    = "FashionEvents",
                        proxyAddresses  = new string[] {
                            "SMTP:[email protected]",
                            "SPO:SPO_c1e5444e-12d8-43d3-96b1-f2f66559ef58@SPO_dcd219dd-bc68-4b9b-bf0b-4a33a796be35"
                        },
                        renewedDateTime    = "2017-07-31T17:36:25Z",
                        securityEnabled    = true,
                        securityIdentifier = "S-1-12-1-3514457990-1224234996-1987682439-115853341",
                        visibility         = "Public"
                    }
                }
            });
            GraphServiceClient client = new GraphServiceClient(new MockAuthenticationHelper(), mockHttpProvider);
            var response = client.Me.MemberOf.Request().GetAsync().Result;

            Assert.AreEqual("d17a5f86-57f4-48f8-87a0-79761dc8e706", response.FirstOrDefault().Id);
            Assert.AreEqual("Fashion Events", response.FirstOrDefault().AdditionalData["displayName"].ToString());
        }
示例#13
0
        public void GraphListItemProvider_Test_GetListItems()
        {
            //Arrage
            DateTime         createdDate      = DateTime.Now.AddDays(-10);
            DateTime         modifiedDate     = DateTime.Now.AddDays(-5);
            MockHttpProvider mockHttpProvider = new MockHttpProvider();

            mockHttpProvider.Responses.Add("GET:https://graph.microsoft.com/v1.0/sites/test-site-id/lists/test-list-id/items?$filter=AuthorLookupId eq '10'&$expand=fields", new ListItemsCollectionResponse()
            {
                Value = new ListItemsCollectionPage()
                {
                    new ListItem()
                    {
                        ContentType = new ContentTypeInfo()
                        {
                            Id = "0x01"
                        },
                        Id     = "10",
                        Fields = new FieldValueSet()
                        {
                            AdditionalData = new Dictionary <string, object>()
                            {
                                { "AuthorLookupId", 10 },
                                { "EditorLookupId", 11 },
                                { "Created", createdDate },
                                { "Modified", modifiedDate }
                            }
                        },
                        CreatedBy = new IdentitySet()
                        {
                            User = new Identity()
                            {
                                Id             = "test-author-id",
                                DisplayName    = "Test Author",
                                AdditionalData = new Dictionary <string, object>()
                                {
                                    { "email", "*****@*****.**" }
                                }
                            }
                        },
                        LastModifiedBy = new IdentitySet()
                        {
                            User = new Identity()
                            {
                                Id             = "test-editor-id",
                                DisplayName    = "Test Editor",
                                AdditionalData = new Dictionary <string, object>()
                                {
                                    { "email", "*****@*****.**" }
                                }
                            }
                        },
                    }
                }
            });

            //Act
            GraphServiceClient client = new GraphServiceClient(new MockAuthenticationHelper(), mockHttpProvider);
            GraphListItemProvider <SPListItem> listItemProvider = new GraphListItemProvider <SPListItem>("test-site-id", client);


            IEnumerable <SPListItem> listItems = listItemProvider.GetListItems("test-list-id", "AuthorLookupId eq '10'");

            //Assert
            SPListItem item = listItems.FirstOrDefault();

            Assert.AreEqual(10, item.Id);
            Assert.AreEqual("test-author-id", item.Author.Id);
            Assert.AreEqual(10, item.Author.SPId);
            Assert.AreEqual(11, item.Editor.SPId);
            Assert.AreEqual(createdDate, item.Created);
        }