예제 #1
0
        public async Task ItDeletesVideoFromLibrary()
        {
            // 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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // Create video for library
            const string vidTitle       = "Video Title";
            const string videoUrl       = "https://www.youtube.com/watch?v=-O5kNPlUV7w";
            const string vidDescription = "Video description";

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

            // Get videos just created by user
            var getVideosRequest = new GetVideosOfLibrary(libraryId);
            var videos           = await _fixture.SendAsync(getVideosRequest);

            // Make sure there's only one video
            var videoDtos = videos.ToList();

            Assert.Single(videoDtos);

            var videoId = videoDtos.ToList().ElementAt(0).Id;

            //delete video from library
            var deleteVideoRequest = new DeleteVideoFromLibrary(videoId);
            await _fixture.SendAsync(deleteVideoRequest);

            // Check for any remaining videos (should be 0)
            var getVideosRequest1 = new GetVideosOfLibrary(libraryId);
            var videosLeft        = await _fixture.SendAsync(getVideosRequest1);

            var videoCount = videosLeft.Count();

            Assert.Equal(0, videoCount);
        }
예제 #2
0
        public async Task Should_ThrowInvalidOperationException_When_GivenInvalidId()
        {
            // 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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // Create two videos for library
            const string videoTitle       = "Video Title";
            const string videoUrl         = "https://www.youtube.com/watch?v=-O5kNPlUV7w";
            const string videoDescription = "Video Description";

            var createVideosRequest1 = new CreateVideo(user.Id, libraryId, videoTitle, videoUrl, videoDescription);

            await _fixture.SendAsync(createVideosRequest1);

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

            // Make sure correct number of videos returned
            var videoDtos = videos.ToList();

            Assert.Single(videoDtos);

            // Get video id
            int videoId = videoDtos.ElementAt(0).Id;

            // make videoId invalid
            videoId++;

            // Create request with invalid id
            var getVideoRequest = new GetVideoById(videoId);

            // Make sure that an exception is thrown when video retrieval is attempted
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await _fixture.SendAsync(getVideoRequest));
        }
예제 #3
0
        public async Task Should_ReturnCorrectVideo_When_GivenValidId()
        {
            // 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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // Create two videos for library
            const string videoTitle       = "Video Title";
            const string videoUrl         = "https://www.youtube.com/watch?v=-O5kNPlUV7w";
            const string videoDescription = "Video Description";

            var createVideosRequest1 = new CreateVideo(user.Id, libraryId, videoTitle, videoUrl, videoDescription);

            await _fixture.SendAsync(createVideosRequest1);

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

            // Make sure correct number of videos returned
            var videoDtos = videos.ToList();

            Assert.Single(videoDtos);

            // Get video id
            int videoId = videoDtos.ElementAt(0).Id;

            // Get the video using the id
            var getVideoRequest = new GetVideoById(videoId);
            var video           = await _fixture.SendAsync(getVideoRequest);

            // Make sure the video's properties match the properties given on creation
            Assert.Equal(videoTitle, video.Title);
            Assert.Equal(videoDescription, video.Description);
        }
예제 #4
0
        public async Task Should_ReturnTwoVideos_When_UserCreatesTwoVideos()
        {
            // 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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // Create two videos for library
            const string vidTitle       = "Video Title";
            const string videoUrl       = "https://www.youtube.com/watch?v=-O5kNPlUV7w";
            const string videoUrl2      = "https://www.youtube.com/watch?v=-O5kNPlUV7a";
            const string vidDescription = "Video description";

            var createVideosRequest1 = new CreateVideo(user.Id, libraryId, vidTitle, videoUrl, vidDescription);
            var createVideosRequest2 = new CreateVideo(user.Id, libraryId, vidTitle, videoUrl2, vidDescription);

            await _fixture.SendAsync(createVideosRequest1);

            await _fixture.SendAsync(createVideosRequest2);

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

            // Make sure correct number of videos returned
            var videoDtos = videos.ToList();

            Assert.Equal(2, videoDtos.Count);

            // Make sure the videos have the same content
            foreach (var video in videoDtos)
            {
                Assert.Equal(vidTitle, video.Title);
                Assert.Equal(vidDescription, video.Description);
            }
        }
