Example #1
0
        public void Execute_MultipleSources_ReturnsSourceListWithMultipleItems()
        {
            var source1 = new Source()
            {
                Id = 1, FriendlyName = "FriendlyName1", Description = "description1"
            };
            var source2 = new Source()
            {
                Id = 2, FriendlyName = "FriendlyName2", Description = "description2"
            };
            var sources = new List <Source>()
            {
                source1, source2
            };
            var mockRepository = new Mock <ISourceRepository>();

            mockRepository.Setup(q => q.GetAll()).Returns(sources.AsQueryable());
            var listQuery = new GetSourceListQuery(mockRepository.Object);

            var result = listQuery.Execute();

            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
            Assert.Equal(1, result[0].Id);
            Assert.Equal("FriendlyName1", result[0].FriendlyName);
            Assert.Equal("description1", result[0].Description);
        }
Example #2
0
        public void ListShouldReturnNotFound_WhenThemeIdNotFound()
        {
            var query = new GetSourceListQuery()
            {
                PathId = 1, ModuleId = 1, ThemeId = 99999
            };

            FluentActions.Invoking(() =>
                                   SendAsync(query)).Should().ThrowAsync <NotFoundException>();
        }
Example #3
0
        public void Execute_NoSources_ReturnsEmptySourceList()
        {
            var mockRepository = new Mock <ISourceRepository>();

            mockRepository.Setup(q => q.GetAll()).Returns(new List <Source>().AsQueryable());
            var listQuery = new GetSourceListQuery(mockRepository.Object);

            var result = listQuery.Execute();

            Assert.NotNull(result);
            Assert.Equal(0, result.Count);
        }
Example #4
0
        public void Get_ShouldThrow_WhenCanceled()
        {
            var cts = new CancellationTokenSource();

            cts.Cancel();

            var query = new GetSourceListQuery()
            {
                PathId = 1, ModuleId = 1, ThemeId = 1
            };

            FluentActions.Invoking(() =>
                                   SendAsync(query, cts.Token)).Should().ThrowAsync <TaskCanceledException>();
        }
Example #5
0
        public async Task Get_ShouldReturnSourcesList()
        {
            var path = await AddAsync(
                new Path { Title = "Some Path", Key = "some-path", Description = "Some Path Description" });

            var module = await SendAsync(new CreateModule
            {
                Key         = "module-key",
                Title       = "New Other Module",
                Description = "New Other Module Description",
                Necessity   = Necessity.MustKnow,
                Tags        = new List <string> {
                    "Tag1", "Tag2", "Tag3"
                }
            });

            var theme = await AddAsync(new Theme
            {
                Title       = "New Theme1",
                ModuleId    = module.Id,
                Description = "New Theme1 Description",
                Necessity   = Necessity.MustKnow,
                Complexity  = Complexity.Beginner,
                Tags        = new List <string> {
                    "Theme1", "ThemeTag2", "Tag3"
                },
                Order = 1
            });

            await AddAsync(new Source
            {
                ThemeId      = theme.Id,
                Title        = "Source 1",
                Url          = "https://source1.com",
                Order        = 0,
                Type         = SourceType.Documentation,
                Availability = Availability.Free,
                Relevance    = Relevance.Relevant
            });
            await AddAsync(new Source
            {
                ThemeId      = theme.Id,
                Title        = "Source 2",
                Url          = "https://source2.com",
                Order        = 1,
                Type         = SourceType.Documentation,
                Availability = Availability.Free,
                Relevance    = Relevance.Relevant
            });
            await AddAsync(new Source
            {
                ThemeId      = theme.Id,
                Title        = "Source 3",
                Url          = "https://source3.com",
                Order        = 2,
                Type         = SourceType.Blog,
                Availability = Availability.Free,
                Relevance    = Relevance.Relevant
            });

            var query = new GetSourceListQuery {
                PathId = path.Id, ModuleId = module.Id, ThemeId = theme.Id
            };

            var result = await SendAsync(query);

            result.Should().HaveCount(3);
            result.ToList()[1].Title.Should().Be("Source 2");
            result.ToList()[2].Url.Should().Be("https://source3.com");
        }