Пример #1
0
        public async Task GetThemes_Returns_Ok()
        {
            var themes = new List <ThemeViewModel>
            {
                new ThemeViewModel
                {
                    Title  = "Theme A",
                    Topics = new List <TopicViewModel>
                    {
                        new TopicViewModel
                        {
                            Title = "Topic A"
                        }
                    }
                }
            };

            var themeService = new Mock <IThemeService>();

            themeService.Setup(s => s.GetThemes()).ReturnsAsync(themes);

            var controller = new ThemeController(themeService.Object);

            var result = await controller.GetThemes();

            Assert.Equal(themes, result.Value);
        }
Пример #2
0
        public async Task GetThemes()
        {
            var fileStorageService = new Mock <IFileStorageService>();

            fileStorageService
            .Setup(
                s => s.GetDeserialized <IEnumerable <ThemeTree <PublicationTreeNode> > >(
                    "publications/tree.json"
                    )
                )
            .ReturnsAsync(
                new List <ThemeTree <PublicationTreeNode> >
            {
                new ThemeTree <PublicationTreeNode>
                {
                    Topics = new List <TopicTree <PublicationTreeNode> >
                    {
                        new TopicTree <PublicationTreeNode>
                        {
                            Publications = new List <PublicationTreeNode>
                            {
                                new PublicationTreeNode()
                            }
                        }
                    }
                }
            }
                );

            var controller = new ThemeController(fileStorageService.Object);

            var result = await controller.GetThemes();

            Assert.IsAssignableFrom <IEnumerable <ThemeTree <PublicationTreeNode> > >(result.Value);
            Assert.Single(result.Value);

            var theme = result.Value.First();

            Assert.IsType <ThemeTree <PublicationTreeNode> >(theme);
            Assert.Single(theme.Topics);

            var topic = theme.Topics.First();

            Assert.Single(topic.Publications);
        }