예제 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var library = Library;
            await CreateLibrary.CreateLibraryAndPostAsync(library);


            return(RedirectToPage("./Index"));
        }
예제 #6
0
        public async Task ItDeletesRoleById()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            const string title       = "My Fantastic Library";
            const string roleTitle   = "Student";
            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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // User creates role for that library
            var createRoleRequest = new CreateRole(roleTitle, libraryId);
            await _fixture.SendAsync(createRoleRequest);

            // Retrieve roles
            var getRoleRequest = new GetRolesForLibrary(libraryId);
            var role           = await _fixture.SendAsync(getRoleRequest);

            // Return roles
            var roleDtos = role.ToList();

            // RoleId of role after default (our created role)
            var roleId = roleDtos.ToList().ElementAt(1).Id;

            // Delete that role
            var deleteRoleRequest = new DeleteRoleById(roleId);
            await _fixture.SendAsync(deleteRoleRequest);

            // Retrieve remaining roles
            var getRolesLeftRequest = new GetRolesForLibrary(libraryId);
            var roleLeft            = await _fixture.SendAsync(getRolesLeftRequest);

            var roleCount = roleLeft.Count();

            Assert.Equal(1, roleCount);
        }
예제 #7
0
        public async Task Should_ReturnCorrectNumberOfLibraries_When_MultipleUsersCreateLibraries()
        {
            const string title1                  = "Library Title 1";
            const string description1            = "Library Description 1";
            const int    numOfLibrariesFromUser1 = 2;

            const string title2                  = "Library Title 2";
            const string description2            = "Library Description 2";
            const int    numOfLibrariesFromUser2 = 3;

            // Create test users
            var userRequest1 = new CreateUserWithoutAuth("Alice");
            var user1        = await _fixture.SendAsync(userRequest1);

            var userRequest2 = new CreateUserWithoutAuth("Bob");
            var user2        = await _fixture.SendAsync(userRequest2);

            // Send the requests to create a library many times (synchronously) for user1
            var request1 = new CreateLibrary(user1.Id, title1, description1);

            for (var i = 0; i < numOfLibrariesFromUser1; i++)
            {
                await _fixture.SendAsync(request1);
            }

            // Send the requests to create a library many times (synchronously) for user2
            var request2 = new CreateLibrary(user2.Id, title2, description2);

            for (var i = 0; i < numOfLibrariesFromUser2; i++)
            {
                await _fixture.SendAsync(request2);
            }

            // Get all libraries for user1
            var librariesRequest1 = new GetLibrariesForUser(user1.Id);
            var libraries1        = await _fixture.SendAsync(librariesRequest1);

            // Get all libraries for user2
            var librariesRequest2 = new GetLibrariesForUser(user2.Id);
            var libraries2        = await _fixture.SendAsync(librariesRequest2);

            // Check that it returns the correct number of libraries for user1 and user2
            Assert.True(libraries1.Count() == numOfLibrariesFromUser1);
            Assert.True(libraries2.Count() == numOfLibrariesFromUser2);
        }
예제 #8
0
파일: TestUtility.cs 프로젝트: kjones7/Plum
        public async Task <LibraryDto> CreateLibraryAsync()
        {
            const string title       = "My Fantastic Library";
            const string description = "A suitable description.";

            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            // Create a library with that user
            var request = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(request);

            // Get all libraries created by that user
            var librariesRequest = new GetLibrariesCreatedByUserId(user.Id);

            return((await _fixture.SendAsync(librariesRequest)).Single());
        }
예제 #9
0
        public async Task ShouldGetRolesForMembers()
        {
            // 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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // Return member
            var getMembersRequest = new GetMembersOfLibrary(libraryId);
            var members           = await _fixture.SendAsync(getMembersRequest);

            // Get that member's id
            var memberId = members.ToList().ElementAt(0).Id;

            // Put membership Id's into list
            var memberIds = new List <int>();

            memberIds.Add(memberId);

            // Retrieve roles from list
            var getRolesForMembersRequest = new GetRolesForMembers(memberIds);
            var memberRolesReturn         = await _fixture.SendAsync(getRolesForMembersRequest);

            // Check to make sure roles returned from list
            Assert.Contains("Instructor", memberRolesReturn.Single().Value.Title);
        }
