Esempio n. 1
0
        public void UserService_EditAsync_CreatesUserIfNotInDbWithPassword()
        {
            // Arrange
            var dbUser = new DBUser { Id = "dummyId", UserName = "******", Email = "Email2", LDAPAuthenticated_bl = false, Password = "******" };
            
            var dbUsers = new DBUser[] { dbUser };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser.Id)).Returns(Task.FromResult<DBUser>(null));
            mockAppUserManager.Setup(x => x.CreateAsync(dbUser, It.IsIn(new[] { dbUser.Password }))).Returns(Task.FromResult(IdentityResult.Success));
            mockAppUserManager.Setup(x => x.UpdateAsync(It.IsAny<DBUser>())).Verifiable();

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.EditAsync(dbUsers).Wait();

            //Assert
            mockAppUserManager.Verify(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>()), Times.Once);
            mockAppUserManager.Verify(x => x.UpdateAsync(It.IsAny<DBUser>()), Times.Never);
            Assert.IsTrue(dbUser.Password == "NewPassword");
            
        }
Esempio n. 2
0
        public void UserService_EditAsync_UpdateSingleUserwithGUID()
        {
            // Arrange
            var dbEntry = new DBUser { Id = "dummyId1", UserName = "******", Email = "Email", LDAPAuthenticated_bl = false };
            var dbUser = new DBUser { Id = "dummyId2", UserName = "******", Email = "Email2", LDAPAuthenticated_bl = true, 
                Password = "******", ModifiedProperties = new[] {"Password"} };
            
            var dbUsers = new DBUser[] { dbUser };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser.Id)).Returns(Task.FromResult(dbEntry));
            mockAppUserManager.Setup(x => x.UpdateAsync(dbEntry)).Returns(Task.FromResult(IdentityResult.Success));
            mockAppUserManager.Setup(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>())).Verifiable();
            mockAppUserManager.Setup(x => x.HashPassword(It.IsAny<string>())).Returns((string s) => s + "out");

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.EditAsync(dbUsers).Wait();

            //Assert
            Assert.IsTrue(dbEntry.Id != dbUser.Id);
            Assert.IsTrue(dbEntry.UserName != dbUser.UserName);
            Assert.IsTrue(dbEntry.Email != dbUser.Email);
            Assert.IsTrue(dbEntry.LDAPAuthenticated_bl != dbUser.LDAPAuthenticated_bl);
            var regex = new Regex(@"\w*-\w*-\w*-\w*-\w*out\b"); Assert.IsTrue(regex.IsMatch(dbEntry.PasswordHash));
            mockAppUserManager.Verify(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>()), Times.Never);
        }
Esempio n. 3
0
        //-----------------------------------------------------------------------------------------------------------------------

        // Create and Update records given in []
        public virtual async Task EditAsync(DBUser[] records)
        {
            if (records == null || records.Length == 0) { throw new ArgumentNullException("records"); }

            checkDbUserBeforeEditHelper(records);
            await editDbUserHelperAsync(records).ConfigureAwait(false);
        }
Esempio n. 4
0
        public void UserService_EditRolesAsync_ReturnErrorIfUserNotFound()
        {
            // Arrange
            var userIds = new string[] { "dummyUserId1", "dummyUserId2", "dummyUserId3" };
            var dbRoles = new string[] { "dummyRole1", "dummyRole2" };

            var dbEntry1 = new DBUser
            {
                Id = "dummyUserId1",
                UserName = "******",
                Email = "Email1",
                LDAPAuthenticated_bl = false
            };
            var dbEntry2 = new DBUser
            {
                Id = "dummyUserId2",
                UserName = "******",
                Email = "Email2",
                LDAPAuthenticated_bl = true
            };
            var dbEntries = (new List<DBUser> { dbEntry1, dbEntry2 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<DBUser>>();
            mockDbSet.As<IDbAsyncEnumerable<DBUser>>().Setup(m => m.GetAsyncEnumerator())
                .Returns(new MockDbAsyncEnumerator<DBUser>(dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.Provider)
                .Returns(new MockDbAsyncQueryProvider<PersonLogEntry>(dbEntries.Provider));
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator());
            mockDbSet.Setup(x => x.Include(It.IsAny<string>())).Returns(mockDbSet.Object);

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.Users).Returns(mockDbSet.Object);

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.AddRemoveRolesAsync(userIds, dbRoles, true).Wait();

            //Assert
        }
Esempio n. 5
0
        public void UserService_DeleteAsync_DeletesAndReturnsOK()
        {
            // Arrange
            var ids = new string[] { "dummyEntryId1" };

            var dbEntry = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "Email2", LDAPAuthenticated_bl = true,
                Password = "******" };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync("dummyEntryId1")).Returns(Task.FromResult<DBUser>(dbEntry));
            mockAppUserManager.Setup(x => x.DeleteAsync(dbEntry)).Returns(Task.FromResult(IdentityResult.Success));

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.DeleteAsync(ids).Wait();

            //Assert
            mockAppUserManager.Verify(m => m.DeleteAsync(It.IsIn(new DBUser[] { dbEntry })), Times.Once());
        }
