Esempio n. 1
0
        public async Task GetUserTest()
        {
            IGraphServiceUsersCollectionPage users = new GraphServiceUsersCollectionPage();

            for (int i = 0; i < 3; i++)
            {
                var user = new User()
                {
                    DisplayName = "Conf Room" + i,
                };

                users.Add(user);
            }

            for (int i = 0; i < 12; i++)
            {
                var user = new User()
                {
                    DisplayName = "TestUser" + i,
                };

                users.Add(user);
            }

            var mockGraphServiceClient = new MockGraphServiceClient
            {
                Users = users
            };

            mockGraphServiceClient.SetMockBehavior();

            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphUserService  userService   = new MSGraphUserService(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            var result = await userService.GetUserAsync("test");

            // Test get 0-10 user per page
            Assert.IsTrue(result.Count >= 1);
            Assert.IsTrue(result.Count <= 10);

            // "Conf Room" is filtered
            foreach (var user in result)
            {
                Assert.IsFalse(user.DisplayName.StartsWith("Conf Room"));
            }
        }
Esempio n. 2
0
        private IGraphServiceUsersCollectionPage GetUsersCollectionPage()
        {
            IGraphServiceUsersCollectionPage users = new GraphServiceUsersCollectionPage();

            foreach (var user in _users)
            {
                users.Add(user);
            }
            return(users);
        }
        static MockMSGraphUserClient()
        {
            mockMsGraphUserService = new Mock <IGraphServiceClient>();
            mockMsGraphUserService.Setup(service => service.Users.Request(It.IsAny <List <QueryOption> >()).GetAsync()).Returns(() =>
            {
                IGraphServiceUsersCollectionPage result = new GraphServiceUsersCollectionPage();

                User user = new User()
                {
                    DisplayName       = "Jane Doe",
                    GivenName         = "Jane",
                    Surname           = "Doe",
                    UserPrincipalName = "Jane Doe",
                    Mail = "*****@*****.**"
                };
                result.Add(user);

                user = new User()
                {
                    DisplayName       = "John Doe",
                    GivenName         = "John",
                    Surname           = "Doe",
                    UserPrincipalName = "John Doe",
                    Mail = "*****@*****.**"
                };
                result.Add(user);

                user = new User()
                {
                    DisplayName = "Conf Room Test",
                    Mail        = "*****@*****.**"
                };
                result.Add(user);

                return(Task.FromResult(result));
            });
            mockMsGraphUserService.Setup(service => service.Me.Contacts.Request(It.IsAny <List <QueryOption> >()).GetAsync()).Returns(() =>
            {
                IUserContactsCollectionPage result = new UserContactsCollectionPage();

                List <EmailAddress> emailAddresses = new List <EmailAddress>
                {
                    new EmailAddress()
                    {
                        Address = "*****@*****.**"
                    }
                };
                Contact contact = new Contact()
                {
                    DisplayName    = "Jane Doe",
                    GivenName      = "Jane",
                    Surname        = "Doe",
                    EmailAddresses = emailAddresses
                };
                result.Add(contact);

                emailAddresses = new List <EmailAddress>
                {
                    new EmailAddress()
                    {
                        Address = "*****@*****.**"
                    }
                };
                contact = new Contact()
                {
                    DisplayName    = "John Doe",
                    GivenName      = "John",
                    Surname        = "Doe",
                    EmailAddresses = emailAddresses
                };
                result.Add(contact);

                emailAddresses = new List <EmailAddress>
                {
                    new EmailAddress()
                    {
                        Address = "*****@*****.**"
                    }
                };
                contact = new Contact()
                {
                    DisplayName    = "Conf Room Test",
                    EmailAddresses = emailAddresses
                };
                result.Add(contact);

                return(Task.FromResult(result));
            });
            mockMsGraphUserService.Setup(service => service.Me.People.Request(It.IsAny <List <QueryOption> >()).GetAsync()).Returns(() =>
            {
                IUserPeopleCollectionPage result = new UserPeopleCollectionPage();

                List <ScoredEmailAddress> emailAddresses = new List <ScoredEmailAddress>
                {
                    new ScoredEmailAddress()
                    {
                        Address = "*****@*****.**", RelevanceScore = 1
                    }
                };
                Person person = new Person()
                {
                    DisplayName          = "Jane Doe",
                    GivenName            = "Jane",
                    Surname              = "Doe",
                    UserPrincipalName    = "Jane Doe",
                    ScoredEmailAddresses = emailAddresses
                };
                result.Add(person);

                emailAddresses = new List <ScoredEmailAddress>
                {
                    new ScoredEmailAddress()
                    {
                        Address = "*****@*****.**", RelevanceScore = 1
                    }
                };
                person = new Person()
                {
                    DisplayName          = "John Doe",
                    GivenName            = "John",
                    Surname              = "Doe",
                    UserPrincipalName    = "John Doe",
                    ScoredEmailAddresses = emailAddresses
                };
                result.Add(person);

                emailAddresses = new List <ScoredEmailAddress>
                {
                    new ScoredEmailAddress()
                    {
                        Address = "*****@*****.**", RelevanceScore = 1
                    }
                };
                person = new Person()
                {
                    DisplayName          = "Conf Room Test",
                    ScoredEmailAddresses = emailAddresses
                };
                result.Add(person);

                return(Task.FromResult(result));
            });
        }