public async Task AddAnalysisAsyncShouldHandleErrorsAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddAnalysisAsyncShouldHandleErrorsAsync")
                          .Options;

            using var context = new YouTubeJamContext(options);
            var mapper = new DBMapper(context);
            var repo   = new Repository(context, mapper);

            BusinessLogic.Creator b = new BusinessLogic.Creator()
            {
                Email       = "*****@*****.**",
                ChannelName = "Mathemartian"
            };
            AverageSentiment avg = new AverageSentiment()
            {
                VideoURL = "Abc",
                AverageSentimentScore = 0.5
            };

            //act
            try
            {
                await repo.AddAnalysisAsync(avg, b);

                Assert.True(false);
            } catch (CreatorDoesNotExistException)
            {
                //assert
                Assert.True(true);
            }
        }
        public async Task AddAnalysisShouldNotCreateNewCreatorsAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddAnalysisShouldNotCreateNewCreators")
                          .Options;

            using var context = new YouTubeJamContext(options);
            var mapper = new DBMapper(context);
            var repo   = new Repository(context, mapper);

            BusinessLogic.Creator c = new BusinessLogic.Creator()
            {
                FirstName = "Marielle",
                LastName  = "Nolasco",
                Email     = "*****@*****.**"
            };

            AverageSentiment avg = new AverageSentiment()
            {
                VideoURL = "Abc",
                AverageSentimentScore = 0.5
            };

            //act
            await repo.AddCreatorAsync(c);

            await repo.AddChannelAsync(c, "MatheMartian");

            await repo.AddVideoAsync("Abc", "MatheMartian");

            await repo.AddAnalysisAsync(avg, c);

            //assert
            using var assertContext = new YouTubeJamContext(options);
            mapper = new DBMapper(assertContext);
            repo   = new Repository(assertContext, mapper);
            var result = await repo.GetCreatorsAsync();

            if (result.Count > 1)
            {
                Assert.True(false);
            }
            else
            {
                Assert.True(true);
            }
        }
        public async Task AddAnalysisAsyncWithLimitedInfoShouldAddAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddAnalysisAsyncWithLimitedInfoShouldAddAsync")
                          .Options;

            using var context = new YouTubeJamContext(options);
            var mapper = new DBMapper(context);
            var repo   = new Repository(context, mapper);

            BusinessLogic.Creator c = new BusinessLogic.Creator()
            {
                FirstName = "Marielle",
                LastName  = "Nolasco",
                Email     = "*****@*****.**"
            };
            BusinessLogic.Creator b = new BusinessLogic.Creator()
            {
                Email       = "*****@*****.**",
                ChannelName = "Mathemartian"
            };
            AverageSentiment avg = new AverageSentiment()
            {
                VideoURL = "Abc",
                AverageSentimentScore = 0.5
            };

            //act
            await repo.AddCreatorAsync(c);

            await repo.AddChannelAsync(c, "MatheMartian");

            await repo.AddAnalysisAsync(avg, b);

            //assert
            using var assertContext = new YouTubeJamContext(options);
            var rest = await assertContext.Analysis1.FirstAsync();

            Assert.NotNull(rest);
        }
        public async Task GetUserHistoryShouldGetSomethingAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("GetUserHistoryShouldGetSomething")
                          .Options;

            using var context = new YouTubeJamContext(options);
            var mapper = new DBMapper(context);
            var repo   = new Repository(context, mapper);

            BusinessLogic.Creator c = new BusinessLogic.Creator()
            {
                FirstName = "Marielle",
                LastName  = "Nolasco",
                Email     = "*****@*****.**"
            };

            AverageSentiment avg = new AverageSentiment()
            {
                VideoURL = "Abc",
                AverageSentimentScore = 0.5
            };

            //act
            await repo.AddCreatorAsync(c);

            await repo.AddChannelAsync(c, "MatheMartian");

            await repo.AddVideoAsync("Abc", "MatheMartian");

            await repo.AddAnalysisAsync(avg, c);

            //assert
            using var assertContext = new YouTubeJamContext(options);
            mapper = new DBMapper(assertContext);
            repo   = new Repository(assertContext, mapper);
            var result = await repo.GetUserSearchHistoryAsync("*****@*****.**");

            Assert.NotNull(result[0].VideoURL);
        }
        public async Task <IActionResult> PostAsync([FromBody] VideoHistory inputVideo)
        {
            try
            {
                AverageSentiment inputAnalysis = new AverageSentiment()
                {
                    VideoURL = inputVideo.VideoUrl,
                    AverageSentimentScore = inputVideo.AverageSentimentScore
                };
                Creator inputCreator = new Creator()
                {
                    Email       = inputVideo.Email,
                    ChannelName = inputVideo.ChannelName
                };
                await _repository.AddAnalysisAsync(inputAnalysis, inputCreator);

                return(CreatedAtAction("Post", inputVideo));
            }
            catch
            {
                return(BadRequest());
            }
        }
Exemple #6
0
        private AverageSentiment ParseCommentThreadListResponse(CommentThreadListResponse commentThreadListResponse)
        {
            // Construct the empty parsed comment threads list
            AverageSentiment averageScore = new AverageSentiment();

            // Iterate over the comment thread list response and add each comment text
            foreach (CommentThread commentThread in commentThreadListResponse.Items)
            {
                var comment = new YoutubeComment();
                comment.AuthorName     = commentThread.Snippet.TopLevelComment.Snippet.AuthorDisplayName;
                comment.Content        = commentThread.Snippet.TopLevelComment.Snippet.TextDisplay;
                comment.SentimentScore = SentimentAnalysis.SelectComments(comment.Content);

                averageScore.CommentList.Add(comment);
            }

            // Set the average sentiment score
            averageScore.AverageSentimentScore = averageScore.CommentList.Average(c => c.SentimentScore);
            averageScore.VideoURL     = commentThreadListResponse.Items[0].Snippet.VideoId;
            averageScore.AnalysisDate = DateTime.Now;

            // Return the parsed comment threads list
            return(averageScore);
        }