Esempio n. 6
0
        public void UserService_DeleteAsync_ReturnsDeleteError()
        {
            // Arrange
            var ids = new string[] { "dummyEntryId1", "dummyEntryId11" };

            var dbEntry = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "Email2", LDAPAuthenticated_bl = true, Password = "******" };


            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync("dummyEntryId11")).Returns(Task.FromResult<DBUser>(null));
            mockAppUserManager.Setup(x => x.FindByIdAsync("dummyEntryId1")).Returns(Task.FromResult<DBUser>(dbEntry));
            mockAppUserManager.Setup(x => x.DeleteAsync(dbEntry)).Returns(Task.FromResult(IdentityResult.Failed(new[] { "Error deleting dbentry" })));

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.DeleteAsync(ids).Wait();

            //Assert
            
        }
Esempio n. 7
0
        public void UserService_GetAsync_ReturnsResultWithUsers()
        {
            // Arrange
            var dbEntry1 = new DBUser
            {
                Id = "dummyUserId1",
                UserName = "******",
                Email = "Email1",
                LDAPAuthenticated_bl = false
            };
            var dbEntry2 = new DBUser
            {
                Id = "dummyUserId2",
                UserName = "******",
                Email = "Email2",
                LDAPAuthenticated_bl = true
            };
            var dbEntries = (new List<DBUser> { dbEntry1, dbEntry2 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<DBUser>>();
            mockDbSet.As<IDbAsyncEnumerable<DBUser>>().Setup(m => m.GetAsyncEnumerator())
                .Returns(new MockDbAsyncEnumerator<DBUser>(dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.Provider)
                .Returns(new MockDbAsyncQueryProvider<PersonLogEntry>(dbEntries.Provider));
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator());
            mockDbSet.Setup(x => x.Include(It.IsAny<string>())).Returns(mockDbSet.Object);

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.Users).Returns(mockDbSet.Object);

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            var dbUserList = dbUserService.GetAsync().Result;

            //Assert
            Assert.IsTrue(dbUserList.Count() == dbEntries.Count());
            Assert.IsTrue(dbUserList[0].Email == (dbEntries.ToList())[0].Email);
            mockAppUserManager.Verify(x => x.Users, Times.Once);
        }
Esempio n. 8
0
        public void UserService_EditAsync_DoesNotUpdateUserifPasswordChangedAndNoPassword()
        {
            // Arrange
            var dbEntry = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "Email", LDAPAuthenticated_bl = true };
            var dbUser = new DBUser
            {
                Id = "dummyUserId1",
                UserName = "******",
                Email = "Email2",
                LDAPAuthenticated_bl = false,
                Password = "",
                ModifiedProperties = new[] { "Password" },
            };

            var dbUsers = new DBUser[] { dbUser };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser.Id)).Returns(Task.FromResult(dbEntry));
            mockAppUserManager.Setup(x => x.UpdateAsync(It.IsAny<DBUser>())).Verifiable();
            mockAppUserManager.Setup(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>())).Verifiable();

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.EditAsync(dbUsers).Wait();

            //Assert
            Assert.IsTrue(dbEntry.Id != dbUser.Id);
            Assert.IsTrue(dbEntry.UserName != dbUser.UserName);
            Assert.IsTrue(dbEntry.Email != dbUser.Email);
            Assert.IsTrue(dbEntry.LDAPAuthenticated_bl != dbUser.LDAPAuthenticated_bl);
            Assert.IsTrue(dbEntry.PasswordHash == null);
            mockAppUserManager.Verify(x => x.FindByIdAsync(It.IsAny<string>()), Times.Never());
            mockAppUserManager.Verify(x => x.UpdateAsync(It.IsAny<DBUser>()), Times.Never());
            mockAppUserManager.Verify(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>()), Times.Never);
        }
