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"); }
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"); }
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); }
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); }
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); }
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"); }
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")); } }
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")); } }
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")); } }
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); }