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 void InvokingTheScanQRCodeCommandNavigatesToTheQRPage()
        {
            var logging    = A.Fake <ILoggingService>();
            var navigation = A.Fake <INavigationService>();
            var device     = A.Fake <IPlatformSpecific>();
            var client     = A.Fake <IWallabagClient>();
            var apiService = A.Fake <IApiClientCreationService>();
            var database   = TestsHelper.CreateFakeDatabase();

            var viewModel = new LoginPageViewModel(logging, navigation, device, client, apiService, database);

            viewModel.ScanQRCodeCommand.Execute();

            A.CallTo(() => navigation.Navigate(Data.Common.Navigation.Pages.QRScanPage)).MustHaveHappened();
        }
예제 #3
0
        public void ParsingTheTagQueryWontAddEmptyOrSpaceStrings()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            var viewModel = new EditTagsViewModel(offlineTaskService, loggingService, database, navigationService)
            {
                TagQuery = ",  ,"
            };

            viewModel.TagSubmittedCommand.Execute(null);
            Assert.Equal(0, viewModel.Suggestions.Count);
        }
        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 ExecutingATaskWithFalseAPIResultDoesNotRemoveThemFromTheDatabase()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

            A.CallTo(() => client.ArchiveAsync(A <WallabagItem> .Ignored, A <CancellationToken> .Ignored)).Returns(false);

            var taskService = new OfflineTaskService(client, database, loggingService, platform);
            int count       = taskService.Count;

            await taskService.AddAsync(0, OfflineTask.OfflineTaskAction.MarkAsRead);

            Assert.Equal(count + 1, taskService.Count);
        }
예제 #6
0
        public void AddingAnMicrosoftEdgeUriAddsTheCorrectOne()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            var viewModel = new AddItemViewModel(offlineTaskService, loggingService, database, navigationService)
            {
                UriString = "read:http://wallabag.org"
            };

            viewModel.AddCommand.Execute(null);

            A.CallTo(() => navigationService.GoBack()).MustHaveHappened();
            A.CallTo(() => offlineTaskService.AddAsync(A <string> .That.IsEqualTo("http://wallabag.org"), A <IEnumerable <string> > .Ignored)).MustHaveHappened();
            // TODO: Add database check
        }
예제 #7
0
        public void AddingAnInvalidUriDoesNotExecuteTheOfflineTaskService()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            var viewModel = new AddItemViewModel(offlineTaskService, loggingService, database, navigationService)
            {
                UriString = "fake"
            };

            viewModel.AddCommand.Execute(null);

            A.CallTo(() => navigationService.GoBack()).MustNotHaveHappened();
            A.CallTo(() => offlineTaskService.AddAsync(A <string> .Ignored, A <IEnumerable <string> > .Ignored)).MustNotHaveHappened();
            // TODO: Add database check
        }