Esempio n. 9
0
 //checkDbUserBeforeEditHelperAsync - override for array of records
 private void checkDbUserBeforeEditHelper(DBUser[] records)
 {
     for (int i = 0; i < records.Length; i++)
     {
         checkDbUserBeforeEditHelper(records[i]);
     }
 }
Esempio n. 10
0
        public void UserService_EditAsync_UpdateManyUsersDoUpdateModified()
        {
            // Arrange
            var dbEntry1 = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "EntryEmail1", LDAPAuthenticated_bl = true };
            var dbEntry2 = new DBUser { Id = "dummyEntryId2", UserName = "******", Email = "EntryEmail2", LDAPAuthenticated_bl = false };
            var dbUser1 = new DBUser { Id = "dummyUserId1", UserName = "******", Email = "UserEmail1", LDAPAuthenticated_bl = false, Password = "******", 
                ModifiedProperties = new[] { "UserName", "Email", "LDAPAuthenticated_bl", } };
            var dbUser2 = new DBUser { Id = "dummyUserId2", UserName = "******", Email = "UserEmail2", LDAPAuthenticated_bl = true, Password = "******" };

            var dbUsers = new DBUser[] { dbUser1, dbUser2 };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser1.Id)).Returns(Task.FromResult(dbEntry1));
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser2.Id)).Returns(Task.FromResult(dbEntry2));
            mockAppUserManager.Setup(x => x.UpdateAsync(dbEntry1)).Returns(Task.FromResult(IdentityResult.Success));
            mockAppUserManager.Setup(x => x.UpdateAsync(dbEntry2)).Returns(Task.FromResult(IdentityResult.Success));
            mockAppUserManager.Setup(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>())).Verifiable();
            mockAppUserManager.Setup(x => x.HashPassword(It.IsAny<string>())).Returns((string s) => s + "out");

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);
            
            //Act   
            dbUserService.EditAsync(dbUsers).Wait();

            //Assert
            Assert.IsTrue(dbEntry1.Id != dbUser1.Id);
            Assert.IsTrue(dbEntry1.UserName == dbUser1.UserName);
            Assert.IsTrue(dbEntry1.Email == dbUser1.Email);
            Assert.IsTrue(dbEntry1.LDAPAuthenticated_bl == dbUser1.LDAPAuthenticated_bl);
            Assert.IsTrue(dbEntry1.PasswordHash == null);
            Assert.IsTrue(dbEntry2.Id != dbUser2.Id);
            Assert.IsTrue(dbEntry2.UserName != dbUser2.UserName);
            Assert.IsTrue(dbEntry2.Email != dbUser2.Email);
            Assert.IsTrue(dbEntry2.LDAPAuthenticated_bl != dbUser2.LDAPAuthenticated_bl);
            Assert.IsTrue(dbEntry2.PasswordHash == null);
            mockAppUserManager.Verify(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>()), Times.Never);
            mockAppUserManager.Verify(x => x.UpdateAsync(It.IsAny<DBUser>()), Times.Exactly(2));
        }
Esempio n. 11
0
 //helper - Add (or Remove  when set isAdd to false) role to dbUser 
 //taking taking single roleName and dbUser + userRoles and isAdd
 private async Task addRemoveRoleHelper(DBUser user, IList<string> userRoles, string roleName, bool isAdd)
 {
     if (isAdd && !userRoles.Contains(roleName))
     {
         var addResult = await appUserManager.AddToRoleAsync(user.Id, roleName).ConfigureAwait(false);
         if (!addResult.Succeeded)
         {
             throw new DbBadRequestException(string.Format("Error adding role {0} to user {1}: {2}",
                 roleName, user.UserName, getErrorsFromIdResult(addResult)));
         }
     }
     if (!isAdd && userRoles.Contains(roleName))
     {
         var removeResult = await appUserManager.RemoveFromRoleAsync(user.Id, roleName).ConfigureAwait(false);
         if (!removeResult.Succeeded)
         {
             throw new DbBadRequestException(string.Format("Error removing role {0} from user {1}: {2}",
                 roleName, user.UserName, getErrorsFromIdResult(removeResult)));
         }
     }
 }
