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); }
public PlaylistService(TubeDbContext context, IUserService userService, IVideoService videoService, IMapper mapper) { this.context = context; this.userService = userService; this.videoService = videoService; this.mapper = mapper; }
private void SeedData(TubeDbContext context) { context.Users.Add(User); context.Histories.AddRange(Histories); context.SaveChanges(); }
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); }
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); }
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); }
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); }
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); }
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; }
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); }
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); }
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(); }
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); }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }
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); }
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); }
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); }
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(); }
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); }
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); }
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); }
public VoteService(TubeDbContext context, IMapper mapper) { this.context = context; this.mapper = mapper; }
public ChannelService(TubeDbContext context, IUserService userService, IMapper mapper) { this.context = context; this.userService = userService; this.mapper = mapper; }