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); }
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 ItReturnsTheCorrectCount() { const string title = "My Fantastic Library"; const string description = "A suitable description."; const int numOfLibraries = 12; // 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 created by that user var librariesRequest = new GetLibrariesCreatedByUserId(user.Id); var libraries = await _fixture.SendAsync(librariesRequest); // Check that it returns the correct number of libraries Assert.True(libraries.Count() == numOfLibraries); }
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); }
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 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); }
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); }