Example #1
0
        private async Task <FastTrack> CreateFastTrack(Guid releaseId, DataBlock dataBlock)
        {
            var table = await GetTableAsync();

            // Use the DataBlock id as the FastTrack id
            var releaseFastTrack = new ReleaseFastTrack(releaseId, dataBlock.Id, dataBlock.HighlightName);
            await table.ExecuteAsync(TableOperation.Insert(releaseFastTrack));

            return(new FastTrack(dataBlock.Id, dataBlock.Table, dataBlock.Query, releaseId));
        }
        public async Task GetSubjectsForLatestRelease()
        {
            var publication = new Publication
            {
                Id = Guid.NewGuid(),
            };

            var publicationRelease1 = new Release
            {
                Id             = Guid.NewGuid(),
                PublicationId  = publication.Id,
                Published      = DateTime.UtcNow,
                TimeIdentifier = AcademicYearQ1,
                Year           = 2018
            };

            var publicationRelease2 = new Release
            {
                Id             = Guid.NewGuid(),
                PublicationId  = publication.Id,
                Published      = DateTime.UtcNow,
                TimeIdentifier = AcademicYearQ4,
                Year           = 2017
            };

            var publicationRelease3 = new Release
            {
                Id             = Guid.NewGuid(),
                PublicationId  = publication.Id,
                Published      = null,
                TimeIdentifier = AcademicYearQ2,
                Year           = 2018
            };

            var publicationRelease1Subject1 = new Subject
            {
                Id   = Guid.NewGuid(),
                Name = "Release 1 subject 1",
            };

            var publicationRelease1Subject1Link = new ReleaseSubject
            {
                ReleaseId = publicationRelease1.Id,
                SubjectId = publicationRelease1Subject1.Id
            };

            var publicationRelease1Subject2 = new Subject
            {
                Id   = Guid.NewGuid(),
                Name = "Release 1 subject 2"
            };

            var publicationRelease1Subject2Link = new ReleaseSubject
            {
                ReleaseId = publicationRelease1.Id,
                SubjectId = publicationRelease1Subject2.Id
            };

            var publicationRelease2Subject = new Subject
            {
                Id   = Guid.NewGuid(),
                Name = "Release 2 subject"
            };

            var publicationRelease2SubjectLink = new ReleaseSubject
            {
                ReleaseId = publicationRelease2.Id,
                SubjectId = publicationRelease2Subject.Id
            };

            var publicationRelease3Subject = new Subject
            {
                Id   = Guid.NewGuid(),
                Name = "Release 3 subject"
            };

            var publicationRelease3SubjectLink = new ReleaseSubject
            {
                ReleaseId = publicationRelease3.Id,
                SubjectId = publicationRelease3Subject.Id
            };

            var releaseFastTrack1 = new ReleaseFastTrack(publicationRelease1.Id, Guid.NewGuid(), "table 1");
            var releaseFastTrack2 = new ReleaseFastTrack(publicationRelease1.Id, Guid.NewGuid(), "table 2");

            var builder = new DbContextOptionsBuilder <StatisticsDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var options = builder.Options;

            await using (var context = new StatisticsDbContext(options, null))
            {
                context.Add(publication);

                await context.AddRangeAsync(new List <Release>
                {
                    publicationRelease1, publicationRelease2, publicationRelease3
                });

                await context.AddRangeAsync(new List <Subject>
                {
                    publicationRelease1Subject1,
                    publicationRelease1Subject2,
                    publicationRelease2Subject,
                    publicationRelease3Subject
                });

                await context.AddRangeAsync(new List <ReleaseSubject>
                {
                    publicationRelease1Subject1Link,
                    publicationRelease1Subject2Link,
                    publicationRelease2SubjectLink,
                    publicationRelease3SubjectLink
                });

                await context.SaveChangesAsync();

                var mocks = Mocks();

                mocks.TableStorageService.Setup(storageService =>
                                                storageService.ExecuteQueryAsync(PublicReleaseFastTrackTableName,
                                                                                 It.IsAny <TableQuery <ReleaseFastTrack> >())).ReturnsAsync(new List <ReleaseFastTrack>
                {
                    releaseFastTrack1, releaseFastTrack2
                });

                var service = BuildPublicationMetaService(context, mocks);

                var result     = (await service.GetSubjectsForLatestRelease(publication.Id)).Right;
                var highlights = result.Highlights.ToList();
                var subjects   = result.Subjects.ToList();

                Assert.Equal(publication.Id, result.PublicationId);
                Assert.Equal(2, highlights.Count);
                Assert.Equal(releaseFastTrack1.FastTrackId, highlights[0].Id);
                Assert.Equal(releaseFastTrack1.HighlightName, highlights[0].Label);
                Assert.Equal(releaseFastTrack2.FastTrackId, highlights[1].Id);
                Assert.Equal(releaseFastTrack2.HighlightName, highlights[1].Label);
                Assert.Equal(2, subjects.Count);
                Assert.Equal(publicationRelease1Subject1.Id, subjects[0].Id);
                Assert.Equal(publicationRelease1Subject1.Name, subjects[0].Label);
                Assert.Equal(publicationRelease1Subject2.Id, subjects[1].Id);
                Assert.Equal(publicationRelease1Subject2.Name, subjects[1].Label);
            }
        }