Esempio n. 1
0
        public async Task Should_ReturnRightPhrase_When_UserEditsReply()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Wendy");
            var user        = await _fixture.SendAsync(userRequest);

            const string title       = "The New Cold War";
            const string description = "Dork alert.";

            // User creates library
            var createLibraryRequest = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(createLibraryRequest);

            // Get libraries just created by user
            var getLibrariesRequest = new GetLibrariesForUser(user.Id);
            var libraries           = await _fixture.SendAsync(getLibrariesRequest);

            // Get id of the single library
            var libraryDtos = libraries.ToList();
            var libraryId   = libraryDtos.ElementAt(0).Id;

            // create video
            var vidTitle       = "Video title";
            var vidLink        = "Link goes here";
            var vidDescription = "Video description";

            var createVideoRequest = new CreateVideo(user.Id, libraryId, vidTitle, vidLink, vidDescription);
            await _fixture.SendAsync(createVideoRequest);

            // Get video
            var getVideosRequest = new GetVideosOfLibrary(libraryId);
            var videos           = await _fixture.SendAsync(getVideosRequest);

            var video = videos.ToList().ElementAt(0);

            // Create 1 annotation
            var comment1   = "God you're so stupid!";
            var timestamp1 = 0.46;

            var annotationRequest1 = new CreateAnnotation(user.Id, comment1, video.Id, timestamp1);

            await _fixture.SendAsync(annotationRequest1);

            // get annotations
            var getAnnotationsRequest = new GetAnnotationsByVideoId(video.Id);
            var results = await _fixture.SendAsync(getAnnotationsRequest);

            var annotation = results.ToList().ElementAt(0);

            // create reply
            var replyText1    = "I have three thousand dollars, cash";
            var new_replyText = "I have $38 and a gold bracelet";

            var createReplyRequest1 = new CreateAnnotationReply(user.Id, annotation.Id, replyText1);

            await _fixture.SendAsync(createReplyRequest1);

            // get reply
            var getReplyRequest = new GetAnnotationRepliesByVideoId(video.Id);
            var replyResults1   = await _fixture.SendAsync(getReplyRequest);

            var reply = replyResults1.Single();

            // edit reply
            var editReplyRequest = new EditAnnotationReply(user.Id, reply.Id, new_replyText);
            await _fixture.SendAsync(editReplyRequest);

            // get replies
            var getRepliesRequest = new GetAnnotationRepliesByVideoId(video.Id);
            var replyResults      = await _fixture.SendAsync(getRepliesRequest);

            var replies = replyResults.ToList();
            var reply1  = replies.ElementAt(0);

            // Check that reply got created
            Assert.Single(replies);

            // Check that reply returns right thing
            Assert.Equal(new_replyText, reply1.Text);
        }
