Esempio n. 1
0
        public async Task CreateTopic()
        {
            var theme = new Theme
            {
                Title = "Test theme",
            };

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

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

                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.CreateTopic(
                    new TopicSaveViewModel
                {
                    Title   = "Test topic",
                    ThemeId = theme.Id
                }
                    );

                VerifyAllMocks(publishingService);

                Assert.True(result.IsRight);
                Assert.Equal("Test topic", result.Right.Title);
                Assert.Equal("test-topic", result.Right.Slug);
                Assert.Equal(theme.Id, result.Right.ThemeId);

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

                Assert.NotNull(savedTopic);
                Assert.Equal("Test topic", savedTopic !.Title);
                Assert.Equal("test-topic", savedTopic.Slug);
                Assert.Equal(theme.Id, savedTopic.ThemeId);
            }
        }
Esempio n. 2
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);
            }
        }