Exemple #1
0
        public async Task Delete_ForInvalidPermission_ShouldThrow()
        {
            int  invalidPermissionId = -1;
            long validUserId         = (await UserDAOTests.CreateRandomUser(DbConnection)).Id;

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await UserPermissionsDAO.Delete(DbConnection, validUserId, invalidPermissionId));
        }
Exemple #2
0
        public async Task GetByUserId_ForUserWithoutPermissions_ShouldSucceed()
        {
            var user = await UserDAOTests.CreateRandomUser(DbConnection);

            List <UserPermission> userPermsOriginal = await UserPermissionsDAO.GetByUserId(DbConnection, user.Id);

            Assert.Equal(userPermsOriginal.Count, 0);
        }
Exemple #3
0
        public async Task GetByUserId_ShouldSucceed()
        {
            var user = await UserDAOTests.CreateRandomUser(DbConnection);

            List <UserPermission> userPermsOriginal = await UserPermissionsDAO.GetByUserId(DbConnection, user.Id);

            Assert.Equal(userPermsOriginal.Count, 0);

            await UserPermissionsDAO.Create(DbConnection, user.Id, (int)(Permission.VerifyToken));

            var userPermsUpdated = await UserPermissionsDAO.GetByUserId(DbConnection, user.Id);

            Assert.Equal(userPermsUpdated.First().UserId, user.Id);
        }
Exemple #4
0
        public async Task GetUserEmailsWithPermission_ShouldSucceed()
        {
            Permission testPermission = Permission.ManageAnyUser;

            var userA = await UserDAOTests.CreateRandomUser(DbConnection);

            var userB = await UserDAOTests.CreateRandomUser(DbConnection);

            var userC = await UserDAOTests.CreateRandomUser(DbConnection);

            var userD = await UserDAOTests.CreateRandomUser(DbConnection);

            await UserPermissionsDAO.Create(DbConnection, userA.Id, (int)testPermission);

            await UserPermissionsDAO.Create(DbConnection, userB.Id, (int)testPermission);

            await UserPermissionsDAO.Create(DbConnection, userC.Id, (int)testPermission);

            await UserPermissionsDAO.Create(DbConnection, userD.Id, (int)Permission.ManageSelfUser);

            var firstPage = await UserPermissionsDAO.GetUserEmailsWithPermission(DbConnection, new List <Permission> {
                testPermission
            }, 0, 2);

            Assert.Equal(firstPage.Count, 2);
            Assert.Equal(firstPage[0].Item1, userA.Id);
            Assert.Equal(firstPage[0].Item2, userA.Email);
            Assert.Equal(firstPage[1].Item1, userB.Id);
            Assert.Equal(firstPage[1].Item2, userB.Email);

            var nextPage = await UserPermissionsDAO.GetUserEmailsWithPermission(
                DbConnection, new List <Permission> {
                testPermission
            }, firstPage[1].Item1, 2);

            Assert.Equal(nextPage.Count, 1);
            Assert.Equal(nextPage[0].Item1, userC.Id);
            Assert.Equal(nextPage[0].Item2, userC.Email);
        }