public async Task OnReplyClick_HandlesMattermostExceptionsWhileCreatingPost() { var postIdProvider = new Mock <IStringProvider>(); postIdProvider.Setup(x => x.Get()).Returns(string.Empty); var post = new Mock <IChatPost>(); post.Setup(x => x.Reply(It.IsAny <string>())) .Throws(new MattermostException(new Error())); var session = new Mock <ISession>(); session.Setup(x => x.GetPost(It.IsAny <string>())).Returns(post.Object); var sessionRepository = new Mock <ISessionRepository>(); sessionRepository.Setup(x => x.RestoreSession()).Returns(Task.FromResult(session.Object)); var errorDisplay = new Mock <IErrorDisplay>(); var classUnderTest = new MailItemContextMenuEntry( MockOfMailExplorer(), DefaultSettingsLoadService, Mock.Of <ISettingsSaveService>(), errorDisplay.Object, Mock.Of <ISettingsUserInterface>(), sessionRepository.Object, postIdProvider.Object); await classUnderTest.OnReplyClick(Mock.Of <IRibbonControl>()); errorDisplay.Verify(x => x.Display(It.IsAny <MattermostException>())); }
public async Task OnReplyClick_CanHandleUserPermalinkAbort() { var postIdProvider = new Mock <IStringProvider>(); postIdProvider.Setup(x => x.Get()).Throws <UserAbortException>(); var session = new Mock <ISession>(); var mattermost = new Mock <IClient>(); mattermost.Setup( x => x.LoginByUsername(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(session.Object); var errorDisplay = new Mock <IErrorDisplay>(); var classUnderTest = new MailItemContextMenuEntry( MockOfMailExplorer(), DefaultSettingsLoadService, Mock.Of <ISettingsSaveService>(), errorDisplay.Object, Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), postIdProvider.Object); await classUnderTest.OnReplyClick(Mock.Of <IRibbonControl>()); errorDisplay.Verify(x => x.Display(It.IsAny <Exception>()), Times.Never); }
public async Task OnReplyClick_ReplysToPost() { const string postId = "postId"; var post = new Mock <IChatPost>(); var session = new Mock <ISession>(); session.Setup(x => x.GetPost(postId)).Returns(post.Object); var sessionRepository = new Mock <ISessionRepository>(); sessionRepository.Setup(x => x.RestoreSession()).Returns(Task.FromResult(session.Object)); var explorer = new Mock <IMailExplorer>(); explorer.Setup(x => x.QuerySelectedMailItem()).Returns(MockMailItem()); var rootPostIdProvider = new Mock <IStringProvider>(); rootPostIdProvider.Setup(x => x.Get()).Returns(postId); var classUnderTest = new MailItemContextMenuEntry( explorer.Object, Mock.Of <ISettingsLoadService>(), Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), sessionRepository.Object, rootPostIdProvider.Object); await classUnderTest.OnReplyClick(Mock.Of <IRibbonControl>()); post.Verify(x => x.Reply(":email: From: sender\n:email: Subject: subject\nmessage")); }
public async Task OnPostIntoChannelClick_CreatesPostUsingSession() { const string channelId = "funny ChannelId"; const string channelIdWithPrefix = "channel_id-funny ChannelId"; var control = new Mock <IRibbonControl>(); control.Setup(x => x.Id).Returns(channelIdWithPrefix); var channel = new Mock <IChatChannel>(); var session = new Mock <ISession>(); session.Setup(x => x.GetChannel(channelId)).Returns(channel.Object); var sessionRepository = new Mock <ISessionRepository>(); sessionRepository.Setup(x => x.RestoreSession()).Returns(Task.FromResult(session.Object)); var explorer = new Mock <IMailExplorer>(); explorer.Setup(x => x.QuerySelectedMailItem()).Returns(MockMailItem()); var classUnderTest = new MailItemContextMenuEntry( explorer.Object, Mock.Of <ISettingsLoadService>(), Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), sessionRepository.Object, Mock.Of <IStringProvider>()); await classUnderTest.OnPostIntoChannelClick(control.Object); channel.Verify( x => x.CreatePost(":email: From: sender\n:email: Subject: subject\nmessage")); }
public async Task OnPostIntoChannelClick_HandlesAnyExceptionsWhileCreatingPost() { var control = MockOfRibbonControl(); var channel = new Mock <IChatChannel>(); channel.Setup(x => x.CreatePost(It.IsAny <string>())) .Throws(new Exception()); var session = new Mock <ISession>(); session.Setup(x => x.GetChannel(It.IsAny <string>())).Returns(channel.Object); var sessionRepository = new Mock <ISessionRepository>(); sessionRepository.Setup(x => x.RestoreSession()).Returns(Task.FromResult(session.Object)); var errorDisplay = new Mock <IErrorDisplay>(); var classUnderTest = new MailItemContextMenuEntry( MockOfMailExplorer(), DefaultSettingsLoadService, Mock.Of <ISettingsSaveService>(), errorDisplay.Object, Mock.Of <ISettingsUserInterface>(), sessionRepository.Object, Mock.Of <IStringProvider>()); await classUnderTest.OnPostIntoChannelClick(control); errorDisplay.Verify(x => x.Display(It.IsAny <Exception>())); }
public void GetDynamicMenu_ReturnZeroChannelButtons_IfSettingsHasNoChannelsSaved() { const string subscribedChannelAttribut = "OnPostIntoChannelClick"; var channels = string.Empty; var settings = new AddInSettings("http://localhost", "teamId", "username", channels, It.IsAny <MattermostVersion>()); var settingsLoadService = new Mock <ISettingsLoadService>(); settingsLoadService.Setup(x => x.Load()).Returns(settings); var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), settingsLoadService.Object, Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); var result = classUnderTest.GetDynamicMenu(Mock.Of <IRibbonControl>()); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .DoNotContainXmlNode(@"//ns:button[contains(@onAction, """ + subscribedChannelAttribut + @""")]", "because there should be one button for each channel"); }
public void GetDynamicMenu_ReturnsSettingsButton() { var settings = new AddInSettings(string.Empty, string.Empty, string.Empty, string.Empty, It.IsAny <MattermostVersion>()); var settingsLoadService = new Mock <ISettingsLoadService>(); settingsLoadService.Setup(x => x.Load()).Returns(settings); var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), settingsLoadService.Object, Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); var result = classUnderTest.GetDynamicMenu(Mock.Of <IRibbonControl>()); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .ContainXmlNode(@"//ns:button[contains(@label, ""Settings..."")]", "because there should always be a settings button"); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .ContainXmlNode(@"//ns:button[contains(@onAction, ""OnSettingsClick"")]", "because the settings button should be connected to the 'OnSettingsClick'-Method"); }
public void GetCustomUI_ReturnsNull_IfRibbonIdIvalid() { var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), Mock.Of <ISettingsLoadService>(), Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); var result = classUnderTest.GetCustomUI("unknown"); result.Should().BeNull(); }
public void OnSettingsClick_OpensSettingsUserInterface() { var settingsUi = new Mock <ISettingsUserInterface>(); var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), Mock.Of <ISettingsLoadService>(), Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), settingsUi.Object, Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); classUnderTest.OnSettingsClick(Mock.Of <IRibbonControl>()); settingsUi.Verify(x => x.OpenSettings()); }
public void GetCustomUI_ReturnsCustomUiForExplorer() { var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), Mock.Of <ISettingsLoadService>(), Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); var result = classUnderTest.GetCustomUI("Microsoft.Outlook.Explorer"); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .ContainXmlNode(@"//ns:dynamicMenu[contains(@getContent, ""GetDynamicMenu"")]", "because there should be a dynamic menu which loads its contents using the 'GetDynamicMenu' function"); }
public void GetDynamicMenu_ReturnsPostButton_ForSubscribedChannel() { const string channelButtonIdPrefix = "channel_id-"; const string channelName = "FunnyChannelName"; const string channelId = "1234"; const ChannelType publicChannel = ChannelType.Public; var channelList = new ChannelList { Channels = new List <Channel> { new Channel { ChannelName = channelName, ChannelId = channelId, Type = publicChannel } } }; var channels = JsonConvert.SerializeObject(channelList); var settings = new AddInSettings("http://localhost", "teamId", "username", channels, It.IsAny <MattermostVersion>()); var settingsLoadService = new Mock <ISettingsLoadService>(); settingsLoadService.Setup(x => x.Load()).Returns(settings); var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), settingsLoadService.Object, Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); var result = classUnderTest.GetDynamicMenu(Mock.Of <IRibbonControl>()); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .ContainXmlNode(@"//ns:button[contains(@label, ""FunnyChannelName"")]", "because there should be one button for each channel"); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .ContainXmlNode(@"//ns:button[contains(@id, """ + channelButtonIdPrefix + channelId + @""")]", "because the tag of the button should match the channelId"); }
public async Task OnPostIntoChannelClick_CanHandleUserPasswordAbort() { var control = MockOfRibbonControl(); var passwordProvider = new Mock <IPasswordProvider>(); passwordProvider.Setup(x => x.GetPassword(It.IsAny <string>())).Throws <Exception>(); var sessionCache = new SingleSignOnSessionRepository(Mock.Of <IClientFactory>(), DefaultSettingsLoadService, passwordProvider.Object); var classUnderTest = new MailItemContextMenuEntry( MockOfMailExplorer(), DefaultSettingsLoadService, Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), sessionCache, Mock.Of <IStringProvider>()); await classUnderTest.OnPostIntoChannelClick(control); }
public void GetDynamicMenu_ReturnsNoChannelButtons_IfChannelTypeIsDirect() { const string channelName = "FunnyChannelName"; const string channelId = "1234"; const ChannelType directChannel = ChannelType.Direct; const string subscribedChannelAttribut = "OnPostIntoChannelClick"; var channelList = new ChannelList { Channels = new List <Channel> { new Channel { ChannelName = channelName, ChannelId = channelId, Type = directChannel } } }; var channels = JsonConvert.SerializeObject(channelList); var settings = new AddInSettings("http://localhost", "teamId", "username", channels, It.IsAny <MattermostVersion>()); var settingsLoadService = new Mock <ISettingsLoadService>(); settingsLoadService.Setup(x => x.Load()).Returns(settings); var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), settingsLoadService.Object, Mock.Of <ISettingsSaveService>(), Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), Mock.Of <ISessionRepository>(), Mock.Of <IStringProvider>()); var result = classUnderTest.GetDynamicMenu(Mock.Of <IRibbonControl>()); result.Should() .WithNamespace("ns", "http://schemas.microsoft.com/office/2009/07/customui") .DoNotContainXmlNode(@"//ns:button[contains(@onAction, """ + subscribedChannelAttribut + @""")]", "because there should be one button for each channel"); }
public async Task OnRefreshChannelListClick_SavesChannelList() { const string expectedChannelMapResult = "{\"channels\":[{\"id\":\"channel id\",\"display_name\":\"channel name\",\"type\":\"O\"}]}"; var channel = new Mock <IChatChannel>(); channel.Setup(x => x.ToSetting()) .Returns(new ChannelSetting() { ChannelId = "channel id", ChannelName = "channel name", Type = ChannelTypeSetting.Public }); var channels = new List <IChatChannel> { channel.Object }; var session = new Mock <ISession>(); session.Setup(x => x.GetChannels()).Returns(channels); var sessionRepository = new Mock <ISessionRepository>(); sessionRepository.Setup(x => x.RestoreSession()).Returns(Task.FromResult(session.Object)); var saveService = new Mock <ISettingsSaveService>(); var classUnderTest = new MailItemContextMenuEntry( Mock.Of <IMailExplorer>(), Mock.Of <ISettingsLoadService>(), saveService.Object, Mock.Of <IErrorDisplay>(), Mock.Of <ISettingsUserInterface>(), sessionRepository.Object, Mock.Of <IStringProvider>()); await classUnderTest.OnRefreshChannelListClick(Mock.Of <IRibbonControl>()); saveService.Verify(x => x.SaveChannels(expectedChannelMapResult)); }
public async Task OnRefreshChannelListClick_HandlesMattermostExceptionWhileFetchingChannels() { var control = MockOfRibbonControl(); var session = new Mock <ISession>(); session.Setup(x => x.GetChannels()) .Throws(new MattermostException(new Error())); var sessionRepository = new Mock <ISessionRepository>(); sessionRepository.Setup(x => x.RestoreSession()).Returns(Task.FromResult(session.Object)); var errorDisplay = new Mock <IErrorDisplay>(); var classUnderTest = new MailItemContextMenuEntry( MockOfMailExplorer(), DefaultSettingsLoadService, Mock.Of <ISettingsSaveService>(), errorDisplay.Object, Mock.Of <ISettingsUserInterface>(), sessionRepository.Object, Mock.Of <IStringProvider>()); await classUnderTest.OnRefreshChannelListClick(control); errorDisplay.Verify(x => x.Display(It.IsAny <MattermostException>())); }