public IUserService InitUserService(string token, EventSource source)
        {
            if (token == null)
            {
                throw new Exception("API token is null");
            }

            IUserService userService = null;

            switch (source)
            {
            case EventSource.Microsoft:
                var serviceClient = GraphClient.GetAuthenticatedClient(token);
                userService = new MSGraphUserService(serviceClient);
                break;

            case EventSource.Google:
                var googleClient       = GoogleClient.GetGoogleClient(_settings);
                var googlePeopleClient = GooglePeopleService.GetServiceClient(googleClient, token);
                userService = new GooglePeopleService(googlePeopleClient);
                break;

            default:
                throw new Exception("Event Type not Defined");
            }

            return(new UserService(userService));
        }
Exemplo n.º 2
0
        public IUserService InitUserService(string token, TimeZoneInfo timeZoneInfo, MailSource source)
        {
            var mockGraphServiceClient        = new MockGraphServiceClient();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphUserService  userService   = new MSGraphUserService(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            return(userService);
        }
Exemplo n.º 3
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"));
            }
        }
Exemplo n.º 4
0
        public async Task GetPeopleTest()
        {
            IUserPeopleCollectionPage people = new UserPeopleCollectionPage();

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

                people.Add(person);
            }

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

                people.Add(user);
            }

            var mockGraphServiceClient = new MockGraphServiceClient
            {
                People = people
            };

            mockGraphServiceClient.SetMockBehavior();

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

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

            Assert.IsTrue(result.Count == 12);

            // "Conf Room" is filtered
            foreach (var user in result)
            {
                Assert.IsFalse(user.DisplayName.StartsWith("Conf Room"));
            }
        }
Exemplo n.º 5
0
        public async Task GetContactsTest()
        {
            IUserContactsCollectionPage contacts = new UserContactsCollectionPage();

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

                contacts.Add(contact);
            }

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

                contacts.Add(contact);
            }

            var mockGraphServiceClient = new MockGraphServiceClient
            {
                Contacts = contacts
            };

            mockGraphServiceClient.SetMockBehavior();

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

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

            Assert.IsTrue(result.Count == 10);

            // "Conf Room" is filtered
            foreach (var user in result)
            {
                Assert.IsFalse(user.DisplayName.StartsWith("Conf Room"));
            }
        }