Esempio n. 12
0
        //-----------------------------------------------------------------------------------------------------------------------

        //helper - Add (or Remove  when set isAdd to false) roles to dbUser 
        //taking taking single DBUser + rolenames and isAdd
        private async Task addRemoveRolesHelper(DBUser user, string[] roleNames, bool isAdd)
        {
            var userRoles = await appUserManager.GetRolesAsync(user.Id).ConfigureAwait(false);
            foreach (var dbRoleName in roleNames)
            {
                await addRemoveRoleHelper(user, userRoles, dbRoleName, isAdd).ConfigureAwait(false);
            }
        }
Esempio n. 13
0
 //editDbUserHelperAsync - override for array of records
 private async Task editDbUserHelperAsync(DBUser[] records)
 {
     for (int i = 0; i < records.Length; i++)
     {
         await editDbUserHelperAsync(records[i]).ConfigureAwait(false);
     }
 }
Esempio n. 14
0
        //editDbUserHelperAsync - single record
        private async Task editDbUserHelperAsync(DBUser record)
        {
            if (record.LDAPAuthenticated_bl)
            { record.Password = Guid.NewGuid().ToString(); record.PasswordConf = record.Password; }

            var dbEntry = await appUserManager.FindByIdAsync(record.Id).ConfigureAwait(false);
            if (dbEntry == null)
            {
                var createResult = await appUserManager.CreateAsync(record, record.Password).ConfigureAwait(false);
                if (!createResult.Succeeded)
                {
                    throw new DbBadRequestException(
                        String.Format("Error creating user {0}:{1}\n", record.UserName, getErrorsFromIdResult(createResult)));
                }
            }
            else
            {
                if (record.PropIsModified(x => x.UserName)) dbEntry.UserName = record.UserName;
                if (record.PropIsModified(x => x.Email)) dbEntry.Email = record.Email;
                if (record.PropIsModified(x => x.LDAPAuthenticated_bl)) dbEntry.LDAPAuthenticated_bl = record.LDAPAuthenticated_bl;
                if (record.PropIsModified(x => x.Password)) dbEntry.PasswordHash = appUserManager.HashPassword(record.Password);
                var updateResult = await appUserManager.UpdateAsync(dbEntry).ConfigureAwait(false);
                if (!updateResult.Succeeded)
                {
                    throw new DbBadRequestException(
                        String.Format("Error editing user {0}:{1}\n", record.UserName, getErrorsFromIdResult(updateResult)));
                }
            }
        }
Esempio n. 15
0
        public void UserService_EditAsync_UpdateSingleUserReportErrorsFromIdentityResult()
        {
            // Arrange
            var dbEntry1 = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "EntryEmail1", LDAPAuthenticated_bl = true };
            var dbUser1 = new DBUser
            {
                Id = "dummyUserId1",
                UserName = "******",
                Email = "UserEmail1",
                LDAPAuthenticated_bl = false,
                Password = "******",
                ModifiedProperties = new[] { "UserName", "Email", "LDAPAuthenticated_bl", "Password" }
            };

            var dbUsers = new DBUser[] { dbUser1 };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser1.Id)).Returns(Task.FromResult(dbEntry1));
            mockAppUserManager.Setup(x => x.UpdateAsync(dbEntry1)).Returns(Task.FromResult(IdentityResult.Failed(new[] { "Error1", "Error2" })));
            mockAppUserManager.Setup(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>())).Verifiable();
            mockAppUserManager.Setup(x => x.HashPassword(It.IsAny<string>())).Returns((string s) => s + "out");

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.EditAsync(dbUsers).Wait();

            //Assert
        }
