public async Task ExecutingAQueueOfTasksActuallyExecutesEachOfThem()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

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

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

            for (int i = 0; i < 10; i++)
            {
                await taskService.AddAsync($"https://test-{i}.de", Array.Empty <string>());
            }

            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   = "https://test.de",
                Tags  = new List <WallabagTag>()
            });

            await taskService.ExecuteAllAsync();

            A.CallTo(() => client.AddAsync(A <Uri> .Ignored, A <IEnumerable <string> > .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).MustHaveHappened(Repeated.Exactly.Times(10));
        }
        public async Task ExecutingAnOfflineTaskWithoutInternetConnectionDoesNotCallTheAPI()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

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

            var taskService = new OfflineTaskService(client, database, loggingService, platform);
            await taskService.AddAsync("http://test.de", new List <string>());

            A.CallTo(() => client.AddAsync(A <Uri> .Ignored, A <IEnumerable <string> > .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).MustNotHaveHappened();
        }
        public async Task AddingANewTaskForExistingArticleFiresTheTaskAddedEvent()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

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

            await Assert.RaisesAsync <OfflineTaskAddedEventArgs>(
                x => taskService.TaskAdded += x,
                x => taskService.TaskAdded -= x,
                () => taskService.AddAsync(0, OfflineTask.OfflineTaskAction.MarkAsRead));
        }
        public async Task AddingANewTaskForNewUrlFiresTheTaskAddedEvent()
        {
            var client         = A.Fake <IWallabagClient>();
            var platform       = A.Fake <IPlatformSpecific>();
            var loggingService = A.Fake <ILoggingService>();
            var database       = TestsHelper.CreateFakeDatabase();

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

            await Assert.RaisesAsync <OfflineTaskAddedEventArgs>(
                x => taskService.TaskAdded += x,
                x => taskService.TaskAdded -= x,
                () => taskService.AddAsync("https://test.de", Array.Empty <string>()));
        }
        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);
        }
        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();
        }