Example #1
0
        public void AddRandomComic_Type0WhenFull_SelectsComic()
        {
            int totalComics = 10;
            var allComics = new List<XKCDComic>();

            var comicService = new MockComicService(new XKCDComic(totalComics));
            var viewModel = new MainWindowViewModel(new MockInteractionService(), comicService, new MockPropertiesService());
            viewModel.LoadedCommand.ExecuteAsync(null).Wait();

            for (int i = 1; i <= totalComics; i++)
            {
                var comic = new XKCDComic(i);
                allComics.Add(comic);
                viewModel.Comics.Add(comic);
            }

            viewModel.AddRandomComicCommand.ExecuteAsync("0").Wait();

            Assert.AreEqual(viewModel.Comics.Count, totalComics);
            Assert.IsTrue(allComics.Contains(viewModel.SelectedComic));
        }
Example #2
0
        public void AddRandomComic_Type1WhenFull_DoesNothing()
        {
            int totalComics = 10;

            var comicService = new MockComicService(new XKCDComic(totalComics));
            var viewModel = new MainWindowViewModel(new MockInteractionService(), comicService, new MockPropertiesService());
            viewModel.LoadedCommand.ExecuteAsync(null).Wait();

            for (int i = 1; i <= totalComics; i++)
            {
                viewModel.Comics.Add(new XKCDComic(i));
            }

            viewModel.AddRandomComicCommand.ExecuteAsync("1").Wait();

            Assert.AreEqual(viewModel.Comics.Count, totalComics);
            Assert.IsNull(viewModel.SelectedComic);
        }
Example #3
0
        public void Closed_WhenSaveCacheIsFalse_DeletesCache()
        {
            bool called = false;
            var comicService = new MockComicService(null);
            comicService.ClearCacheCalled += () => called = true;

            var viewModel = new MainWindowViewModel(new MockInteractionService(), comicService, new MockPropertiesService { SaveCache = false });
            viewModel.ClosedCommand.ExecuteAsync(null).Wait();

            Assert.IsTrue(called);
        }
Example #4
0
        public void AddRandomComic_Type1WhenEmpty_AddsComic()
        {
            var current = new XKCDComic(10);
            var comicService = new MockComicService(current);

            var viewModel = new MainWindowViewModel(new MockInteractionService(), comicService, new MockPropertiesService());
            viewModel.LoadedCommand.ExecuteAsync(null).Wait();
            viewModel.AddRandomComicCommand.ExecuteAsync("1").Wait();

            Assert.AreEqual(viewModel.Comics.Count, 1);

            var comicNumber = comicService.LastNumberParameter;

            Assert.IsTrue(comicNumber > 1);
            Assert.IsTrue(comicNumber <= current.Number);
        }