Exemplo n.º 1
0
        public async Task DeleteTopic()
        {
            var topicId       = Guid.NewGuid();
            var releaseId     = Guid.NewGuid();
            var publicationId = Guid.NewGuid();

            var methodology = new Methodology();

            var topic = new Topic
            {
                Id    = topicId,
                Title = "UI test topic"
            };

            var publication = new Publication
            {
                Id            = publicationId,
                Topic         = topic,
                Methodologies = new List <PublicationMethodology>
                {
                    new()
                    {
                        PublicationId = publicationId,
                        Methodology   = methodology,
                        Owner         = true
                    }
                },
Exemplo n.º 2
0
        public async Task GetTopic()
        {
            var topic = new Topic
            {
                Title = "Test topic",
                Slug  = "test-topic",
                Theme = new Theme
                {
                    Title = "Test theme"
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = DbUtils.InMemoryApplicationDbContext(contextId))
            {
                context.Add(topic);
                await context.SaveChangesAsync();
            }

            await using (var context = DbUtils.InMemoryApplicationDbContext(contextId))
            {
                var service = SetupTopicService(context);

                var result = await service.GetTopic(topic.Id);

                Assert.True(result.IsRight);

                Assert.Equal(topic.Id, result.Right.Id);
                Assert.Equal("Test topic", result.Right.Title);
                Assert.Equal(topic.ThemeId, result.Right.ThemeId);
            }
        }
Exemplo n.º 3
0
        public async Task UpdateTopic_FailsNonUniqueSlug()
        {
            var theme = new Theme
            {
                Title = "Test theme",
            };
            var topic = new Topic
            {
                Title = "Old title",
                Slug  = "old-title",
                Theme = theme
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = DbUtils.InMemoryApplicationDbContext(contextId))
            {
                context.Add(topic);
                context.Add(
                    new Topic
                {
                    Title = "Other topic",
                    Slug  = "other-topic",
                    Theme = theme
                }
                    );

                await context.SaveChangesAsync();
            }

            await using (var context = DbUtils.InMemoryApplicationDbContext(contextId))
            {
                var service = SetupTopicService(context);

                var result = await service.UpdateTopic(
                    topic.Id,
                    new TopicSaveViewModel
                {
                    Title   = "Other topic",
                    ThemeId = topic.ThemeId
                }
                    );

                result.AssertBadRequest(SlugNotUnique);
            }
        }
Exemplo n.º 4
0
        public async Task UpdateTopic()
        {
            var theme = new Theme
            {
                Title = "New theme",
            };

            var topic = new Topic
            {
                Title = "Old title",
                Slug  = "old-title",
                Theme = new Theme
                {
                    Title = "Old theme"
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = DbUtils.InMemoryApplicationDbContext(contextId))
            {
                context.Add(theme);
                context.Add(topic);

                await context.SaveChangesAsync();
            }

            var publishingService = new Mock <IPublishingService>(Strict);

            publishingService.Setup(s => s.TaxonomyChanged())
            .ReturnsAsync(Unit.Instance);

            await using (var context = DbUtils.InMemoryApplicationDbContext(contextId))
            {
                var service = SetupTopicService(contentContext: context,
                                                publishingService: publishingService.Object);

                var result = await service.UpdateTopic(
                    topic.Id,
                    new TopicSaveViewModel
                {
                    Title   = "New title",
                    ThemeId = theme.Id
                }
                    );

                VerifyAllMocks(publishingService);

                Assert.True(result.IsRight);
                Assert.Equal(topic.Id, result.Right.Id);
                Assert.Equal("New title", result.Right.Title);
                Assert.Equal("new-title", result.Right.Slug);
                Assert.Equal(theme.Id, result.Right.ThemeId);

                var savedTopic = await context.Topics.FindAsync(result.Right.Id);

                Assert.NotNull(savedTopic);
                Assert.Equal("New title", savedTopic !.Title);
                Assert.Equal("new-title", savedTopic.Slug);
                Assert.Equal(theme.Id, savedTopic.ThemeId);
            }
        }