diff --git a/Source/Xamarin/Prism.Forms.Tests/Services/DialogServiceTests.cs b/Source/Xamarin/Prism.Forms.Tests/Services/DialogServiceTests.cs new file mode 100644 index 0000000000..ee6ce5df80 --- /dev/null +++ b/Source/Xamarin/Prism.Forms.Tests/Services/DialogServiceTests.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Prism.Ioc; +using Prism.Services.Dialogs; +using Xunit; +using Prism.Forms.Tests.Mocks; +using Prism.Common; +using Prism.Forms.Tests.Services.Mocks.Dialogs; +using Xamarin.Forms; +using Prism.Forms.Tests.Services.Mocks; +using Prism.Services.Dialogs.Xaml; + +namespace Prism.Forms.Tests.Services +{ + public class DialogServiceTests + { + private const string DialogMockViewName = nameof(DialogMock); + private MockApplication _currentApp; + + public DialogServiceTests() + { + Xamarin.Forms.Mocks.MockForms.Init(); + } + + [Fact] + public void DoesNotThrowExceptionWithNullParametersAndCallback() + { + SetMainPage(); + var dialogService = CreateDialogService(); + var ex = Record.Exception(() => dialogService.ShowDialog(DialogMockViewName)); + Assert.Null(ex); + ex = Record.Exception(() => DialogMock.Current.ViewModel.SendRequestClose()); + Assert.Null(ex); + _currentApp = null; + } + + [Fact] + public void DoesNotThrowExceptionWithNullParameters() + { + SetMainPage(); + var dialogService = CreateDialogService(); + var ex = Record.Exception(() => dialogService.ShowDialog(DialogMockViewName, null, p => { })); + Assert.Null(ex); + ex = Record.Exception(() => DialogMock.Current.ViewModel.SendRequestClose()); + Assert.Null(ex); + _currentApp = null; + } + + [Fact] + public void DoesNotThrowExceptionWithNullCallback() + { + SetMainPage(); + var dialogService = CreateDialogService(); + var ex = Record.Exception(() => dialogService.ShowDialog(DialogMockViewName, new DialogParameters(), null)); + Assert.Null(ex); + ex = Record.Exception(() => DialogMock.Current.ViewModel.SendRequestClose()); + Assert.Null(ex); + _currentApp = null; + } + + [Fact] + public void MainPageContentPreservedOnClose() + { + SetMainPage(); + var dialogService = CreateDialogService(); + dialogService.ShowDialog(DialogMockViewName); + + Assert.IsType(_currentApp.MainPage); + var mainPage = _currentApp.MainPage as ContentPage; + Assert.IsType(mainPage.Content); + Assert.True((bool)mainPage.Content.GetValue(DialogService.IsPopupHostProperty)); + + DialogMock.Current.ViewModel.SendRequestClose(); + + Assert.IsType