public static UserRoleInfo CreateRole(this IFixture fixture, StandardRoles role) { return(fixture.Build <UserRoleInfo>() .With(ur => ur.Role, fixture.Build <RoleInfo>() .With(r => r.Name, role.ToString()) .Create()) .Create()); }
public async Task <IList <UserProfile> > GetStrictInRoleUserProfilesAsync(StandardRoles role) { var query = GetUsersInRoleProfileQAsync(role.ToString()); if (role < StandardRoles.Admin) { query = FilterNotInRoleQAsync(query, StandardRoles.Admin.ToString()); } if (role < StandardRoles.Coach) { query = FilterNotInRoleQAsync(query, StandardRoles.Coach.ToString()); } return(await query.ToListAsync()); }
public async Task Index_ShouldReturn_CorrectUserRole(StandardRoles role) { var fixture = FixtureExtensions.CreateFixture(); AddCustomizations(fixture); // Arrange var userName = fixture.Create <string>(); var uInfo = fixture.CreateUser( fixture.CreateMany <StandardRoles>() .Where(r => r < role) .Distinct() .Concat(new[] { role }) .ToList() ); var uService = fixture.Freeze <Mock <IUserService> >(); uService.Setup(s => s.FindUserByNameAsync(It.IsAny <string>())) .Returns(Task.FromResult(uInfo)); var sut = fixture.CreateController <UserProfileController>(); // Act var view = await sut.Index(userName) as ViewResult; var model = view.Model as UserProfileVM; // Assert if (role == StandardRoles.Normal) { Assert.Equal("", model.Role); } else { Assert.Equal(role.ToString(), model.Role); } }
public bool IsInRole(StandardRoles role) => IsInRole(role.ToString());
public async Task <IList <UserProfile> > GetUsersInRoleProfileAsync(StandardRoles role) { return(await GetUsersInRoleProfileAsync(role.ToString())); }