using AutoFixture; using FluentAssertions; using FluentTerminal.App.Services.Dialogs; using FluentTerminal.App.Services.Implementation; using Moq; using System; using System.Linq; using System.Threading.Tasks; using Xunit; namespace FluentTerminal.App.Services.Test { public class DialogServiceTests { private readonly Fixture _fixture; public DialogServiceTests() { _fixture = new Fixture(); } [Fact] public void ShowCreateKeyBindingDialog_Default_UsesCreateKeyBindingDialog() { var createKeyBindingDialog = new Mock(); var dialogService = new DialogService(Mock.Of, () => createKeyBindingDialog.Object, Mock.Of, Mock.Of, Mock.Of, Mock.Of); dialogService.ShowCreateKeyBindingDialog(); createKeyBindingDialog.Verify(x => x.CreateKeyBinding(), Times.Once); } [Fact] public void ShowMessageDialogAsnyc_TitleIsEmpty_ThrowsArgumentNullException() { var title = string.Empty; var content = _fixture.Create(); var buttons = _fixture.CreateMany(2); var dialogService = new DialogService(Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); showMessageDialogAsnyc.Should().Throw().And.ParamName.Should().Be("title"); } [Fact] public void ShowMessageDialogAsnyc_ContentIsEmpty_ThrowsArgumentNullException() { var title = _fixture.Create(); var content = string.Empty; var buttons = _fixture.CreateMany(2); var dialogService = new DialogService(Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); showMessageDialogAsnyc.Should().Throw().And.ParamName.Should().Be("content"); } [Fact] public void ShowMessageDialogAsnyc_NoButtonsPassed_ThrowsArgumentException() { var title = _fixture.Create(); var content = _fixture.Create(); var dialogService = new DialogService(Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content); showMessageDialogAsnyc.Should().Throw().And.ParamName.Should().Be("buttons"); } [Fact] public void ShowMessageDialogAsnyc_Default_UsesMessageDialog() { var title = _fixture.Create(); var content = _fixture.Create(); var buttons = _fixture.CreateMany(2); var messageDialog = new Mock(); var dialogService = new DialogService(() => messageDialog.Object, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); messageDialog.Verify(x => x.ShowAsync(), Times.Once); } [Fact] public void ShowInputDialogAsync_UsesIInputDialogSetTitle() { var title = "title"; var inputDialog = new Mock(); var dialogService = new DialogService(Mock.Of, Mock.Of, () => inputDialog.Object, Mock.Of, Mock.Of, Mock.Of); dialogService.ShowInputDialogAsync(title); inputDialog.Verify(x => x.SetTitle(title), Times.Once); inputDialog.Verify(x => x.GetInput(), Times.Once); } } }