예제 #10
0
        public async Task Should_ReturnNone_When_VideoHasNoAnnotations()
        {
            // 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 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);

            // Get annotations, and ensure none exist yet, since none have been created
            var getAnnotationsRequest = new GetAnnotationsByVideoId(video.Id);
            var annotations           = await _fixture.SendAsync(getAnnotationsRequest);

            Assert.Empty(annotations);
        }
예제 #11
0
        public async Task ItDeletesLibrary()
        {
            // 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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            //Delete that library
            var deleteLibraryRequest = new DeleteLibrary(libraryId);
            await _fixture.SendAsync(deleteLibraryRequest);

            //check to make sure there are no libraries remaining
            var remainingLibrariesRequest = new GetLibrariesForUser(user.Id);
            var librariesLeft             = await _fixture.SendAsync(getLibrariesRequest);

            // Make sure there's no library left
            var libraryDtosLeft = librariesLeft.ToList();

            Assert.Empty(libraryDtosLeft);
        }
예제 #12
0
        public async Task Should_Get_Roles_For_Library()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            const string title       = "My Fantastic Library";
            const string roleTitle   = "Student";
            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);

            // Make sure there's only one library
            var libraryDtos = libraries.ToList();

            Assert.Single(libraryDtos);

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

            // User creates role for that library
            var createRoleRequest = new CreateRole(roleTitle, libraryId);
            await _fixture.SendAsync(createRoleRequest);

            // Retrieve that role
            var getRoleRequest = new GetRolesForLibrary(libraryId);
            var role           = await _fixture.SendAsync(getRoleRequest);

            // Check that our role is the only role and that title equals the one returned
            Assert.Contains(roleTitle, role.Select(r => r.Title));
        }
예제 #13
0
        public async Task ItRunsAndCreatesLibrary()
        {
            const string title       = "My Fantastic Library";
            const string description = "A suitable description.";

            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            // Create a library with that user
            var request = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(request);

            // Get all libraries created by that user
            var librariesRequest = new GetLibrariesCreatedByUserId(user.Id);
            var libraries        = (await _fixture.SendAsync(librariesRequest)).ToArray();

            // Check that our library is the only library returned
            Assert.Single(libraries);

            // Check that the fields match the feilds we set
            Assert.Equal(title, libraries.Single().Title);
            Assert.Equal(description, libraries.Single().Description);
        }
예제 #14
0
        public async Task ItRunsAndEditsLibrary()
        {
            //const int libraryId = 1;
            const string title          = "My Fantastic Library";
            const string description    = "A suitable description.";
            const string newTitle       = "My Fantastic New Library Title";
            const string newDescription = "A (new) suitable description.";

            // Create a test user (don't think this is needed here)
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            // Create a library with that user
            var request = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(request);

            // Get all libraries created by that user
            var librariesRequest1 = new GetLibrariesForUser(user.Id);
            var libraries1        = (await _fixture.SendAsync(librariesRequest1)).ToArray();

            // Edit a library with that user
            var libraryId            = libraries1.Single().Id;
            var updateLibraryRequest = new UpdateLibraryInfo(libraryId, newTitle, newDescription);
            await _fixture.SendAsync(updateLibraryRequest);

            // Get all libraries created by that user
            var librariesRequest2 = new GetLibrariesForUser(user.Id);
            var libraries2        = (await _fixture.SendAsync(librariesRequest2)).ToArray();

            // Check that our library is the only library returned
            Assert.Single(libraries2);

            // Check that the fields match the fields we set
            Assert.Equal(newTitle, libraries2.Single().Title);
            Assert.Equal(newDescription, libraries2.Single().Description);
        }