Esempio n. 2
0
        public async Task Should_ReturnZero_When_UserDeletesReply()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Bebe");
            var user        = await _fixture.SendAsync(userRequest);

            const string title       = "My Cat Thumper";
            const string description = "Thumper is 12 years old";

            // User creates library
            var createLibraryRequest = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(createLibraryRequest);

            // Get libraries just created by user
            var getLibrariesRequest = new GetLibrariesForUser(user.Id);
            var libraries           = await _fixture.SendAsync(getLibrariesRequest);

            // Get id of the single library
            var libraryDtos = libraries.ToList();
            var libraryId   = libraryDtos.ElementAt(0).Id;

            // create video
            var vidTitle       = "Video title";
            var vidLink        = "Link goes here";
            var vidDescription = "Video description";

            var createVideoRequest = new CreateVideo(user.Id, libraryId, vidTitle, vidLink, vidDescription);
            await _fixture.SendAsync(createVideoRequest);

            // Get video
            var getVideosRequest = new GetVideosOfLibrary(libraryId);
            var videos           = await _fixture.SendAsync(getVideosRequest);

            var video = videos.ToList().ElementAt(0);

            // Create 1 annotation
            var comment1   = "This is a comment!";
            var timestamp1 = 2.05;

            var annotationRequest1 = new CreateAnnotation(user.Id, comment1, video.Id, timestamp1);

            await _fixture.SendAsync(annotationRequest1);

            // get annotations
            var getAnnotationsRequest = new GetAnnotationsByVideoId(video.Id);
            var results = await _fixture.SendAsync(getAnnotationsRequest);

            var annotation = results.ToList().ElementAt(0);

            // create reply
            var replyText1          = "Such a great annotation";
            var createReplyRequest1 = new CreateAnnotationReply(user.Id, annotation.Id, replyText1);
            await _fixture.SendAsync(createReplyRequest1);

            // Get reply
            var getReplyRequest = new GetAnnotationRepliesByVideoId(video.Id);
            var replyResults1   = await _fixture.SendAsync(getReplyRequest);

            var reply = replyResults1.Single();

            // delete reply
            var deleteReplyRequest = new DeleteAnnotationReply(user.Id, reply.Id);
            await _fixture.SendAsync(deleteReplyRequest);

            // get replies
            var getRepliesRequest = new GetAnnotationRepliesByVideoId(video.Id);
            var replyResults      = await _fixture.SendAsync(getRepliesRequest);

            var replies = replyResults.ToList();

            // Check that no replies are in database
            Assert.Empty(replies);
        }
        public async Task Should_ReturnTwoReplies_When_UserCreatesTwoRepliesOnSameAnnotation()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            const string title       = "My Fantastic Library";
            const string description = "A suitable description.";

            // User creates library
            var createLibraryRequest = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(createLibraryRequest);

            // Get libraries just created by user
            var getLibrariesRequest = new GetLibrariesForUser(user.Id);
            var libraries           = await _fixture.SendAsync(getLibrariesRequest);

            // Get id of the single library
            var libraryDtos = libraries.ToList();
            var libraryId   = libraryDtos.ElementAt(0).Id;

            // create two videos
            var vidTitle        = "Video title";
            var vidTitle2       = "Video title2";
            var vidLink         = "Link goes here";
            var vidLink2        = "Link goes here2";
            var vidDescription  = "Video description";
            var vidDescription2 = "Video description2";

            var createVideoRequest  = new CreateVideo(user.Id, libraryId, vidTitle, vidLink, vidDescription);
            var createVideoRequest2 = new CreateVideo(user.Id, libraryId, vidTitle2, vidLink2, vidDescription2);
            await _fixture.SendAsync(createVideoRequest);

            await _fixture.SendAsync(createVideoRequest2);

            // Get video
            var getVideosRequest = new GetVideosOfLibrary(libraryId);
            var videosResults    = await _fixture.SendAsync(getVideosRequest);

            var videos = videosResults.ToList();
            var video1 = videos.ToList().ElementAt(0);
            var video2 = videos.ToList().ElementAt(1);

            // Create an annotation on each video
            var comment1   = "This is a comment!";
            var timestamp1 = 1.25;
            var comment2   = "This is another comment!";
            var timestamp2 = 18.90;

            var annotationRequest1 = new CreateAnnotation(user.Id, comment1, video1.Id, timestamp1);
            var annotationRequest2 = new CreateAnnotation(user.Id, comment2, video2.Id, timestamp2);

            await _fixture.SendAsync(annotationRequest1);

            await _fixture.SendAsync(annotationRequest2);

            // get annotations
            var getAnnotationsRequest1 = new GetAnnotationsByVideoId(video1.Id);
            var getAnnotationsRequest2 = new GetAnnotationsByVideoId(video2.Id);

            var annotationResults1 = await _fixture.SendAsync(getAnnotationsRequest1);

            var annotationResults2 = await _fixture.SendAsync(getAnnotationsRequest2);

            var video1Annotation = annotationResults1.ToList().ElementAt(0);
            var video2Annotation = annotationResults2.ToList().ElementAt(0);

            // create replies
            var replyText1 = "This is a reply";
            var replyText2 = "This is another reply";

            var createReplyRequest1 = new CreateAnnotationReply(user.Id, video1Annotation.Id, replyText1);
            var createReplyRequest2 = new CreateAnnotationReply(user.Id, video2Annotation.Id, replyText2);

            await _fixture.SendAsync(createReplyRequest1);

            await _fixture.SendAsync(createReplyRequest2);

            // get replies
            var getRepliesRequest1 = new GetAnnotationRepliesByVideoId(video1.Id);
            var getRepliesRequest2 = new GetAnnotationRepliesByVideoId(video2.Id);

            var replyResults1 = await _fixture.SendAsync(getRepliesRequest1);

            var replyResults2 = await _fixture.SendAsync(getRepliesRequest2);

            var replies1 = replyResults1.ToList();
            var replies2 = replyResults2.ToList();

            var reply1 = replies1.ElementAt(0);
            var reply2 = replies2.ElementAt(0);

            // Check that the properties of the replies are correct
            Assert.Equal(replyText1, reply1.Text);
            Assert.Equal(replyText2, reply2.Text);
        }