Beispiel #1
0
        public async Task ItCreatesRole()
        {
            const string title          = "Student";
            const string libTitle       = "My Fantastic Library";
            const string libDescription = "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, libTitle, libDescription);
            await _fixture.SendAsync(request);

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

            // Get libraryId of that library
            var libraryId = libraries1.Single().Id;

            //Create a role for that library
            var roleRequest = new CreateRole(title, libraryId);
            await _fixture.SendAsync(roleRequest);

            //Get roles for selected library
            var returnRoleRequest = new GetRolesForLibrary(libraryId);
            var result            = await _fixture.SendAsync(returnRoleRequest);

            //make sure role matches our role title
            Assert.Contains(title, result.Select(r => r.Title));
        }
        public async Task It_Updates_A_DisplayName()
        {
            const string title       = "My Fantastic Library";
            const string description = "A 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 library created by that user
            var librariesRequest = new GetLibrariesForUser(user.Id);
            var library          = (await _fixture.SendAsync(librariesRequest)).ToArray();
            var libraryId        = library.Single().Id;

            //Return that member
            var getMemberRequest = new GetMembersOfLibrary(libraryId);
            var member           = await _fixture.SendAsync(getMemberRequest);

            //Update name from Alice to Bob
            var updateDisplayNameRequest = new UpdateDisplayName(member.Single().Id, "Bob");
            await _fixture.SendAsync(updateDisplayNameRequest);

            //Return same member with changed display name
            var getMemberRequest1 = new GetMembersOfLibrary(member.Single().Id);
            var member1           = await _fixture.SendAsync(getMemberRequest1);

            //Bob should be new name
            Assert.Equal("Bob", member1.Single().DisplayName);
        }
        public async Task Should_ReturnOneMember_When_UserCreatesLibrary()
        {
            // 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 all libraries created by that user
            var librariesRequest = new GetLibrariesCreatedByUserId(user.Id);
            var libraries        = await _fixture.SendAsync(librariesRequest);

            // Check that only one library was returned
            Assert.Single(libraries);

            // Check that the created library only has one member, the creator
            var libraryId = libraries.ToList().ElementAt(0).Id;

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

            Assert.Single(members);

            //Check that member by id
            var memberUserId = members.ToList().ElementAt(0).UserId;

            Assert.Equal(user.Id, memberUserId);
        }
Beispiel #4
0
        public async Task Should_ReturnCorrectNumberOfLibraries_When_UserCreatesLibraries()
        {
            const string title          = "My Fantastic Library";
            const string description    = "A suitable description.";
            const int    numOfLibraries = 3;

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

            // Send the same request to create a library many times (synchronously)
            var request = new CreateLibrary(user.Id, title, description);

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

            // Get all libraries for that user
            var librariesRequest = new GetLibrariesForUser(user.Id);
            var libraries        = await _fixture.SendAsync(librariesRequest);

            // Check that it returns the correct number of libraries
            Assert.True(libraries.Count() == numOfLibraries);
        }
Beispiel #5
0
        public async Task Should_ReturnNone_When_LibraryHasNoVideos()
        {
            // 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;

            // 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.Empty(videoDtos);
        }
        public async Task Should_ReturnCorrectLibraryData_When_LibraryIsCreated()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

            // Create a library for user
            const string title                = "Library Title";
            const string description          = "Library description";
            var          createLibraryRequest = new CreateLibrary(user.Id, title, description);
            await _fixture.SendAsync(createLibraryRequest);

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

            // Make sure that only a single library was returned
            var libraryDtos = libraries.ToList();

            Assert.True(libraryDtos.Count() == 1);

            var library = libraryDtos.ElementAt(0);

            // Get library from database using id
            var getLibraryRequest     = new GetLibraryDtoById(library.Id);
            var libraryDtoFromRequest = await _fixture.SendAsync(getLibraryRequest);

            // Make sure that the retrieved library matches the one retrieved using GetLibrariesCreatedByUserId()
            Assert.Equal(library.Id, libraryDtoFromRequest.Id);
            Assert.Equal(library.Description, libraryDtoFromRequest.Description);
            Assert.Equal(library.CreatedAt, libraryDtoFromRequest.CreatedAt);
            Assert.Equal(library.CreatedBy, libraryDtoFromRequest.CreatedBy);
        }
        public async Task ItUpdatesRoleOfMember()
        {
            // 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 newDisplayName = "Some guy";
            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 memberUserId = members.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);

            // Make sure 1 role returned
            //var roleDtos = role.ToList();

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

            // Update that role
            var newRoleRequest = new UpdateRoleOfMember(memberUserId, roleId, newDisplayName);
            await _fixture.SendAsync(newRoleRequest);

            // Retrieve that member
            var getMemberRequest = new GetRoleForMember(memberUserId);
            var updatedRole      = await _fixture.SendAsync(getMemberRequest);

            // Make sure the role was updated
            Assert.Equal(roleId, updatedRole.Id);
        }
        public async Task Should_ReturnNone_When_AnnotationHasNoReplies()
        {
            // 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 annotation
            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 annotation
            var getAnnotationsRequest = new GetAnnotationsByVideoId(video.Id);
            var results = await _fixture.SendAsync(getAnnotationsRequest);

            var annotation = results.Single();

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

            var replies = repliesResults.ToList();

            // Check that nothing got returned, since no replies were created
            Assert.Empty(replies);
        }