예제 #15
0
        public async Task ItDeletesLibraryMember()
        {
            const string title       = "My Fantastic Library";
            const string description = "A suitable description.";

            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            // Create a library with that user
            var request = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(request);

            // Get all libraries created by that user
            var librariesRequest = new GetLibrariesCreatedByUserId(user.Id);
            var libraries        = (await _fixture.SendAsync(librariesRequest)).ToArray();

            //get single library from that user
            var library = libraries.Single();

            //get id for user
            var membershipRequest = new GetMembersOfLibrary(library.Id);
            var memberShip        = await _fixture.SendAsync(membershipRequest);

            //delete user from library
            var deleteMemberRequest = new DeleteMemberOfLibrary(memberShip.Single().Id);
            await _fixture.SendAsync(deleteMemberRequest);

            //get members of library (should be 0)
            var memberRequest  = new GetMembersOfLibrary(library.Id);
            var currentMembers = await _fixture.SendAsync(memberRequest);

            var member = currentMembers.Count();

            Assert.Equal(0, member);
        }
예제 #16
0
        public async Task Should_ReturnCorrectData_When_UserEditsAnnotation()
        {
            // 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 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 two annotations
            var comment1   = "This is a comment!";
            var comment2   = "This is another comment!";
            var timestamp1 = 1.25;
            var timestamp2 = 18.45;

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

            await _fixture.SendAsync(annotationRequest1);

            await _fixture.SendAsync(annotationRequest2);

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

            var annotations = results.ToList();

            // Edit annotations
            var newComment1 = "New comment1!";
            var newComment2 = "New Comment2!";

            var editAnnotationRequest1 = new EditAnnotation(user.Id, newComment1, annotations.ElementAt(0).Id);
            var editAnnotationRequest2 = new EditAnnotation(user.Id, newComment2, annotations.ElementAt(1).Id);
            await _fixture.SendAsync(editAnnotationRequest1);

            await _fixture.SendAsync(editAnnotationRequest2);

            // Get edited annotations
            var getEditedAnnotationsRequest = new GetAnnotationsByVideoId(video.Id);
            var editedResults = await _fixture.SendAsync(getEditedAnnotationsRequest);

            var editedAnnotations = editedResults.ToList();

            // Check that there are two annotations
            Assert.Equal(2, editedAnnotations.Count);

            // Check that the comments of each annotation match the edited comments
            var annotation1 = editedAnnotations.ElementAt(0);
            var annotation2 = editedAnnotations.ElementAt(1);

            Assert.Equal(newComment1, annotation1.Comment);
            Assert.Equal(newComment2, annotation2.Comment);
        }
예제 #17
0
        public async Task Should_DeleteAnnotation_When_UserDeletesAnnotation()
        {
            // 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 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 two annotations
            var comment1   = "This is a comment!";
            var comment2   = "This is another comment!";
            var timestamp1 = 1.25;
            var timestamp2 = 18.45;

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

            await _fixture.SendAsync(annotationRequest1);

            await _fixture.SendAsync(annotationRequest2);

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

            var annotations = results.ToList();

            // Check that two annotations were created
            Assert.Equal(2, annotations.Count);

            // Delete the first annotation in the list
            var annotation1 = annotations.ElementAt(0);

            var deleteAnnotationRequest = new DeleteAnnotation(user.Id, annotation1.Id);
            await _fixture.SendAsync(deleteAnnotationRequest);

            // Get annotations after deleting one of them and make sure there's only one now
            var getNewAnnotationsRequest = new GetAnnotationsByVideoId(video.Id);
            var afterDeleteResults       = await _fixture.SendAsync(getNewAnnotationsRequest);

            var afterDeleteAnnotations = afterDeleteResults.ToList();

            // Check that there are two annotations
            Assert.Equal(1, afterDeleteAnnotations.Count);
            Assert.Equal(comment1, afterDeleteAnnotations.ElementAt(0).Comment);
        }
예제 #18
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);
        }
