Пример #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));
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }