Beispiel #1
0
        public void TestGetSubscriptionsByUserName_ShouldReturnUserSubscriptions()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var username = "******";

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper      = mockMapper.CreateMapper();
            var userService = new UserService(context, mapper);

            var expectedData = new List <TubeUserChannelDTO> {
                TubeUserChannel
            };
            var actualData = userService.GetSubscriptionsByUserName(username);

            Assert.True(expectedData[0].ChannelId == actualData[0].ChannelId);
            Assert.True(expectedData[0].TubeUserId == actualData[0].TubeUserId);
        }
Beispiel #2
0
 public PlaylistService(TubeDbContext context, IUserService userService, IVideoService videoService, IMapper mapper)
 {
     this.context      = context;
     this.userService  = userService;
     this.videoService = videoService;
     this.mapper       = mapper;
 }
Beispiel #3
0
        private void SeedData(TubeDbContext context)
        {
            context.Users.Add(User);
            context.Histories.AddRange(Histories);

            context.SaveChanges();
        }
Beispiel #4
0
        public void TestGetCommentVotes_ShouldRetturnCorrectVotes()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper      = mockMapper.CreateMapper();
            var voteService = new VoteService(context, mapper);

            var commentId = "1";

            var expectedData = Comment.Likes.ToList();
            var actualData   = voteService.GetDomainCommentVotesByCommenId(commentId);


            Assert.True(expectedData[0].CommentId == mapper.Map <List <VoteDTO> >(actualData)[0].CommentId);
        }
Beispiel #5
0
        public void TestGetChannelByUserName_ShouldReturnCorrectChannel()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userService    = new UserService(context, mapper);
            var channelService = new ChannelService(context, userService, mapper);

            var channelName        = "MyChannel";
            var channelDescription = "TestChannel";
            var tubeUsername       = "******";

            channelService.Create(channelName, channelDescription, string.Empty, tubeUsername);

            var expectedData = channelService.GetChannelByTubeUserName(tubeUsername);

            Assert.False(expectedData == null);
        }
Beispiel #6
0
        public void TestGetTubeUserHistoriesById_ShouldReturnCorrectHistories()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userService    = new UserService(context, mapper);
            var historyService = new HistoryService(context, userService, mapper);

            var tubeUserId = "1";

            var histories = historyService.GetTubeUserHistoriesById(tubeUserId);

            Assert.True(histories.Count == 2);
        }
Beispiel #7
0
        public void TestIsYours_ShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userService    = new UserService(context, mapper);
            var channelService = new ChannelService(context, userService, mapper);

            var channelName        = "MyChannel";
            var channelDescription = "TestChannel";
            var tubeUsername       = "******";

            var channel  = channelService.Create(channelName, channelDescription, string.Empty, tubeUsername);
            var id       = channel.Id;
            var username = Users[1].UserName;

            var isYours = channelService.IsYours(id, username);

            Assert.False(isYours);
        }
Beispiel #8
0
        public void TestSubscribe_UserShouldSubscribeChannel()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userService    = new UserService(context, mapper);
            var channelService = new ChannelService(context, userService, mapper);

            var channelName        = "MyChannel";
            var channelDescription = "TestChannel";
            var tubeUsername       = "******";

            var channel = new Channel {
                Id = "1", Name = channelName, Description = channelDescription
            };
            //var channel = channelService.Create(channelName, channelDescription, string.Empty,  tubeUsername);
            var id = "1";

            channelService.Subscribe(id, tubeUsername);
            var subscribers = channelService.GetSubscribersByChannelId(id);

            Assert.Single(subscribers);
        }
Beispiel #9
0
 public VideoService(TubeDbContext context, IVoteService voteService, IChannelService channelService, ICommentService commentService, IMapper mapper)
 {
     this.context        = context;
     this.voteService    = voteService;
     this.channelService = channelService;
     this.commentService = commentService;
     this.mapper         = mapper;
 }
Beispiel #10
0
        private CommentService GetCommentService(TubeDbContext context)
        {
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userService    = new UserService(context, mapper);
            var channelService = new ChannelService(context, userService, mapper);
            var voteService    = new VoteService(context, mapper);
            var commentService = new CommentService(context, voteService, mapper);

            return(commentService);
        }
Beispiel #11
0
        public void TestGetMostLikedVideos_ShouldReturnCorrectVideos()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var videoService = this.GetVideoService(context);
            var videos       = videoService.GetMostLikedVideos();

            Assert.True(videos[0].Id == Videos[0].Id);
        }
Beispiel #12
0
        private void SeedData(TubeDbContext context)
        {
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var videoForDB   = mapper.Map <Video>(Video);
            var commentForDB = mapper.Map <Comment>(Comment);

            context.Videos.Add(videoForDB);
            context.Comments.Add(commentForDB);

            context.SaveChanges();
        }
Beispiel #13
0
        public void TestGetUserPlayListsByUsername_ShouldReturnCorrectPlaylists()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var playlistTubeUserName = "******";
            var playlistService      = this.GetPlaylistService(context);
            var playlists            = playlistService.GetUserPlayListsByUsername(playlistTubeUserName);

            Assert.True(playlists.Count == 2);
        }
Beispiel #14
0
        private void SeedData(TubeDbContext context)
        {
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userForDB            = mapper.Map <TubeUser>(TubeUser);
            var tubeUserChannelForDB = mapper.Map <TubeUserChannel>(TubeUserChannel);

            context.Users.Add(userForDB);
            context.TubeUserChannels.Add(tubeUserChannelForDB);

            context.SaveChanges();
        }