Beispiel #9
0
        public async Task ItRunsAndEditsVideos()
        {
            //const int libraryId = 1;
            const string title       = "My Fantastic Library";
            const string description = "A 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();

            // Make sure there's only one library
            var libraryDtos = libraries1.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 newVidTitle       = "My Fantastic New Video Title";
            const string videoUrl          = "https://www.youtube.com/watch?v=-O5kNPlUV7w";
            const string vidDescription    = "Video description";
            const string newVidDescription = "A (new) suitable video description.";

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

            await _fixture.SendAsync(createVideosRequest1);

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

            // Edit video with that user
            var videoId            = video.Single().Id;
            var updateVideoRequest = new UpdateVideoInfo(videoId, newVidTitle, newVidDescription);
            await _fixture.SendAsync(updateVideoRequest);

            // Get video created by that user
            var getVideoRequest1 = new GetVideosOfLibrary(libraryId);
            var video1           = await _fixture.SendAsync(getVideoRequest1);

            // Check that our video is the only video returned
            Assert.Single(video1);

            // Check that the fields match the fields we set
            Assert.Equal(newVidTitle, video1.Single().Title);
            Assert.Equal(newVidDescription, video1.Single().Description);
        }
Beispiel #10
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);
        }
Beispiel #11
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));
        }
        public async Task ItRuns()
        {
            //Create test user named Alice
            var request = new CreateUserWithoutAuth("Alice");
            var result  = await _fixture.SendAsync(request);

            // Check that the fields match the fields we set
            Assert.NotNull(result);
            Assert.Equal("Alice", result.DisplayName);
            Assert.Null(result.GoogleClaimNameIdentifier);
        }
Beispiel #13
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);
        }
Beispiel #14
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);
            }
        }
Beispiel #15
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);
        }
        public async Task ItReturnsNone()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

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

            // Check that none were returned
            Assert.Empty(libraries);
        }
Beispiel #17
0
        public async Task Should_ReturnNone_When_UserBelongsToNoLibraries()
        {
            // Create a test user
            var userRequest = new CreateUserWithoutAuth("Alice");
            var user        = await _fixture.SendAsync(userRequest);

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

            // Check that none were returned
            Assert.Empty(libraries);
        }
Beispiel #18
0
        public async Task It_Gets_User_By_UserId()
        {
            //Create user named Alice
            var request = new CreateUserWithoutAuth("Alice");
            var result  = await _fixture.SendAsync(request);

            //Retrieve user by id, should be Alice
            var userId   = result.Id;
            var request1 = new GetUserByUserId(userId);
            var result1  = await _fixture.SendAsync(request1);

            Assert.Equal("Alice", result1.DisplayName);
        }
Beispiel #19
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);
        }
Beispiel #20
0
        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());
        }
        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);
        }
Beispiel #22
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);
        }
Beispiel #23
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);
        }
Beispiel #24
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));
        }
Beispiel #25
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);
        }
Beispiel #26
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);
        }
Beispiel #27
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);
        }
Beispiel #28
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);
        }
Beispiel #29
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);
        }
Beispiel #30
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);
        }