public BrowserUrlTests()
 {
     _sut = new BrowserUrl(new[] {
         "http://google.com",
         "youtube.com",
         "https://www.example.com",
         "contoso.org/contacts",
         "wiki.com?a=1&b=2",
         "abc.ru#data"
     });
 }
        public MainWindow(BrowserUrl browserUrl)
        {
            if (browserUrl is null)
            {
                throw new ArgumentNullException(nameof(browserUrl));
            }

            InitializeComponent();

            _viewModel = new MainWindowViewModel(browserUrl);

            DataContext = _viewModel;
        }
        public BrowserViewModel(BrowserUrl browserUrl)
        {
            _browserUrl = browserUrl ?? throw new ArgumentNullException(nameof(browserUrl));

            Browser = new WebView();
            Browser.NavigationStarting  += OnNavigationStarting;
            Browser.NavigationCompleted += OnNavigationCompleted;
            Browser.NewWindowRequested  += (sender, args) =>
            {
                NewWindowRequested(this, args);
            };

            BackCommand = new RelayCommand(
                (arg) => { Browser.GoBack(); },
                (arg) => Browser.CanGoBack
                );

            ForwardCommand = new RelayCommand(
                (arg) => { Browser.GoForward(); },
                (arg) => Browser.CanGoForward
                );

            RefreshCommand = new RelayCommand(
                (arg) => Browser.Refresh()
                );

            GoToBookmarkCommand = new RelayCommand(arg => {
                var address = (string)arg;

                GoToAddress(address);
            });

            CloseCommand = new RelayCommand(arg => {
                Closing(this, this);
            });
        }
        public MainWindowViewModel(
            BrowserUrl browserUrl)
        {
            _browserUrl = browserUrl ?? throw new ArgumentNullException(nameof(browserUrl));

            ExitCommand = new RelayCommand(
                (arg) => Application.Current.Shutdown()
                );

            Bookmarks = _bookmarksViewModel.Bookmarks;

            _addressCompletionProvider.RegisterProvider(new BookmarksUriProvider(() => _bookmarksViewModel.Bookmarks.Select(b => b.Bookmark)));
            _addressCompletionProvider.RegisterProvider(new AllowedUrisProvider(_browserUrl));

            AddBookmarkCommand = new RelayCommand(
                (arg) =>
            {
                var viewModel = new BookmarkViewModel()
                {
                    Title   = SelectedBrowser.Browser.DocumentTitle,
                    Address = SelectedBrowser.Browser.Source.ToString()
                };

                var dialog = new EditBookmark(viewModel);

                if (dialog.ShowDialog() == true)
                {
                    _bookmarksViewModel.AddBookmarkCommand.Execute(viewModel);
                }
            }
                );

            AddNewTabCommand = new RelayCommand(arg =>
            {
                var viewModel                 = new BrowserViewModel(_browserUrl);
                viewModel.Closing            += OnBrowserTabClosing;
                viewModel.NewWindowRequested += OnNewWindowRequested;

                Browsers.Add(viewModel);

                SelectedBrowser = viewModel;
            });

            SetLanguageCommand = new RelayCommand(arg => {
                var language = (string)arg;

                if (string.IsNullOrWhiteSpace(language) ||
                    CultureInfo.GetCultureInfo(language) == null)
                {
                    Configuration.Language = null;
                }
                else
                {
                    Configuration.Language = language;
                }

                NotifyPropertyChanged(nameof(Language));

                Configuration.SetCurrentCulture();
            });

            _selectedBrowser                     = new BrowserViewModel(_browserUrl);
            _selectedBrowser.Closing            += OnBrowserTabClosing;
            _selectedBrowser.NewWindowRequested += OnNewWindowRequested;

            Browsers.Add(_selectedBrowser);
        }