public async Task UserHasRoleOnPublication_TrueIfRoleExists() { var userPublicationRole = new UserPublicationRole { User = new User(), Publication = new Publication(), Role = Owner }; var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.UserPublicationRoles.AddAsync(userPublicationRole); await contentDbContext.SaveChangesAsync(); } await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { var service = SetupUserPublicationRoleRepository(contentDbContext); Assert.True(await service.UserHasRoleOnPublication( userPublicationRole.UserId, userPublicationRole.PublicationId, Owner)); } }
public async Task UserHasRoleOnPublication_FalseIfRoleDoesNotExist() { var publication = new Publication(); // Setup a role but for a different publication to make sure it has no influence var userPublicationRoleOtherPublication = new UserPublicationRole { User = new User(), Publication = new Publication(), Role = Owner }; var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.Publications.AddAsync(publication); await contentDbContext.UserPublicationRoles.AddAsync(userPublicationRoleOtherPublication); await contentDbContext.SaveChangesAsync(); } await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { var service = SetupUserPublicationRoleRepository(contentDbContext); Assert.False(await service.UserHasRoleOnPublication( userPublicationRoleOtherPublication.UserId, publication.Id, Owner)); } }
public async Task ListReleasesForUser_PublicationRole_Approved() { var userId = Guid.NewGuid(); var userPublicationRole1 = new UserPublicationRole() { UserId = userId, Publication = new Publication { Title = "Test publication 1", Slug = "test-publication-1", Contact = new Contact(), Releases = new List <Release> { new Release { ApprovalStatus = ReleaseApprovalStatus.Approved, TimePeriodCoverage = TimeIdentifier.AcademicYear, ReleaseName = "2001", }, } }, Role = PublicationRole.Owner, }; var otherPublication = new Publication { Title = "Test publication 2", Slug = "test-publication-2", Contact = new Contact(), Releases = new List <Release> { new Release { ApprovalStatus = ReleaseApprovalStatus.Approved, TimePeriodCoverage = TimeIdentifier.AcademicYear, ReleaseName = "2001", }, } }; var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.AddRangeAsync(userPublicationRole1, otherPublication); await contentDbContext.SaveChangesAsync(); } await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { var releaseRepository = BuildReleaseRepository(contentDbContext); var result = await releaseRepository.ListReleasesForUser(userId, ReleaseApprovalStatus.Approved); Assert.Single(result); Assert.Equal(userPublicationRole1.Publication.Releases[0].Id, result[0].Id); } }
public async Task <UserPublicationRole> Create(Guid userId, Guid publicationId, PublicationRole role, Guid createdById) { var userPublicationRole = new UserPublicationRole { UserId = userId, PublicationId = publicationId, Role = role, Created = DateTime.UtcNow, CreatedById = createdById }; var created = (await _contentDbContext.UserPublicationRoles.AddAsync(userPublicationRole)).Entity; await _contentDbContext.SaveChangesAsync(); return(created); }