示例#1
0
 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());
 }
示例#2
0
        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());
        }
示例#3
0
        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);
            }
        }
示例#4
0
 public bool IsInRole(StandardRoles role) => IsInRole(role.ToString());
示例#5
0
 public async Task <IList <UserProfile> > GetUsersInRoleProfileAsync(StandardRoles role)
 {
     return(await GetUsersInRoleProfileAsync(role.ToString()));
 }