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 AddVideoShouldAddVideoAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddVideoShouldAdd")
                          .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     = "*****@*****.**"
            };
            var    url         = "abc";
            string channelName = "MatheMartian";

            //act
            await repo.AddCreatorAsync(c);

            await repo.AddChannelAsync(c, channelName);

            await repo.AddVideoAsync(url, channelName);

            //assert
            using var assertContext = new YouTubeJamContext(options);
            var rest = await assertContext.Video.FirstAsync(v => v.URL == url);

            Assert.NotNull(rest);
        }
        public async Task AddCreatorandChannelShouldBeUniqueAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddCreatorandChannelShouldBeUnique")
                          .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     = "*****@*****.**"
            };
            string channelName = "MatheMartian";

            //act
            try
            {
                await repo.AddCreatorandChannelAsync(c, channelName);

                await repo.AddCreatorandChannelAsync(c, channelName);

                Assert.True(false);
            }
            catch (ChannelNameTakenException)
            {
                Assert.True(true);
            }
        }
        public async Task ChannelNameShouldBeUniqueTest2Async()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("ChannelNameShouldBeUniqueTest2")
                          .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     = "*****@*****.**"
            };

            //act
            await repo.AddCreatorAsync(c);

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

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

                //assert
                Assert.True(false);
            }
            catch
            {
                Assert.True(true);
            }
        }
        public async Task AddCreatorandChannelShouldAddAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddCreatorandChannelShouldAdd")
                          .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     = "*****@*****.**"
            };
            string channelName = "MatheMartian";
            //act
            await repo.AddCreatorandChannelAsync(c, channelName);

            //assert
            using var assertContext = new YouTubeJamContext(options);
            var result = assertContext.Channel.FirstOrDefaultAsync(c => c.ChannelName == channelName);

            Assert.NotNull(result);
        }
        public async Task LogInShouldHandleExceptionsAsync()
        {
            //assert
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("LogInShouldHandleExceptions")
                          .Options;


            string email = "*****@*****.**";


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

            //act & assert
            try
            {
                var result = await repo.LogInAsync(email);

                Assert.True(false);
            }
            catch (Persistence.CreatorDoesNotExistException)
            {
                Assert.True(true);
            }
        }
        public async Task UpdateChannelNameShouldUpdateAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("UpdateChannelNameShouldUpdate")
                          .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     = "*****@*****.**"
            };

            //act
            await repo.AddCreatorAsync(c);

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

            await repo.UpdateChannelNameAsync("MathMars", c);

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

            Assert.True(result.ChannelName == "MathMars");
        }
        public async Task LogInShouldLogInAsync()
        {
            //assert
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("LogInShouldLogIn")
                          .Options;

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

            string email = "*****@*****.**";

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

            //act
            await repo.AddCreatorAsync(c);

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

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

            Assert.NotNull(result);
        }
        public async Task AddCreatorsShouldAddCreatorsAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <YouTubeJamContext>()
                          .UseInMemoryDatabase("AddCreatorsShouldAdd")
                          .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     = "*****@*****.**"
            };

            //act
            await repo.AddCreatorAsync(c);

            //assert
            using var assertContext = new YouTubeJamContext(options);
            var rest = assertContext.Creator.Select(c => c);

            Assert.NotNull(rest);
        }
        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);
        }
Beispiel #13
0
 /// <summary>
 /// Set up the dependencies of Repository
 /// </summary>
 public Repository(YouTubeJamContext context, IMapper map)
 {
     _context = context;
     _map     = map;
 }
Beispiel #14
0
 public DBMapper(YouTubeJamContext context)
 {
     _context = context;
 }