Beispiel #15
0
        public void TestGetVideosByChannelId_ShouldReturnCorrectVideos()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var videoService = this.GetVideoService(context);
            var channelId    = "1";
            var videos       = videoService.GetVideosByChannelId(channelId);

            Assert.True(videos.Count == 2);
        }
Beispiel #16
0
        public void TestGetCommentsByVideoId_ShouldReturnCorrectComments()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var commentService = this.GetCommentService(context);
            var videoId        = "1";

            var comments = commentService.GetDomainVideoCommentsByVideoId(videoId);

            Assert.True(comments.Count == 1);
        }
Beispiel #17
0
        public void TestGetPlaylistVideos_ShouldReturnCorrectPlaylistVideos()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var playlistId      = "1";
            var playlistService = this.GetPlaylistService(context);

            var videoPlaylists = playlistService.GetPlaylistVideos(playlistId);

            Assert.True(videoPlaylists.Count == 1);
        }
Beispiel #18
0
        public void TestGetCommentById_ShouldReturnCorrectComment()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var commentService = this.GetCommentService(context);

            var expectedComment = Comments[1];
            var actualComment   = commentService.GetCommentById(expectedComment.Id);

            Assert.True(expectedComment.Id == actualComment.Id);
        }
Beispiel #19
0
        public void TestGetPlaylistById_ShouldReturnCorrectPlaylist()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var playlistId      = "1";
            var playlistService = this.GetPlaylistService(context);

            var expectedPlaylist = Playlists[0];
            var actualPlaylist   = playlistService.GetPlaylistById(playlistId);

            Assert.True(expectedPlaylist.Id == actualPlaylist.Id);
        }
Beispiel #20
0
        public void TestGetVideoByName_ShouldReturnCorrectVideo()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var videoService = this.GetVideoService(context);
            var videoName    = "VideoTest";

            var expectedVideo = Videos[0];
            var actualVideo   = videoService.GetVideoByName(videoName);

            Assert.True(expectedVideo.Id == actualVideo.Id);
        }
Beispiel #21
0
        private void SeedData(TubeDbContext context)
        {
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var usersForDB   = mapper.Map <List <TubeUser> >(Users);
            var videosForDB  = mapper.Map <List <Video> >(Videos);
            var channelForDB = mapper.Map <Channel>(Channel);

            context.Users.AddRange(usersForDB);
            context.Videos.AddRange(videosForDB);
            context.Channels.Add(channelForDB);

            context.SaveChanges();
        }
Beispiel #22
0
        public void TestGetSearchedVideos_ShouldReturnCorrectVideos()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var videoService = this.GetVideoService(context);
            var searchText   = "VideoT";

            var expectedData = Videos;
            var actualData   = videoService.GetSearchedVideos(searchText);

            Assert.True(expectedData[0].Id == actualData[0].Id);
            Assert.True(expectedData[1].Id == actualData[1].Id);
        }
Beispiel #23
0
        public void TestUnLike_ShouldDecreaseVideoLikes()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var videoService = this.GetVideoService(context);
            var video        = Videos[0];
            var username     = "******";

            videoService.Like(video, username);
            videoService.UnLike(video, username);

            Assert.True(video.Likes.Count == 1);
        }
Beispiel #24
0
        public void TestAdd_ShouldCreateVideo()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var videoService = this.GetVideoService(context);

            var videoName     = "TestAddVideo";
            var videoCategory = "TestAddVideoCategory";
            var tubeUsername  = "******";

            var video = videoService.Add(videoName, videoCategory, string.Empty, tubeUsername);

            Assert.False(video == null);
        }
Beispiel #25
0
        private void SeedData(TubeDbContext context)
        {
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var userForDB     = mapper.Map <TubeUser>(User);
            var videoForDB    = mapper.Map <Video>(Video);
            var video2ForDB   = mapper.Map <Video>(Video2);
            var commentsForDB = mapper.Map <List <Comment> >(Comments);

            context.Users.Add(userForDB);
            context.Videos.Add(videoForDB);
            context.Videos.Add(video2ForDB);
            context.Comments.AddRange(commentsForDB);

            context.SaveChanges();
        }
Beispiel #26
0
        public void TestGetTubeUserByUsername_WithoutAnyData_ShouldReturnNull()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            var username = "******";

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper      = mockMapper.CreateMapper();
            var userService = new UserService(context, mapper);

            var actualData = userService.GetTubeUserByUsername(username);

            Assert.True(actualData == null);
        }
Beispiel #27
0
        public void TestCreateForComment_ShouldCreateCommentVote()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper      = mockMapper.CreateMapper();
            var voteService = new VoteService(context, mapper);

            var vote = voteService.CreateForComment(Comment, "TestUsername");

            Assert.True(vote != null);
        }
Beispiel #28
0
        public void TestGetTubeUserById_ShouldReturnTubeUserWithThatId()
        {
            var options = new DbContextOptionsBuilder <TubeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new TubeDbContext(options);

            SeedData(context);

            var id = "2222234434546456456";

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TubeProfile());
            });
            var mapper      = mockMapper.CreateMapper();
            var userService = new UserService(context, mapper);

            var expectedData = TubeUser;
            var actualData   = userService.GetTubeUserById(id);

            Assert.True(expectedData.Id == actualData.Id);
        }
Beispiel #29
0
 public VoteService(TubeDbContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
Beispiel #30
0
 public ChannelService(TubeDbContext context, IUserService userService, IMapper mapper)
 {
     this.context     = context;
     this.userService = userService;
     this.mapper      = mapper;
 }