public async Task GetAllPresentations_returns_all_presentationsAsync()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <PlanificatorDbContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new PlanificatorDbContext(options))
                {
                    context.Database.EnsureCreated();

                    var service = new PresentationManager(context);
                    var query   = new PresentationRepository(context);

                    var testData1 = new PresentationRepositoryTestsData();
                    var testData2 = new PresentationRepositoryTestsData();
                    var testData3 = new PresentationRepositoryTestsData();

                    List <Presentation> presentations = new List <Presentation>();
                    presentations.Add(testData1.presentation);
                    presentations.Add(testData2.presentation);
                    presentations.Add(testData3.presentation);

                    await service.AddPresentation(testData1.presentationTags);

                    await service.AddPresentation(testData2.presentationTags);

                    await service.AddPresentation(testData3.presentationTags);

                    context.SaveChanges();

                    Assert.Equal(context.Presentations.Count(), query.GetAllPresentations().Count());
                    Assert.Equal(presentations, query.GetAllPresentations());
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task AssignSpeakerToPresentation_writes_to_databaseAsync()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            SpeakerProfile speaker = new SpeakerProfile
            {
                SpeakerId = Guid.NewGuid().ToString(),
                FirstName = "Test First Name",
                LastName  = "Test Last Name",
                Email     = "*****@*****.**",
                Bio       = "My test bio",
                Company   = "Test company",
                PhotoPath = "Test Path"
            };

            try
            {
                var options = new DbContextOptionsBuilder <PlanificatorDbContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new PlanificatorDbContext(options))
                {
                    context.Database.EnsureCreated();

                    var presentationService = new PresentationManager(context);
                    var speakerServie       = new SpeakerManager(context);

                    var testData = new PresentationRepositoryTestsData();

                    await speakerServie.AddSpeakerProfileAsync(speaker);

                    await presentationService.AddPresentation(testData.presentationTags);

                    await presentationService.AssignSpeakerToPresentationAsync(speaker, testData.presentation);

                    context.SaveChanges();

                    Assert.Equal(1, context.PresentationSpeakers.Count());
                    Assert.Equal(speaker, context.PresentationSpeakers.Single().SpeakerProfile);
                    Assert.Equal(testData.presentation, context.PresentationSpeakers.Include(p => p.Presentation).Single().Presentation);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task GetAllTags_returns_all_tags_from_one_presentationAsync()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <PlanificatorDbContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new PlanificatorDbContext(options))
                {
                    context.Database.EnsureCreated();

                    var service  = new PresentationManager(context);
                    var testData = new PresentationRepositoryTestsData();

                    await service.AddPresentation(testData.presentationTags);

                    context.SaveChanges();

                    Assert.Equal(testData.presentationTags.Count(), context.PresentationTags.Count());
                    Assert.Equal(1, context.Presentations.Count());
                    Assert.Equal(testData.tags.Count(), context.Tags.Count());

                    Assert.Equal(testData.presentationTags, context.PresentationTags);
                    Assert.Equal(testData.presentation.ToString(), context.Presentations.Single().ToString());
                    Assert.Equal(testData.tags, context.Tags);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task AddPresentation_writes_to_databaseAsync()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <PlanificatorDbContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new PlanificatorDbContext(options))
                {
                    context.Database.EnsureCreated();

                    var service = new PresentationManager(context);
                    var query   = new PresentationRepository(context);

                    var testData = new PresentationRepositoryTestsData();

                    await service.AddPresentation(testData.presentationTags);

                    context.SaveChanges();

                    List <string> tagsNames = testData.tags.Select(tag => tag.TagName).ToList();

                    Assert.Equal(tagsNames.Count, query.GetAllTagsNames(testData.presentation.PresentationId).Count());
                    Assert.Equal(tagsNames, query.GetAllTagsNames(testData.presentation.PresentationId));
                }
            }
            finally
            {
                connection.Close();
            }
        }