/// <summary> /// Delete specified user from database /// </summary> /// <param name="user">dot User data</param> public void DeleteUser(UserDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users); //Find user which has been deleted. User existingUser = (User)dbContext.Users.Single(u => u.Id == dto.UserId); //If required user doesn't exists, throw exception. if (existingUser == null) { throw new Exception("Users does not exist"); } //else perform deleting from database else { //Delete user. dbContext.DeleteObject(existingUser); //Saves chages. dbContext.SaveChanges(); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
public void UserDtoConstructorTest() { int userId = 0; // TODO: Initialize to an appropriate value string userName = string.Empty; // TODO: Initialize to an appropriate value string userPassword = string.Empty; // TODO: Initialize to an appropriate value UserDto target = new UserDto(userId, userName, userPassword); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void UserIdTest() { UserDto target = new UserDto(); // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; target.UserId = expected; actual = target.UserId; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// Returns list of all users from database. /// </summary> /// <returns>List list of UserDto's</returns> public List<UserDto> GetAllUsers() { //Instantiate list of dto users which has been returned. List<UserDto> listDto = new List<UserDto>(); try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users); //list of users List<User> list = dbContext.Users.OrderBy(u => u.Id).ToList(); //filling the list foreach (User u in list) { UserDto userDto = new UserDto(u.Id, u.UserName, u.UserPassword); listDto.Add(userDto); } } catch (Exception exception) { throw new Exception("UserDataMenager: " + exception.Message); } //returns list of all users as list of dtoes. return listDto; }
/// <summary> /// Update User data in database /// </summary> /// <param name="dto">dto user data</param> public void UpdateUser(UserDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users); //Find user which have to bee updated. User existingUser = dbContext.Users.Single(u => u.Id == dto.UserId); //If required user doesn't exists, throw exception. if (existingUser == null) { throw new Exception("User does not exist"); } //else prepare all data for storing to database. else { existingUser.UserName = dto.UserName; existingUser.UserPassword = dto.UserPassword; } //Save changes dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("UserDataMenagers: " + exception.Message); } }
/// <summary> /// Insert specified user in database /// </summary> /// <param name="dto">dto data for user</param> public void InsertUser(UserDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users); //New user - setting data User u = new User(); u.UserName = dto.UserName; u.UserPassword = dto.UserPassword; //Adds new user to context dbContext.Users.AddObject(u); //saves changes. dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("UserDataMenagers: " + exception.Message); } }
public void UserNameTest() { UserDto target = new UserDto(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; target.UserName = expected; actual = target.UserName; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void UserDtoConstructorTest1() { UserDto target = new UserDto(); Assert.Inconclusive("TODO: Implement code to verify target"); }