コード例 #1
0
        public UserServiceTest()
        {
            AutomapperSingleton.Initialize();

            _config = new ConfigurationBuilder()
                      .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "baseUrl", "Value1" }
            })
                      .Build();
        }
コード例 #2
0
        public async Task UpdateAsync_NotAdminSetHigherRole_ExceptionAsync(Role currentUserRole)
        {
            await using var context = InMemoryDatabaseHelper.GetDbContext();
            var userRepo = new UserRepository(context);

            var user1 = await new ApplicationUserFactory(Role.Employee).BuildAsync(userRepo);
            var user2 = await new ApplicationUserFactory(Role.Employee).BuildAsync(userRepo);

            IAuthorizationManager authMock = new FakeAuth(currentUserRole);

            var service = Target(context, authMock);

            var data = new UserDto("John", "Test", "*****@*****.**");

            long userId = await service.InsertAsync(data);

            data      = AutomapperSingleton.Map <UserDto>(await service.GetByIdAsync(userId));
            data.Role = Role.SystemAdministrator;

            await Assert.ThrowsAsync <BadAssException>(() => service.UpdateAsync(data));
        }
コード例 #3
0
        public async Task UpdateAsync_NotAdminLowerRole_ExceptionAsync(Role currentUserRole)
        {
            await using var context = InMemoryDatabaseHelper.GetDbContext();
            var user1 = await new ApplicationUserFactory(Role.Employee).BuildAsync(context);
            var user2 = await new ApplicationUserFactory(Role.Employee).BuildAsync(context);

            var service = Target(context, FakeAuth.SysAdmin);

            var  createData = new UserDto("John", "Test", "*****@*****.**");
            long userId     = await service.InsertAsync(createData);

            var updateData = AutomapperSingleton.Map <UserDto>(await service.GetByIdAsync(userId));

            updateData.Role = Role.SystemAdministrator;

            await service.UpdateAsync(updateData);

            service = Target(context, new FakeAuth(currentUserRole));

            updateData      = AutomapperSingleton.Map <UserDto>(await service.GetByIdAsync(userId));
            updateData.Role = Role.Employee;

            await Assert.ThrowsAsync <NoPermissionsException>(() => service.UpdateAsync(updateData));
        }
コード例 #4
0
 public EmailServiceTest()
 {
     AutomapperSingleton.Initialize();
 }
コード例 #5
0
 public ApplicationUserProfileTest()
 {
     AutomapperSingleton.Initialize();
 }
コード例 #6
0
 public User Please()
 {
     AutomapperSingleton.Initialize();
     return(AutomapperSingleton.Map <User>(this));
 }
コード例 #7
0
 public UserServiceForIdentityServerTest()
 {
     AutomapperSingleton.Initialize();
 }
コード例 #8
0
 public ProfileTests()
 {
     AutomapperSingleton.Initialize();
 }
コード例 #9
0
 public AuthorizationTest()
 {
     AutomapperSingleton.Initialize();
 }