Esempio n. 16
0
        public void UserService_EditRolesAsync_Remove_RemovesRoles()
        {
            // Arrange
            var userIds = new string[] { "dummyUserId1", "dummyUserId2" };
            var dbRoles = new string[] { "dummyRole1", "dummyRole2" };

            var dbEntry1 = new DBUser
            {
                Id = "dummyUserId1",
                UserName = "******",
                Email = "Email1",
                LDAPAuthenticated_bl = false
            };
            var dbEntry2 = new DBUser
            {
                Id = "dummyUserId2",
                UserName = "******",
                Email = "Email2",
                LDAPAuthenticated_bl = true
            };
            var dbEntries = (new List<DBUser> { dbEntry1, dbEntry2 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<DBUser>>();
            mockDbSet.As<IDbAsyncEnumerable<DBUser>>().Setup(m => m.GetAsyncEnumerator())
                .Returns(new MockDbAsyncEnumerator<DBUser>(dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.Provider)
                .Returns(new MockDbAsyncQueryProvider<PersonLogEntry>(dbEntries.Provider));
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<DBUser>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator());
            mockDbSet.Setup(x => x.Include(It.IsAny<string>())).Returns(mockDbSet.Object);

            var mockRolesList = new Mock<IList<string>>();
            mockRolesList.Setup(x => x.Contains(dbRoles[0])).Returns(true);
            mockRolesList.Setup(x => x.Contains(dbRoles[1])).Returns(true);
            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(Task.FromResult(new DBUser { }));
            mockAppUserManager.Setup(x => x.GetRolesAsync(It.IsAny<string>())).Returns(Task.FromResult(mockRolesList.Object));
            mockAppUserManager.Setup(x => x.AddToRoleAsync(It.IsAny<string>(), It.IsAny<string>())).Returns(Task.FromResult(IdentityResult.Success));
            mockAppUserManager.Setup(x => x.RemoveFromRoleAsync(It.IsAny<string>(), It.IsAny<string>())).Returns(Task.FromResult(IdentityResult.Success));
            mockAppUserManager.Setup(x => x.Users).Returns(mockDbSet.Object);
            
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.AddRemoveRolesAsync(userIds, dbRoles, false).Wait();

            //Assert
            mockAppUserManager.Verify(x => x.AddToRoleAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
            mockAppUserManager.Verify(x => x.RemoveFromRoleAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(4));
        }
Esempio n. 17
0
        public void UserService_EditAsync_ReturnsErrorifNewUserwithNoPasswordAndLDAPFalse()
        {
            // Arrange
            var dbUser1 = new DBUser
            {
                Id = "dummyUserId1",
                UserName = "******",
                Email = "UserEmail1",
                LDAPAuthenticated_bl = false,
                ModifiedProperties = new[] { "UserName", "Email", "LDAPAuthenticated_bl" }
            };

            var dbUsers = new DBUser[] { dbUser1 };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync(dbUser1.Id)).Returns(Task.FromResult((DBUser)null));
            mockAppUserManager.Setup(x => x.UpdateAsync(It.IsAny<DBUser>())).Verifiable();
            mockAppUserManager.Setup(x => x.CreateAsync(It.IsAny<DBUser>(), It.IsAny<string>()))
                .Returns(Task.FromResult(new IdentityResult("no password")));
            mockAppUserManager.Setup(x => x.HashPassword(It.IsAny<string>())).Returns((string s) => s + "out");

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.EditAsync(dbUsers).Wait();

            //Assert
            
        }
Esempio n. 18
0
 public async Task<ActionResult> Edit(DBUser[] records)
 {
     ViewBag.ServiceName = "DBUserService.EditAsync";
     await dbUserService.EditAsync(records).ConfigureAwait(false);
     return DbJson(new { Success = "True" });
 }
Esempio n. 19
0
        //Helpers--------------------------------------------------------------------------------------------------------------//
        #region Helpers

        //checkDbUserBeforeEditHelperAsync - single record
        private void checkDbUserBeforeEditHelper(DBUser record)
        {
            if (record.PropIsModified(x => x.LDAPAuthenticated_bl) && !record.LDAPAuthenticated_bl && String.IsNullOrEmpty(record.Password))
            {
                throw new DbBadRequestException(
                    String.Format("User {0}: Password is required if not LDAP authenticated\n", record.UserName));
            }
        }