예제 #19
0
        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 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 two annotations
            var comment1   = "This is a comment!";
            var timestamp1 = 1.25;

            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 replies
            var replyText1 = "This is a reply";
            var replyText2 = "This is another reply";

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

            await _fixture.SendAsync(createReplyRequest1);

            await _fixture.SendAsync(createReplyRequest2);

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

            var replies = replyResults.ToList();

            var reply1 = replies.ElementAt(0);
            var reply2 = replies.ElementAt(1);

            // Check that both replies got created
            Assert.Equal(2, replies.Count);

            // Check that the properties of the replies are correct
            Assert.Equal(replyText1, reply1.Text);
            Assert.Equal(replyText2, reply2.Text);
        }
예제 #20
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);
        }
예제 #21
0
        /// <summary>
        /// Call the compiler with appropriate arguments for compiling the <paramref name="Unit"/>
        /// </summary>
        /// <remarks>
        /// This actually calls the linker as well, so that a shared library is built rather than just object code
        /// </remarks>
        /// <param name="Unit">Unit to compile</param>
        /// <param name="Architecture">Target architecture</param>
        /// <param name="WindowsSubsystem">Windows Subsystem to build for</param>
        public static void Compile(Unit Unit, Architecture Architecture = Architecture.Generic, WindowsSubsystem WindowsSubsystem = WindowsSubsystem.Console)
        {
            String arch;

            switch (Architecture)
            {
            case Architecture.Generic:
                arch = "-mtune=generic";
                break;

            case Architecture.Native:
            default:
                arch = "-march=native";
                break;
            }
            try {
                Process          GnatMake  = new Process();
                ProcessStartInfo StartInfo = new ProcessStartInfo();
                StartInfo.FileName = "gnatmake";
                StartInfo.EnvironmentVariables["ADA_INCLUDE_PATH"] = "";
                StartInfo.EnvironmentVariables["ADA_OBJECTS_PATH"] = "";
                switch (Environment.OSVersion.Platform)
                {
                case (PlatformID)1:
                case (PlatformID)2:
                case (PlatformID)3:
                    switch (WindowsSubsystem)
                    {
                    case WindowsSubsystem.Windows:
                        StartInfo.Arguments = "-shared -shared-libgcc -fPIC -mwindows " + arch + " " + String.Join(' ', Unit.GetFiles()) + Unit.LinkerArguments;
                        break;

                    case WindowsSubsystem.Console:
                    default:
                        StartInfo.Arguments = "-shared -shared-libgcc -fPIC -mconsole " + arch + " " + String.Join(' ', Unit.GetFiles()) + Unit.LinkerArguments;
                        break;
                    }
                    break;

                case PlatformID.Unix:
                    StartInfo.Arguments = "-shared -fPIC " + arch + " " + String.Join(' ', Unit.GetFiles()) + Unit.LinkerArguments;
                    break;

                default:
                    throw new PlatformNotSupportedException("Unable to determine what the Operating System is");
                }
                GnatMake.StartInfo = StartInfo;
                GnatMake.Start();
                GnatMake.WaitForExit();                 // We need to wait here, because otherwise units will be compiled before their dependencies are finished compiling. That's bad.
                GnatMake.Dispose();
            } catch (Win32Exception) {
                throw new MissingGNATProgramException("gnatmake");
            }
            if (Unit is PackageUnit || Unit is SubroutineUnit)
            {
                Process CreateLibrary;
                // Linking is a very different procedure on different systems, so figure out what we're supposed to do
                switch (Environment.OSVersion.Platform)
                {
                case (PlatformID)1:
                case (PlatformID)2:
                case (PlatformID)3:
                    CreateLibrary = Process.Start("gcc", "-shared " + Unit.Name + ".o " + Unit.LinkerArguments + " -o " + Unit.Name + ".dll -Wl,--export-all-symbols");
                    break;

                case PlatformID.Unix:
                    CreateLibrary = Process.Start("ld", "-shared " + Unit.Name + ".o " + Unit.LinkerArguments + " -o " + Unit.Name + ".so");
                    break;

                default:
                    throw new PlatformNotSupportedException("Unable to determine what the Operating System is");
                }
                CreateLibrary.WaitForExit();                 //? We might not need to wait here
                CreateLibrary.Dispose();
            }
        }