예제 #8
0
        public void SubmittingWillClearTheQueryAfterwards()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            var viewModel = new EditTagsViewModel(offlineTaskService, loggingService, database, navigationService)
            {
                TagQuery = "test1"
            };

            viewModel.TagSubmittedCommand.Execute(null);
            Assert.Equal(1, viewModel.Tags.Count);

            Assert.False(viewModel.TagsCountIsZero);
            Assert.True(string.IsNullOrEmpty(viewModel.TagQuery));
        }
        public async Task NavigationWithParameterSetsProperties()
        {
            var logging    = A.Fake <ILoggingService>();
            var navigation = A.Fake <INavigationService>();
            var device     = A.Fake <IPlatformSpecific>();
            var client     = A.Fake <IWallabagClient>();
            var apiService = A.Fake <IApiClientCreationService>();
            var database   = TestsHelper.CreateFakeDatabase();
            var viewModel  = new LoginPageViewModel(logging, navigation, device, client, apiService, database);

            var param = new ProtocolSetupNavigationParameter("user", "http://test.de");

            await viewModel.ActivateAsync(param, new Dictionary <string, object>(), Data.Common.NavigationMode.New);

            Assert.True(WallabagProvider.GetOther(device).Equals(viewModel.SelectedProvider));
            Assert.Equal("user", viewModel.Username);
            Assert.Equal("http://test.de", viewModel.Url);
        }
        public void TheUrlFieldIsVisibleIfTheSelectedProviderUrlIsNotNull()
        {
            var logging    = A.Fake <ILoggingService>();
            var navigation = A.Fake <INavigationService>();
            var device     = A.Fake <IPlatformSpecific>();
            var client     = A.Fake <IWallabagClient>();
            var apiService = A.Fake <IApiClientCreationService>();
            var database   = TestsHelper.CreateFakeDatabase();
            var viewModel  = new LoginPageViewModel(logging, navigation, device, client, apiService, database)
            {
                SelectedProvider = WallabagProvider.GetOther(device)
            };

            viewModel.RaisePropertyChanged(nameof(viewModel.SelectedProvider));

            Assert.Null(viewModel.SelectedProvider.Url);
            Assert.True(viewModel.UrlFieldIsVisible);
        }
        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 RegisterCommandCanNotBeExecutedIfSelectedProviderIsNull()
        {
            var logging    = A.Fake <ILoggingService>();
            var navigation = A.Fake <INavigationService>();
            var device     = A.Fake <IPlatformSpecific>();
            var client     = A.Fake <IWallabagClient>();
            var apiService = A.Fake <IApiClientCreationService>();
            var database   = TestsHelper.CreateFakeDatabase();

            var uriToTest = new Uri("https://test.de");

            var viewModel = new LoginPageViewModel(logging, navigation, device, client, apiService, database)
            {
                SelectedProvider = null
            };

            Assert.False(viewModel.RegisterCommand.CanExecute(null));
            A.CallTo(() => device.LaunchUri(A <Uri> .That.IsEqualTo(uriToTest.Append("/register")), A <Uri> .Ignored)).MustNotHaveHappened();
        }
예제 #13
0
        public void SubmittingASuggestionAddsItToTheTagsList()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            var viewModel = new EditTagsViewModel(offlineTaskService, loggingService, database, navigationService);
            var tagToTest = new Tag()
            {
                Id    = 1337,
                Label = "My suggestion tag"
            };

            viewModel.TagSubmittedCommand.Execute(tagToTest);

            Assert.Equal(1, viewModel.Tags.Count);
            Assert.Equal(tagToTest, viewModel.Tags[0]);
        }
        public void HavingItemsInTheDatabaseAtStartShouldIncludeThemOnInit()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

            for (int i = 0; i < 3; i++)
            {
                database.Insert(new OfflineTask()
                {
                    Id = i, ItemId = i
                });
            }

            var taskService = new OfflineTaskService(client, database, loggingService, platform);

            Assert.Equal(database.ExecuteScalar <int>("select count(*) from OfflineTask"), taskService.Count);
        }
        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);
        }
