Exemplo n.º 1
0
        public async Task MarkAsReadTest()
        {
            var mockGraphServiceClient        = new MockGraphServiceClient();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphMailAPI      mailService   = new MSGraphMailAPI(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            await mailService.MarkMessageAsReadAsync("1");
        }
Exemplo n.º 2
0
        public async Task ReplyToMessageTest()
        {
            var mockGraphServiceClient        = new MockGraphServiceClient();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphMailAPI      mailService   = new MSGraphMailAPI(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            await mailService.ReplyToMessageAsync("1", "test");
        }
Exemplo n.º 3
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.º 4
0
        public async Task ForwardMessageTest()
        {
            var mockGraphServiceClient        = new MockGraphServiceClient();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphMailAPI      mailService   = new MSGraphMailAPI(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            List <Recipient> recipients = new List <Recipient>();
            await mailService.ForwardMessageAsync("1", "Test", recipients);
        }
Exemplo n.º 5
0
        public async Task UpdateMessageTest()
        {
            var mockGraphServiceClient        = new MockGraphServiceClient();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphMailAPI      mailService   = new MSGraphMailAPI(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            Message msg = new Message();
            await mailService.UpdateMessage(msg);
        }
Exemplo n.º 6
0
        public async Task GetMyMessagesTest()
        {
            IMailFolderMessagesCollectionPage messages = new MailFolderMessagesCollectionPage();

            for (int i = 0; i < 6; i++)
            {
                var message = new Message()
                {
                    Subject     = "TestSubject" + i,
                    BodyPreview = "TestBodyPreview" + i,
                    Body        = new ItemBody()
                    {
                        Content     = "TestBody" + i,
                        ContentType = BodyType.Text,
                    },
                    ReceivedDateTime = DateTime.Now.AddHours(-1),
                    WebLink          = "http://www.test.com",
                    Sender           = new Recipient()
                    {
                        EmailAddress = new EmailAddress()
                        {
                            Name = "TestSender" + i,
                        },
                    },
                };

                var recipients = new List <Recipient>();
                var recipient  = new Recipient()
                {
                    EmailAddress = new EmailAddress(),
                };
                recipient.EmailAddress.Address = i + "*****@*****.**";
                recipient.EmailAddress.Name    = "Test Test";
                recipients.Add(recipient);
                message.ToRecipients = recipients;

                messages.Add(message);
            }

            var mockGraphServiceClient = new MockGraphServiceClient
            {
                MyMessages = messages
            };

            mockGraphServiceClient.SetMockBehavior();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphMailAPI      mailService   = new MSGraphMailAPI(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            List <Message> result = await mailService.GetMyMessagesAsync(DateTime.Today.AddDays(-2), DateTime.Today.AddDays(1), getUnRead : false, isImportant : false, directlyToMe : false, fromAddress : "*****@*****.**");

            // Test get 0-5 message per page
            Assert.IsTrue(result.Count >= 1);

            // Test ranking correctly by time
            Assert.IsTrue(result[0].Subject == "TestSubject5");
        }
Exemplo n.º 7
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.º 8
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.º 9
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"));
            }
        }
Exemplo n.º 10
0
        public async Task SendMessageTest()
        {
            // Send a self to self message
            var recipient = new Recipient()
            {
                EmailAddress = new EmailAddress(),
            };

            recipient.EmailAddress.Address = "*****@*****.**";
            recipient.EmailAddress.Name    = "Test Test";

            List <Recipient> recipientList = new List <Recipient>
            {
                recipient
            };

            var mockGraphServiceClient        = new MockGraphServiceClient();
            IGraphServiceClient serviceClient = mockGraphServiceClient.GetMockGraphServiceClient().Object;
            MSGraphMailAPI      mailService   = new MSGraphMailAPI(serviceClient, timeZoneInfo: TimeZoneInfo.Local);

            await mailService.SendMessageAsync("test content", "test subject", recipientList);
        }