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 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 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 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);
        }