예제 #19
0
        public void SubmittingNothingParsesTheCurrentTagQueryWithoutDuplicates()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            var viewModel = new EditTagsViewModel(offlineTaskService, loggingService, database, navigationService)
            {
                TagQuery = "test1,test2,test2"
            };

            viewModel.TagSubmittedCommand.Execute(null);
            Assert.Equal(2, viewModel.Tags.Count);

            foreach (var tag in viewModel.Tags)
            {
                Assert.Matches("test[1-2]", tag.Label);
            }

            Assert.False(viewModel.TagsCountIsZero);
        }
        public async Task ClientIsCreatedIfTheClientCredentialsAreUnset()
        {
            var logging    = A.Fake <ILoggingService>();
            var navigation = A.Fake <INavigationService>();
            var device     = A.Fake <IPlatformSpecific>();
            var client     = A.Fake <IWallabagClient>();
            var apiService = A.Fake <IApiClientCreationService>();
            var database   = TestsHelper.CreateFakeDatabase();
            var viewModel  = new LoginPageViewModel(logging, navigation, device, client, apiService, database)
            {
                Url      = "http://v2.wallabag.org",
                Username = "******",
                Password = "******"
            };

            Assert.True(string.IsNullOrEmpty(viewModel.ClientId));
            Assert.True(string.IsNullOrEmpty(viewModel.ClientSecret));

            await viewModel.TestConfigurationAsync();

            A.CallTo(() => apiService.CreateClientAsync(A <string> .Ignored, A <string> .That.IsEqualTo("myuser"), A <string> .That.IsEqualTo("password"))).MustHaveHappened();
        }
        public async Task ExecutionOfTaskFiresTheTaskExecutedEventWithoutInternetConnection()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

            var task = new OfflineTask()
            {
                Id     = 1,
                Action = OfflineTask.OfflineTaskAction.AddItem,
                ItemId = 0,
                Url    = "https://test.de"
            };
            var taskService = new OfflineTaskService(client, database, loggingService, platform);

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

            await Assert.RaisesAsync <OfflineTaskExecutedEventArgs>(
                x => taskService.TaskExecuted += x,
                x => taskService.TaskExecuted -= x,
                () => taskService.ExecuteAsync(task));
        }
예제 #22
0
        public void EnteringATagQueryOnlyRespectsTheLastString()
        {
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var loggingService     = A.Fake <ILoggingService>();
            var database           = TestsHelper.CreateFakeDatabase();
            var navigationService  = A.Fake <INavigationService>();

            // Fake some tags
            database.Insert(new Tag()
            {
                Id = 0, Label = "random tag"
            });

            var viewModel = new EditTagsViewModel(offlineTaskService, loggingService, database, navigationService)
            {
                TagQuery = "test1,test2,random"
            };

            viewModel.TagQueryChangedCommand.Execute(null);

            Assert.Equal(1, viewModel.Suggestions.Count);
            Assert.Equal("random tag", viewModel.Suggestions[0].Label);
        }
        public void MarkingAnItemAsUnreadInvokesProperActions()
        {
            var item = new Item()
            {
                Id     = 10,
                IsRead = true
            };
            var offlineTaskService = A.Fake <IOfflineTaskService>();
            var navigation         = A.Fake <INavigationService>();
            var logging            = A.Fake <ILoggingService>();
            var device             = A.Fake <IPlatformSpecific>();
            var database           = TestsHelper.CreateFakeDatabase();

            database.Insert(item);

            var viewModel = new ItemViewModel(item,
                                              offlineTaskService,
                                              navigation,
                                              logging,
                                              device,
                                              database);

            bool propertyChangedEventWasFired = false;

            viewModel.PropertyChanged += (s, e) => propertyChangedEventWasFired = true;

            viewModel.UnmarkAsReadCommand.Execute(null);

            A.CallTo(() => offlineTaskService.AddAsync(
                         10,
                         A <OfflineTask.OfflineTaskAction> .That.IsEqualTo(OfflineTask.OfflineTaskAction.UnmarkAsRead),
                         A <List <Tag> > .Ignored,
                         A <List <Tag> > .Ignored)).MustHaveHappened();
            Assert.True(propertyChangedEventWasFired);
            Assert.False(database.Get <Item>(10).IsRead);
        }
        public async Task AddingATaskExecutesItDirectly()
        {
            string uriString = "https://wallabag.org";
            var    uriToTest = new Uri(uriString);

            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

            A.CallTo(() => platform.InternetConnectionIsAvailable).Returns(true);
            A.CallTo(() => client.AddAsync(A <Uri> .Ignored, A <IEnumerable <string> > .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).Returns(new WallabagItem()
            {
                Id    = 1,
                Title = "My fake item",
                Url   = uriString,
                Tags  = new List <WallabagTag>()
            });

            var taskService = new OfflineTaskService(client, database, loggingService, platform);
            await taskService.AddAsync(uriString, new List <string>());

            A.CallTo(() => client.AddAsync(uriToTest, A <IEnumerable <string> > .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).MustHaveHappened();
        }
        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();
        }