Ejemplo n.º 1
0
        public async Task GetViewModelAsync_NotYetPublished()
        {
            var builder = new DbContextOptionsBuilder <ContentDbContext>();

            builder.UseInMemoryDatabase("ViewModel_NotYetPublished");
            var options = builder.Options;

            await using (var context = new ContentDbContext(options))
            {
                context.Add(MethodologyC);
                await context.SaveChangesAsync();
            }

            await using (var contentDbContext = new ContentDbContext(options))
            {
                var service = new MethodologyService(contentDbContext, MapperForProfile <MappingProfiles>());

                var context = PublishContext();
                var result  = await service.GetViewModelAsync(MethodologyC.Id, context);

                Assert.Equal(MethodologyC.Id, result.Id);
                Assert.Equal("Methodology C", result.Title);
                Assert.Equal(context.Published, result.Published);
                Assert.Equal(new DateTime(2019, 6, 15), result.Updated);
                Assert.Equal("third methodology", result.Summary);

                var annexes = result.Annexes;
                Assert.NotNull(annexes);
                Assert.Empty(annexes);

                var content = result.Content;
                Assert.NotNull(content);
                Assert.Empty(content);
            }
        }
Ejemplo n.º 2
0
        public void GetTree()
        {
            var builder = new DbContextOptionsBuilder <ContentDbContext>();

            builder.UseInMemoryDatabase("GetMethodologyTree");
            var options = builder.Options;

            using (var context = new ContentDbContext(options))
            {
                context.AddRange(new List <Methodology>
                {
                    MethodologyA, MethodologyB
                });

                context.Add(Theme);
                context.Add(Topic);

                context.AddRange(new List <Publication>
                {
                    PublicationA, PublicationB
                });

                context.AddRange(new List <Release>
                {
                    PublicationARelease1, PublicationBRelease1
                });

                context.SaveChanges();
            }

            using (var context = new ContentDbContext(options))
            {
                var service = new MethodologyService(context, MapperForProfile <MappingProfiles>());

                var result = service.GetTree(Enumerable.Empty <Guid>());

                Assert.Single(result);
                var theme = result.First();
                Assert.Equal("Theme A", theme.Title);

                Assert.Single(theme.Topics);
                var topic = theme.Topics.First();
                Assert.Equal("Topic A", topic.Title);

                Assert.Single(topic.Publications);
                var publication = topic.Publications.First();
                Assert.Equal("Publication A", publication.Title);

                var methodology = publication.Methodology;
                Assert.Equal("methodology-a", methodology.Slug);
                Assert.Equal("first methodology", methodology.Summary);
                Assert.Equal("Methodology A", methodology.Title);
            }
        }