public void EditingTheTagsNavigatesToProperPage()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var item = new Item()
            {
                Id   = 1,
                Tags = new System.Collections.ObjectModel.ObservableCollection <Tag>()
                {
                    new Tag()
                    {
                        Label = "test"
                    }
                }
            };

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                Item = new ItemViewModel(item, offlineTaskService, navigationService, loggingService, platform, database)
            };

            viewModel.EditTagsCommand.Execute(null);

            A.CallTo(() => navigationService.Navigate(A <Data.Common.Navigation.Pages> .That.IsEqualTo(Data.Common.Navigation.Pages.EditTagsPage), A <object> .Ignored)).MustHaveHappened();
        }
        public void ExecutingTheChangeFavoriteStatusCommandChangesItemPropertiesCorrect()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var item = new Item()
            {
                Id        = 1,
                Content   = string.Empty,
                IsStarred = false
            };

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                Item = new ItemViewModel(item, offlineTaskService, navigationService, loggingService, platform, database)
            };

            Assert.False(viewModel.Item.Model.IsStarred);

            viewModel.ChangeFavoriteStatusCommand.Execute(null);
            Assert.True(viewModel.Item.Model.IsStarred);

            viewModel.ChangeFavoriteStatusCommand.Execute(null);
            Assert.False(viewModel.Item.Model.IsStarred);
        }
        public async Task ArticleWithEmptyContentShouldFailWithoutAnInternetConnection()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            // Insert a sample item without content to the database
            var item = new Item()
            {
                Id      = 1,
                Content = string.Empty
            };

            database.Insert(item);

            // If the ViewModel asks for an internet connection, return false
            A.CallTo(() => platform.InternetConnectionIsAvailable).Returns(false);

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database);
            await viewModel.ActivateAsync(item.Id, new Dictionary <string, object>(), Data.Common.NavigationMode.New);

            A.CallTo(() => platform.InternetConnectionIsAvailable).MustHaveHappened();
            A.CallTo(() => client.GetItemAsync(A <int> .That.IsEqualTo(1), A <CancellationToken> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => platform.GetArticleTemplateAsync()).MustNotHaveHappened();
            Assert.True(viewModel.ErrorDuringInitialization);
            Assert.True(string.IsNullOrEmpty(viewModel?.FormattedHtml));
        }
        public NewItemPage()
        {
            InitializeComponent();

            viewModel = new ItemPageViewModel();

            BindingContext = viewModel;
        }
        public ItemDetailPage(ItemPageViewModel viewModel)
        {
            InitializeComponent();

            this.viewModel       = viewModel;
            this.viewModel.Title = "Edit TODO";

            BindingContext = this.viewModel;
        }
        public async Task ArticleWithEmptyContentIsReFetchedFromTheServerAndContinuesIfSuccessful()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            // Insert a sample item without content to the database
            var item = new Item()
            {
                Id      = 1,
                Content = string.Empty
            };

            database.Insert(item);

            // If the ViewModel asks for an internet connection, return true
            A.CallTo(() => platform.InternetConnectionIsAvailable).Returns(true);

            // This is our custom template to see if the formatting was fine
            A.CallTo(() => platform.GetArticleTemplateAsync()).Returns("{{title}}");

            // Return an item if asked for
            A.CallTo(() => client.GetItemAsync(A <int> .That.IsEqualTo(1), A <CancellationToken> .Ignored)).Returns(new WallabagItem()
            {
                Id                   = 1,
                Content              = "This is my content.",
                CreationDate         = DateTime.Now,
                DomainName           = "test.de",
                EstimatedReadingTime = 10,
                IsRead               = false,
                IsStarred            = false,
                Language             = "de-DE",
                LastUpdated          = DateTime.Now,
                Mimetype             = "text/html",
                Title                = "This is my title",
                Url                  = "https://test.de"
            });

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database);
            await viewModel.ActivateAsync(item.Id, new Dictionary <string, object>(), Data.Common.NavigationMode.New);

            // Everything should be fine and our custom template should be applied
            A.CallTo(() => platform.InternetConnectionIsAvailable).MustHaveHappened();
            A.CallTo(() => client.GetItemAsync(A <int> .That.IsEqualTo(1), A <CancellationToken> .Ignored)).MustHaveHappened();
            A.CallTo(() => platform.GetArticleTemplateAsync()).MustHaveHappened();
            Assert.False(viewModel.ErrorDuringInitialization);
            Assert.False(string.IsNullOrEmpty(viewModel.FormattedHtml));
            Assert.Equal("This is my title", viewModel.FormattedHtml);
        }
        public async Task NavigationWithAWrongParameterReportsError()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database);
            await viewModel.ActivateAsync(9999, new Dictionary <string, object>(), Data.Common.NavigationMode.New);

            Assert.True(viewModel.ErrorDuringInitialization);
            A.CallTo(() => platform.GetArticleTemplateAsync()).MustNotHaveHappened();
        }
        public async Task GettingAPreviewImageForAVideoReturnsValidValue(string provider, string videoId)
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var    viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database);
            string result    = await viewModel.GetPreviewImageForVideoAsync(provider, videoId);

            Assert.NotEqual(string.Empty, result);
            Assert.True(result.StartsWith("http"));
        }
        public async Task UsingYoutubeOrVimeoAsHostnameSetsTheHostnameEmpty()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var fakeItems = new List <Item>
            {
                new Item()
                {
                    Id              = 1,
                    Hostname        = "youtube.com",
                    Content         = "test content",
                    PreviewImageUri = new Uri("https://test.de")
                },
                new Item()
                {
                    Id              = 2,
                    Hostname        = "vimeo.com",
                    Content         = "test content",
                    PreviewImageUri = new Uri("https://test.de")
                }
            };

            A.CallTo(() => platform.GetArticleTemplateAsync()).Returns("{{imageHeader}}");

            foreach (var item in fakeItems)
            {
                database.Insert(item);

                var fakeItemViewModel = new ItemViewModel(item, offlineTaskService, navigationService, loggingService, platform, database);
                var viewModel         = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
                {
                    Item = fakeItemViewModel
                };
                await viewModel.ActivateAsync(item.Id, new Dictionary <string, object>(), Data.Common.NavigationMode.New);

                Assert.False(viewModel.ErrorDuringInitialization);
                Assert.Equal(string.Empty, viewModel.FormattedHtml);
            }
        }
        public void OpeningARightClickUriExecutesTheProperActions()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            A.CallTo(() => platform.InternetConnectionIsAvailable).Returns(true);

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                RightClickUri = new Uri("https://google.de")
            };

            viewModel.OpenRightClickLinkInBrowserCommand.Execute(null);

            A.CallTo(() => platform.LaunchUri(A <Uri> .That.IsEqualTo(viewModel.RightClickUri), A <Uri> .Ignored)).MustHaveHappened();
        }
        public void SavingARightClickUriExecutesTheProperActions()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            A.CallTo(() => platform.InternetConnectionIsAvailable).Returns(true);

            var viewModel = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                RightClickUri = new Uri("https://google.de")
            };

            viewModel.SaveRightClickLinkCommand.Execute(null);

            A.CallTo(() => offlineTaskService.AddAsync(A <string> .Ignored, A <IEnumerable <string> > .Ignored)).MustHaveHappened();
        }
        public void CopyingAccessDeviceFunctions()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var fakeItem = new Item()
            {
                Id                   = 1,
                Hostname             = "wallabag.it",
                Content              = string.Empty,
                CreationDate         = DateTime.Now,
                LastModificationDate = DateTime.Now,
                EstimatedReadingTime = 10,
                IsRead               = false,
                IsStarred            = false,
                Language             = "de-DE",
                Mimetype             = "text/html",
                Title                = "My title",
                Url                  = "https://wallabag.it",
                PreviewImageUri      = new Uri("https://test.de")
            };

            database.Insert(fakeItem);

            var testUri = new Uri("https://framabag.org");

            var fakeItemViewModel = new ItemViewModel(fakeItem, offlineTaskService, navigationService, loggingService, platform, database);
            var viewModel         = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                Item          = fakeItemViewModel,
                RightClickUri = testUri
            };

            viewModel.CopyLinkToClipboardCommand.Execute(null);

            A.CallTo(() => platform.SetClipboardUri(A <Uri> .That.IsEqualTo(testUri))).MustHaveHappened();
        }
        public async Task VideoPreviewImageIsCorrectlyFetchedFromIFrames(string iframe, string expectedResult)
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var fakeItem = new Item()
            {
                Id                   = 1,
                Hostname             = "wallabag.it",
                Content              = iframe,
                CreationDate         = DateTime.Now,
                LastModificationDate = DateTime.Now,
                EstimatedReadingTime = 10,
                IsRead               = false,
                IsStarred            = false,
                Language             = "de-DE",
                Mimetype             = "text/html",
                Title                = "My title",
                Url                  = "https://wallabag.it",
                PreviewImageUri      = new Uri("https://test.de")
            };

            A.CallTo(() => platform.GetArticleTemplateAsync()).Returns("{{content}}");

            database.Insert(fakeItem);

            var fakeItemViewModel = new ItemViewModel(fakeItem, offlineTaskService, navigationService, loggingService, platform, database);
            var viewModel         = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                Item = fakeItemViewModel
            };
            await viewModel.ActivateAsync(fakeItem.Id, new Dictionary <string, object>(), Data.Common.NavigationMode.New);

            Assert.False(viewModel.ErrorDuringInitialization);
            Assert.Matches(expectedResult, viewModel.FormattedHtml);
        }
        public void DeletingAnItemDeletesTheItemAndNavigatesBack()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var platform           = A.Fake <IPlatformSpecific>();
            var navigationService  = A.Fake <INavigationService>();
            var client             = A.Fake <IWallabagClient>();
            var database           = TestsHelper.CreateFakeDatabase();

            var item = new Item()
            {
                Id = 1
            };

            var fakeItemViewModel = A.Fake <ItemViewModel>(x => x.WithArgumentsForConstructor(() => new ItemViewModel(item, offlineTaskService, navigationService, loggingService, platform, database)));
            var viewModel         = new ItemPageViewModel(offlineTaskService, loggingService, platform, navigationService, client, database)
            {
                Item = fakeItemViewModel
            };

            viewModel.DeleteCommand.Execute(null);

            A.CallTo(() => navigationService.GoBack()).MustHaveHappened();
        }
 public ItemPage(IConnectionService connectionService, Move move)
 {
     InitializeComponent();
     _connectionService = connectionService;
     BindingContext     = new ItemPageViewModel(connectionService, move.id);
 }
Exemple #16
0
 public ItemPage(string PackageCode)
 {
     InitializeComponent();
     BindingContext = _itemPageViewModel = new ItemPageViewModel();
     _PackageCode   = PackageCode;
 }
Exemple #17
0
 public ItemPage(Models.RetListResult item)
 {
     InitializeComponent();
     BindingContext = new ItemPageViewModel(item);
 }